Completed
Branch BUG/escape-localized-variables (801a84)
by
unknown
26:44 queued 18:27
created
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.82.rc.014');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.82.rc.014');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
admin/extend/registrations/Extend_Registrations_Admin_Page.core.php 2 patches
Indentation   +1210 added lines, -1210 removed lines patch added patch discarded remove patch
@@ -16,1267 +16,1267 @@
 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();
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 25
 
26 26
 
27
-    /**
28
-     * Extend_Registrations_Admin_Page constructor.
29
-     *
30
-     * @param bool $routing
31
-     */
32
-    public function __construct($routing = true)
33
-    {
34
-        parent::__construct($routing);
35
-        if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
39
-        }
40
-    }
27
+	/**
28
+	 * Extend_Registrations_Admin_Page constructor.
29
+	 *
30
+	 * @param bool $routing
31
+	 */
32
+	public function __construct($routing = true)
33
+	{
34
+		parent::__construct($routing);
35
+		if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
+			define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
+			define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
+			define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
39
+		}
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * Extending page configuration.
45
-     */
46
-    protected function _extend_page_config()
47
-    {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
-            ? $this->_req_data['_REG_ID']
51
-            : 0;
52
-        $new_page_routes = array(
53
-            'reports'                      => array(
54
-                'func'       => '_registration_reports',
55
-                'capability' => 'ee_read_registrations',
56
-            ),
57
-            'registration_checkins'        => array(
58
-                'func'       => '_registration_checkin_list_table',
59
-                'capability' => 'ee_read_checkins',
60
-            ),
61
-            'newsletter_selected_send'     => array(
62
-                'func'       => '_newsletter_selected_send',
63
-                'noheader'   => true,
64
-                'capability' => 'ee_send_message',
65
-            ),
66
-            'delete_checkin_rows'          => array(
67
-                'func'       => '_delete_checkin_rows',
68
-                'noheader'   => true,
69
-                'capability' => 'ee_delete_checkins',
70
-            ),
71
-            'delete_checkin_row'           => array(
72
-                'func'       => '_delete_checkin_row',
73
-                'noheader'   => true,
74
-                'capability' => 'ee_delete_checkin',
75
-                'obj_id'     => $reg_id,
76
-            ),
77
-            'toggle_checkin_status'        => array(
78
-                'func'       => '_toggle_checkin_status',
79
-                'noheader'   => true,
80
-                'capability' => 'ee_edit_checkin',
81
-                'obj_id'     => $reg_id,
82
-            ),
83
-            'toggle_checkin_status_bulk'   => array(
84
-                'func'       => '_toggle_checkin_status',
85
-                'noheader'   => true,
86
-                'capability' => 'ee_edit_checkins',
87
-            ),
88
-            'event_registrations'          => array(
89
-                'func'       => '_event_registrations_list_table',
90
-                'capability' => 'ee_read_checkins',
91
-            ),
92
-            'registrations_checkin_report' => array(
93
-                'func'       => '_registrations_checkin_report',
94
-                'noheader'   => true,
95
-                'capability' => 'ee_read_registrations',
96
-            ),
97
-        );
98
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
99
-        $new_page_config = array(
100
-            'reports'               => array(
101
-                'nav'           => array(
102
-                    'label' => esc_html__('Reports', 'event_espresso'),
103
-                    'order' => 30,
104
-                ),
105
-                'help_tabs'     => array(
106
-                    'registrations_reports_help_tab' => array(
107
-                        'title'    => esc_html__('Registration Reports', 'event_espresso'),
108
-                        'filename' => 'registrations_reports',
109
-                    ),
110
-                ),
111
-                /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
112
-                'require_nonce' => false,
113
-            ),
114
-            'event_registrations'   => array(
115
-                'nav'           => array(
116
-                    'label'      => esc_html__('Event Check-In', 'event_espresso'),
117
-                    'order'      => 10,
118
-                    'persistent' => true,
119
-                ),
120
-                'help_tabs'     => array(
121
-                    'registrations_event_checkin_help_tab'                       => array(
122
-                        'title'    => esc_html__('Registrations Event Check-In', 'event_espresso'),
123
-                        'filename' => 'registrations_event_checkin',
124
-                    ),
125
-                    'registrations_event_checkin_table_column_headings_help_tab' => array(
126
-                        'title'    => esc_html__('Event Check-In Table Column Headings', 'event_espresso'),
127
-                        'filename' => 'registrations_event_checkin_table_column_headings',
128
-                    ),
129
-                    'registrations_event_checkin_filters_help_tab'               => array(
130
-                        'title'    => esc_html__('Event Check-In Filters', 'event_espresso'),
131
-                        'filename' => 'registrations_event_checkin_filters',
132
-                    ),
133
-                    'registrations_event_checkin_views_help_tab'                 => array(
134
-                        'title'    => esc_html__('Event Check-In Views', 'event_espresso'),
135
-                        'filename' => 'registrations_event_checkin_views',
136
-                    ),
137
-                    'registrations_event_checkin_other_help_tab'                 => array(
138
-                        'title'    => esc_html__('Event Check-In Other', 'event_espresso'),
139
-                        'filename' => 'registrations_event_checkin_other',
140
-                    ),
141
-                ),
142
-                'help_tour'     => array('Event_Checkin_Help_Tour'),
143
-                'qtips'         => array('Registration_List_Table_Tips'),
144
-                'list_table'    => 'EE_Event_Registrations_List_Table',
145
-                'metaboxes'     => array(),
146
-                'require_nonce' => false,
147
-            ),
148
-            'registration_checkins' => array(
149
-                'nav'           => array(
150
-                    'label'      => esc_html__('Check-In Records', 'event_espresso'),
151
-                    'order'      => 15,
152
-                    'persistent' => false,
153
-                    'url'        => '',
154
-                ),
155
-                'list_table'    => 'EE_Registration_CheckIn_List_Table',
156
-                // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
157
-                'metaboxes'     => array(),
158
-                'require_nonce' => false,
159
-            ),
160
-        );
161
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
162
-        $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
163
-        $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
164
-    }
43
+	/**
44
+	 * Extending page configuration.
45
+	 */
46
+	protected function _extend_page_config()
47
+	{
48
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
+			? $this->_req_data['_REG_ID']
51
+			: 0;
52
+		$new_page_routes = array(
53
+			'reports'                      => array(
54
+				'func'       => '_registration_reports',
55
+				'capability' => 'ee_read_registrations',
56
+			),
57
+			'registration_checkins'        => array(
58
+				'func'       => '_registration_checkin_list_table',
59
+				'capability' => 'ee_read_checkins',
60
+			),
61
+			'newsletter_selected_send'     => array(
62
+				'func'       => '_newsletter_selected_send',
63
+				'noheader'   => true,
64
+				'capability' => 'ee_send_message',
65
+			),
66
+			'delete_checkin_rows'          => array(
67
+				'func'       => '_delete_checkin_rows',
68
+				'noheader'   => true,
69
+				'capability' => 'ee_delete_checkins',
70
+			),
71
+			'delete_checkin_row'           => array(
72
+				'func'       => '_delete_checkin_row',
73
+				'noheader'   => true,
74
+				'capability' => 'ee_delete_checkin',
75
+				'obj_id'     => $reg_id,
76
+			),
77
+			'toggle_checkin_status'        => array(
78
+				'func'       => '_toggle_checkin_status',
79
+				'noheader'   => true,
80
+				'capability' => 'ee_edit_checkin',
81
+				'obj_id'     => $reg_id,
82
+			),
83
+			'toggle_checkin_status_bulk'   => array(
84
+				'func'       => '_toggle_checkin_status',
85
+				'noheader'   => true,
86
+				'capability' => 'ee_edit_checkins',
87
+			),
88
+			'event_registrations'          => array(
89
+				'func'       => '_event_registrations_list_table',
90
+				'capability' => 'ee_read_checkins',
91
+			),
92
+			'registrations_checkin_report' => array(
93
+				'func'       => '_registrations_checkin_report',
94
+				'noheader'   => true,
95
+				'capability' => 'ee_read_registrations',
96
+			),
97
+		);
98
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
99
+		$new_page_config = array(
100
+			'reports'               => array(
101
+				'nav'           => array(
102
+					'label' => esc_html__('Reports', 'event_espresso'),
103
+					'order' => 30,
104
+				),
105
+				'help_tabs'     => array(
106
+					'registrations_reports_help_tab' => array(
107
+						'title'    => esc_html__('Registration Reports', 'event_espresso'),
108
+						'filename' => 'registrations_reports',
109
+					),
110
+				),
111
+				/*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
112
+				'require_nonce' => false,
113
+			),
114
+			'event_registrations'   => array(
115
+				'nav'           => array(
116
+					'label'      => esc_html__('Event Check-In', 'event_espresso'),
117
+					'order'      => 10,
118
+					'persistent' => true,
119
+				),
120
+				'help_tabs'     => array(
121
+					'registrations_event_checkin_help_tab'                       => array(
122
+						'title'    => esc_html__('Registrations Event Check-In', 'event_espresso'),
123
+						'filename' => 'registrations_event_checkin',
124
+					),
125
+					'registrations_event_checkin_table_column_headings_help_tab' => array(
126
+						'title'    => esc_html__('Event Check-In Table Column Headings', 'event_espresso'),
127
+						'filename' => 'registrations_event_checkin_table_column_headings',
128
+					),
129
+					'registrations_event_checkin_filters_help_tab'               => array(
130
+						'title'    => esc_html__('Event Check-In Filters', 'event_espresso'),
131
+						'filename' => 'registrations_event_checkin_filters',
132
+					),
133
+					'registrations_event_checkin_views_help_tab'                 => array(
134
+						'title'    => esc_html__('Event Check-In Views', 'event_espresso'),
135
+						'filename' => 'registrations_event_checkin_views',
136
+					),
137
+					'registrations_event_checkin_other_help_tab'                 => array(
138
+						'title'    => esc_html__('Event Check-In Other', 'event_espresso'),
139
+						'filename' => 'registrations_event_checkin_other',
140
+					),
141
+				),
142
+				'help_tour'     => array('Event_Checkin_Help_Tour'),
143
+				'qtips'         => array('Registration_List_Table_Tips'),
144
+				'list_table'    => 'EE_Event_Registrations_List_Table',
145
+				'metaboxes'     => array(),
146
+				'require_nonce' => false,
147
+			),
148
+			'registration_checkins' => array(
149
+				'nav'           => array(
150
+					'label'      => esc_html__('Check-In Records', 'event_espresso'),
151
+					'order'      => 15,
152
+					'persistent' => false,
153
+					'url'        => '',
154
+				),
155
+				'list_table'    => 'EE_Registration_CheckIn_List_Table',
156
+				// 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
157
+				'metaboxes'     => array(),
158
+				'require_nonce' => false,
159
+			),
160
+		);
161
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
162
+		$this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
163
+		$this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
164
+	}
165 165
 
166 166
 
167
-    /**
168
-     * Ajax hooks for all routes in this page.
169
-     */
170
-    protected function _ajax_hooks()
171
-    {
172
-        parent::_ajax_hooks();
173
-        add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
174
-    }
167
+	/**
168
+	 * Ajax hooks for all routes in this page.
169
+	 */
170
+	protected function _ajax_hooks()
171
+	{
172
+		parent::_ajax_hooks();
173
+		add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
174
+	}
175 175
 
176 176
 
177
-    /**
178
-     * Global scripts for all routes in this page.
179
-     */
180
-    public function load_scripts_styles()
181
-    {
182
-        parent::load_scripts_styles();
183
-        // if newsletter message type is active then let's add filter and load js for it.
184
-        if (EEH_MSG_Template::is_mt_active('newsletter')) {
185
-            // enqueue newsletter js
186
-            wp_enqueue_script(
187
-                'ee-newsletter-trigger',
188
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
189
-                array('ee-dialog'),
190
-                EVENT_ESPRESSO_VERSION,
191
-                true
192
-            );
193
-            wp_enqueue_style(
194
-                'ee-newsletter-trigger-css',
195
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
196
-                array(),
197
-                EVENT_ESPRESSO_VERSION
198
-            );
199
-            // hook in buttons for newsletter message type trigger.
200
-            add_action(
201
-                'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
202
-                array($this, 'add_newsletter_action_buttons'),
203
-                10
204
-            );
205
-        }
206
-    }
177
+	/**
178
+	 * Global scripts for all routes in this page.
179
+	 */
180
+	public function load_scripts_styles()
181
+	{
182
+		parent::load_scripts_styles();
183
+		// if newsletter message type is active then let's add filter and load js for it.
184
+		if (EEH_MSG_Template::is_mt_active('newsletter')) {
185
+			// enqueue newsletter js
186
+			wp_enqueue_script(
187
+				'ee-newsletter-trigger',
188
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
189
+				array('ee-dialog'),
190
+				EVENT_ESPRESSO_VERSION,
191
+				true
192
+			);
193
+			wp_enqueue_style(
194
+				'ee-newsletter-trigger-css',
195
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
196
+				array(),
197
+				EVENT_ESPRESSO_VERSION
198
+			);
199
+			// hook in buttons for newsletter message type trigger.
200
+			add_action(
201
+				'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
202
+				array($this, 'add_newsletter_action_buttons'),
203
+				10
204
+			);
205
+		}
206
+	}
207 207
 
208 208
 
209
-    /**
210
-     * Scripts and styles for just the reports route.
211
-     */
212
-    public function load_scripts_styles_reports()
213
-    {
214
-        wp_register_script(
215
-            'ee-reg-reports-js',
216
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
217
-            array('google-charts'),
218
-            EVENT_ESPRESSO_VERSION,
219
-            true
220
-        );
221
-        wp_enqueue_script('ee-reg-reports-js');
222
-        $this->_registration_reports_js_setup();
223
-    }
209
+	/**
210
+	 * Scripts and styles for just the reports route.
211
+	 */
212
+	public function load_scripts_styles_reports()
213
+	{
214
+		wp_register_script(
215
+			'ee-reg-reports-js',
216
+			REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
217
+			array('google-charts'),
218
+			EVENT_ESPRESSO_VERSION,
219
+			true
220
+		);
221
+		wp_enqueue_script('ee-reg-reports-js');
222
+		$this->_registration_reports_js_setup();
223
+	}
224 224
 
225 225
 
226
-    /**
227
-     * Register screen options for event_registrations route.
228
-     */
229
-    protected function _add_screen_options_event_registrations()
230
-    {
231
-        $this->_per_page_screen_option();
232
-    }
226
+	/**
227
+	 * Register screen options for event_registrations route.
228
+	 */
229
+	protected function _add_screen_options_event_registrations()
230
+	{
231
+		$this->_per_page_screen_option();
232
+	}
233 233
 
234 234
 
235
-    /**
236
-     * Register screen options for registration_checkins route
237
-     */
238
-    protected function _add_screen_options_registration_checkins()
239
-    {
240
-        $page_title = $this->_admin_page_title;
241
-        $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso');
242
-        $this->_per_page_screen_option();
243
-        $this->_admin_page_title = $page_title;
244
-    }
235
+	/**
236
+	 * Register screen options for registration_checkins route
237
+	 */
238
+	protected function _add_screen_options_registration_checkins()
239
+	{
240
+		$page_title = $this->_admin_page_title;
241
+		$this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso');
242
+		$this->_per_page_screen_option();
243
+		$this->_admin_page_title = $page_title;
244
+	}
245 245
 
246 246
 
247
-    /**
248
-     * Set views property for event_registrations route.
249
-     */
250
-    protected function _set_list_table_views_event_registrations()
251
-    {
252
-        $this->_views = array(
253
-            'all' => array(
254
-                'slug'        => 'all',
255
-                'label'       => esc_html__('All', 'event_espresso'),
256
-                'count'       => 0,
257
-                'bulk_action' => ! isset($this->_req_data['event_id'])
258
-                    ? array()
259
-                    : array(
260
-                        'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'),
261
-                    ),
262
-            ),
263
-        );
264
-    }
247
+	/**
248
+	 * Set views property for event_registrations route.
249
+	 */
250
+	protected function _set_list_table_views_event_registrations()
251
+	{
252
+		$this->_views = array(
253
+			'all' => array(
254
+				'slug'        => 'all',
255
+				'label'       => esc_html__('All', 'event_espresso'),
256
+				'count'       => 0,
257
+				'bulk_action' => ! isset($this->_req_data['event_id'])
258
+					? array()
259
+					: array(
260
+						'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'),
261
+					),
262
+			),
263
+		);
264
+	}
265 265
 
266 266
 
267
-    /**
268
-     * Set views property for registration_checkins route.
269
-     */
270
-    protected function _set_list_table_views_registration_checkins()
271
-    {
272
-        $this->_views = array(
273
-            'all' => array(
274
-                'slug'        => 'all',
275
-                'label'       => esc_html__('All', 'event_espresso'),
276
-                'count'       => 0,
277
-                'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')),
278
-            ),
279
-        );
280
-    }
267
+	/**
268
+	 * Set views property for registration_checkins route.
269
+	 */
270
+	protected function _set_list_table_views_registration_checkins()
271
+	{
272
+		$this->_views = array(
273
+			'all' => array(
274
+				'slug'        => 'all',
275
+				'label'       => esc_html__('All', 'event_espresso'),
276
+				'count'       => 0,
277
+				'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')),
278
+			),
279
+		);
280
+	}
281 281
 
282 282
 
283
-    /**
284
-     * callback for ajax action.
285
-     *
286
-     * @since 4.3.0
287
-     * @return void (JSON)
288
-     * @throws EE_Error
289
-     * @throws InvalidArgumentException
290
-     * @throws InvalidDataTypeException
291
-     * @throws InvalidInterfaceException
292
-     */
293
-    public function get_newsletter_form_content()
294
-    {
295
-        // do a nonce check cause we're not coming in from an normal route here.
296
-        $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
297
-            $this->_req_data['get_newsletter_form_content_nonce']
298
-        ) : '';
299
-        $nonce_ref = 'get_newsletter_form_content_nonce';
300
-        $this->_verify_nonce($nonce, $nonce_ref);
301
-        // let's get the mtp for the incoming MTP_ ID
302
-        if (! isset($this->_req_data['GRP_ID'])) {
303
-            EE_Error::add_error(
304
-                esc_html__(
305
-                    'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
306
-                    'event_espresso'
307
-                ),
308
-                __FILE__,
309
-                __FUNCTION__,
310
-                __LINE__
311
-            );
312
-            $this->_template_args['success'] = false;
313
-            $this->_template_args['error'] = true;
314
-            $this->_return_json();
315
-        }
316
-        $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
317
-        if (! $MTPG instanceof EE_Message_Template_Group) {
318
-            EE_Error::add_error(
319
-                sprintf(
320
-                    esc_html__(
321
-                        'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
322
-                        'event_espresso'
323
-                    ),
324
-                    $this->_req_data['GRP_ID']
325
-                ),
326
-                __FILE__,
327
-                __FUNCTION__,
328
-                __LINE__
329
-            );
330
-            $this->_template_args['success'] = false;
331
-            $this->_template_args['error'] = true;
332
-            $this->_return_json();
333
-        }
334
-        $MTPs = $MTPG->context_templates();
335
-        $MTPs = $MTPs['attendee'];
336
-        $template_fields = array();
337
-        /** @var EE_Message_Template $MTP */
338
-        foreach ($MTPs as $MTP) {
339
-            $field = $MTP->get('MTP_template_field');
340
-            if ($field === 'content') {
341
-                $content = $MTP->get('MTP_content');
342
-                if (! empty($content['newsletter_content'])) {
343
-                    $template_fields['newsletter_content'] = $content['newsletter_content'];
344
-                }
345
-                continue;
346
-            }
347
-            $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
348
-        }
349
-        $this->_template_args['success'] = true;
350
-        $this->_template_args['error'] = false;
351
-        $this->_template_args['data'] = array(
352
-            'batch_message_from'    => isset($template_fields['from'])
353
-                ? $template_fields['from']
354
-                : '',
355
-            'batch_message_subject' => isset($template_fields['subject'])
356
-                ? $template_fields['subject']
357
-                : '',
358
-            'batch_message_content' => isset($template_fields['newsletter_content'])
359
-                ? $template_fields['newsletter_content']
360
-                : '',
361
-        );
362
-        $this->_return_json();
363
-    }
283
+	/**
284
+	 * callback for ajax action.
285
+	 *
286
+	 * @since 4.3.0
287
+	 * @return void (JSON)
288
+	 * @throws EE_Error
289
+	 * @throws InvalidArgumentException
290
+	 * @throws InvalidDataTypeException
291
+	 * @throws InvalidInterfaceException
292
+	 */
293
+	public function get_newsletter_form_content()
294
+	{
295
+		// do a nonce check cause we're not coming in from an normal route here.
296
+		$nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
297
+			$this->_req_data['get_newsletter_form_content_nonce']
298
+		) : '';
299
+		$nonce_ref = 'get_newsletter_form_content_nonce';
300
+		$this->_verify_nonce($nonce, $nonce_ref);
301
+		// let's get the mtp for the incoming MTP_ ID
302
+		if (! isset($this->_req_data['GRP_ID'])) {
303
+			EE_Error::add_error(
304
+				esc_html__(
305
+					'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
306
+					'event_espresso'
307
+				),
308
+				__FILE__,
309
+				__FUNCTION__,
310
+				__LINE__
311
+			);
312
+			$this->_template_args['success'] = false;
313
+			$this->_template_args['error'] = true;
314
+			$this->_return_json();
315
+		}
316
+		$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
317
+		if (! $MTPG instanceof EE_Message_Template_Group) {
318
+			EE_Error::add_error(
319
+				sprintf(
320
+					esc_html__(
321
+						'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
322
+						'event_espresso'
323
+					),
324
+					$this->_req_data['GRP_ID']
325
+				),
326
+				__FILE__,
327
+				__FUNCTION__,
328
+				__LINE__
329
+			);
330
+			$this->_template_args['success'] = false;
331
+			$this->_template_args['error'] = true;
332
+			$this->_return_json();
333
+		}
334
+		$MTPs = $MTPG->context_templates();
335
+		$MTPs = $MTPs['attendee'];
336
+		$template_fields = array();
337
+		/** @var EE_Message_Template $MTP */
338
+		foreach ($MTPs as $MTP) {
339
+			$field = $MTP->get('MTP_template_field');
340
+			if ($field === 'content') {
341
+				$content = $MTP->get('MTP_content');
342
+				if (! empty($content['newsletter_content'])) {
343
+					$template_fields['newsletter_content'] = $content['newsletter_content'];
344
+				}
345
+				continue;
346
+			}
347
+			$template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
348
+		}
349
+		$this->_template_args['success'] = true;
350
+		$this->_template_args['error'] = false;
351
+		$this->_template_args['data'] = array(
352
+			'batch_message_from'    => isset($template_fields['from'])
353
+				? $template_fields['from']
354
+				: '',
355
+			'batch_message_subject' => isset($template_fields['subject'])
356
+				? $template_fields['subject']
357
+				: '',
358
+			'batch_message_content' => isset($template_fields['newsletter_content'])
359
+				? $template_fields['newsletter_content']
360
+				: '',
361
+		);
362
+		$this->_return_json();
363
+	}
364 364
 
365 365
 
366
-    /**
367
-     * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
368
-     *
369
-     * @since 4.3.0
370
-     * @param EE_Admin_List_Table $list_table
371
-     * @return void
372
-     * @throws InvalidArgumentException
373
-     * @throws InvalidDataTypeException
374
-     * @throws InvalidInterfaceException
375
-     */
376
-    public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
377
-    {
378
-        if (! EE_Registry::instance()->CAP->current_user_can(
379
-            'ee_send_message',
380
-            'espresso_registrations_newsletter_selected_send'
381
-        )
382
-        ) {
383
-            return;
384
-        }
385
-        $routes_to_add_to = array(
386
-            'contact_list',
387
-            'event_registrations',
388
-            'default',
389
-        );
390
-        if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
391
-            if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
392
-                || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
393
-            ) {
394
-                echo '';
395
-            } else {
396
-                $button_text = sprintf(
397
-                    esc_html__('Send Batch Message (%s selected)', 'event_espresso'),
398
-                    '<span class="send-selected-newsletter-count">0</span>'
399
-                );
400
-                echo '<button id="selected-batch-send-trigger" class="button secondary-button">'
401
-                     . '<span class="dashicons dashicons-email "></span>'
402
-                     . $button_text
403
-                     . '</button>';
404
-                add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
405
-            }
406
-        }
407
-    }
366
+	/**
367
+	 * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
368
+	 *
369
+	 * @since 4.3.0
370
+	 * @param EE_Admin_List_Table $list_table
371
+	 * @return void
372
+	 * @throws InvalidArgumentException
373
+	 * @throws InvalidDataTypeException
374
+	 * @throws InvalidInterfaceException
375
+	 */
376
+	public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
377
+	{
378
+		if (! EE_Registry::instance()->CAP->current_user_can(
379
+			'ee_send_message',
380
+			'espresso_registrations_newsletter_selected_send'
381
+		)
382
+		) {
383
+			return;
384
+		}
385
+		$routes_to_add_to = array(
386
+			'contact_list',
387
+			'event_registrations',
388
+			'default',
389
+		);
390
+		if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
391
+			if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
392
+				|| (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
393
+			) {
394
+				echo '';
395
+			} else {
396
+				$button_text = sprintf(
397
+					esc_html__('Send Batch Message (%s selected)', 'event_espresso'),
398
+					'<span class="send-selected-newsletter-count">0</span>'
399
+				);
400
+				echo '<button id="selected-batch-send-trigger" class="button secondary-button">'
401
+					 . '<span class="dashicons dashicons-email "></span>'
402
+					 . $button_text
403
+					 . '</button>';
404
+				add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
405
+			}
406
+		}
407
+	}
408 408
 
409 409
 
410
-    /**
411
-     * @throws DomainException
412
-     * @throws EE_Error
413
-     * @throws InvalidArgumentException
414
-     * @throws InvalidDataTypeException
415
-     * @throws InvalidInterfaceException
416
-     */
417
-    public function newsletter_send_form_skeleton()
418
-    {
419
-        $list_table = $this->_list_table_object;
420
-        $codes = array();
421
-        // need to templates for the newsletter message type for the template selector.
422
-        $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0);
423
-        $mtps = EEM_Message_Template_Group::instance()->get_all(
424
-            array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
425
-        );
426
-        foreach ($mtps as $mtp) {
427
-            $name = $mtp->name();
428
-            $values[] = array(
429
-                'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name,
430
-                'id'   => $mtp->ID(),
431
-            );
432
-        }
433
-        // need to get a list of shortcodes that are available for the newsletter message type.
434
-        $shortcodes = EEH_MSG_Template::get_shortcodes(
435
-            'newsletter',
436
-            'email',
437
-            array(),
438
-            'attendee',
439
-            false
440
-        );
441
-        foreach ($shortcodes as $field => $shortcode_array) {
442
-            $available_shortcodes = array();
443
-            foreach ($shortcode_array as $shortcode => $shortcode_details) {
444
-                $field_id = $field === '[NEWSLETTER_CONTENT]'
445
-                    ? 'content'
446
-                    : $field;
447
-                $field_id = 'batch-message-' . strtolower($field_id);
448
-                $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
449
-                                          . $shortcode
450
-                                          . '" data-linked-input-id="' . $field_id . '">'
451
-                                          . $shortcode
452
-                                          . '</span>';
453
-            }
454
-            $codes[ $field ] = implode(', ', $available_shortcodes);
455
-        }
456
-        $shortcodes = $codes;
457
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
458
-        $form_template_args = array(
459
-            'form_action'       => admin_url('admin.php?page=espresso_registrations'),
460
-            'form_route'        => 'newsletter_selected_send',
461
-            'form_nonce_name'   => 'newsletter_selected_send_nonce',
462
-            'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
463
-            'redirect_back_to'  => $this->_req_action,
464
-            'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
465
-            'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
466
-            'shortcodes'        => $shortcodes,
467
-            'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
468
-        );
469
-        EEH_Template::display_template($form_template, $form_template_args);
470
-    }
410
+	/**
411
+	 * @throws DomainException
412
+	 * @throws EE_Error
413
+	 * @throws InvalidArgumentException
414
+	 * @throws InvalidDataTypeException
415
+	 * @throws InvalidInterfaceException
416
+	 */
417
+	public function newsletter_send_form_skeleton()
418
+	{
419
+		$list_table = $this->_list_table_object;
420
+		$codes = array();
421
+		// need to templates for the newsletter message type for the template selector.
422
+		$values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0);
423
+		$mtps = EEM_Message_Template_Group::instance()->get_all(
424
+			array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
425
+		);
426
+		foreach ($mtps as $mtp) {
427
+			$name = $mtp->name();
428
+			$values[] = array(
429
+				'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name,
430
+				'id'   => $mtp->ID(),
431
+			);
432
+		}
433
+		// need to get a list of shortcodes that are available for the newsletter message type.
434
+		$shortcodes = EEH_MSG_Template::get_shortcodes(
435
+			'newsletter',
436
+			'email',
437
+			array(),
438
+			'attendee',
439
+			false
440
+		);
441
+		foreach ($shortcodes as $field => $shortcode_array) {
442
+			$available_shortcodes = array();
443
+			foreach ($shortcode_array as $shortcode => $shortcode_details) {
444
+				$field_id = $field === '[NEWSLETTER_CONTENT]'
445
+					? 'content'
446
+					: $field;
447
+				$field_id = 'batch-message-' . strtolower($field_id);
448
+				$available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
449
+										  . $shortcode
450
+										  . '" data-linked-input-id="' . $field_id . '">'
451
+										  . $shortcode
452
+										  . '</span>';
453
+			}
454
+			$codes[ $field ] = implode(', ', $available_shortcodes);
455
+		}
456
+		$shortcodes = $codes;
457
+		$form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
458
+		$form_template_args = array(
459
+			'form_action'       => admin_url('admin.php?page=espresso_registrations'),
460
+			'form_route'        => 'newsletter_selected_send',
461
+			'form_nonce_name'   => 'newsletter_selected_send_nonce',
462
+			'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
463
+			'redirect_back_to'  => $this->_req_action,
464
+			'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
465
+			'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
466
+			'shortcodes'        => $shortcodes,
467
+			'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
468
+		);
469
+		EEH_Template::display_template($form_template, $form_template_args);
470
+	}
471 471
 
472 472
 
473
-    /**
474
-     * Handles sending selected registrations/contacts a newsletter.
475
-     *
476
-     * @since  4.3.0
477
-     * @return void
478
-     * @throws EE_Error
479
-     * @throws InvalidArgumentException
480
-     * @throws InvalidDataTypeException
481
-     * @throws InvalidInterfaceException
482
-     */
483
-    protected function _newsletter_selected_send()
484
-    {
485
-        $success = true;
486
-        // first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
487
-        if (empty($this->_req_data['newsletter_mtp_selected'])) {
488
-            EE_Error::add_error(
489
-                esc_html__(
490
-                    'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
491
-                    'event_espresso'
492
-                ),
493
-                __FILE__,
494
-                __FUNCTION__,
495
-                __LINE__
496
-            );
497
-            $success = false;
498
-        }
499
-        if ($success) {
500
-            // update Message template in case there are any changes
501
-            $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
502
-                $this->_req_data['newsletter_mtp_selected']
503
-            );
504
-            $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
505
-                ? $Message_Template_Group->context_templates()
506
-                : array();
507
-            if (empty($Message_Templates)) {
508
-                EE_Error::add_error(
509
-                    esc_html__(
510
-                        'Unable to retrieve message template fields from the db. Messages not sent.',
511
-                        'event_espresso'
512
-                    ),
513
-                    __FILE__,
514
-                    __FUNCTION__,
515
-                    __LINE__
516
-                );
517
-            }
518
-            // let's just update the specific fields
519
-            foreach ($Message_Templates['attendee'] as $Message_Template) {
520
-                if ($Message_Template instanceof EE_Message_Template) {
521
-                    $field = $Message_Template->get('MTP_template_field');
522
-                    $content = $Message_Template->get('MTP_content');
523
-                    $new_content = $content;
524
-                    switch ($field) {
525
-                        case 'from':
526
-                            $new_content = ! empty($this->_req_data['batch_message']['from'])
527
-                                ? $this->_req_data['batch_message']['from']
528
-                                : $content;
529
-                            break;
530
-                        case 'subject':
531
-                            $new_content = ! empty($this->_req_data['batch_message']['subject'])
532
-                                ? $this->_req_data['batch_message']['subject']
533
-                                : $content;
534
-                            break;
535
-                        case 'content':
536
-                            $new_content = $content;
537
-                            $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
538
-                                ? $this->_req_data['batch_message']['content']
539
-                                : $content['newsletter_content'];
540
-                            break;
541
-                        default:
542
-                            // continue the foreach loop, we don't want to set $new_content nor save.
543
-                            continue 2;
544
-                    }
545
-                    $Message_Template->set('MTP_content', $new_content);
546
-                    $Message_Template->save();
547
-                }
548
-            }
549
-            // great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
550
-            $id_type = ! empty($this->_req_data['batch_message']['id_type'])
551
-                ? $this->_req_data['batch_message']['id_type']
552
-                : 'registration';
553
-            // id_type will affect how we assemble the ids.
554
-            $ids = ! empty($this->_req_data['batch_message']['ids'])
555
-                ? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
556
-                : array();
557
-            $registrations_used_for_contact_data = array();
558
-            // using switch because eventually we'll have other contexts that will be used for generating messages.
559
-            switch ($id_type) {
560
-                case 'registration':
561
-                    $registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
562
-                        array(
563
-                            array(
564
-                                'REG_ID' => array('IN', $ids),
565
-                            ),
566
-                        )
567
-                    );
568
-                    break;
569
-                case 'contact':
570
-                    $registrations_used_for_contact_data = EEM_Registration::instance()
571
-                                                                           ->get_latest_registration_for_each_of_given_contacts(
572
-                                                                               $ids
573
-                                                                           );
574
-                    break;
575
-            }
576
-            do_action_ref_array(
577
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
578
-                array(
579
-                    $registrations_used_for_contact_data,
580
-                    $Message_Template_Group->ID(),
581
-                )
582
-            );
583
-            // kept for backward compat, internally we no longer use this action.
584
-            // @deprecated 4.8.36.rc.002
585
-            $contacts = $id_type === 'registration'
586
-                ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
587
-                : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
588
-            do_action_ref_array(
589
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
590
-                array(
591
-                    $contacts,
592
-                    $Message_Template_Group->ID(),
593
-                )
594
-            );
595
-        }
596
-        $query_args = array(
597
-            'action' => ! empty($this->_req_data['redirect_back_to'])
598
-                ? $this->_req_data['redirect_back_to']
599
-                : 'default',
600
-        );
601
-        $this->_redirect_after_action(false, '', '', $query_args, true);
602
-    }
473
+	/**
474
+	 * Handles sending selected registrations/contacts a newsletter.
475
+	 *
476
+	 * @since  4.3.0
477
+	 * @return void
478
+	 * @throws EE_Error
479
+	 * @throws InvalidArgumentException
480
+	 * @throws InvalidDataTypeException
481
+	 * @throws InvalidInterfaceException
482
+	 */
483
+	protected function _newsletter_selected_send()
484
+	{
485
+		$success = true;
486
+		// first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
487
+		if (empty($this->_req_data['newsletter_mtp_selected'])) {
488
+			EE_Error::add_error(
489
+				esc_html__(
490
+					'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
491
+					'event_espresso'
492
+				),
493
+				__FILE__,
494
+				__FUNCTION__,
495
+				__LINE__
496
+			);
497
+			$success = false;
498
+		}
499
+		if ($success) {
500
+			// update Message template in case there are any changes
501
+			$Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
502
+				$this->_req_data['newsletter_mtp_selected']
503
+			);
504
+			$Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
505
+				? $Message_Template_Group->context_templates()
506
+				: array();
507
+			if (empty($Message_Templates)) {
508
+				EE_Error::add_error(
509
+					esc_html__(
510
+						'Unable to retrieve message template fields from the db. Messages not sent.',
511
+						'event_espresso'
512
+					),
513
+					__FILE__,
514
+					__FUNCTION__,
515
+					__LINE__
516
+				);
517
+			}
518
+			// let's just update the specific fields
519
+			foreach ($Message_Templates['attendee'] as $Message_Template) {
520
+				if ($Message_Template instanceof EE_Message_Template) {
521
+					$field = $Message_Template->get('MTP_template_field');
522
+					$content = $Message_Template->get('MTP_content');
523
+					$new_content = $content;
524
+					switch ($field) {
525
+						case 'from':
526
+							$new_content = ! empty($this->_req_data['batch_message']['from'])
527
+								? $this->_req_data['batch_message']['from']
528
+								: $content;
529
+							break;
530
+						case 'subject':
531
+							$new_content = ! empty($this->_req_data['batch_message']['subject'])
532
+								? $this->_req_data['batch_message']['subject']
533
+								: $content;
534
+							break;
535
+						case 'content':
536
+							$new_content = $content;
537
+							$new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
538
+								? $this->_req_data['batch_message']['content']
539
+								: $content['newsletter_content'];
540
+							break;
541
+						default:
542
+							// continue the foreach loop, we don't want to set $new_content nor save.
543
+							continue 2;
544
+					}
545
+					$Message_Template->set('MTP_content', $new_content);
546
+					$Message_Template->save();
547
+				}
548
+			}
549
+			// great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
550
+			$id_type = ! empty($this->_req_data['batch_message']['id_type'])
551
+				? $this->_req_data['batch_message']['id_type']
552
+				: 'registration';
553
+			// id_type will affect how we assemble the ids.
554
+			$ids = ! empty($this->_req_data['batch_message']['ids'])
555
+				? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
556
+				: array();
557
+			$registrations_used_for_contact_data = array();
558
+			// using switch because eventually we'll have other contexts that will be used for generating messages.
559
+			switch ($id_type) {
560
+				case 'registration':
561
+					$registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
562
+						array(
563
+							array(
564
+								'REG_ID' => array('IN', $ids),
565
+							),
566
+						)
567
+					);
568
+					break;
569
+				case 'contact':
570
+					$registrations_used_for_contact_data = EEM_Registration::instance()
571
+																		   ->get_latest_registration_for_each_of_given_contacts(
572
+																			   $ids
573
+																		   );
574
+					break;
575
+			}
576
+			do_action_ref_array(
577
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
578
+				array(
579
+					$registrations_used_for_contact_data,
580
+					$Message_Template_Group->ID(),
581
+				)
582
+			);
583
+			// kept for backward compat, internally we no longer use this action.
584
+			// @deprecated 4.8.36.rc.002
585
+			$contacts = $id_type === 'registration'
586
+				? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
587
+				: EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
588
+			do_action_ref_array(
589
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
590
+				array(
591
+					$contacts,
592
+					$Message_Template_Group->ID(),
593
+				)
594
+			);
595
+		}
596
+		$query_args = array(
597
+			'action' => ! empty($this->_req_data['redirect_back_to'])
598
+				? $this->_req_data['redirect_back_to']
599
+				: 'default',
600
+		);
601
+		$this->_redirect_after_action(false, '', '', $query_args, true);
602
+	}
603 603
 
604 604
 
605
-    /**
606
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
607
-     * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
608
-     */
609
-    protected function _registration_reports_js_setup()
610
-    {
611
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
612
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
613
-    }
605
+	/**
606
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
607
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
608
+	 */
609
+	protected function _registration_reports_js_setup()
610
+	{
611
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
612
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
613
+	}
614 614
 
615 615
 
616
-    /**
617
-     *        generates Business Reports regarding Registrations
618
-     *
619
-     * @access protected
620
-     * @return void
621
-     * @throws DomainException
622
-     */
623
-    protected function _registration_reports()
624
-    {
625
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
626
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
627
-            $template_path,
628
-            $this->_reports_template_data,
629
-            true
630
-        );
631
-        // the final template wrapper
632
-        $this->display_admin_page_with_no_sidebar();
633
-    }
616
+	/**
617
+	 *        generates Business Reports regarding Registrations
618
+	 *
619
+	 * @access protected
620
+	 * @return void
621
+	 * @throws DomainException
622
+	 */
623
+	protected function _registration_reports()
624
+	{
625
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
626
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
627
+			$template_path,
628
+			$this->_reports_template_data,
629
+			true
630
+		);
631
+		// the final template wrapper
632
+		$this->display_admin_page_with_no_sidebar();
633
+	}
634 634
 
635 635
 
636
-    /**
637
-     * Generates Business Report showing total registrations per day.
638
-     *
639
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
640
-     * @return string
641
-     * @throws EE_Error
642
-     * @throws InvalidArgumentException
643
-     * @throws InvalidDataTypeException
644
-     * @throws InvalidInterfaceException
645
-     */
646
-    private function _registrations_per_day_report($period = '-1 month')
647
-    {
648
-        $report_ID = 'reg-admin-registrations-per-day-report-dv';
649
-        $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
650
-        $results = (array) $results;
651
-        $regs = array();
652
-        $subtitle = '';
653
-        if ($results) {
654
-            $column_titles = array();
655
-            $tracker = 0;
656
-            foreach ($results as $result) {
657
-                $report_column_values = array();
658
-                foreach ($result as $property_name => $property_value) {
659
-                    $property_value = $property_name === 'Registration_REG_date' ? $property_value
660
-                        : (int) $property_value;
661
-                    $report_column_values[] = $property_value;
662
-                    if ($tracker === 0) {
663
-                        if ($property_name === 'Registration_REG_date') {
664
-                            $column_titles[] = esc_html__(
665
-                                'Date (only days with registrations are shown)',
666
-                                'event_espresso'
667
-                            );
668
-                        } else {
669
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
670
-                        }
671
-                    }
672
-                }
673
-                $tracker++;
674
-                $regs[] = $report_column_values;
675
-            }
676
-            // make sure the column_titles is pushed to the beginning of the array
677
-            array_unshift($regs, $column_titles);
678
-            // setup the date range.
679
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
680
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
681
-            $ending_date = new DateTime("now", $DateTimeZone);
682
-            $subtitle = sprintf(
683
-                wp_strip_all_tags(
684
-                    _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso')
685
-                ),
686
-                $beginning_date->format('Y-m-d'),
687
-                $ending_date->format('Y-m-d')
688
-            );
689
-        }
690
-        $report_title = wp_strip_all_tags(__('Total Registrations per Day', 'event_espresso'));
691
-        $report_params = array(
692
-            'title'     => $report_title,
693
-            'subtitle'  => $subtitle,
694
-            'id'        => $report_ID,
695
-            'regs'      => $regs,
696
-            'noResults' => empty($regs),
697
-            'noRegsMsg' => sprintf(
698
-                wp_strip_all_tags(
699
-                    __(
700
-                        '%sThere are currently no registration records in the last month for this report.%s',
701
-                        'event_espresso'
702
-                    )
703
-                ),
704
-                '<h2>' . $report_title . '</h2><p>',
705
-                '</p>'
706
-            ),
707
-        );
708
-        wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
709
-        return $report_ID;
710
-    }
636
+	/**
637
+	 * Generates Business Report showing total registrations per day.
638
+	 *
639
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
640
+	 * @return string
641
+	 * @throws EE_Error
642
+	 * @throws InvalidArgumentException
643
+	 * @throws InvalidDataTypeException
644
+	 * @throws InvalidInterfaceException
645
+	 */
646
+	private function _registrations_per_day_report($period = '-1 month')
647
+	{
648
+		$report_ID = 'reg-admin-registrations-per-day-report-dv';
649
+		$results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
650
+		$results = (array) $results;
651
+		$regs = array();
652
+		$subtitle = '';
653
+		if ($results) {
654
+			$column_titles = array();
655
+			$tracker = 0;
656
+			foreach ($results as $result) {
657
+				$report_column_values = array();
658
+				foreach ($result as $property_name => $property_value) {
659
+					$property_value = $property_name === 'Registration_REG_date' ? $property_value
660
+						: (int) $property_value;
661
+					$report_column_values[] = $property_value;
662
+					if ($tracker === 0) {
663
+						if ($property_name === 'Registration_REG_date') {
664
+							$column_titles[] = esc_html__(
665
+								'Date (only days with registrations are shown)',
666
+								'event_espresso'
667
+							);
668
+						} else {
669
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
670
+						}
671
+					}
672
+				}
673
+				$tracker++;
674
+				$regs[] = $report_column_values;
675
+			}
676
+			// make sure the column_titles is pushed to the beginning of the array
677
+			array_unshift($regs, $column_titles);
678
+			// setup the date range.
679
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
680
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
681
+			$ending_date = new DateTime("now", $DateTimeZone);
682
+			$subtitle = sprintf(
683
+				wp_strip_all_tags(
684
+					_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso')
685
+				),
686
+				$beginning_date->format('Y-m-d'),
687
+				$ending_date->format('Y-m-d')
688
+			);
689
+		}
690
+		$report_title = wp_strip_all_tags(__('Total Registrations per Day', 'event_espresso'));
691
+		$report_params = array(
692
+			'title'     => $report_title,
693
+			'subtitle'  => $subtitle,
694
+			'id'        => $report_ID,
695
+			'regs'      => $regs,
696
+			'noResults' => empty($regs),
697
+			'noRegsMsg' => sprintf(
698
+				wp_strip_all_tags(
699
+					__(
700
+						'%sThere are currently no registration records in the last month for this report.%s',
701
+						'event_espresso'
702
+					)
703
+				),
704
+				'<h2>' . $report_title . '</h2><p>',
705
+				'</p>'
706
+			),
707
+		);
708
+		wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
709
+		return $report_ID;
710
+	}
711 711
 
712 712
 
713
-    /**
714
-     * Generates Business Report showing total registrations per event.
715
-     *
716
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
717
-     * @return string
718
-     * @throws EE_Error
719
-     * @throws InvalidArgumentException
720
-     * @throws InvalidDataTypeException
721
-     * @throws InvalidInterfaceException
722
-     */
723
-    private function _registrations_per_event_report($period = '-1 month')
724
-    {
725
-        $report_ID = 'reg-admin-registrations-per-event-report-dv';
726
-        $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
727
-        $results = (array) $results;
728
-        $regs = array();
729
-        $subtitle = '';
730
-        if ($results) {
731
-            $column_titles = array();
732
-            $tracker = 0;
733
-            foreach ($results as $result) {
734
-                $report_column_values = array();
735
-                foreach ($result as $property_name => $property_value) {
736
-                    $property_value = $property_name === 'Registration_Event' ? wp_trim_words(
737
-                        $property_value,
738
-                        4,
739
-                        '...'
740
-                    ) : (int) $property_value;
741
-                    $report_column_values[] = $property_value;
742
-                    if ($tracker === 0) {
743
-                        if ($property_name === 'Registration_Event') {
744
-                            $column_titles[] = esc_html__('Event', 'event_espresso');
745
-                        } else {
746
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
747
-                        }
748
-                    }
749
-                }
750
-                $tracker++;
751
-                $regs[] = $report_column_values;
752
-            }
753
-            // make sure the column_titles is pushed to the beginning of the array
754
-            array_unshift($regs, $column_titles);
755
-            // setup the date range.
756
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
757
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
758
-            $ending_date = new DateTime("now", $DateTimeZone);
759
-            $subtitle = sprintf(
760
-                wp_strip_all_tags(
761
-                    _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso')
762
-                ),
763
-                $beginning_date->format('Y-m-d'),
764
-                $ending_date->format('Y-m-d')
765
-            );
766
-        }
767
-        $report_title = wp_strip_all_tags(__('Total Registrations per Event', 'event_espresso'));
768
-        $report_params = array(
769
-            'title'     => $report_title,
770
-            'subtitle'  => $subtitle,
771
-            'id'        => $report_ID,
772
-            'regs'      => $regs,
773
-            'noResults' => empty($regs),
774
-            'noRegsMsg' => sprintf(
775
-                wp_strip_all_tags(
776
-                    __(
777
-                        '%sThere are currently no registration records in the last month for this report.%s',
778
-                        'event_espresso'
779
-                    )
780
-                ),
781
-                '<h2>' . $report_title . '</h2><p>',
782
-                '</p>'
783
-            ),
784
-        );
785
-        wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
786
-        return $report_ID;
787
-    }
713
+	/**
714
+	 * Generates Business Report showing total registrations per event.
715
+	 *
716
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
717
+	 * @return string
718
+	 * @throws EE_Error
719
+	 * @throws InvalidArgumentException
720
+	 * @throws InvalidDataTypeException
721
+	 * @throws InvalidInterfaceException
722
+	 */
723
+	private function _registrations_per_event_report($period = '-1 month')
724
+	{
725
+		$report_ID = 'reg-admin-registrations-per-event-report-dv';
726
+		$results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
727
+		$results = (array) $results;
728
+		$regs = array();
729
+		$subtitle = '';
730
+		if ($results) {
731
+			$column_titles = array();
732
+			$tracker = 0;
733
+			foreach ($results as $result) {
734
+				$report_column_values = array();
735
+				foreach ($result as $property_name => $property_value) {
736
+					$property_value = $property_name === 'Registration_Event' ? wp_trim_words(
737
+						$property_value,
738
+						4,
739
+						'...'
740
+					) : (int) $property_value;
741
+					$report_column_values[] = $property_value;
742
+					if ($tracker === 0) {
743
+						if ($property_name === 'Registration_Event') {
744
+							$column_titles[] = esc_html__('Event', 'event_espresso');
745
+						} else {
746
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
747
+						}
748
+					}
749
+				}
750
+				$tracker++;
751
+				$regs[] = $report_column_values;
752
+			}
753
+			// make sure the column_titles is pushed to the beginning of the array
754
+			array_unshift($regs, $column_titles);
755
+			// setup the date range.
756
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
757
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
758
+			$ending_date = new DateTime("now", $DateTimeZone);
759
+			$subtitle = sprintf(
760
+				wp_strip_all_tags(
761
+					_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso')
762
+				),
763
+				$beginning_date->format('Y-m-d'),
764
+				$ending_date->format('Y-m-d')
765
+			);
766
+		}
767
+		$report_title = wp_strip_all_tags(__('Total Registrations per Event', 'event_espresso'));
768
+		$report_params = array(
769
+			'title'     => $report_title,
770
+			'subtitle'  => $subtitle,
771
+			'id'        => $report_ID,
772
+			'regs'      => $regs,
773
+			'noResults' => empty($regs),
774
+			'noRegsMsg' => sprintf(
775
+				wp_strip_all_tags(
776
+					__(
777
+						'%sThere are currently no registration records in the last month for this report.%s',
778
+						'event_espresso'
779
+					)
780
+				),
781
+				'<h2>' . $report_title . '</h2><p>',
782
+				'</p>'
783
+			),
784
+		);
785
+		wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
786
+		return $report_ID;
787
+	}
788 788
 
789 789
 
790
-    /**
791
-     * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
792
-     *
793
-     * @access protected
794
-     * @return void
795
-     * @throws EE_Error
796
-     * @throws InvalidArgumentException
797
-     * @throws InvalidDataTypeException
798
-     * @throws InvalidInterfaceException
799
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
800
-     */
801
-    protected function _registration_checkin_list_table()
802
-    {
803
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
804
-        $reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null;
805
-        /** @var EE_Registration $registration */
806
-        $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
807
-        $attendee = $registration->attendee();
808
-        $this->_admin_page_title .= $this->get_action_link_or_button(
809
-            'new_registration',
810
-            'add-registrant',
811
-            array('event_id' => $registration->event_ID()),
812
-            'add-new-h2'
813
-        );
814
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
815
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
816
-        $legend_items = array(
817
-            'checkin'  => array(
818
-                'class' => $checked_in->cssClasses(),
819
-                'desc'  => $checked_in->legendLabel(),
820
-            ),
821
-            'checkout' => array(
822
-                'class' => $checked_out->cssClasses(),
823
-                'desc'  => $checked_out->legendLabel(),
824
-            ),
825
-        );
826
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
827
-        $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
828
-        /** @var EE_Datetime $datetime */
829
-        $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
830
-        $datetime_label = '';
831
-        if ($datetime instanceof EE_Datetime) {
832
-            $datetime_label = $datetime->get_dtt_display_name(true);
833
-            $datetime_label .= ! empty($datetime_label)
834
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
835
-                : $datetime->get_dtt_display_name();
836
-        }
837
-        $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
838
-            ? EE_Admin_Page::add_query_args_and_nonce(
839
-                array(
840
-                    'action'   => 'event_registrations',
841
-                    'event_id' => $registration->event_ID(),
842
-                    'DTT_ID'   => $dtt_id,
843
-                ),
844
-                $this->_admin_base_url
845
-            )
846
-            : '';
847
-        $datetime_link = ! empty($datetime_link)
848
-            ? '<a href="' . $datetime_link . '">'
849
-              . '<span id="checkin-dtt">'
850
-              . $datetime_label
851
-              . '</span></a>'
852
-            : $datetime_label;
853
-        $attendee_name = $attendee instanceof EE_Attendee
854
-            ? $attendee->full_name()
855
-            : '';
856
-        $attendee_link = $attendee instanceof EE_Attendee
857
-            ? $attendee->get_admin_details_link()
858
-            : '';
859
-        $attendee_link = ! empty($attendee_link)
860
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
861
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
862
-              . '<span id="checkin-attendee-name">'
863
-              . $attendee_name
864
-              . '</span></a>'
865
-            : '';
866
-        $event_link = $registration->event() instanceof EE_Event
867
-            ? $registration->event()->get_admin_details_link()
868
-            : '';
869
-        $event_link = ! empty($event_link)
870
-            ? '<a href="' . $event_link . '"'
871
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
872
-              . '<span id="checkin-event-name">'
873
-              . $registration->event_name()
874
-              . '</span>'
875
-              . '</a>'
876
-            : '';
877
-        $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
878
-            ? '<h2>' . sprintf(
879
-                esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
880
-                $attendee_link,
881
-                $datetime_link,
882
-                $event_link
883
-            ) . '</h2>'
884
-            : '';
885
-        $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
886
-            ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
887
-        $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
888
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
889
-        $this->display_admin_list_table_page_with_no_sidebar();
890
-    }
790
+	/**
791
+	 * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
792
+	 *
793
+	 * @access protected
794
+	 * @return void
795
+	 * @throws EE_Error
796
+	 * @throws InvalidArgumentException
797
+	 * @throws InvalidDataTypeException
798
+	 * @throws InvalidInterfaceException
799
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
800
+	 */
801
+	protected function _registration_checkin_list_table()
802
+	{
803
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
804
+		$reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null;
805
+		/** @var EE_Registration $registration */
806
+		$registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
807
+		$attendee = $registration->attendee();
808
+		$this->_admin_page_title .= $this->get_action_link_or_button(
809
+			'new_registration',
810
+			'add-registrant',
811
+			array('event_id' => $registration->event_ID()),
812
+			'add-new-h2'
813
+		);
814
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
815
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
816
+		$legend_items = array(
817
+			'checkin'  => array(
818
+				'class' => $checked_in->cssClasses(),
819
+				'desc'  => $checked_in->legendLabel(),
820
+			),
821
+			'checkout' => array(
822
+				'class' => $checked_out->cssClasses(),
823
+				'desc'  => $checked_out->legendLabel(),
824
+			),
825
+		);
826
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
827
+		$dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
828
+		/** @var EE_Datetime $datetime */
829
+		$datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
830
+		$datetime_label = '';
831
+		if ($datetime instanceof EE_Datetime) {
832
+			$datetime_label = $datetime->get_dtt_display_name(true);
833
+			$datetime_label .= ! empty($datetime_label)
834
+				? ' (' . $datetime->get_dtt_display_name() . ')'
835
+				: $datetime->get_dtt_display_name();
836
+		}
837
+		$datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
838
+			? EE_Admin_Page::add_query_args_and_nonce(
839
+				array(
840
+					'action'   => 'event_registrations',
841
+					'event_id' => $registration->event_ID(),
842
+					'DTT_ID'   => $dtt_id,
843
+				),
844
+				$this->_admin_base_url
845
+			)
846
+			: '';
847
+		$datetime_link = ! empty($datetime_link)
848
+			? '<a href="' . $datetime_link . '">'
849
+			  . '<span id="checkin-dtt">'
850
+			  . $datetime_label
851
+			  . '</span></a>'
852
+			: $datetime_label;
853
+		$attendee_name = $attendee instanceof EE_Attendee
854
+			? $attendee->full_name()
855
+			: '';
856
+		$attendee_link = $attendee instanceof EE_Attendee
857
+			? $attendee->get_admin_details_link()
858
+			: '';
859
+		$attendee_link = ! empty($attendee_link)
860
+			? '<a href="' . $attendee->get_admin_details_link() . '"'
861
+			  . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
862
+			  . '<span id="checkin-attendee-name">'
863
+			  . $attendee_name
864
+			  . '</span></a>'
865
+			: '';
866
+		$event_link = $registration->event() instanceof EE_Event
867
+			? $registration->event()->get_admin_details_link()
868
+			: '';
869
+		$event_link = ! empty($event_link)
870
+			? '<a href="' . $event_link . '"'
871
+			  . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
872
+			  . '<span id="checkin-event-name">'
873
+			  . $registration->event_name()
874
+			  . '</span>'
875
+			  . '</a>'
876
+			: '';
877
+		$this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
878
+			? '<h2>' . sprintf(
879
+				esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
880
+				$attendee_link,
881
+				$datetime_link,
882
+				$event_link
883
+			) . '</h2>'
884
+			: '';
885
+		$this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
886
+			? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
887
+		$this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
888
+			? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
889
+		$this->display_admin_list_table_page_with_no_sidebar();
890
+	}
891 891
 
892 892
 
893
-    /**
894
-     * toggle the Check-in status for the given registration (coming from ajax)
895
-     *
896
-     * @return void (JSON)
897
-     * @throws EE_Error
898
-     * @throws InvalidArgumentException
899
-     * @throws InvalidDataTypeException
900
-     * @throws InvalidInterfaceException
901
-     */
902
-    public function toggle_checkin_status()
903
-    {
904
-        // first make sure we have the necessary data
905
-        if (! isset($this->_req_data['_regid'])) {
906
-            EE_Error::add_error(
907
-                esc_html__(
908
-                    'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
909
-                    'event_espresso'
910
-                ),
911
-                __FILE__,
912
-                __FUNCTION__,
913
-                __LINE__
914
-            );
915
-            $this->_template_args['success'] = false;
916
-            $this->_template_args['error'] = true;
917
-            $this->_return_json();
918
-        };
919
-        // do a nonce check cause we're not coming in from an normal route here.
920
-        $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
921
-            : '';
922
-        $nonce_ref = 'checkin_nonce';
923
-        $this->_verify_nonce($nonce, $nonce_ref);
924
-        // beautiful! Made it this far so let's get the status.
925
-        $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
926
-        // setup new class to return via ajax
927
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
928
-        $this->_template_args['success'] = true;
929
-        $this->_return_json();
930
-    }
893
+	/**
894
+	 * toggle the Check-in status for the given registration (coming from ajax)
895
+	 *
896
+	 * @return void (JSON)
897
+	 * @throws EE_Error
898
+	 * @throws InvalidArgumentException
899
+	 * @throws InvalidDataTypeException
900
+	 * @throws InvalidInterfaceException
901
+	 */
902
+	public function toggle_checkin_status()
903
+	{
904
+		// first make sure we have the necessary data
905
+		if (! isset($this->_req_data['_regid'])) {
906
+			EE_Error::add_error(
907
+				esc_html__(
908
+					'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
909
+					'event_espresso'
910
+				),
911
+				__FILE__,
912
+				__FUNCTION__,
913
+				__LINE__
914
+			);
915
+			$this->_template_args['success'] = false;
916
+			$this->_template_args['error'] = true;
917
+			$this->_return_json();
918
+		};
919
+		// do a nonce check cause we're not coming in from an normal route here.
920
+		$nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
921
+			: '';
922
+		$nonce_ref = 'checkin_nonce';
923
+		$this->_verify_nonce($nonce, $nonce_ref);
924
+		// beautiful! Made it this far so let's get the status.
925
+		$new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
926
+		// setup new class to return via ajax
927
+		$this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
928
+		$this->_template_args['success'] = true;
929
+		$this->_return_json();
930
+	}
931 931
 
932 932
 
933
-    /**
934
-     * handles toggling the checkin status for the registration,
935
-     *
936
-     * @access protected
937
-     * @return int|void
938
-     * @throws EE_Error
939
-     * @throws InvalidArgumentException
940
-     * @throws InvalidDataTypeException
941
-     * @throws InvalidInterfaceException
942
-     */
943
-    protected function _toggle_checkin_status()
944
-    {
945
-        // first let's get the query args out of the way for the redirect
946
-        $query_args = array(
947
-            'action'   => 'event_registrations',
948
-            'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
949
-            'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
950
-        );
951
-        $new_status = false;
952
-        // bulk action check in toggle
953
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
954
-            // cycle thru checkboxes
955
-            while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
956
-                $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
957
-                $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
958
-            }
959
-        } elseif (isset($this->_req_data['_regid'])) {
960
-            // coming from ajax request
961
-            $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
962
-            $query_args['DTT_ID'] = $DTT_ID;
963
-            $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
964
-        } else {
965
-            EE_Error::add_error(
966
-                esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'),
967
-                __FILE__,
968
-                __FUNCTION__,
969
-                __LINE__
970
-            );
971
-        }
972
-        if (defined('DOING_AJAX')) {
973
-            return $new_status;
974
-        }
975
-        $this->_redirect_after_action(false, '', '', $query_args, true);
976
-    }
933
+	/**
934
+	 * handles toggling the checkin status for the registration,
935
+	 *
936
+	 * @access protected
937
+	 * @return int|void
938
+	 * @throws EE_Error
939
+	 * @throws InvalidArgumentException
940
+	 * @throws InvalidDataTypeException
941
+	 * @throws InvalidInterfaceException
942
+	 */
943
+	protected function _toggle_checkin_status()
944
+	{
945
+		// first let's get the query args out of the way for the redirect
946
+		$query_args = array(
947
+			'action'   => 'event_registrations',
948
+			'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
949
+			'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
950
+		);
951
+		$new_status = false;
952
+		// bulk action check in toggle
953
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
954
+			// cycle thru checkboxes
955
+			while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
956
+				$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
957
+				$new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
958
+			}
959
+		} elseif (isset($this->_req_data['_regid'])) {
960
+			// coming from ajax request
961
+			$DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
962
+			$query_args['DTT_ID'] = $DTT_ID;
963
+			$new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
964
+		} else {
965
+			EE_Error::add_error(
966
+				esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'),
967
+				__FILE__,
968
+				__FUNCTION__,
969
+				__LINE__
970
+			);
971
+		}
972
+		if (defined('DOING_AJAX')) {
973
+			return $new_status;
974
+		}
975
+		$this->_redirect_after_action(false, '', '', $query_args, true);
976
+	}
977 977
 
978 978
 
979
-    /**
980
-     * This is toggles a single Check-in for the given registration and datetime.
981
-     *
982
-     * @param  int $REG_ID The registration we're toggling
983
-     * @param  int $DTT_ID The datetime we're toggling
984
-     * @return int The new status toggled to.
985
-     * @throws EE_Error
986
-     * @throws InvalidArgumentException
987
-     * @throws InvalidDataTypeException
988
-     * @throws InvalidInterfaceException
989
-     */
990
-    private function _toggle_checkin($REG_ID, $DTT_ID)
991
-    {
992
-        /** @var EE_Registration $REG */
993
-        $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
994
-        $new_status = $REG->toggle_checkin_status($DTT_ID);
995
-        if ($new_status !== false) {
996
-            EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
997
-        } else {
998
-            EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
999
-            $new_status = false;
1000
-        }
1001
-        return $new_status;
1002
-    }
979
+	/**
980
+	 * This is toggles a single Check-in for the given registration and datetime.
981
+	 *
982
+	 * @param  int $REG_ID The registration we're toggling
983
+	 * @param  int $DTT_ID The datetime we're toggling
984
+	 * @return int The new status toggled to.
985
+	 * @throws EE_Error
986
+	 * @throws InvalidArgumentException
987
+	 * @throws InvalidDataTypeException
988
+	 * @throws InvalidInterfaceException
989
+	 */
990
+	private function _toggle_checkin($REG_ID, $DTT_ID)
991
+	{
992
+		/** @var EE_Registration $REG */
993
+		$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
994
+		$new_status = $REG->toggle_checkin_status($DTT_ID);
995
+		if ($new_status !== false) {
996
+			EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
997
+		} else {
998
+			EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
999
+			$new_status = false;
1000
+		}
1001
+		return $new_status;
1002
+	}
1003 1003
 
1004 1004
 
1005
-    /**
1006
-     * Takes care of deleting multiple EE_Checkin table rows
1007
-     *
1008
-     * @access protected
1009
-     * @return void
1010
-     * @throws EE_Error
1011
-     * @throws InvalidArgumentException
1012
-     * @throws InvalidDataTypeException
1013
-     * @throws InvalidInterfaceException
1014
-     */
1015
-    protected function _delete_checkin_rows()
1016
-    {
1017
-        $query_args = array(
1018
-            'action'  => 'registration_checkins',
1019
-            'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1020
-            '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1021
-        );
1022
-        $errors = 0;
1023
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1024
-            while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1025
-                if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1026
-                    $errors++;
1027
-                }
1028
-            }
1029
-        } else {
1030
-            EE_Error::add_error(
1031
-                esc_html__(
1032
-                    'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
1033
-                    'event_espresso'
1034
-                ),
1035
-                __FILE__,
1036
-                __FUNCTION__,
1037
-                __LINE__
1038
-            );
1039
-            $this->_redirect_after_action(false, '', '', $query_args, true);
1040
-        }
1041
-        if ($errors > 0) {
1042
-            EE_Error::add_error(
1043
-                sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
1044
-                __FILE__,
1045
-                __FUNCTION__,
1046
-                __LINE__
1047
-            );
1048
-        } else {
1049
-            EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
1050
-        }
1051
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1052
-    }
1005
+	/**
1006
+	 * Takes care of deleting multiple EE_Checkin table rows
1007
+	 *
1008
+	 * @access protected
1009
+	 * @return void
1010
+	 * @throws EE_Error
1011
+	 * @throws InvalidArgumentException
1012
+	 * @throws InvalidDataTypeException
1013
+	 * @throws InvalidInterfaceException
1014
+	 */
1015
+	protected function _delete_checkin_rows()
1016
+	{
1017
+		$query_args = array(
1018
+			'action'  => 'registration_checkins',
1019
+			'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1020
+			'_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1021
+		);
1022
+		$errors = 0;
1023
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1024
+			while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1025
+				if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1026
+					$errors++;
1027
+				}
1028
+			}
1029
+		} else {
1030
+			EE_Error::add_error(
1031
+				esc_html__(
1032
+					'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
1033
+					'event_espresso'
1034
+				),
1035
+				__FILE__,
1036
+				__FUNCTION__,
1037
+				__LINE__
1038
+			);
1039
+			$this->_redirect_after_action(false, '', '', $query_args, true);
1040
+		}
1041
+		if ($errors > 0) {
1042
+			EE_Error::add_error(
1043
+				sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
1044
+				__FILE__,
1045
+				__FUNCTION__,
1046
+				__LINE__
1047
+			);
1048
+		} else {
1049
+			EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
1050
+		}
1051
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1052
+	}
1053 1053
 
1054 1054
 
1055
-    /**
1056
-     * Deletes a single EE_Checkin row
1057
-     *
1058
-     * @return void
1059
-     * @throws EE_Error
1060
-     * @throws InvalidArgumentException
1061
-     * @throws InvalidDataTypeException
1062
-     * @throws InvalidInterfaceException
1063
-     */
1064
-    protected function _delete_checkin_row()
1065
-    {
1066
-        $query_args = array(
1067
-            'action'  => 'registration_checkins',
1068
-            'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1069
-            '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1070
-        );
1071
-        if (! empty($this->_req_data['CHK_ID'])) {
1072
-            if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1073
-                EE_Error::add_error(
1074
-                    esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1075
-                    __FILE__,
1076
-                    __FUNCTION__,
1077
-                    __LINE__
1078
-                );
1079
-            } else {
1080
-                EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
1081
-            }
1082
-        } else {
1083
-            EE_Error::add_error(
1084
-                esc_html__(
1085
-                    'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1086
-                    'event_espresso'
1087
-                ),
1088
-                __FILE__,
1089
-                __FUNCTION__,
1090
-                __LINE__
1091
-            );
1092
-        }
1093
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1094
-    }
1055
+	/**
1056
+	 * Deletes a single EE_Checkin row
1057
+	 *
1058
+	 * @return void
1059
+	 * @throws EE_Error
1060
+	 * @throws InvalidArgumentException
1061
+	 * @throws InvalidDataTypeException
1062
+	 * @throws InvalidInterfaceException
1063
+	 */
1064
+	protected function _delete_checkin_row()
1065
+	{
1066
+		$query_args = array(
1067
+			'action'  => 'registration_checkins',
1068
+			'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1069
+			'_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1070
+		);
1071
+		if (! empty($this->_req_data['CHK_ID'])) {
1072
+			if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1073
+				EE_Error::add_error(
1074
+					esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1075
+					__FILE__,
1076
+					__FUNCTION__,
1077
+					__LINE__
1078
+				);
1079
+			} else {
1080
+				EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
1081
+			}
1082
+		} else {
1083
+			EE_Error::add_error(
1084
+				esc_html__(
1085
+					'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1086
+					'event_espresso'
1087
+				),
1088
+				__FILE__,
1089
+				__FUNCTION__,
1090
+				__LINE__
1091
+			);
1092
+		}
1093
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1094
+	}
1095 1095
 
1096 1096
 
1097
-    /**
1098
-     *        generates HTML for the Event Registrations List Table
1099
-     *
1100
-     * @access protected
1101
-     * @return void
1102
-     * @throws EE_Error
1103
-     * @throws InvalidArgumentException
1104
-     * @throws InvalidDataTypeException
1105
-     * @throws InvalidInterfaceException
1106
-     */
1107
-    protected function _event_registrations_list_table()
1108
-    {
1109
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1110
-        $this->_admin_page_title .= isset($this->_req_data['event_id'])
1111
-            ? $this->get_action_link_or_button(
1112
-                'new_registration',
1113
-                'add-registrant',
1114
-                array('event_id' => $this->_req_data['event_id']),
1115
-                'add-new-h2',
1116
-                '',
1117
-                false
1118
-            )
1119
-            : '';
1120
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1121
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1122
-        $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1123
-        $legend_items = array(
1124
-            'star-icon'        => array(
1125
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1126
-                'desc'  => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'),
1127
-            ),
1128
-            'checkin'          => array(
1129
-                'class' => $checked_in->cssClasses(),
1130
-                'desc'  => $checked_in->legendLabel(),
1131
-            ),
1132
-            'checkout'         => array(
1133
-                'class' => $checked_out->cssClasses(),
1134
-                'desc'  => $checked_out->legendLabel(),
1135
-            ),
1136
-            'nocheckinrecord'  => array(
1137
-                'class' => $checked_never->cssClasses(),
1138
-                'desc'  => $checked_never->legendLabel(),
1139
-            ),
1140
-            'approved_status'  => array(
1141
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1142
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1143
-            ),
1144
-            'cancelled_status' => array(
1145
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1146
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1147
-            ),
1148
-            'declined_status'  => array(
1149
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1150
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1151
-            ),
1152
-            'not_approved'     => array(
1153
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1154
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1155
-            ),
1156
-            'pending_status'   => array(
1157
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1158
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1159
-            ),
1160
-            'wait_list'        => array(
1161
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1162
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1163
-            ),
1164
-        );
1165
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1166
-        $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1167
-        /** @var EE_Event $event */
1168
-        $event = EEM_Event::instance()->get_one_by_ID($event_id);
1169
-        $this->_template_args['before_list_table'] = $event instanceof EE_Event
1170
-            ? '<h2>' . sprintf(
1171
-                esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1172
-                EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1173
-            ) . '</h2>'
1174
-            : '';
1175
-        // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1176
-        // the event.
1177
-        $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1178
-        $datetime = null;
1179
-        if ($event instanceof EE_Event) {
1180
-            $datetimes_on_event = $event->datetimes();
1181
-            if (count($datetimes_on_event) === 1) {
1182
-                $datetime = reset($datetimes_on_event);
1183
-            }
1184
-        }
1185
-        $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1186
-        if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1187
-            $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1188
-            $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1189
-            $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1190
-            $this->_template_args['before_list_table'] .= $datetime->name();
1191
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1192
-            $this->_template_args['before_list_table'] .= '</span></h2>';
1193
-        }
1194
-        // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1195
-        // column represents
1196
-        if (! $datetime instanceof EE_Datetime) {
1197
-            $this->_template_args['before_list_table'] .= '<br><p class="description">'
1198
-                                                          . esc_html__(
1199
-                                                              'In this view, the check-in status represents the latest check-in record for the registration in that row.',
1200
-                                                              'event_espresso'
1201
-                                                          )
1202
-                                                          . '</p>';
1203
-        }
1204
-        $this->display_admin_list_table_page_with_no_sidebar();
1205
-    }
1097
+	/**
1098
+	 *        generates HTML for the Event Registrations List Table
1099
+	 *
1100
+	 * @access protected
1101
+	 * @return void
1102
+	 * @throws EE_Error
1103
+	 * @throws InvalidArgumentException
1104
+	 * @throws InvalidDataTypeException
1105
+	 * @throws InvalidInterfaceException
1106
+	 */
1107
+	protected function _event_registrations_list_table()
1108
+	{
1109
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1110
+		$this->_admin_page_title .= isset($this->_req_data['event_id'])
1111
+			? $this->get_action_link_or_button(
1112
+				'new_registration',
1113
+				'add-registrant',
1114
+				array('event_id' => $this->_req_data['event_id']),
1115
+				'add-new-h2',
1116
+				'',
1117
+				false
1118
+			)
1119
+			: '';
1120
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1121
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1122
+		$checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1123
+		$legend_items = array(
1124
+			'star-icon'        => array(
1125
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1126
+				'desc'  => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'),
1127
+			),
1128
+			'checkin'          => array(
1129
+				'class' => $checked_in->cssClasses(),
1130
+				'desc'  => $checked_in->legendLabel(),
1131
+			),
1132
+			'checkout'         => array(
1133
+				'class' => $checked_out->cssClasses(),
1134
+				'desc'  => $checked_out->legendLabel(),
1135
+			),
1136
+			'nocheckinrecord'  => array(
1137
+				'class' => $checked_never->cssClasses(),
1138
+				'desc'  => $checked_never->legendLabel(),
1139
+			),
1140
+			'approved_status'  => array(
1141
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1142
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1143
+			),
1144
+			'cancelled_status' => array(
1145
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1146
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1147
+			),
1148
+			'declined_status'  => array(
1149
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1150
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1151
+			),
1152
+			'not_approved'     => array(
1153
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1154
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1155
+			),
1156
+			'pending_status'   => array(
1157
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1158
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1159
+			),
1160
+			'wait_list'        => array(
1161
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1162
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1163
+			),
1164
+		);
1165
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1166
+		$event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1167
+		/** @var EE_Event $event */
1168
+		$event = EEM_Event::instance()->get_one_by_ID($event_id);
1169
+		$this->_template_args['before_list_table'] = $event instanceof EE_Event
1170
+			? '<h2>' . sprintf(
1171
+				esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1172
+				EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1173
+			) . '</h2>'
1174
+			: '';
1175
+		// need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1176
+		// the event.
1177
+		$DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1178
+		$datetime = null;
1179
+		if ($event instanceof EE_Event) {
1180
+			$datetimes_on_event = $event->datetimes();
1181
+			if (count($datetimes_on_event) === 1) {
1182
+				$datetime = reset($datetimes_on_event);
1183
+			}
1184
+		}
1185
+		$datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1186
+		if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1187
+			$this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1188
+			$this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1189
+			$this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1190
+			$this->_template_args['before_list_table'] .= $datetime->name();
1191
+			$this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1192
+			$this->_template_args['before_list_table'] .= '</span></h2>';
1193
+		}
1194
+		// if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1195
+		// column represents
1196
+		if (! $datetime instanceof EE_Datetime) {
1197
+			$this->_template_args['before_list_table'] .= '<br><p class="description">'
1198
+														  . esc_html__(
1199
+															  'In this view, the check-in status represents the latest check-in record for the registration in that row.',
1200
+															  'event_espresso'
1201
+														  )
1202
+														  . '</p>';
1203
+		}
1204
+		$this->display_admin_list_table_page_with_no_sidebar();
1205
+	}
1206 1206
 
1207
-    /**
1208
-     * Download the registrations check-in report (same as the normal registration report, but with different where
1209
-     * conditions)
1210
-     *
1211
-     * @return void ends the request by a redirect or download
1212
-     */
1213
-    public function _registrations_checkin_report()
1214
-    {
1215
-        $this->_registrations_report_base('_get_checkin_query_params_from_request');
1216
-    }
1207
+	/**
1208
+	 * Download the registrations check-in report (same as the normal registration report, but with different where
1209
+	 * conditions)
1210
+	 *
1211
+	 * @return void ends the request by a redirect or download
1212
+	 */
1213
+	public function _registrations_checkin_report()
1214
+	{
1215
+		$this->_registrations_report_base('_get_checkin_query_params_from_request');
1216
+	}
1217 1217
 
1218
-    /**
1219
-     * Gets the query params from the request, plus adds a where condition for the registration status,
1220
-     * because on the checkin page we only ever want to see approved and pending-approval registrations
1221
-     *
1222
-     * @param array $request
1223
-     * @param int   $per_page
1224
-     * @param bool  $count
1225
-     * @return array
1226
-     * @throws EE_Error
1227
-     */
1228
-    protected function _get_checkin_query_params_from_request(
1229
-        $request,
1230
-        $per_page = 10,
1231
-        $count = false
1232
-    ) {
1233
-        $query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1234
-        // unlike the regular registrations list table,
1235
-        $status_ids_array = apply_filters(
1236
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1237
-            array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1238
-        );
1239
-        $query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1240
-        return $query_params;
1241
-    }
1218
+	/**
1219
+	 * Gets the query params from the request, plus adds a where condition for the registration status,
1220
+	 * because on the checkin page we only ever want to see approved and pending-approval registrations
1221
+	 *
1222
+	 * @param array $request
1223
+	 * @param int   $per_page
1224
+	 * @param bool  $count
1225
+	 * @return array
1226
+	 * @throws EE_Error
1227
+	 */
1228
+	protected function _get_checkin_query_params_from_request(
1229
+		$request,
1230
+		$per_page = 10,
1231
+		$count = false
1232
+	) {
1233
+		$query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1234
+		// unlike the regular registrations list table,
1235
+		$status_ids_array = apply_filters(
1236
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1237
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1238
+		);
1239
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1240
+		return $query_params;
1241
+	}
1242 1242
 
1243 1243
 
1244
-    /**
1245
-     * Gets registrations for an event
1246
-     *
1247
-     * @param int    $per_page
1248
-     * @param bool   $count whether to return count or data.
1249
-     * @param bool   $trash
1250
-     * @param string $orderby
1251
-     * @return EE_Registration[]|int
1252
-     * @throws EE_Error
1253
-     * @throws InvalidArgumentException
1254
-     * @throws InvalidDataTypeException
1255
-     * @throws InvalidInterfaceException
1256
-     */
1257
-    public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1258
-    {
1259
-        // normalize some request params that get setup by the parent `get_registrations` method.
1260
-        $request = $this->_req_data;
1261
-        $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1262
-        $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1263
-        if ($trash) {
1264
-            $request['status'] = 'trash';
1265
-        }
1266
-        $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1267
-        /**
1268
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1269
-         *
1270
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1271
-         * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1272
-         *                             or if you have the development copy of EE you can view this at the path:
1273
-         *                             /docs/G--Model-System/model-query-params.md
1274
-         */
1275
-        $query_params['group_by'] = '';
1244
+	/**
1245
+	 * Gets registrations for an event
1246
+	 *
1247
+	 * @param int    $per_page
1248
+	 * @param bool   $count whether to return count or data.
1249
+	 * @param bool   $trash
1250
+	 * @param string $orderby
1251
+	 * @return EE_Registration[]|int
1252
+	 * @throws EE_Error
1253
+	 * @throws InvalidArgumentException
1254
+	 * @throws InvalidDataTypeException
1255
+	 * @throws InvalidInterfaceException
1256
+	 */
1257
+	public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1258
+	{
1259
+		// normalize some request params that get setup by the parent `get_registrations` method.
1260
+		$request = $this->_req_data;
1261
+		$request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1262
+		$request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1263
+		if ($trash) {
1264
+			$request['status'] = 'trash';
1265
+		}
1266
+		$query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1267
+		/**
1268
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1269
+		 *
1270
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1271
+		 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1272
+		 *                             or if you have the development copy of EE you can view this at the path:
1273
+		 *                             /docs/G--Model-System/model-query-params.md
1274
+		 */
1275
+		$query_params['group_by'] = '';
1276 1276
 
1277
-        return $count
1278
-            ? EEM_Registration::instance()->count($query_params)
1279
-            /** @type EE_Registration[] */
1280
-            : EEM_Registration::instance()->get_all($query_params);
1281
-    }
1277
+		return $count
1278
+			? EEM_Registration::instance()->count($query_params)
1279
+			/** @type EE_Registration[] */
1280
+			: EEM_Registration::instance()->get_all($query_params);
1281
+	}
1282 1282
 }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
     public function __construct($routing = true)
33 33
     {
34 34
         parent::__construct($routing);
35
-        if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
35
+        if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
36
+            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/');
37
+            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/');
38
+            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/');
39 39
         }
40 40
     }
41 41
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      */
46 46
     protected function _extend_page_config()
47 47
     {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
48
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations';
49 49
         $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50 50
             ? $this->_req_data['_REG_ID']
51 51
             : 0;
@@ -185,14 +185,14 @@  discard block
 block discarded – undo
185 185
             // enqueue newsletter js
186 186
             wp_enqueue_script(
187 187
                 'ee-newsletter-trigger',
188
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
188
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js',
189 189
                 array('ee-dialog'),
190 190
                 EVENT_ESPRESSO_VERSION,
191 191
                 true
192 192
             );
193 193
             wp_enqueue_style(
194 194
                 'ee-newsletter-trigger-css',
195
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
195
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css',
196 196
                 array(),
197 197
                 EVENT_ESPRESSO_VERSION
198 198
             );
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
     {
214 214
         wp_register_script(
215 215
             'ee-reg-reports-js',
216
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
216
+            REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js',
217 217
             array('google-charts'),
218 218
             EVENT_ESPRESSO_VERSION,
219 219
             true
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
         $nonce_ref = 'get_newsletter_form_content_nonce';
300 300
         $this->_verify_nonce($nonce, $nonce_ref);
301 301
         // let's get the mtp for the incoming MTP_ ID
302
-        if (! isset($this->_req_data['GRP_ID'])) {
302
+        if ( ! isset($this->_req_data['GRP_ID'])) {
303 303
             EE_Error::add_error(
304 304
                 esc_html__(
305 305
                     'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
             $this->_return_json();
315 315
         }
316 316
         $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
317
-        if (! $MTPG instanceof EE_Message_Template_Group) {
317
+        if ( ! $MTPG instanceof EE_Message_Template_Group) {
318 318
             EE_Error::add_error(
319 319
                 sprintf(
320 320
                     esc_html__(
@@ -339,12 +339,12 @@  discard block
 block discarded – undo
339 339
             $field = $MTP->get('MTP_template_field');
340 340
             if ($field === 'content') {
341 341
                 $content = $MTP->get('MTP_content');
342
-                if (! empty($content['newsletter_content'])) {
342
+                if ( ! empty($content['newsletter_content'])) {
343 343
                     $template_fields['newsletter_content'] = $content['newsletter_content'];
344 344
                 }
345 345
                 continue;
346 346
             }
347
-            $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
347
+            $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
348 348
         }
349 349
         $this->_template_args['success'] = true;
350 350
         $this->_template_args['error'] = false;
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
      */
376 376
     public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
377 377
     {
378
-        if (! EE_Registry::instance()->CAP->current_user_can(
378
+        if ( ! EE_Registry::instance()->CAP->current_user_can(
379 379
             'ee_send_message',
380 380
             'espresso_registrations_newsletter_selected_send'
381 381
         )
@@ -444,17 +444,17 @@  discard block
 block discarded – undo
444 444
                 $field_id = $field === '[NEWSLETTER_CONTENT]'
445 445
                     ? 'content'
446 446
                     : $field;
447
-                $field_id = 'batch-message-' . strtolower($field_id);
447
+                $field_id = 'batch-message-'.strtolower($field_id);
448 448
                 $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
449 449
                                           . $shortcode
450
-                                          . '" data-linked-input-id="' . $field_id . '">'
450
+                                          . '" data-linked-input-id="'.$field_id.'">'
451 451
                                           . $shortcode
452 452
                                           . '</span>';
453 453
             }
454
-            $codes[ $field ] = implode(', ', $available_shortcodes);
454
+            $codes[$field] = implode(', ', $available_shortcodes);
455 455
         }
456 456
         $shortcodes = $codes;
457
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
457
+        $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php';
458 458
         $form_template_args = array(
459 459
             'form_action'       => admin_url('admin.php?page=espresso_registrations'),
460 460
             'form_route'        => 'newsletter_selected_send',
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
      */
623 623
     protected function _registration_reports()
624 624
     {
625
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
625
+        $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
626 626
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
627 627
             $template_path,
628 628
             $this->_reports_template_data,
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
             array_unshift($regs, $column_titles);
678 678
             // setup the date range.
679 679
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
680
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
680
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
681 681
             $ending_date = new DateTime("now", $DateTimeZone);
682 682
             $subtitle = sprintf(
683 683
                 wp_strip_all_tags(
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
                         'event_espresso'
702 702
                     )
703 703
                 ),
704
-                '<h2>' . $report_title . '</h2><p>',
704
+                '<h2>'.$report_title.'</h2><p>',
705 705
                 '</p>'
706 706
             ),
707 707
         );
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
             array_unshift($regs, $column_titles);
755 755
             // setup the date range.
756 756
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
757
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
757
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
758 758
             $ending_date = new DateTime("now", $DateTimeZone);
759 759
             $subtitle = sprintf(
760 760
                 wp_strip_all_tags(
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
                         'event_espresso'
779 779
                     )
780 780
                 ),
781
-                '<h2>' . $report_title . '</h2><p>',
781
+                '<h2>'.$report_title.'</h2><p>',
782 782
                 '</p>'
783 783
             ),
784 784
         );
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
         if ($datetime instanceof EE_Datetime) {
832 832
             $datetime_label = $datetime->get_dtt_display_name(true);
833 833
             $datetime_label .= ! empty($datetime_label)
834
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
834
+                ? ' ('.$datetime->get_dtt_display_name().')'
835 835
                 : $datetime->get_dtt_display_name();
836 836
         }
837 837
         $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
@@ -845,7 +845,7 @@  discard block
 block discarded – undo
845 845
             )
846 846
             : '';
847 847
         $datetime_link = ! empty($datetime_link)
848
-            ? '<a href="' . $datetime_link . '">'
848
+            ? '<a href="'.$datetime_link.'">'
849 849
               . '<span id="checkin-dtt">'
850 850
               . $datetime_label
851 851
               . '</span></a>'
@@ -857,8 +857,8 @@  discard block
 block discarded – undo
857 857
             ? $attendee->get_admin_details_link()
858 858
             : '';
859 859
         $attendee_link = ! empty($attendee_link)
860
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
861
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
860
+            ? '<a href="'.$attendee->get_admin_details_link().'"'
861
+              . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">'
862 862
               . '<span id="checkin-attendee-name">'
863 863
               . $attendee_name
864 864
               . '</span></a>'
@@ -867,25 +867,25 @@  discard block
 block discarded – undo
867 867
             ? $registration->event()->get_admin_details_link()
868 868
             : '';
869 869
         $event_link = ! empty($event_link)
870
-            ? '<a href="' . $event_link . '"'
871
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
870
+            ? '<a href="'.$event_link.'"'
871
+              . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">'
872 872
               . '<span id="checkin-event-name">'
873 873
               . $registration->event_name()
874 874
               . '</span>'
875 875
               . '</a>'
876 876
             : '';
877 877
         $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
878
-            ? '<h2>' . sprintf(
878
+            ? '<h2>'.sprintf(
879 879
                 esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
880 880
                 $attendee_link,
881 881
                 $datetime_link,
882 882
                 $event_link
883
-            ) . '</h2>'
883
+            ).'</h2>'
884 884
             : '';
885 885
         $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
886
-            ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
886
+            ? '<input type="hidden" name="_REG_ID" value="'.$reg_id.'">' : '';
887 887
         $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
888
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
888
+            ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : '';
889 889
         $this->display_admin_list_table_page_with_no_sidebar();
890 890
     }
891 891
 
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
     public function toggle_checkin_status()
903 903
     {
904 904
         // first make sure we have the necessary data
905
-        if (! isset($this->_req_data['_regid'])) {
905
+        if ( ! isset($this->_req_data['_regid'])) {
906 906
             EE_Error::add_error(
907 907
                 esc_html__(
908 908
                     'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
         // beautiful! Made it this far so let's get the status.
925 925
         $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
926 926
         // setup new class to return via ajax
927
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
927
+        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin '.$new_status->cssClasses();
928 928
         $this->_template_args['success'] = true;
929 929
         $this->_return_json();
930 930
     }
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
         );
951 951
         $new_status = false;
952 952
         // bulk action check in toggle
953
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
953
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
954 954
             // cycle thru checkboxes
955 955
             while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
956 956
                 $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
@@ -1020,9 +1020,9 @@  discard block
 block discarded – undo
1020 1020
             '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1021 1021
         );
1022 1022
         $errors = 0;
1023
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1023
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1024 1024
             while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1025
-                if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1025
+                if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1026 1026
                     $errors++;
1027 1027
                 }
1028 1028
             }
@@ -1068,8 +1068,8 @@  discard block
 block discarded – undo
1068 1068
             'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1069 1069
             '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1070 1070
         );
1071
-        if (! empty($this->_req_data['CHK_ID'])) {
1072
-            if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1071
+        if ( ! empty($this->_req_data['CHK_ID'])) {
1072
+            if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1073 1073
                 EE_Error::add_error(
1074 1074
                     esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1075 1075
                     __FILE__,
@@ -1138,27 +1138,27 @@  discard block
 block discarded – undo
1138 1138
                 'desc'  => $checked_never->legendLabel(),
1139 1139
             ),
1140 1140
             'approved_status'  => array(
1141
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1141
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
1142 1142
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1143 1143
             ),
1144 1144
             'cancelled_status' => array(
1145
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1145
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1146 1146
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1147 1147
             ),
1148 1148
             'declined_status'  => array(
1149
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1149
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
1150 1150
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1151 1151
             ),
1152 1152
             'not_approved'     => array(
1153
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1153
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
1154 1154
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1155 1155
             ),
1156 1156
             'pending_status'   => array(
1157
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1157
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
1158 1158
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1159 1159
             ),
1160 1160
             'wait_list'        => array(
1161
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1161
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
1162 1162
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1163 1163
             ),
1164 1164
         );
@@ -1167,10 +1167,10 @@  discard block
 block discarded – undo
1167 1167
         /** @var EE_Event $event */
1168 1168
         $event = EEM_Event::instance()->get_one_by_ID($event_id);
1169 1169
         $this->_template_args['before_list_table'] = $event instanceof EE_Event
1170
-            ? '<h2>' . sprintf(
1170
+            ? '<h2>'.sprintf(
1171 1171
                 esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1172 1172
                 EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1173
-            ) . '</h2>'
1173
+            ).'</h2>'
1174 1174
             : '';
1175 1175
         // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1176 1176
         // the event.
@@ -1188,12 +1188,12 @@  discard block
 block discarded – undo
1188 1188
             $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1189 1189
             $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1190 1190
             $this->_template_args['before_list_table'] .= $datetime->name();
1191
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1191
+            $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )';
1192 1192
             $this->_template_args['before_list_table'] .= '</span></h2>';
1193 1193
         }
1194 1194
         // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1195 1195
         // column represents
1196
-        if (! $datetime instanceof EE_Datetime) {
1196
+        if ( ! $datetime instanceof EE_Datetime) {
1197 1197
             $this->_template_args['before_list_table'] .= '<br><p class="description">'
1198 1198
                                                           . esc_html__(
1199 1199
                                                               'In this view, the check-in status represents the latest check-in record for the registration in that row.',
Please login to merge, or discard this patch.
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/libraries/form_sections/base/EE_Form_Section_Proper.form.php 1 patch
Indentation   +1524 added lines, -1524 removed lines patch added patch discarded remove patch
@@ -14,1528 +14,1528 @@
 block discarded – undo
14 14
 class EE_Form_Section_Proper extends EE_Form_Section_Validatable
15 15
 {
16 16
 
17
-    const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
-
19
-    /**
20
-     * Subsections
21
-     *
22
-     * @var EE_Form_Section_Validatable[]
23
-     */
24
-    protected $_subsections = array();
25
-
26
-    /**
27
-     * Strategy for laying out the form
28
-     *
29
-     * @var EE_Form_Section_Layout_Base
30
-     */
31
-    protected $_layout_strategy;
32
-
33
-    /**
34
-     * Whether or not this form has received and validated a form submission yet
35
-     *
36
-     * @var boolean
37
-     */
38
-    protected $_received_submission = false;
39
-
40
-    /**
41
-     * message displayed to users upon successful form submission
42
-     *
43
-     * @var string
44
-     */
45
-    protected $_form_submission_success_message = '';
46
-
47
-    /**
48
-     * message displayed to users upon unsuccessful form submission
49
-     *
50
-     * @var string
51
-     */
52
-    protected $_form_submission_error_message = '';
53
-
54
-    /**
55
-     * @var array like $_REQUEST
56
-     */
57
-    protected $cached_request_data;
58
-
59
-    /**
60
-     * Stores whether this form (and its sub-sections) were found to be valid or not.
61
-     * Starts off as null, but once the form is validated, it set to either true or false
62
-     * @var boolean|null
63
-     */
64
-    protected $is_valid;
65
-
66
-    /**
67
-     * Stores all the data that will localized for form validation
68
-     *
69
-     * @var array
70
-     */
71
-    static protected $_js_localization = array();
72
-
73
-    /**
74
-     * whether or not the form's localized validation JS vars have been set
75
-     *
76
-     * @type boolean
77
-     */
78
-    static protected $_scripts_localized = false;
79
-
80
-
81
-    /**
82
-     * when constructing a proper form section, calls _construct_finalize on children
83
-     * so that they know who their parent is, and what name they've been given.
84
-     *
85
-     * @param array[] $options_array   {
86
-     * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
-     * @type          $include         string[] numerically-indexed where values are section names to be included,
88
-     *                                 and in that order. This is handy if you want
89
-     *                                 the subsections to be ordered differently than the default, and if you override
90
-     *                                 which fields are shown
91
-     * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
-     *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
-     *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
-     *                                 items from that list of inclusions)
95
-     * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
-     *                                 } @see EE_Form_Section_Validatable::__construct()
97
-     * @throws EE_Error
98
-     */
99
-    public function __construct($options_array = array())
100
-    {
101
-        $options_array = (array) apply_filters(
102
-            'FHEE__EE_Form_Section_Proper___construct__options_array',
103
-            $options_array,
104
-            $this
105
-        );
106
-        // call parent first, as it may be setting the name
107
-        parent::__construct($options_array);
108
-        // if they've included subsections in the constructor, add them now
109
-        if (isset($options_array['include'])) {
110
-            // we are going to make sure we ONLY have those subsections to include
111
-            // AND we are going to make sure they're in that specified order
112
-            $reordered_subsections = array();
113
-            foreach ($options_array['include'] as $input_name) {
114
-                if (isset($this->_subsections[ $input_name ])) {
115
-                    $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
-                }
117
-            }
118
-            $this->_subsections = $reordered_subsections;
119
-        }
120
-        if (isset($options_array['exclude'])) {
121
-            $exclude            = $options_array['exclude'];
122
-            $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
-        }
124
-        if (isset($options_array['layout_strategy'])) {
125
-            $this->_layout_strategy = $options_array['layout_strategy'];
126
-        }
127
-        if (! $this->_layout_strategy) {
128
-            $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
-        }
130
-        $this->_layout_strategy->_construct_finalize($this);
131
-        // ok so we are definitely going to want the forms JS,
132
-        // so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
-            // ok so they've constructed this object after when they should have.
135
-            // just enqueue the generic form scripts and initialize the form immediately in the JS
136
-            EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
-        } else {
138
-            add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
-            add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
-        }
141
-        add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
-        /**
143
-         * Gives other plugins a chance to hook in before construct finalize is called.
144
-         * The form probably doesn't yet have a parent form section.
145
-         * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
-         * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
-         * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
-         *
149
-         * @since 4.9.32
150
-         * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
-         *                                              except maybe calling _construct_finalize has been done
152
-         * @param array                  $options_array options passed into the constructor
153
-         */
154
-        do_action(
155
-            'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
-            $this,
157
-            $options_array
158
-        );
159
-        if (isset($options_array['name'])) {
160
-            $this->_construct_finalize(null, $options_array['name']);
161
-        }
162
-    }
163
-
164
-
165
-    /**
166
-     * Finishes construction given the parent form section and this form section's name
167
-     *
168
-     * @param EE_Form_Section_Proper $parent_form_section
169
-     * @param string                 $name
170
-     * @throws EE_Error
171
-     */
172
-    public function _construct_finalize($parent_form_section, $name)
173
-    {
174
-        parent::_construct_finalize($parent_form_section, $name);
175
-        $this->_set_default_name_if_empty();
176
-        $this->_set_default_html_id_if_empty();
177
-        foreach ($this->_subsections as $subsection_name => $subsection) {
178
-            if ($subsection instanceof EE_Form_Section_Base) {
179
-                $subsection->_construct_finalize($this, $subsection_name);
180
-            } else {
181
-                throw new EE_Error(
182
-                    sprintf(
183
-                        esc_html__(
184
-                            'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
-                            'event_espresso'
186
-                        ),
187
-                        $subsection_name,
188
-                        get_class($this),
189
-                        $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
-                    )
191
-                );
192
-            }
193
-        }
194
-        /**
195
-         * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
-         * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
-         * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
-         * This might only happen just before displaying the form, or just before it receives form submission data.
199
-         * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
-         * ensured it has a name, HTML IDs, etc
201
-         *
202
-         * @param EE_Form_Section_Proper      $this
203
-         * @param EE_Form_Section_Proper|null $parent_form_section
204
-         * @param string                      $name
205
-         */
206
-        do_action(
207
-            'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
-            $this,
209
-            $parent_form_section,
210
-            $name
211
-        );
212
-    }
213
-
214
-
215
-    /**
216
-     * Gets the layout strategy for this form section
217
-     *
218
-     * @return EE_Form_Section_Layout_Base
219
-     */
220
-    public function get_layout_strategy()
221
-    {
222
-        return $this->_layout_strategy;
223
-    }
224
-
225
-
226
-    /**
227
-     * Gets the HTML for a single input for this form section according
228
-     * to the layout strategy
229
-     *
230
-     * @param EE_Form_Input_Base $input
231
-     * @return string
232
-     */
233
-    public function get_html_for_input($input)
234
-    {
235
-        return $this->_layout_strategy->layout_input($input);
236
-    }
237
-
238
-
239
-    /**
240
-     * was_submitted - checks if form inputs are present in request data
241
-     * Basically an alias for form_data_present_in() (which is used by both
242
-     * proper form sections and form inputs)
243
-     *
244
-     * @param null $form_data
245
-     * @return boolean
246
-     * @throws EE_Error
247
-     */
248
-    public function was_submitted($form_data = null)
249
-    {
250
-        return $this->form_data_present_in($form_data);
251
-    }
252
-
253
-    /**
254
-     * Gets the cached request data; but if there is none, or $req_data was set with
255
-     * something different, refresh the cache, and then return it
256
-     * @param null $req_data
257
-     * @return array
258
-     */
259
-    protected function getCachedRequest($req_data = null)
260
-    {
261
-        if ($this->cached_request_data === null
262
-            || (
263
-                $req_data !== null &&
264
-                $req_data !== $this->cached_request_data
265
-            )
266
-        ) {
267
-            $req_data = apply_filters(
268
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
269
-                $req_data,
270
-                $this
271
-            );
272
-            if ($req_data === null) {
273
-                $req_data = array_merge($_GET, $_POST);
274
-            }
275
-            $req_data = apply_filters(
276
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
277
-                $req_data,
278
-                $this
279
-            );
280
-            $this->cached_request_data = (array) $req_data;
281
-        }
282
-        return $this->cached_request_data;
283
-    }
284
-
285
-
286
-    /**
287
-     * After the form section is initially created, call this to sanitize the data in the submission
288
-     * which relates to this form section, validate it, and set it as properties on the form.
289
-     *
290
-     * @param array|null $req_data should usually be $_POST (the default).
291
-     *                             However, you CAN supply a different array.
292
-     *                             Consider using set_defaults() instead however.
293
-     *                             (If you rendered the form in the page using echo $form_x->get_html()
294
-     *                             the inputs will have the correct name in the request data for this function
295
-     *                             to find them and populate the form with them.
296
-     *                             If you have a flat form (with only input subsections),
297
-     *                             you can supply a flat array where keys
298
-     *                             are the form input names and values are their values)
299
-     * @param boolean    $validate whether or not to perform validation on this data. Default is,
300
-     *                             of course, to validate that data, and set errors on the invalid values.
301
-     *                             But if the data has already been validated
302
-     *                             (eg you validated the data then stored it in the DB)
303
-     *                             you may want to skip this step.
304
-     * @throws InvalidArgumentException
305
-     * @throws InvalidInterfaceException
306
-     * @throws InvalidDataTypeException
307
-     * @throws EE_Error
308
-     */
309
-    public function receive_form_submission($req_data = null, $validate = true)
310
-    {
311
-        $req_data = $this->getCachedRequest($req_data);
312
-        $this->_normalize($req_data);
313
-        if ($validate) {
314
-            $this->_validate();
315
-            // if it's invalid, we're going to want to re-display so remember what they submitted
316
-            if (! $this->is_valid()) {
317
-                $this->store_submitted_form_data_in_session();
318
-            }
319
-        }
320
-        if ($this->submission_error_message() === '' && ! $this->is_valid()) {
321
-            $this->set_submission_error_message();
322
-        }
323
-        do_action(
324
-            'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
325
-            $req_data,
326
-            $this,
327
-            $validate
328
-        );
329
-    }
330
-
331
-
332
-    /**
333
-     * caches the originally submitted input values in the session
334
-     * so that they can be used to repopulate the form if it failed validation
335
-     *
336
-     * @return boolean whether or not the data was successfully stored in the session
337
-     * @throws InvalidArgumentException
338
-     * @throws InvalidInterfaceException
339
-     * @throws InvalidDataTypeException
340
-     * @throws EE_Error
341
-     */
342
-    protected function store_submitted_form_data_in_session()
343
-    {
344
-        return EE_Registry::instance()->SSN->set_session_data(
345
-            array(
346
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
347
-            )
348
-        );
349
-    }
350
-
351
-
352
-    /**
353
-     * retrieves the originally submitted input values in the session
354
-     * so that they can be used to repopulate the form if it failed validation
355
-     *
356
-     * @return array
357
-     * @throws InvalidArgumentException
358
-     * @throws InvalidInterfaceException
359
-     * @throws InvalidDataTypeException
360
-     */
361
-    protected function get_submitted_form_data_from_session()
362
-    {
363
-        $session = EE_Registry::instance()->SSN;
364
-        if ($session instanceof EE_Session) {
365
-            return $session->get_session_data(
366
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
367
-            );
368
-        }
369
-        return array();
370
-    }
371
-
372
-
373
-    /**
374
-     * flushed the originally submitted input values from the session
375
-     *
376
-     * @return boolean whether or not the data was successfully removed from the session
377
-     * @throws InvalidArgumentException
378
-     * @throws InvalidInterfaceException
379
-     * @throws InvalidDataTypeException
380
-     */
381
-    public static function flush_submitted_form_data_from_session()
382
-    {
383
-        return EE_Registry::instance()->SSN->reset_data(
384
-            array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
385
-        );
386
-    }
387
-
388
-
389
-    /**
390
-     * Populates this form and its subsections with data from the session.
391
-     * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
392
-     * validation errors when displaying too)
393
-     * Returns true if the form was populated from the session, false otherwise
394
-     *
395
-     * @return boolean
396
-     * @throws InvalidArgumentException
397
-     * @throws InvalidInterfaceException
398
-     * @throws InvalidDataTypeException
399
-     * @throws EE_Error
400
-     */
401
-    public function populate_from_session()
402
-    {
403
-        $form_data_in_session = $this->get_submitted_form_data_from_session();
404
-        if (empty($form_data_in_session)) {
405
-            return false;
406
-        }
407
-        $this->receive_form_submission($form_data_in_session);
408
-        add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session'));
409
-        if ($this->form_data_present_in($form_data_in_session)) {
410
-            return true;
411
-        }
412
-        return false;
413
-    }
414
-
415
-
416
-    /**
417
-     * Populates the default data for the form, given an array where keys are
418
-     * the input names, and values are their values (preferably normalized to be their
419
-     * proper PHP types, not all strings... although that should be ok too).
420
-     * Proper subsections are sub-arrays, the key being the subsection's name, and
421
-     * the value being an array formatted in teh same way
422
-     *
423
-     * @param array $default_data
424
-     * @throws EE_Error
425
-     */
426
-    public function populate_defaults($default_data)
427
-    {
428
-        foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
-            if (isset($default_data[ $subsection_name ])) {
430
-                if ($subsection instanceof EE_Form_Input_Base) {
431
-                    $subsection->set_default($default_data[ $subsection_name ]);
432
-                } elseif ($subsection instanceof EE_Form_Section_Proper) {
433
-                    $subsection->populate_defaults($default_data[ $subsection_name ]);
434
-                }
435
-            }
436
-        }
437
-    }
438
-
439
-
440
-    /**
441
-     * returns true if subsection exists
442
-     *
443
-     * @param string $name
444
-     * @return boolean
445
-     */
446
-    public function subsection_exists($name)
447
-    {
448
-        return isset($this->_subsections[ $name ]) ? true : false;
449
-    }
450
-
451
-
452
-    /**
453
-     * Gets the subsection specified by its name
454
-     *
455
-     * @param string  $name
456
-     * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
457
-     *                                                      so that the inputs will be properly configured.
458
-     *                                                      However, some client code may be ok
459
-     *                                                      with construction finalize being called later
460
-     *                                                      (realizing that the subsections' html names
461
-     *                                                      might not be set yet, etc.)
462
-     * @return EE_Form_Section_Base
463
-     * @throws EE_Error
464
-     */
465
-    public function get_subsection($name, $require_construction_to_be_finalized = true)
466
-    {
467
-        if ($require_construction_to_be_finalized) {
468
-            $this->ensure_construct_finalized_called();
469
-        }
470
-        return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
471
-    }
472
-
473
-
474
-    /**
475
-     * Gets all the validatable subsections of this form section
476
-     *
477
-     * @return EE_Form_Section_Validatable[]
478
-     * @throws EE_Error
479
-     */
480
-    public function get_validatable_subsections()
481
-    {
482
-        $validatable_subsections = array();
483
-        foreach ($this->subsections() as $name => $obj) {
484
-            if ($obj instanceof EE_Form_Section_Validatable) {
485
-                $validatable_subsections[ $name ] = $obj;
486
-            }
487
-        }
488
-        return $validatable_subsections;
489
-    }
490
-
491
-
492
-    /**
493
-     * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
494
-     * throw an EE_Error.
495
-     *
496
-     * @param string  $name
497
-     * @param boolean $require_construction_to_be_finalized most client code should
498
-     *                                                      leave this as TRUE so that the inputs will be properly
499
-     *                                                      configured. However, some client code may be ok with
500
-     *                                                      construction finalize being called later
501
-     *                                                      (realizing that the subsections' html names might not be
502
-     *                                                      set yet, etc.)
503
-     * @return EE_Form_Input_Base
504
-     * @throws EE_Error
505
-     */
506
-    public function get_input($name, $require_construction_to_be_finalized = true)
507
-    {
508
-        $subsection = $this->get_subsection(
509
-            $name,
510
-            $require_construction_to_be_finalized
511
-        );
512
-        if (! $subsection instanceof EE_Form_Input_Base) {
513
-            throw new EE_Error(
514
-                sprintf(
515
-                    esc_html__(
516
-                        "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
517
-                        'event_espresso'
518
-                    ),
519
-                    $name,
520
-                    get_class($this),
521
-                    $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
522
-                )
523
-            );
524
-        }
525
-        return $subsection;
526
-    }
527
-
528
-
529
-    /**
530
-     * Like get_input(), gets the proper subsection of the form given the name,
531
-     * otherwise throws an EE_Error
532
-     *
533
-     * @param string  $name
534
-     * @param boolean $require_construction_to_be_finalized most client code should
535
-     *                                                      leave this as TRUE so that the inputs will be properly
536
-     *                                                      configured. However, some client code may be ok with
537
-     *                                                      construction finalize being called later
538
-     *                                                      (realizing that the subsections' html names might not be
539
-     *                                                      set yet, etc.)
540
-     * @return EE_Form_Section_Proper
541
-     * @throws EE_Error
542
-     */
543
-    public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
544
-    {
545
-        $subsection = $this->get_subsection(
546
-            $name,
547
-            $require_construction_to_be_finalized
548
-        );
549
-        if (! $subsection instanceof EE_Form_Section_Proper) {
550
-            throw new EE_Error(
551
-                sprintf(
552
-                    esc_html__(
553
-                        "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
554
-                        'event_espresso'
555
-                    ),
556
-                    $name,
557
-                    get_class($this)
558
-                )
559
-            );
560
-        }
561
-        return $subsection;
562
-    }
563
-
564
-
565
-    /**
566
-     * Gets the value of the specified input. Should be called after receive_form_submission()
567
-     * or populate_defaults() on the form, where the normalized value on the input is set.
568
-     *
569
-     * @param string $name
570
-     * @return mixed depending on the input's type and its normalization strategy
571
-     * @throws EE_Error
572
-     */
573
-    public function get_input_value($name)
574
-    {
575
-        $input = $this->get_input($name);
576
-        return $input->normalized_value();
577
-    }
578
-
579
-
580
-    /**
581
-     * Checks if this form section itself is valid, and then checks its subsections
582
-     *
583
-     * @throws EE_Error
584
-     * @return boolean
585
-     */
586
-    public function is_valid()
587
-    {
588
-        if ($this->is_valid === null) {
589
-            if (! $this->has_received_submission()) {
590
-                throw new EE_Error(
591
-                    sprintf(
592
-                        esc_html__(
593
-                            'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
594
-                            'event_espresso'
595
-                        )
596
-                    )
597
-                );
598
-            }
599
-            if (! parent::is_valid()) {
600
-                $this->is_valid = false;
601
-            } else {
602
-                // ok so no general errors to this entire form section.
603
-                // so let's check the subsections, but only set errors if that hasn't been done yet
604
-                $this->is_valid = true;
605
-                foreach ($this->get_validatable_subsections() as $subsection) {
606
-                    if (! $subsection->is_valid()) {
607
-                        $this->is_valid = false;
608
-                    }
609
-                }
610
-            }
611
-        }
612
-        return $this->is_valid;
613
-    }
614
-
615
-
616
-    /**
617
-     * gets the default name of this form section if none is specified
618
-     *
619
-     * @return void
620
-     */
621
-    protected function _set_default_name_if_empty()
622
-    {
623
-        if (! $this->_name) {
624
-            $classname    = get_class($this);
625
-            $default_name = str_replace('EE_', '', $classname);
626
-            $this->_name  = $default_name;
627
-        }
628
-    }
629
-
630
-
631
-    /**
632
-     * Returns the HTML for the form, except for the form opening and closing tags
633
-     * (as the form section doesn't know where you necessarily want to send the information to),
634
-     * and except for a submit button. Enqueues JS and CSS; if called early enough we will
635
-     * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
636
-     * Not doing_it_wrong because theoretically this CAN be used properly,
637
-     * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
638
-     * any CSS.
639
-     *
640
-     * @throws InvalidArgumentException
641
-     * @throws InvalidInterfaceException
642
-     * @throws InvalidDataTypeException
643
-     * @throws EE_Error
644
-     */
645
-    public function get_html_and_js()
646
-    {
647
-        $this->enqueue_js();
648
-        return $this->get_html();
649
-    }
650
-
651
-
652
-    /**
653
-     * returns HTML for displaying this form section. recursively calls display_section() on all subsections
654
-     *
655
-     * @param bool $display_previously_submitted_data
656
-     * @return string
657
-     * @throws InvalidArgumentException
658
-     * @throws InvalidInterfaceException
659
-     * @throws InvalidDataTypeException
660
-     * @throws EE_Error
661
-     * @throws EE_Error
662
-     * @throws EE_Error
663
-     */
664
-    public function get_html($display_previously_submitted_data = true)
665
-    {
666
-        $this->ensure_construct_finalized_called();
667
-        if ($display_previously_submitted_data) {
668
-            $this->populate_from_session();
669
-        }
670
-        return $this->_form_html_filter
671
-            ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
672
-            : $this->_layout_strategy->layout_form();
673
-    }
674
-
675
-
676
-    /**
677
-     * enqueues JS and CSS for the form.
678
-     * It is preferred to call this before wp_enqueue_scripts so the
679
-     * scripts and styles can be put in the header, but if called later
680
-     * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
681
-     * only be in the header; but in HTML5 its ok in the body.
682
-     * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
683
-     * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
684
-     *
685
-     * @return void
686
-     * @throws EE_Error
687
-     */
688
-    public function enqueue_js()
689
-    {
690
-        $this->_enqueue_and_localize_form_js();
691
-        foreach ($this->subsections() as $subsection) {
692
-            $subsection->enqueue_js();
693
-        }
694
-    }
695
-
696
-
697
-    /**
698
-     * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
699
-     * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
700
-     * the wp_enqueue_scripts hook.
701
-     * However, registering the form js and localizing it can happen when we
702
-     * actually output the form (which is preferred, seeing how teh form's fields
703
-     * could change until it's actually outputted)
704
-     *
705
-     * @param boolean $init_form_validation_automatically whether or not we want the form validation
706
-     *                                                    to be triggered automatically or not
707
-     * @return void
708
-     */
709
-    public static function wp_enqueue_scripts($init_form_validation_automatically = true)
710
-    {
711
-        wp_register_script(
712
-            'ee_form_section_validation',
713
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
714
-            array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715
-            EVENT_ESPRESSO_VERSION,
716
-            true
717
-        );
718
-        wp_localize_script(
719
-            'ee_form_section_validation',
720
-            'ee_form_section_validation_init',
721
-            array('init' => $init_form_validation_automatically ? '1' : '0')
722
-        );
723
-    }
724
-
725
-
726
-    /**
727
-     * gets the variables used by form_section_validation.js.
728
-     * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
729
-     * but before the wordpress hook wp_loaded
730
-     *
731
-     * @throws EE_Error
732
-     */
733
-    public function _enqueue_and_localize_form_js()
734
-    {
735
-        $this->ensure_construct_finalized_called();
736
-        // actually, we don't want to localize just yet. There may be other forms on the page.
737
-        // so we need to add our form section data to a static variable accessible by all form sections
738
-        // and localize it just before the footer
739
-        $this->localize_validation_rules();
740
-        add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
741
-        add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
742
-    }
743
-
744
-
745
-    /**
746
-     * add our form section data to a static variable accessible by all form sections
747
-     *
748
-     * @param bool $return_for_subsection
749
-     * @return void
750
-     * @throws EE_Error
751
-     */
752
-    public function localize_validation_rules($return_for_subsection = false)
753
-    {
754
-        // we only want to localize vars ONCE for the entire form,
755
-        // so if the form section doesn't have a parent, then it must be the top dog
756
-        if ($return_for_subsection || ! $this->parent_section()) {
757
-            EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
758
-                'form_section_id'  => $this->html_id(true),
759
-                'validation_rules' => $this->get_jquery_validation_rules(),
760
-                'other_data'       => $this->get_other_js_data(),
761
-                'errors'           => $this->subsection_validation_errors_by_html_name(),
762
-            );
763
-            EE_Form_Section_Proper::$_scripts_localized                                = true;
764
-        }
765
-    }
766
-
767
-
768
-    /**
769
-     * Gets an array of extra data that will be useful for client-side javascript.
770
-     * This is primarily data added by inputs and forms in addition to any
771
-     * scripts they might enqueue
772
-     *
773
-     * @param array $form_other_js_data
774
-     * @return array
775
-     * @throws EE_Error
776
-     */
777
-    public function get_other_js_data($form_other_js_data = array())
778
-    {
779
-        foreach ($this->subsections() as $subsection) {
780
-            $form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
781
-        }
782
-        return $form_other_js_data;
783
-    }
784
-
785
-
786
-    /**
787
-     * Gets a flat array of inputs for this form section and its subsections.
788
-     * Keys are their form names, and values are the inputs themselves
789
-     *
790
-     * @return EE_Form_Input_Base
791
-     * @throws EE_Error
792
-     */
793
-    public function inputs_in_subsections()
794
-    {
795
-        $inputs = array();
796
-        foreach ($this->subsections() as $subsection) {
797
-            if ($subsection instanceof EE_Form_Input_Base) {
798
-                $inputs[ $subsection->html_name() ] = $subsection;
799
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
800
-                $inputs += $subsection->inputs_in_subsections();
801
-            }
802
-        }
803
-        return $inputs;
804
-    }
805
-
806
-
807
-    /**
808
-     * Gets a flat array of all the validation errors.
809
-     * Keys are html names (because those should be unique)
810
-     * and values are a string of all their validation errors
811
-     *
812
-     * @return string[]
813
-     * @throws EE_Error
814
-     */
815
-    public function subsection_validation_errors_by_html_name()
816
-    {
817
-        $inputs = $this->inputs();
818
-        $errors = array();
819
-        foreach ($inputs as $form_input) {
820
-            if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
-                $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
822
-            }
823
-        }
824
-        return $errors;
825
-    }
826
-
827
-
828
-    /**
829
-     * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
830
-     * Should be setup by each form during the _enqueues_and_localize_form_js
831
-     *
832
-     * @throws InvalidArgumentException
833
-     * @throws InvalidInterfaceException
834
-     * @throws InvalidDataTypeException
835
-     */
836
-    public static function localize_script_for_all_forms()
837
-    {
838
-        // allow inputs and stuff to hook in their JS and stuff here
839
-        do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
840
-        EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
841
-        $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
843
-            : 'wp_default';
844
-        EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
845
-        wp_enqueue_script('ee_form_section_validation');
846
-        wp_localize_script(
847
-            'ee_form_section_validation',
848
-            'ee_form_section_vars',
849
-            EE_Form_Section_Proper::$_js_localization
850
-        );
851
-    }
852
-
853
-
854
-    /**
855
-     * ensure_scripts_localized
856
-     *
857
-     * @throws EE_Error
858
-     */
859
-    public function ensure_scripts_localized()
860
-    {
861
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
862
-            $this->_enqueue_and_localize_form_js();
863
-        }
864
-    }
865
-
866
-
867
-    /**
868
-     * Gets the hard-coded validation error messages to be used in the JS. The convention
869
-     * is that the key here should be the same as the custom validation rule put in the JS file
870
-     *
871
-     * @return array keys are custom validation rules, and values are internationalized strings
872
-     */
873
-    private static function _get_localized_error_messages()
874
-    {
875
-        return array(
876
-            'validUrl' => wp_strip_all_tags(__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso')),
877
-            'regex'    => wp_strip_all_tags(__('Please check your input', 'event_espresso'))
878
-        );
879
-    }
880
-
881
-
882
-    /**
883
-     * @return array
884
-     */
885
-    public static function js_localization()
886
-    {
887
-        return self::$_js_localization;
888
-    }
889
-
890
-
891
-    /**
892
-     * @return void
893
-     */
894
-    public static function reset_js_localization()
895
-    {
896
-        self::$_js_localization = array();
897
-    }
898
-
899
-
900
-    /**
901
-     * Gets the JS to put inside the jquery validation rules for subsection of this form section.
902
-     * See parent function for more...
903
-     *
904
-     * @return array
905
-     * @throws EE_Error
906
-     */
907
-    public function get_jquery_validation_rules()
908
-    {
909
-        $jquery_validation_rules = array();
910
-        foreach ($this->get_validatable_subsections() as $subsection) {
911
-            $jquery_validation_rules = array_merge(
912
-                $jquery_validation_rules,
913
-                $subsection->get_jquery_validation_rules()
914
-            );
915
-        }
916
-        return $jquery_validation_rules;
917
-    }
918
-
919
-
920
-    /**
921
-     * Sanitizes all the data and sets the sanitized value of each field
922
-     *
923
-     * @param array $req_data like $_POST
924
-     * @return void
925
-     * @throws EE_Error
926
-     */
927
-    protected function _normalize($req_data)
928
-    {
929
-        $this->_received_submission = true;
930
-        $this->_validation_errors   = array();
931
-        foreach ($this->get_validatable_subsections() as $subsection) {
932
-            try {
933
-                $subsection->_normalize($req_data);
934
-            } catch (EE_Validation_Error $e) {
935
-                $subsection->add_validation_error($e);
936
-            }
937
-        }
938
-    }
939
-
940
-
941
-    /**
942
-     * Performs validation on this form section and its subsections.
943
-     * For each subsection,
944
-     * calls _validate_{subsection_name} on THIS form (if the function exists)
945
-     * and passes it the subsection, then calls _validate on that subsection.
946
-     * If you need to perform validation on the form as a whole (considering multiple)
947
-     * you would be best to override this _validate method,
948
-     * calling parent::_validate() first.
949
-     *
950
-     * @throws EE_Error
951
-     */
952
-    protected function _validate()
953
-    {
954
-        // reset the cache of whether this form is valid or not- we're re-validating it now
955
-        $this->is_valid = null;
956
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
-            if (method_exists($this, '_validate_' . $subsection_name)) {
958
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
959
-            }
960
-            $subsection->_validate();
961
-        }
962
-    }
963
-
964
-
965
-    /**
966
-     * Gets all the validated inputs for the form section
967
-     *
968
-     * @return array
969
-     * @throws EE_Error
970
-     */
971
-    public function valid_data()
972
-    {
973
-        $inputs = array();
974
-        foreach ($this->subsections() as $subsection_name => $subsection) {
975
-            if ($subsection instanceof EE_Form_Section_Proper) {
976
-                $inputs[ $subsection_name ] = $subsection->valid_data();
977
-            } elseif ($subsection instanceof EE_Form_Input_Base) {
978
-                $inputs[ $subsection_name ] = $subsection->normalized_value();
979
-            }
980
-        }
981
-        return $inputs;
982
-    }
983
-
984
-
985
-    /**
986
-     * Gets all the inputs on this form section
987
-     *
988
-     * @return EE_Form_Input_Base[]
989
-     * @throws EE_Error
990
-     */
991
-    public function inputs()
992
-    {
993
-        $inputs = array();
994
-        foreach ($this->subsections() as $subsection_name => $subsection) {
995
-            if ($subsection instanceof EE_Form_Input_Base) {
996
-                $inputs[ $subsection_name ] = $subsection;
997
-            }
998
-        }
999
-        return $inputs;
1000
-    }
1001
-
1002
-
1003
-    /**
1004
-     * Gets all the subsections which are a proper form
1005
-     *
1006
-     * @return EE_Form_Section_Proper[]
1007
-     * @throws EE_Error
1008
-     */
1009
-    public function subforms()
1010
-    {
1011
-        $form_sections = array();
1012
-        foreach ($this->subsections() as $name => $obj) {
1013
-            if ($obj instanceof EE_Form_Section_Proper) {
1014
-                $form_sections[ $name ] = $obj;
1015
-            }
1016
-        }
1017
-        return $form_sections;
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * Gets all the subsections (inputs, proper subsections, or html-only sections).
1023
-     * Consider using inputs() or subforms()
1024
-     * if you only want form inputs or proper form sections.
1025
-     *
1026
-     * @param boolean $require_construction_to_be_finalized most client code should
1027
-     *                                                      leave this as TRUE so that the inputs will be properly
1028
-     *                                                      configured. However, some client code may be ok with
1029
-     *                                                      construction finalize being called later
1030
-     *                                                      (realizing that the subsections' html names might not be
1031
-     *                                                      set yet, etc.)
1032
-     * @return EE_Form_Section_Proper[]
1033
-     * @throws EE_Error
1034
-     */
1035
-    public function subsections($require_construction_to_be_finalized = true)
1036
-    {
1037
-        if ($require_construction_to_be_finalized) {
1038
-            $this->ensure_construct_finalized_called();
1039
-        }
1040
-        return $this->_subsections;
1041
-    }
1042
-
1043
-
1044
-    /**
1045
-     * Returns whether this form has any subforms or inputs
1046
-     * @return bool
1047
-     */
1048
-    public function hasSubsections()
1049
-    {
1050
-        return ! empty($this->_subsections);
1051
-    }
1052
-
1053
-
1054
-    /**
1055
-     * Returns a simple array where keys are input names, and values are their normalized
1056
-     * values. (Similar to calling get_input_value on inputs)
1057
-     *
1058
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1059
-     *                                        or just this forms' direct children inputs
1060
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1061
-     *                                        or allow multidimensional array
1062
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1063
-     *                                        with array keys being input names
1064
-     *                                        (regardless of whether they are from a subsection or not),
1065
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1066
-     *                                        where keys are always subsection names and values are either
1067
-     *                                        the input's normalized value, or an array like the top-level array
1068
-     * @throws EE_Error
1069
-     */
1070
-    public function input_values($include_subform_inputs = false, $flatten = false)
1071
-    {
1072
-        return $this->_input_values(false, $include_subform_inputs, $flatten);
1073
-    }
1074
-
1075
-
1076
-    /**
1077
-     * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1078
-     * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1079
-     * is not necessarily the value we want to display to users. This creates an array
1080
-     * where keys are the input names, and values are their display values
1081
-     *
1082
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1083
-     *                                        or just this forms' direct children inputs
1084
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1085
-     *                                        or allow multidimensional array
1086
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1087
-     *                                        with array keys being input names
1088
-     *                                        (regardless of whether they are from a subsection or not),
1089
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1090
-     *                                        where keys are always subsection names and values are either
1091
-     *                                        the input's normalized value, or an array like the top-level array
1092
-     * @throws EE_Error
1093
-     */
1094
-    public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1095
-    {
1096
-        return $this->_input_values(true, $include_subform_inputs, $flatten);
1097
-    }
1098
-
1099
-
1100
-    /**
1101
-     * Gets the input values from the form
1102
-     *
1103
-     * @param boolean $pretty                 Whether to retrieve the pretty value,
1104
-     *                                        or just the normalized value
1105
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1106
-     *                                        or just this forms' direct children inputs
1107
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1108
-     *                                        or allow multidimensional array
1109
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1110
-     *                                        input names (regardless of whether they are from a subsection or not),
1111
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1112
-     *                                        where keys are always subsection names and values are either
1113
-     *                                        the input's normalized value, or an array like the top-level array
1114
-     * @throws EE_Error
1115
-     */
1116
-    public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1117
-    {
1118
-        $input_values = array();
1119
-        foreach ($this->subsections() as $subsection_name => $subsection) {
1120
-            if ($subsection instanceof EE_Form_Input_Base) {
1121
-                $input_values[ $subsection_name ] = $pretty
1122
-                    ? $subsection->pretty_value()
1123
-                    : $subsection->normalized_value();
1124
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1125
-                $subform_input_values = $subsection->_input_values(
1126
-                    $pretty,
1127
-                    $include_subform_inputs,
1128
-                    $flatten
1129
-                );
1130
-                if ($flatten) {
1131
-                    $input_values = array_merge($input_values, $subform_input_values);
1132
-                } else {
1133
-                    $input_values[ $subsection_name ] = $subform_input_values;
1134
-                }
1135
-            }
1136
-        }
1137
-        return $input_values;
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * Gets the originally submitted input values from the form
1143
-     *
1144
-     * @param boolean $include_subforms  Whether to include inputs from subforms,
1145
-     *                                   or just this forms' direct children inputs
1146
-     * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1147
-     *                                   with array keys being input names
1148
-     *                                   (regardless of whether they are from a subsection or not),
1149
-     *                                   and if $flatten is FALSE it can be a multidimensional array
1150
-     *                                   where keys are always subsection names and values are either
1151
-     *                                   the input's normalized value, or an array like the top-level array
1152
-     * @throws EE_Error
1153
-     */
1154
-    public function submitted_values($include_subforms = false)
1155
-    {
1156
-        $submitted_values = array();
1157
-        foreach ($this->subsections() as $subsection) {
1158
-            if ($subsection instanceof EE_Form_Input_Base) {
1159
-                // is this input part of an array of inputs?
1160
-                if (strpos($subsection->html_name(), '[') !== false) {
1161
-                    $full_input_name  = EEH_Array::convert_array_values_to_keys(
1162
-                        explode(
1163
-                            '[',
1164
-                            str_replace(']', '', $subsection->html_name())
1165
-                        ),
1166
-                        $subsection->raw_value()
1167
-                    );
1168
-                    $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169
-                } else {
1170
-                    $submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1171
-                }
1172
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173
-                $subform_input_values = $subsection->submitted_values($include_subforms);
1174
-                $submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1175
-            }
1176
-        }
1177
-        return $submitted_values;
1178
-    }
1179
-
1180
-
1181
-    /**
1182
-     * Indicates whether or not this form has received a submission yet
1183
-     * (ie, had receive_form_submission called on it yet)
1184
-     *
1185
-     * @return boolean
1186
-     * @throws EE_Error
1187
-     */
1188
-    public function has_received_submission()
1189
-    {
1190
-        $this->ensure_construct_finalized_called();
1191
-        return $this->_received_submission;
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * Equivalent to passing 'exclude' in the constructor's options array.
1197
-     * Removes the listed inputs from the form
1198
-     *
1199
-     * @param array $inputs_to_exclude values are the input names
1200
-     * @return void
1201
-     */
1202
-    public function exclude(array $inputs_to_exclude = array())
1203
-    {
1204
-        foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
-            unset($this->_subsections[ $input_to_exclude_name ]);
1206
-        }
1207
-    }
1208
-
1209
-
1210
-    /**
1211
-     * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy.
1212
-     * @param array $inputs_to_hide
1213
-     * @throws EE_Error
1214
-     */
1215
-    public function hide(array $inputs_to_hide = array())
1216
-    {
1217
-        foreach ($inputs_to_hide as $input_to_hide) {
1218
-            $input = $this->get_input($input_to_hide);
1219
-            $input->set_display_strategy(new EE_Hidden_Display_Strategy());
1220
-        }
1221
-    }
1222
-
1223
-
1224
-    /**
1225
-     * add_subsections
1226
-     * Adds the listed subsections to the form section.
1227
-     * If $subsection_name_to_target is provided,
1228
-     * then new subsections are added before or after that subsection,
1229
-     * otherwise to the start or end of the entire subsections array.
1230
-     *
1231
-     * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1232
-     *                                                          where keys are their names
1233
-     * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1234
-     *                                                          should be added before or after
1235
-     *                                                          IF $subsection_name_to_target is null,
1236
-     *                                                          then $new_subsections will be added to
1237
-     *                                                          the beginning or end of the entire subsections array
1238
-     * @param boolean                $add_before                whether to add $new_subsections, before or after
1239
-     *                                                          $subsection_name_to_target,
1240
-     *                                                          or if $subsection_name_to_target is null,
1241
-     *                                                          before or after entire subsections array
1242
-     * @return void
1243
-     * @throws EE_Error
1244
-     */
1245
-    public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1246
-    {
1247
-        foreach ($new_subsections as $subsection_name => $subsection) {
1248
-            if (! $subsection instanceof EE_Form_Section_Base) {
1249
-                EE_Error::add_error(
1250
-                    sprintf(
1251
-                        esc_html__(
1252
-                            "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1253
-                            'event_espresso'
1254
-                        ),
1255
-                        get_class($subsection),
1256
-                        $subsection_name,
1257
-                        $this->name()
1258
-                    )
1259
-                );
1260
-                unset($new_subsections[ $subsection_name ]);
1261
-            }
1262
-        }
1263
-        $this->_subsections = EEH_Array::insert_into_array(
1264
-            $this->_subsections,
1265
-            $new_subsections,
1266
-            $subsection_name_to_target,
1267
-            $add_before
1268
-        );
1269
-        if ($this->_construction_finalized) {
1270
-            foreach ($this->_subsections as $name => $subsection) {
1271
-                $subsection->_construct_finalize($this, $name);
1272
-            }
1273
-        }
1274
-    }
1275
-
1276
-
1277
-    /**
1278
-     * @param string $subsection_name
1279
-     * @param bool   $recursive
1280
-     * @return bool
1281
-     */
1282
-    public function has_subsection($subsection_name, $recursive = false)
1283
-    {
1284
-        foreach ($this->_subsections as $name => $subsection) {
1285
-            if ($name === $subsection_name
1286
-                || (
1287
-                    $recursive
1288
-                    && $subsection instanceof EE_Form_Section_Proper
1289
-                    && $subsection->has_subsection($subsection_name, $recursive)
1290
-                )
1291
-            ) {
1292
-                return true;
1293
-            }
1294
-        }
1295
-        return false;
1296
-    }
1297
-
1298
-
1299
-
1300
-    /**
1301
-     * Just gets all validatable subsections to clean their sensitive data
1302
-     *
1303
-     * @throws EE_Error
1304
-     */
1305
-    public function clean_sensitive_data()
1306
-    {
1307
-        foreach ($this->get_validatable_subsections() as $subsection) {
1308
-            $subsection->clean_sensitive_data();
1309
-        }
1310
-    }
1311
-
1312
-
1313
-    /**
1314
-     * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1315
-     * @param string                           $form_submission_error_message
1316
-     * @param EE_Form_Section_Validatable $form_section unused
1317
-     * @throws EE_Error
1318
-     */
1319
-    public function set_submission_error_message(
1320
-        $form_submission_error_message = ''
1321
-    ) {
1322
-        $this->_form_submission_error_message = ! empty($form_submission_error_message)
1323
-            ? $form_submission_error_message
1324
-            : $this->getAllValidationErrorsString();
1325
-    }
1326
-
1327
-
1328
-    /**
1329
-     * Returns the cached error message. A default value is set for this during _validate(),
1330
-     * (called during receive_form_submission) but it can be explicitly set using
1331
-     * set_submission_error_message
1332
-     *
1333
-     * @return string
1334
-     */
1335
-    public function submission_error_message()
1336
-    {
1337
-        return $this->_form_submission_error_message;
1338
-    }
1339
-
1340
-
1341
-    /**
1342
-     * Sets a message to display if the data submitted to the form was valid.
1343
-     * @param string $form_submission_success_message
1344
-     */
1345
-    public function set_submission_success_message($form_submission_success_message = '')
1346
-    {
1347
-        $this->_form_submission_success_message = ! empty($form_submission_success_message)
1348
-            ? $form_submission_success_message
1349
-            : esc_html__('Form submitted successfully', 'event_espresso');
1350
-    }
1351
-
1352
-
1353
-    /**
1354
-     * Gets a message appropriate for display when the form is correctly submitted
1355
-     * @return string
1356
-     */
1357
-    public function submission_success_message()
1358
-    {
1359
-        return $this->_form_submission_success_message;
1360
-    }
1361
-
1362
-
1363
-    /**
1364
-     * Returns the prefix that should be used on child of this form section for
1365
-     * their html names. If this form section itself has a parent, prepends ITS
1366
-     * prefix onto this form section's prefix. Used primarily by
1367
-     * EE_Form_Input_Base::_set_default_html_name_if_empty
1368
-     *
1369
-     * @return string
1370
-     * @throws EE_Error
1371
-     */
1372
-    public function html_name_prefix()
1373
-    {
1374
-        if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1375
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1376
-        }
1377
-        return $this->name();
1378
-    }
1379
-
1380
-
1381
-    /**
1382
-     * Gets the name, but first checks _construct_finalize has been called. If not,
1383
-     * calls it (assumes there is no parent and that we want the name to be whatever
1384
-     * was set, which is probably nothing, or the classname)
1385
-     *
1386
-     * @return string
1387
-     * @throws EE_Error
1388
-     */
1389
-    public function name()
1390
-    {
1391
-        $this->ensure_construct_finalized_called();
1392
-        return parent::name();
1393
-    }
1394
-
1395
-
1396
-    /**
1397
-     * @return EE_Form_Section_Proper
1398
-     * @throws EE_Error
1399
-     */
1400
-    public function parent_section()
1401
-    {
1402
-        $this->ensure_construct_finalized_called();
1403
-        return parent::parent_section();
1404
-    }
1405
-
1406
-
1407
-    /**
1408
-     * make sure construction finalized was called, otherwise children might not be ready
1409
-     *
1410
-     * @return void
1411
-     * @throws EE_Error
1412
-     */
1413
-    public function ensure_construct_finalized_called()
1414
-    {
1415
-        if (! $this->_construction_finalized) {
1416
-            $this->_construct_finalize($this->_parent_section, $this->_name);
1417
-        }
1418
-    }
1419
-
1420
-
1421
-    /**
1422
-     * Checks if any of this form section's inputs, or any of its children's inputs,
1423
-     * are in teh form data. If any are found, returns true. Else false
1424
-     *
1425
-     * @param array $req_data
1426
-     * @return boolean
1427
-     * @throws EE_Error
1428
-     */
1429
-    public function form_data_present_in($req_data = null)
1430
-    {
1431
-        $req_data = $this->getCachedRequest($req_data);
1432
-        foreach ($this->subsections() as $subsection) {
1433
-            if ($subsection instanceof EE_Form_Input_Base) {
1434
-                if ($subsection->form_data_present_in($req_data)) {
1435
-                    return true;
1436
-                }
1437
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
1438
-                if ($subsection->form_data_present_in($req_data)) {
1439
-                    return true;
1440
-                }
1441
-            }
1442
-        }
1443
-        return false;
1444
-    }
1445
-
1446
-
1447
-    /**
1448
-     * Gets validation errors for this form section and subsections
1449
-     * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1450
-     * gets the validation errors for ALL subsection
1451
-     *
1452
-     * @return EE_Validation_Error[]
1453
-     * @throws EE_Error
1454
-     */
1455
-    public function get_validation_errors_accumulated()
1456
-    {
1457
-        $validation_errors = $this->get_validation_errors();
1458
-        foreach ($this->get_validatable_subsections() as $subsection) {
1459
-            if ($subsection instanceof EE_Form_Section_Proper) {
1460
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1461
-            } else {
1462
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors();
1463
-            }
1464
-            if ($validation_errors_on_this_subsection) {
1465
-                $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1466
-            }
1467
-        }
1468
-        return $validation_errors;
1469
-    }
1470
-
1471
-    /**
1472
-     * Fetch validation errors from children and grandchildren and puts them in a single string.
1473
-     * This traverses the form section tree to generate this, but you probably want to instead use
1474
-     * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1475
-     *
1476
-     * @return string
1477
-     * @since 4.9.59.p
1478
-     */
1479
-    protected function getAllValidationErrorsString()
1480
-    {
1481
-        $submission_error_messages = array();
1482
-        // bad, bad, bad registrant
1483
-        foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1484
-            if ($validation_error instanceof EE_Validation_Error) {
1485
-                $form_section = $validation_error->get_form_section();
1486
-                if ($form_section instanceof EE_Form_Input_Base) {
1487
-                    $label = $validation_error->get_form_section()->html_label_text();
1488
-                } elseif ($form_section instanceof EE_Form_Section_Validatable) {
1489
-                    $label = $validation_error->get_form_section()->name();
1490
-                } else {
1491
-                    $label = esc_html__('Unknown', 'event_espresso');
1492
-                }
1493
-                $submission_error_messages[] = sprintf(
1494
-                    __('%s : %s', 'event_espresso'),
1495
-                    $label,
1496
-                    $validation_error->getMessage()
1497
-                );
1498
-            }
1499
-        }
1500
-        return implode('<br', $submission_error_messages);
1501
-    }
1502
-
1503
-
1504
-    /**
1505
-     * This isn't just the name of an input, it's a path pointing to an input. The
1506
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
1507
-     * dot-dot-slash (../) means to ascend into the parent section.
1508
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1509
-     * which will be returned.
1510
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1511
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1512
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1513
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1514
-     * Etc
1515
-     *
1516
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1517
-     * @return EE_Form_Section_Base
1518
-     * @throws EE_Error
1519
-     */
1520
-    public function find_section_from_path($form_section_path)
1521
-    {
1522
-        // check if we can find the input from purely going straight up the tree
1523
-        $input = parent::find_section_from_path($form_section_path);
1524
-        if ($input instanceof EE_Form_Section_Base) {
1525
-            return $input;
1526
-        }
1527
-        $next_slash_pos = strpos($form_section_path, '/');
1528
-        if ($next_slash_pos !== false) {
1529
-            $child_section_name = substr($form_section_path, 0, $next_slash_pos);
1530
-            $subpath            = substr($form_section_path, $next_slash_pos + 1);
1531
-        } else {
1532
-            $child_section_name = $form_section_path;
1533
-            $subpath            = '';
1534
-        }
1535
-        $child_section = $this->get_subsection($child_section_name);
1536
-        if ($child_section instanceof EE_Form_Section_Base) {
1537
-            return $child_section->find_section_from_path($subpath);
1538
-        }
1539
-        return null;
1540
-    }
17
+	const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
+
19
+	/**
20
+	 * Subsections
21
+	 *
22
+	 * @var EE_Form_Section_Validatable[]
23
+	 */
24
+	protected $_subsections = array();
25
+
26
+	/**
27
+	 * Strategy for laying out the form
28
+	 *
29
+	 * @var EE_Form_Section_Layout_Base
30
+	 */
31
+	protected $_layout_strategy;
32
+
33
+	/**
34
+	 * Whether or not this form has received and validated a form submission yet
35
+	 *
36
+	 * @var boolean
37
+	 */
38
+	protected $_received_submission = false;
39
+
40
+	/**
41
+	 * message displayed to users upon successful form submission
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $_form_submission_success_message = '';
46
+
47
+	/**
48
+	 * message displayed to users upon unsuccessful form submission
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $_form_submission_error_message = '';
53
+
54
+	/**
55
+	 * @var array like $_REQUEST
56
+	 */
57
+	protected $cached_request_data;
58
+
59
+	/**
60
+	 * Stores whether this form (and its sub-sections) were found to be valid or not.
61
+	 * Starts off as null, but once the form is validated, it set to either true or false
62
+	 * @var boolean|null
63
+	 */
64
+	protected $is_valid;
65
+
66
+	/**
67
+	 * Stores all the data that will localized for form validation
68
+	 *
69
+	 * @var array
70
+	 */
71
+	static protected $_js_localization = array();
72
+
73
+	/**
74
+	 * whether or not the form's localized validation JS vars have been set
75
+	 *
76
+	 * @type boolean
77
+	 */
78
+	static protected $_scripts_localized = false;
79
+
80
+
81
+	/**
82
+	 * when constructing a proper form section, calls _construct_finalize on children
83
+	 * so that they know who their parent is, and what name they've been given.
84
+	 *
85
+	 * @param array[] $options_array   {
86
+	 * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
+	 * @type          $include         string[] numerically-indexed where values are section names to be included,
88
+	 *                                 and in that order. This is handy if you want
89
+	 *                                 the subsections to be ordered differently than the default, and if you override
90
+	 *                                 which fields are shown
91
+	 * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
+	 *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
+	 *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
+	 *                                 items from that list of inclusions)
95
+	 * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
+	 *                                 } @see EE_Form_Section_Validatable::__construct()
97
+	 * @throws EE_Error
98
+	 */
99
+	public function __construct($options_array = array())
100
+	{
101
+		$options_array = (array) apply_filters(
102
+			'FHEE__EE_Form_Section_Proper___construct__options_array',
103
+			$options_array,
104
+			$this
105
+		);
106
+		// call parent first, as it may be setting the name
107
+		parent::__construct($options_array);
108
+		// if they've included subsections in the constructor, add them now
109
+		if (isset($options_array['include'])) {
110
+			// we are going to make sure we ONLY have those subsections to include
111
+			// AND we are going to make sure they're in that specified order
112
+			$reordered_subsections = array();
113
+			foreach ($options_array['include'] as $input_name) {
114
+				if (isset($this->_subsections[ $input_name ])) {
115
+					$reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
+				}
117
+			}
118
+			$this->_subsections = $reordered_subsections;
119
+		}
120
+		if (isset($options_array['exclude'])) {
121
+			$exclude            = $options_array['exclude'];
122
+			$this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
+		}
124
+		if (isset($options_array['layout_strategy'])) {
125
+			$this->_layout_strategy = $options_array['layout_strategy'];
126
+		}
127
+		if (! $this->_layout_strategy) {
128
+			$this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
+		}
130
+		$this->_layout_strategy->_construct_finalize($this);
131
+		// ok so we are definitely going to want the forms JS,
132
+		// so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
+			// ok so they've constructed this object after when they should have.
135
+			// just enqueue the generic form scripts and initialize the form immediately in the JS
136
+			EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
+		} else {
138
+			add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
+			add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
+		}
141
+		add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
+		/**
143
+		 * Gives other plugins a chance to hook in before construct finalize is called.
144
+		 * The form probably doesn't yet have a parent form section.
145
+		 * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
+		 * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
+		 * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
+		 *
149
+		 * @since 4.9.32
150
+		 * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
+		 *                                              except maybe calling _construct_finalize has been done
152
+		 * @param array                  $options_array options passed into the constructor
153
+		 */
154
+		do_action(
155
+			'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
+			$this,
157
+			$options_array
158
+		);
159
+		if (isset($options_array['name'])) {
160
+			$this->_construct_finalize(null, $options_array['name']);
161
+		}
162
+	}
163
+
164
+
165
+	/**
166
+	 * Finishes construction given the parent form section and this form section's name
167
+	 *
168
+	 * @param EE_Form_Section_Proper $parent_form_section
169
+	 * @param string                 $name
170
+	 * @throws EE_Error
171
+	 */
172
+	public function _construct_finalize($parent_form_section, $name)
173
+	{
174
+		parent::_construct_finalize($parent_form_section, $name);
175
+		$this->_set_default_name_if_empty();
176
+		$this->_set_default_html_id_if_empty();
177
+		foreach ($this->_subsections as $subsection_name => $subsection) {
178
+			if ($subsection instanceof EE_Form_Section_Base) {
179
+				$subsection->_construct_finalize($this, $subsection_name);
180
+			} else {
181
+				throw new EE_Error(
182
+					sprintf(
183
+						esc_html__(
184
+							'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
+							'event_espresso'
186
+						),
187
+						$subsection_name,
188
+						get_class($this),
189
+						$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
+					)
191
+				);
192
+			}
193
+		}
194
+		/**
195
+		 * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
+		 * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
+		 * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
+		 * This might only happen just before displaying the form, or just before it receives form submission data.
199
+		 * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
+		 * ensured it has a name, HTML IDs, etc
201
+		 *
202
+		 * @param EE_Form_Section_Proper      $this
203
+		 * @param EE_Form_Section_Proper|null $parent_form_section
204
+		 * @param string                      $name
205
+		 */
206
+		do_action(
207
+			'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
+			$this,
209
+			$parent_form_section,
210
+			$name
211
+		);
212
+	}
213
+
214
+
215
+	/**
216
+	 * Gets the layout strategy for this form section
217
+	 *
218
+	 * @return EE_Form_Section_Layout_Base
219
+	 */
220
+	public function get_layout_strategy()
221
+	{
222
+		return $this->_layout_strategy;
223
+	}
224
+
225
+
226
+	/**
227
+	 * Gets the HTML for a single input for this form section according
228
+	 * to the layout strategy
229
+	 *
230
+	 * @param EE_Form_Input_Base $input
231
+	 * @return string
232
+	 */
233
+	public function get_html_for_input($input)
234
+	{
235
+		return $this->_layout_strategy->layout_input($input);
236
+	}
237
+
238
+
239
+	/**
240
+	 * was_submitted - checks if form inputs are present in request data
241
+	 * Basically an alias for form_data_present_in() (which is used by both
242
+	 * proper form sections and form inputs)
243
+	 *
244
+	 * @param null $form_data
245
+	 * @return boolean
246
+	 * @throws EE_Error
247
+	 */
248
+	public function was_submitted($form_data = null)
249
+	{
250
+		return $this->form_data_present_in($form_data);
251
+	}
252
+
253
+	/**
254
+	 * Gets the cached request data; but if there is none, or $req_data was set with
255
+	 * something different, refresh the cache, and then return it
256
+	 * @param null $req_data
257
+	 * @return array
258
+	 */
259
+	protected function getCachedRequest($req_data = null)
260
+	{
261
+		if ($this->cached_request_data === null
262
+			|| (
263
+				$req_data !== null &&
264
+				$req_data !== $this->cached_request_data
265
+			)
266
+		) {
267
+			$req_data = apply_filters(
268
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
269
+				$req_data,
270
+				$this
271
+			);
272
+			if ($req_data === null) {
273
+				$req_data = array_merge($_GET, $_POST);
274
+			}
275
+			$req_data = apply_filters(
276
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
277
+				$req_data,
278
+				$this
279
+			);
280
+			$this->cached_request_data = (array) $req_data;
281
+		}
282
+		return $this->cached_request_data;
283
+	}
284
+
285
+
286
+	/**
287
+	 * After the form section is initially created, call this to sanitize the data in the submission
288
+	 * which relates to this form section, validate it, and set it as properties on the form.
289
+	 *
290
+	 * @param array|null $req_data should usually be $_POST (the default).
291
+	 *                             However, you CAN supply a different array.
292
+	 *                             Consider using set_defaults() instead however.
293
+	 *                             (If you rendered the form in the page using echo $form_x->get_html()
294
+	 *                             the inputs will have the correct name in the request data for this function
295
+	 *                             to find them and populate the form with them.
296
+	 *                             If you have a flat form (with only input subsections),
297
+	 *                             you can supply a flat array where keys
298
+	 *                             are the form input names and values are their values)
299
+	 * @param boolean    $validate whether or not to perform validation on this data. Default is,
300
+	 *                             of course, to validate that data, and set errors on the invalid values.
301
+	 *                             But if the data has already been validated
302
+	 *                             (eg you validated the data then stored it in the DB)
303
+	 *                             you may want to skip this step.
304
+	 * @throws InvalidArgumentException
305
+	 * @throws InvalidInterfaceException
306
+	 * @throws InvalidDataTypeException
307
+	 * @throws EE_Error
308
+	 */
309
+	public function receive_form_submission($req_data = null, $validate = true)
310
+	{
311
+		$req_data = $this->getCachedRequest($req_data);
312
+		$this->_normalize($req_data);
313
+		if ($validate) {
314
+			$this->_validate();
315
+			// if it's invalid, we're going to want to re-display so remember what they submitted
316
+			if (! $this->is_valid()) {
317
+				$this->store_submitted_form_data_in_session();
318
+			}
319
+		}
320
+		if ($this->submission_error_message() === '' && ! $this->is_valid()) {
321
+			$this->set_submission_error_message();
322
+		}
323
+		do_action(
324
+			'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
325
+			$req_data,
326
+			$this,
327
+			$validate
328
+		);
329
+	}
330
+
331
+
332
+	/**
333
+	 * caches the originally submitted input values in the session
334
+	 * so that they can be used to repopulate the form if it failed validation
335
+	 *
336
+	 * @return boolean whether or not the data was successfully stored in the session
337
+	 * @throws InvalidArgumentException
338
+	 * @throws InvalidInterfaceException
339
+	 * @throws InvalidDataTypeException
340
+	 * @throws EE_Error
341
+	 */
342
+	protected function store_submitted_form_data_in_session()
343
+	{
344
+		return EE_Registry::instance()->SSN->set_session_data(
345
+			array(
346
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
347
+			)
348
+		);
349
+	}
350
+
351
+
352
+	/**
353
+	 * retrieves the originally submitted input values in the session
354
+	 * so that they can be used to repopulate the form if it failed validation
355
+	 *
356
+	 * @return array
357
+	 * @throws InvalidArgumentException
358
+	 * @throws InvalidInterfaceException
359
+	 * @throws InvalidDataTypeException
360
+	 */
361
+	protected function get_submitted_form_data_from_session()
362
+	{
363
+		$session = EE_Registry::instance()->SSN;
364
+		if ($session instanceof EE_Session) {
365
+			return $session->get_session_data(
366
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
367
+			);
368
+		}
369
+		return array();
370
+	}
371
+
372
+
373
+	/**
374
+	 * flushed the originally submitted input values from the session
375
+	 *
376
+	 * @return boolean whether or not the data was successfully removed from the session
377
+	 * @throws InvalidArgumentException
378
+	 * @throws InvalidInterfaceException
379
+	 * @throws InvalidDataTypeException
380
+	 */
381
+	public static function flush_submitted_form_data_from_session()
382
+	{
383
+		return EE_Registry::instance()->SSN->reset_data(
384
+			array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
385
+		);
386
+	}
387
+
388
+
389
+	/**
390
+	 * Populates this form and its subsections with data from the session.
391
+	 * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
392
+	 * validation errors when displaying too)
393
+	 * Returns true if the form was populated from the session, false otherwise
394
+	 *
395
+	 * @return boolean
396
+	 * @throws InvalidArgumentException
397
+	 * @throws InvalidInterfaceException
398
+	 * @throws InvalidDataTypeException
399
+	 * @throws EE_Error
400
+	 */
401
+	public function populate_from_session()
402
+	{
403
+		$form_data_in_session = $this->get_submitted_form_data_from_session();
404
+		if (empty($form_data_in_session)) {
405
+			return false;
406
+		}
407
+		$this->receive_form_submission($form_data_in_session);
408
+		add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session'));
409
+		if ($this->form_data_present_in($form_data_in_session)) {
410
+			return true;
411
+		}
412
+		return false;
413
+	}
414
+
415
+
416
+	/**
417
+	 * Populates the default data for the form, given an array where keys are
418
+	 * the input names, and values are their values (preferably normalized to be their
419
+	 * proper PHP types, not all strings... although that should be ok too).
420
+	 * Proper subsections are sub-arrays, the key being the subsection's name, and
421
+	 * the value being an array formatted in teh same way
422
+	 *
423
+	 * @param array $default_data
424
+	 * @throws EE_Error
425
+	 */
426
+	public function populate_defaults($default_data)
427
+	{
428
+		foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
+			if (isset($default_data[ $subsection_name ])) {
430
+				if ($subsection instanceof EE_Form_Input_Base) {
431
+					$subsection->set_default($default_data[ $subsection_name ]);
432
+				} elseif ($subsection instanceof EE_Form_Section_Proper) {
433
+					$subsection->populate_defaults($default_data[ $subsection_name ]);
434
+				}
435
+			}
436
+		}
437
+	}
438
+
439
+
440
+	/**
441
+	 * returns true if subsection exists
442
+	 *
443
+	 * @param string $name
444
+	 * @return boolean
445
+	 */
446
+	public function subsection_exists($name)
447
+	{
448
+		return isset($this->_subsections[ $name ]) ? true : false;
449
+	}
450
+
451
+
452
+	/**
453
+	 * Gets the subsection specified by its name
454
+	 *
455
+	 * @param string  $name
456
+	 * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
457
+	 *                                                      so that the inputs will be properly configured.
458
+	 *                                                      However, some client code may be ok
459
+	 *                                                      with construction finalize being called later
460
+	 *                                                      (realizing that the subsections' html names
461
+	 *                                                      might not be set yet, etc.)
462
+	 * @return EE_Form_Section_Base
463
+	 * @throws EE_Error
464
+	 */
465
+	public function get_subsection($name, $require_construction_to_be_finalized = true)
466
+	{
467
+		if ($require_construction_to_be_finalized) {
468
+			$this->ensure_construct_finalized_called();
469
+		}
470
+		return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
471
+	}
472
+
473
+
474
+	/**
475
+	 * Gets all the validatable subsections of this form section
476
+	 *
477
+	 * @return EE_Form_Section_Validatable[]
478
+	 * @throws EE_Error
479
+	 */
480
+	public function get_validatable_subsections()
481
+	{
482
+		$validatable_subsections = array();
483
+		foreach ($this->subsections() as $name => $obj) {
484
+			if ($obj instanceof EE_Form_Section_Validatable) {
485
+				$validatable_subsections[ $name ] = $obj;
486
+			}
487
+		}
488
+		return $validatable_subsections;
489
+	}
490
+
491
+
492
+	/**
493
+	 * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
494
+	 * throw an EE_Error.
495
+	 *
496
+	 * @param string  $name
497
+	 * @param boolean $require_construction_to_be_finalized most client code should
498
+	 *                                                      leave this as TRUE so that the inputs will be properly
499
+	 *                                                      configured. However, some client code may be ok with
500
+	 *                                                      construction finalize being called later
501
+	 *                                                      (realizing that the subsections' html names might not be
502
+	 *                                                      set yet, etc.)
503
+	 * @return EE_Form_Input_Base
504
+	 * @throws EE_Error
505
+	 */
506
+	public function get_input($name, $require_construction_to_be_finalized = true)
507
+	{
508
+		$subsection = $this->get_subsection(
509
+			$name,
510
+			$require_construction_to_be_finalized
511
+		);
512
+		if (! $subsection instanceof EE_Form_Input_Base) {
513
+			throw new EE_Error(
514
+				sprintf(
515
+					esc_html__(
516
+						"Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
517
+						'event_espresso'
518
+					),
519
+					$name,
520
+					get_class($this),
521
+					$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
522
+				)
523
+			);
524
+		}
525
+		return $subsection;
526
+	}
527
+
528
+
529
+	/**
530
+	 * Like get_input(), gets the proper subsection of the form given the name,
531
+	 * otherwise throws an EE_Error
532
+	 *
533
+	 * @param string  $name
534
+	 * @param boolean $require_construction_to_be_finalized most client code should
535
+	 *                                                      leave this as TRUE so that the inputs will be properly
536
+	 *                                                      configured. However, some client code may be ok with
537
+	 *                                                      construction finalize being called later
538
+	 *                                                      (realizing that the subsections' html names might not be
539
+	 *                                                      set yet, etc.)
540
+	 * @return EE_Form_Section_Proper
541
+	 * @throws EE_Error
542
+	 */
543
+	public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
544
+	{
545
+		$subsection = $this->get_subsection(
546
+			$name,
547
+			$require_construction_to_be_finalized
548
+		);
549
+		if (! $subsection instanceof EE_Form_Section_Proper) {
550
+			throw new EE_Error(
551
+				sprintf(
552
+					esc_html__(
553
+						"Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
554
+						'event_espresso'
555
+					),
556
+					$name,
557
+					get_class($this)
558
+				)
559
+			);
560
+		}
561
+		return $subsection;
562
+	}
563
+
564
+
565
+	/**
566
+	 * Gets the value of the specified input. Should be called after receive_form_submission()
567
+	 * or populate_defaults() on the form, where the normalized value on the input is set.
568
+	 *
569
+	 * @param string $name
570
+	 * @return mixed depending on the input's type and its normalization strategy
571
+	 * @throws EE_Error
572
+	 */
573
+	public function get_input_value($name)
574
+	{
575
+		$input = $this->get_input($name);
576
+		return $input->normalized_value();
577
+	}
578
+
579
+
580
+	/**
581
+	 * Checks if this form section itself is valid, and then checks its subsections
582
+	 *
583
+	 * @throws EE_Error
584
+	 * @return boolean
585
+	 */
586
+	public function is_valid()
587
+	{
588
+		if ($this->is_valid === null) {
589
+			if (! $this->has_received_submission()) {
590
+				throw new EE_Error(
591
+					sprintf(
592
+						esc_html__(
593
+							'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
594
+							'event_espresso'
595
+						)
596
+					)
597
+				);
598
+			}
599
+			if (! parent::is_valid()) {
600
+				$this->is_valid = false;
601
+			} else {
602
+				// ok so no general errors to this entire form section.
603
+				// so let's check the subsections, but only set errors if that hasn't been done yet
604
+				$this->is_valid = true;
605
+				foreach ($this->get_validatable_subsections() as $subsection) {
606
+					if (! $subsection->is_valid()) {
607
+						$this->is_valid = false;
608
+					}
609
+				}
610
+			}
611
+		}
612
+		return $this->is_valid;
613
+	}
614
+
615
+
616
+	/**
617
+	 * gets the default name of this form section if none is specified
618
+	 *
619
+	 * @return void
620
+	 */
621
+	protected function _set_default_name_if_empty()
622
+	{
623
+		if (! $this->_name) {
624
+			$classname    = get_class($this);
625
+			$default_name = str_replace('EE_', '', $classname);
626
+			$this->_name  = $default_name;
627
+		}
628
+	}
629
+
630
+
631
+	/**
632
+	 * Returns the HTML for the form, except for the form opening and closing tags
633
+	 * (as the form section doesn't know where you necessarily want to send the information to),
634
+	 * and except for a submit button. Enqueues JS and CSS; if called early enough we will
635
+	 * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
636
+	 * Not doing_it_wrong because theoretically this CAN be used properly,
637
+	 * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
638
+	 * any CSS.
639
+	 *
640
+	 * @throws InvalidArgumentException
641
+	 * @throws InvalidInterfaceException
642
+	 * @throws InvalidDataTypeException
643
+	 * @throws EE_Error
644
+	 */
645
+	public function get_html_and_js()
646
+	{
647
+		$this->enqueue_js();
648
+		return $this->get_html();
649
+	}
650
+
651
+
652
+	/**
653
+	 * returns HTML for displaying this form section. recursively calls display_section() on all subsections
654
+	 *
655
+	 * @param bool $display_previously_submitted_data
656
+	 * @return string
657
+	 * @throws InvalidArgumentException
658
+	 * @throws InvalidInterfaceException
659
+	 * @throws InvalidDataTypeException
660
+	 * @throws EE_Error
661
+	 * @throws EE_Error
662
+	 * @throws EE_Error
663
+	 */
664
+	public function get_html($display_previously_submitted_data = true)
665
+	{
666
+		$this->ensure_construct_finalized_called();
667
+		if ($display_previously_submitted_data) {
668
+			$this->populate_from_session();
669
+		}
670
+		return $this->_form_html_filter
671
+			? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
672
+			: $this->_layout_strategy->layout_form();
673
+	}
674
+
675
+
676
+	/**
677
+	 * enqueues JS and CSS for the form.
678
+	 * It is preferred to call this before wp_enqueue_scripts so the
679
+	 * scripts and styles can be put in the header, but if called later
680
+	 * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
681
+	 * only be in the header; but in HTML5 its ok in the body.
682
+	 * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
683
+	 * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
684
+	 *
685
+	 * @return void
686
+	 * @throws EE_Error
687
+	 */
688
+	public function enqueue_js()
689
+	{
690
+		$this->_enqueue_and_localize_form_js();
691
+		foreach ($this->subsections() as $subsection) {
692
+			$subsection->enqueue_js();
693
+		}
694
+	}
695
+
696
+
697
+	/**
698
+	 * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
699
+	 * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
700
+	 * the wp_enqueue_scripts hook.
701
+	 * However, registering the form js and localizing it can happen when we
702
+	 * actually output the form (which is preferred, seeing how teh form's fields
703
+	 * could change until it's actually outputted)
704
+	 *
705
+	 * @param boolean $init_form_validation_automatically whether or not we want the form validation
706
+	 *                                                    to be triggered automatically or not
707
+	 * @return void
708
+	 */
709
+	public static function wp_enqueue_scripts($init_form_validation_automatically = true)
710
+	{
711
+		wp_register_script(
712
+			'ee_form_section_validation',
713
+			EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
714
+			array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715
+			EVENT_ESPRESSO_VERSION,
716
+			true
717
+		);
718
+		wp_localize_script(
719
+			'ee_form_section_validation',
720
+			'ee_form_section_validation_init',
721
+			array('init' => $init_form_validation_automatically ? '1' : '0')
722
+		);
723
+	}
724
+
725
+
726
+	/**
727
+	 * gets the variables used by form_section_validation.js.
728
+	 * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
729
+	 * but before the wordpress hook wp_loaded
730
+	 *
731
+	 * @throws EE_Error
732
+	 */
733
+	public function _enqueue_and_localize_form_js()
734
+	{
735
+		$this->ensure_construct_finalized_called();
736
+		// actually, we don't want to localize just yet. There may be other forms on the page.
737
+		// so we need to add our form section data to a static variable accessible by all form sections
738
+		// and localize it just before the footer
739
+		$this->localize_validation_rules();
740
+		add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
741
+		add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
742
+	}
743
+
744
+
745
+	/**
746
+	 * add our form section data to a static variable accessible by all form sections
747
+	 *
748
+	 * @param bool $return_for_subsection
749
+	 * @return void
750
+	 * @throws EE_Error
751
+	 */
752
+	public function localize_validation_rules($return_for_subsection = false)
753
+	{
754
+		// we only want to localize vars ONCE for the entire form,
755
+		// so if the form section doesn't have a parent, then it must be the top dog
756
+		if ($return_for_subsection || ! $this->parent_section()) {
757
+			EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
758
+				'form_section_id'  => $this->html_id(true),
759
+				'validation_rules' => $this->get_jquery_validation_rules(),
760
+				'other_data'       => $this->get_other_js_data(),
761
+				'errors'           => $this->subsection_validation_errors_by_html_name(),
762
+			);
763
+			EE_Form_Section_Proper::$_scripts_localized                                = true;
764
+		}
765
+	}
766
+
767
+
768
+	/**
769
+	 * Gets an array of extra data that will be useful for client-side javascript.
770
+	 * This is primarily data added by inputs and forms in addition to any
771
+	 * scripts they might enqueue
772
+	 *
773
+	 * @param array $form_other_js_data
774
+	 * @return array
775
+	 * @throws EE_Error
776
+	 */
777
+	public function get_other_js_data($form_other_js_data = array())
778
+	{
779
+		foreach ($this->subsections() as $subsection) {
780
+			$form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
781
+		}
782
+		return $form_other_js_data;
783
+	}
784
+
785
+
786
+	/**
787
+	 * Gets a flat array of inputs for this form section and its subsections.
788
+	 * Keys are their form names, and values are the inputs themselves
789
+	 *
790
+	 * @return EE_Form_Input_Base
791
+	 * @throws EE_Error
792
+	 */
793
+	public function inputs_in_subsections()
794
+	{
795
+		$inputs = array();
796
+		foreach ($this->subsections() as $subsection) {
797
+			if ($subsection instanceof EE_Form_Input_Base) {
798
+				$inputs[ $subsection->html_name() ] = $subsection;
799
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
800
+				$inputs += $subsection->inputs_in_subsections();
801
+			}
802
+		}
803
+		return $inputs;
804
+	}
805
+
806
+
807
+	/**
808
+	 * Gets a flat array of all the validation errors.
809
+	 * Keys are html names (because those should be unique)
810
+	 * and values are a string of all their validation errors
811
+	 *
812
+	 * @return string[]
813
+	 * @throws EE_Error
814
+	 */
815
+	public function subsection_validation_errors_by_html_name()
816
+	{
817
+		$inputs = $this->inputs();
818
+		$errors = array();
819
+		foreach ($inputs as $form_input) {
820
+			if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
+				$errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
822
+			}
823
+		}
824
+		return $errors;
825
+	}
826
+
827
+
828
+	/**
829
+	 * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
830
+	 * Should be setup by each form during the _enqueues_and_localize_form_js
831
+	 *
832
+	 * @throws InvalidArgumentException
833
+	 * @throws InvalidInterfaceException
834
+	 * @throws InvalidDataTypeException
835
+	 */
836
+	public static function localize_script_for_all_forms()
837
+	{
838
+		// allow inputs and stuff to hook in their JS and stuff here
839
+		do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
840
+		EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
841
+		$email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842
+			? EE_Registry::instance()->CFG->registration->email_validation_level
843
+			: 'wp_default';
844
+		EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
845
+		wp_enqueue_script('ee_form_section_validation');
846
+		wp_localize_script(
847
+			'ee_form_section_validation',
848
+			'ee_form_section_vars',
849
+			EE_Form_Section_Proper::$_js_localization
850
+		);
851
+	}
852
+
853
+
854
+	/**
855
+	 * ensure_scripts_localized
856
+	 *
857
+	 * @throws EE_Error
858
+	 */
859
+	public function ensure_scripts_localized()
860
+	{
861
+		if (! EE_Form_Section_Proper::$_scripts_localized) {
862
+			$this->_enqueue_and_localize_form_js();
863
+		}
864
+	}
865
+
866
+
867
+	/**
868
+	 * Gets the hard-coded validation error messages to be used in the JS. The convention
869
+	 * is that the key here should be the same as the custom validation rule put in the JS file
870
+	 *
871
+	 * @return array keys are custom validation rules, and values are internationalized strings
872
+	 */
873
+	private static function _get_localized_error_messages()
874
+	{
875
+		return array(
876
+			'validUrl' => wp_strip_all_tags(__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso')),
877
+			'regex'    => wp_strip_all_tags(__('Please check your input', 'event_espresso'))
878
+		);
879
+	}
880
+
881
+
882
+	/**
883
+	 * @return array
884
+	 */
885
+	public static function js_localization()
886
+	{
887
+		return self::$_js_localization;
888
+	}
889
+
890
+
891
+	/**
892
+	 * @return void
893
+	 */
894
+	public static function reset_js_localization()
895
+	{
896
+		self::$_js_localization = array();
897
+	}
898
+
899
+
900
+	/**
901
+	 * Gets the JS to put inside the jquery validation rules for subsection of this form section.
902
+	 * See parent function for more...
903
+	 *
904
+	 * @return array
905
+	 * @throws EE_Error
906
+	 */
907
+	public function get_jquery_validation_rules()
908
+	{
909
+		$jquery_validation_rules = array();
910
+		foreach ($this->get_validatable_subsections() as $subsection) {
911
+			$jquery_validation_rules = array_merge(
912
+				$jquery_validation_rules,
913
+				$subsection->get_jquery_validation_rules()
914
+			);
915
+		}
916
+		return $jquery_validation_rules;
917
+	}
918
+
919
+
920
+	/**
921
+	 * Sanitizes all the data and sets the sanitized value of each field
922
+	 *
923
+	 * @param array $req_data like $_POST
924
+	 * @return void
925
+	 * @throws EE_Error
926
+	 */
927
+	protected function _normalize($req_data)
928
+	{
929
+		$this->_received_submission = true;
930
+		$this->_validation_errors   = array();
931
+		foreach ($this->get_validatable_subsections() as $subsection) {
932
+			try {
933
+				$subsection->_normalize($req_data);
934
+			} catch (EE_Validation_Error $e) {
935
+				$subsection->add_validation_error($e);
936
+			}
937
+		}
938
+	}
939
+
940
+
941
+	/**
942
+	 * Performs validation on this form section and its subsections.
943
+	 * For each subsection,
944
+	 * calls _validate_{subsection_name} on THIS form (if the function exists)
945
+	 * and passes it the subsection, then calls _validate on that subsection.
946
+	 * If you need to perform validation on the form as a whole (considering multiple)
947
+	 * you would be best to override this _validate method,
948
+	 * calling parent::_validate() first.
949
+	 *
950
+	 * @throws EE_Error
951
+	 */
952
+	protected function _validate()
953
+	{
954
+		// reset the cache of whether this form is valid or not- we're re-validating it now
955
+		$this->is_valid = null;
956
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
+			if (method_exists($this, '_validate_' . $subsection_name)) {
958
+				call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
959
+			}
960
+			$subsection->_validate();
961
+		}
962
+	}
963
+
964
+
965
+	/**
966
+	 * Gets all the validated inputs for the form section
967
+	 *
968
+	 * @return array
969
+	 * @throws EE_Error
970
+	 */
971
+	public function valid_data()
972
+	{
973
+		$inputs = array();
974
+		foreach ($this->subsections() as $subsection_name => $subsection) {
975
+			if ($subsection instanceof EE_Form_Section_Proper) {
976
+				$inputs[ $subsection_name ] = $subsection->valid_data();
977
+			} elseif ($subsection instanceof EE_Form_Input_Base) {
978
+				$inputs[ $subsection_name ] = $subsection->normalized_value();
979
+			}
980
+		}
981
+		return $inputs;
982
+	}
983
+
984
+
985
+	/**
986
+	 * Gets all the inputs on this form section
987
+	 *
988
+	 * @return EE_Form_Input_Base[]
989
+	 * @throws EE_Error
990
+	 */
991
+	public function inputs()
992
+	{
993
+		$inputs = array();
994
+		foreach ($this->subsections() as $subsection_name => $subsection) {
995
+			if ($subsection instanceof EE_Form_Input_Base) {
996
+				$inputs[ $subsection_name ] = $subsection;
997
+			}
998
+		}
999
+		return $inputs;
1000
+	}
1001
+
1002
+
1003
+	/**
1004
+	 * Gets all the subsections which are a proper form
1005
+	 *
1006
+	 * @return EE_Form_Section_Proper[]
1007
+	 * @throws EE_Error
1008
+	 */
1009
+	public function subforms()
1010
+	{
1011
+		$form_sections = array();
1012
+		foreach ($this->subsections() as $name => $obj) {
1013
+			if ($obj instanceof EE_Form_Section_Proper) {
1014
+				$form_sections[ $name ] = $obj;
1015
+			}
1016
+		}
1017
+		return $form_sections;
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * Gets all the subsections (inputs, proper subsections, or html-only sections).
1023
+	 * Consider using inputs() or subforms()
1024
+	 * if you only want form inputs or proper form sections.
1025
+	 *
1026
+	 * @param boolean $require_construction_to_be_finalized most client code should
1027
+	 *                                                      leave this as TRUE so that the inputs will be properly
1028
+	 *                                                      configured. However, some client code may be ok with
1029
+	 *                                                      construction finalize being called later
1030
+	 *                                                      (realizing that the subsections' html names might not be
1031
+	 *                                                      set yet, etc.)
1032
+	 * @return EE_Form_Section_Proper[]
1033
+	 * @throws EE_Error
1034
+	 */
1035
+	public function subsections($require_construction_to_be_finalized = true)
1036
+	{
1037
+		if ($require_construction_to_be_finalized) {
1038
+			$this->ensure_construct_finalized_called();
1039
+		}
1040
+		return $this->_subsections;
1041
+	}
1042
+
1043
+
1044
+	/**
1045
+	 * Returns whether this form has any subforms or inputs
1046
+	 * @return bool
1047
+	 */
1048
+	public function hasSubsections()
1049
+	{
1050
+		return ! empty($this->_subsections);
1051
+	}
1052
+
1053
+
1054
+	/**
1055
+	 * Returns a simple array where keys are input names, and values are their normalized
1056
+	 * values. (Similar to calling get_input_value on inputs)
1057
+	 *
1058
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1059
+	 *                                        or just this forms' direct children inputs
1060
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1061
+	 *                                        or allow multidimensional array
1062
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1063
+	 *                                        with array keys being input names
1064
+	 *                                        (regardless of whether they are from a subsection or not),
1065
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1066
+	 *                                        where keys are always subsection names and values are either
1067
+	 *                                        the input's normalized value, or an array like the top-level array
1068
+	 * @throws EE_Error
1069
+	 */
1070
+	public function input_values($include_subform_inputs = false, $flatten = false)
1071
+	{
1072
+		return $this->_input_values(false, $include_subform_inputs, $flatten);
1073
+	}
1074
+
1075
+
1076
+	/**
1077
+	 * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1078
+	 * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1079
+	 * is not necessarily the value we want to display to users. This creates an array
1080
+	 * where keys are the input names, and values are their display values
1081
+	 *
1082
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1083
+	 *                                        or just this forms' direct children inputs
1084
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1085
+	 *                                        or allow multidimensional array
1086
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1087
+	 *                                        with array keys being input names
1088
+	 *                                        (regardless of whether they are from a subsection or not),
1089
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1090
+	 *                                        where keys are always subsection names and values are either
1091
+	 *                                        the input's normalized value, or an array like the top-level array
1092
+	 * @throws EE_Error
1093
+	 */
1094
+	public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1095
+	{
1096
+		return $this->_input_values(true, $include_subform_inputs, $flatten);
1097
+	}
1098
+
1099
+
1100
+	/**
1101
+	 * Gets the input values from the form
1102
+	 *
1103
+	 * @param boolean $pretty                 Whether to retrieve the pretty value,
1104
+	 *                                        or just the normalized value
1105
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1106
+	 *                                        or just this forms' direct children inputs
1107
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1108
+	 *                                        or allow multidimensional array
1109
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1110
+	 *                                        input names (regardless of whether they are from a subsection or not),
1111
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1112
+	 *                                        where keys are always subsection names and values are either
1113
+	 *                                        the input's normalized value, or an array like the top-level array
1114
+	 * @throws EE_Error
1115
+	 */
1116
+	public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1117
+	{
1118
+		$input_values = array();
1119
+		foreach ($this->subsections() as $subsection_name => $subsection) {
1120
+			if ($subsection instanceof EE_Form_Input_Base) {
1121
+				$input_values[ $subsection_name ] = $pretty
1122
+					? $subsection->pretty_value()
1123
+					: $subsection->normalized_value();
1124
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1125
+				$subform_input_values = $subsection->_input_values(
1126
+					$pretty,
1127
+					$include_subform_inputs,
1128
+					$flatten
1129
+				);
1130
+				if ($flatten) {
1131
+					$input_values = array_merge($input_values, $subform_input_values);
1132
+				} else {
1133
+					$input_values[ $subsection_name ] = $subform_input_values;
1134
+				}
1135
+			}
1136
+		}
1137
+		return $input_values;
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * Gets the originally submitted input values from the form
1143
+	 *
1144
+	 * @param boolean $include_subforms  Whether to include inputs from subforms,
1145
+	 *                                   or just this forms' direct children inputs
1146
+	 * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1147
+	 *                                   with array keys being input names
1148
+	 *                                   (regardless of whether they are from a subsection or not),
1149
+	 *                                   and if $flatten is FALSE it can be a multidimensional array
1150
+	 *                                   where keys are always subsection names and values are either
1151
+	 *                                   the input's normalized value, or an array like the top-level array
1152
+	 * @throws EE_Error
1153
+	 */
1154
+	public function submitted_values($include_subforms = false)
1155
+	{
1156
+		$submitted_values = array();
1157
+		foreach ($this->subsections() as $subsection) {
1158
+			if ($subsection instanceof EE_Form_Input_Base) {
1159
+				// is this input part of an array of inputs?
1160
+				if (strpos($subsection->html_name(), '[') !== false) {
1161
+					$full_input_name  = EEH_Array::convert_array_values_to_keys(
1162
+						explode(
1163
+							'[',
1164
+							str_replace(']', '', $subsection->html_name())
1165
+						),
1166
+						$subsection->raw_value()
1167
+					);
1168
+					$submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169
+				} else {
1170
+					$submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1171
+				}
1172
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173
+				$subform_input_values = $subsection->submitted_values($include_subforms);
1174
+				$submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1175
+			}
1176
+		}
1177
+		return $submitted_values;
1178
+	}
1179
+
1180
+
1181
+	/**
1182
+	 * Indicates whether or not this form has received a submission yet
1183
+	 * (ie, had receive_form_submission called on it yet)
1184
+	 *
1185
+	 * @return boolean
1186
+	 * @throws EE_Error
1187
+	 */
1188
+	public function has_received_submission()
1189
+	{
1190
+		$this->ensure_construct_finalized_called();
1191
+		return $this->_received_submission;
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * Equivalent to passing 'exclude' in the constructor's options array.
1197
+	 * Removes the listed inputs from the form
1198
+	 *
1199
+	 * @param array $inputs_to_exclude values are the input names
1200
+	 * @return void
1201
+	 */
1202
+	public function exclude(array $inputs_to_exclude = array())
1203
+	{
1204
+		foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
+			unset($this->_subsections[ $input_to_exclude_name ]);
1206
+		}
1207
+	}
1208
+
1209
+
1210
+	/**
1211
+	 * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy.
1212
+	 * @param array $inputs_to_hide
1213
+	 * @throws EE_Error
1214
+	 */
1215
+	public function hide(array $inputs_to_hide = array())
1216
+	{
1217
+		foreach ($inputs_to_hide as $input_to_hide) {
1218
+			$input = $this->get_input($input_to_hide);
1219
+			$input->set_display_strategy(new EE_Hidden_Display_Strategy());
1220
+		}
1221
+	}
1222
+
1223
+
1224
+	/**
1225
+	 * add_subsections
1226
+	 * Adds the listed subsections to the form section.
1227
+	 * If $subsection_name_to_target is provided,
1228
+	 * then new subsections are added before or after that subsection,
1229
+	 * otherwise to the start or end of the entire subsections array.
1230
+	 *
1231
+	 * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1232
+	 *                                                          where keys are their names
1233
+	 * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1234
+	 *                                                          should be added before or after
1235
+	 *                                                          IF $subsection_name_to_target is null,
1236
+	 *                                                          then $new_subsections will be added to
1237
+	 *                                                          the beginning or end of the entire subsections array
1238
+	 * @param boolean                $add_before                whether to add $new_subsections, before or after
1239
+	 *                                                          $subsection_name_to_target,
1240
+	 *                                                          or if $subsection_name_to_target is null,
1241
+	 *                                                          before or after entire subsections array
1242
+	 * @return void
1243
+	 * @throws EE_Error
1244
+	 */
1245
+	public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1246
+	{
1247
+		foreach ($new_subsections as $subsection_name => $subsection) {
1248
+			if (! $subsection instanceof EE_Form_Section_Base) {
1249
+				EE_Error::add_error(
1250
+					sprintf(
1251
+						esc_html__(
1252
+							"Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1253
+							'event_espresso'
1254
+						),
1255
+						get_class($subsection),
1256
+						$subsection_name,
1257
+						$this->name()
1258
+					)
1259
+				);
1260
+				unset($new_subsections[ $subsection_name ]);
1261
+			}
1262
+		}
1263
+		$this->_subsections = EEH_Array::insert_into_array(
1264
+			$this->_subsections,
1265
+			$new_subsections,
1266
+			$subsection_name_to_target,
1267
+			$add_before
1268
+		);
1269
+		if ($this->_construction_finalized) {
1270
+			foreach ($this->_subsections as $name => $subsection) {
1271
+				$subsection->_construct_finalize($this, $name);
1272
+			}
1273
+		}
1274
+	}
1275
+
1276
+
1277
+	/**
1278
+	 * @param string $subsection_name
1279
+	 * @param bool   $recursive
1280
+	 * @return bool
1281
+	 */
1282
+	public function has_subsection($subsection_name, $recursive = false)
1283
+	{
1284
+		foreach ($this->_subsections as $name => $subsection) {
1285
+			if ($name === $subsection_name
1286
+				|| (
1287
+					$recursive
1288
+					&& $subsection instanceof EE_Form_Section_Proper
1289
+					&& $subsection->has_subsection($subsection_name, $recursive)
1290
+				)
1291
+			) {
1292
+				return true;
1293
+			}
1294
+		}
1295
+		return false;
1296
+	}
1297
+
1298
+
1299
+
1300
+	/**
1301
+	 * Just gets all validatable subsections to clean their sensitive data
1302
+	 *
1303
+	 * @throws EE_Error
1304
+	 */
1305
+	public function clean_sensitive_data()
1306
+	{
1307
+		foreach ($this->get_validatable_subsections() as $subsection) {
1308
+			$subsection->clean_sensitive_data();
1309
+		}
1310
+	}
1311
+
1312
+
1313
+	/**
1314
+	 * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1315
+	 * @param string                           $form_submission_error_message
1316
+	 * @param EE_Form_Section_Validatable $form_section unused
1317
+	 * @throws EE_Error
1318
+	 */
1319
+	public function set_submission_error_message(
1320
+		$form_submission_error_message = ''
1321
+	) {
1322
+		$this->_form_submission_error_message = ! empty($form_submission_error_message)
1323
+			? $form_submission_error_message
1324
+			: $this->getAllValidationErrorsString();
1325
+	}
1326
+
1327
+
1328
+	/**
1329
+	 * Returns the cached error message. A default value is set for this during _validate(),
1330
+	 * (called during receive_form_submission) but it can be explicitly set using
1331
+	 * set_submission_error_message
1332
+	 *
1333
+	 * @return string
1334
+	 */
1335
+	public function submission_error_message()
1336
+	{
1337
+		return $this->_form_submission_error_message;
1338
+	}
1339
+
1340
+
1341
+	/**
1342
+	 * Sets a message to display if the data submitted to the form was valid.
1343
+	 * @param string $form_submission_success_message
1344
+	 */
1345
+	public function set_submission_success_message($form_submission_success_message = '')
1346
+	{
1347
+		$this->_form_submission_success_message = ! empty($form_submission_success_message)
1348
+			? $form_submission_success_message
1349
+			: esc_html__('Form submitted successfully', 'event_espresso');
1350
+	}
1351
+
1352
+
1353
+	/**
1354
+	 * Gets a message appropriate for display when the form is correctly submitted
1355
+	 * @return string
1356
+	 */
1357
+	public function submission_success_message()
1358
+	{
1359
+		return $this->_form_submission_success_message;
1360
+	}
1361
+
1362
+
1363
+	/**
1364
+	 * Returns the prefix that should be used on child of this form section for
1365
+	 * their html names. If this form section itself has a parent, prepends ITS
1366
+	 * prefix onto this form section's prefix. Used primarily by
1367
+	 * EE_Form_Input_Base::_set_default_html_name_if_empty
1368
+	 *
1369
+	 * @return string
1370
+	 * @throws EE_Error
1371
+	 */
1372
+	public function html_name_prefix()
1373
+	{
1374
+		if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1375
+			return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1376
+		}
1377
+		return $this->name();
1378
+	}
1379
+
1380
+
1381
+	/**
1382
+	 * Gets the name, but first checks _construct_finalize has been called. If not,
1383
+	 * calls it (assumes there is no parent and that we want the name to be whatever
1384
+	 * was set, which is probably nothing, or the classname)
1385
+	 *
1386
+	 * @return string
1387
+	 * @throws EE_Error
1388
+	 */
1389
+	public function name()
1390
+	{
1391
+		$this->ensure_construct_finalized_called();
1392
+		return parent::name();
1393
+	}
1394
+
1395
+
1396
+	/**
1397
+	 * @return EE_Form_Section_Proper
1398
+	 * @throws EE_Error
1399
+	 */
1400
+	public function parent_section()
1401
+	{
1402
+		$this->ensure_construct_finalized_called();
1403
+		return parent::parent_section();
1404
+	}
1405
+
1406
+
1407
+	/**
1408
+	 * make sure construction finalized was called, otherwise children might not be ready
1409
+	 *
1410
+	 * @return void
1411
+	 * @throws EE_Error
1412
+	 */
1413
+	public function ensure_construct_finalized_called()
1414
+	{
1415
+		if (! $this->_construction_finalized) {
1416
+			$this->_construct_finalize($this->_parent_section, $this->_name);
1417
+		}
1418
+	}
1419
+
1420
+
1421
+	/**
1422
+	 * Checks if any of this form section's inputs, or any of its children's inputs,
1423
+	 * are in teh form data. If any are found, returns true. Else false
1424
+	 *
1425
+	 * @param array $req_data
1426
+	 * @return boolean
1427
+	 * @throws EE_Error
1428
+	 */
1429
+	public function form_data_present_in($req_data = null)
1430
+	{
1431
+		$req_data = $this->getCachedRequest($req_data);
1432
+		foreach ($this->subsections() as $subsection) {
1433
+			if ($subsection instanceof EE_Form_Input_Base) {
1434
+				if ($subsection->form_data_present_in($req_data)) {
1435
+					return true;
1436
+				}
1437
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
1438
+				if ($subsection->form_data_present_in($req_data)) {
1439
+					return true;
1440
+				}
1441
+			}
1442
+		}
1443
+		return false;
1444
+	}
1445
+
1446
+
1447
+	/**
1448
+	 * Gets validation errors for this form section and subsections
1449
+	 * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1450
+	 * gets the validation errors for ALL subsection
1451
+	 *
1452
+	 * @return EE_Validation_Error[]
1453
+	 * @throws EE_Error
1454
+	 */
1455
+	public function get_validation_errors_accumulated()
1456
+	{
1457
+		$validation_errors = $this->get_validation_errors();
1458
+		foreach ($this->get_validatable_subsections() as $subsection) {
1459
+			if ($subsection instanceof EE_Form_Section_Proper) {
1460
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1461
+			} else {
1462
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors();
1463
+			}
1464
+			if ($validation_errors_on_this_subsection) {
1465
+				$validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1466
+			}
1467
+		}
1468
+		return $validation_errors;
1469
+	}
1470
+
1471
+	/**
1472
+	 * Fetch validation errors from children and grandchildren and puts them in a single string.
1473
+	 * This traverses the form section tree to generate this, but you probably want to instead use
1474
+	 * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1475
+	 *
1476
+	 * @return string
1477
+	 * @since 4.9.59.p
1478
+	 */
1479
+	protected function getAllValidationErrorsString()
1480
+	{
1481
+		$submission_error_messages = array();
1482
+		// bad, bad, bad registrant
1483
+		foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1484
+			if ($validation_error instanceof EE_Validation_Error) {
1485
+				$form_section = $validation_error->get_form_section();
1486
+				if ($form_section instanceof EE_Form_Input_Base) {
1487
+					$label = $validation_error->get_form_section()->html_label_text();
1488
+				} elseif ($form_section instanceof EE_Form_Section_Validatable) {
1489
+					$label = $validation_error->get_form_section()->name();
1490
+				} else {
1491
+					$label = esc_html__('Unknown', 'event_espresso');
1492
+				}
1493
+				$submission_error_messages[] = sprintf(
1494
+					__('%s : %s', 'event_espresso'),
1495
+					$label,
1496
+					$validation_error->getMessage()
1497
+				);
1498
+			}
1499
+		}
1500
+		return implode('<br', $submission_error_messages);
1501
+	}
1502
+
1503
+
1504
+	/**
1505
+	 * This isn't just the name of an input, it's a path pointing to an input. The
1506
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
1507
+	 * dot-dot-slash (../) means to ascend into the parent section.
1508
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1509
+	 * which will be returned.
1510
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1511
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1512
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1513
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1514
+	 * Etc
1515
+	 *
1516
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1517
+	 * @return EE_Form_Section_Base
1518
+	 * @throws EE_Error
1519
+	 */
1520
+	public function find_section_from_path($form_section_path)
1521
+	{
1522
+		// check if we can find the input from purely going straight up the tree
1523
+		$input = parent::find_section_from_path($form_section_path);
1524
+		if ($input instanceof EE_Form_Section_Base) {
1525
+			return $input;
1526
+		}
1527
+		$next_slash_pos = strpos($form_section_path, '/');
1528
+		if ($next_slash_pos !== false) {
1529
+			$child_section_name = substr($form_section_path, 0, $next_slash_pos);
1530
+			$subpath            = substr($form_section_path, $next_slash_pos + 1);
1531
+		} else {
1532
+			$child_section_name = $form_section_path;
1533
+			$subpath            = '';
1534
+		}
1535
+		$child_section = $this->get_subsection($child_section_name);
1536
+		if ($child_section instanceof EE_Form_Section_Base) {
1537
+			return $child_section->find_section_from_path($subpath);
1538
+		}
1539
+		return null;
1540
+	}
1541 1541
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_messenger.lib.php 2 patches
Indentation   +724 added lines, -724 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,481 +406,481 @@  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 = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url('admin.php'));
560
-                $create_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url('admin.php'));
561
-                $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
562
-                $st_args['mt_slug'] = $mtpg->message_type();
563
-                $st_args['messenger_slug'] = $this->name;
564
-                $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');
565
-                // 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).
566
-                $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>';
567
-                $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
568
-                $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>' : '';
569
-                $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
570
-            }
571
-        }
572
-
573
-        // if no selectors present then get out.
574
-        if (empty($selector_rows)) {
575
-            return '';
576
-        }
577
-
578
-        $template_args['selector_rows'] = $selector_rows;
579
-        return EEH_Template::display_template($template_wrapper_path, $template_args, true);
580
-    }
581
-
582
-
583
-
584
-
585
-
586
-
587
-    /**
588
-     * get_template_fields
589
-     *
590
-     * @access public
591
-     * @return array $this->_template_fields
592
-     */
593
-    public function get_template_fields()
594
-    {
595
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
596
-        $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
597
-        return $template_fields;
598
-    }
599
-
600
-
601
-
602
-
603
-    /** SETUP METHODS **/
604
-    /**
605
-     * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
606
-     * @param string $item
607
-     * @param mixed $value
608
-     */
609
-    protected function _set_template_value($item, $value)
610
-    {
611
-        if (array_key_exists($item, $this->_template_fields)) {
612
-            $prop = '_' . $item;
613
-            $this->{$prop}= $value;
614
-        }
615
-    }
616
-
617
-    /**
618
-     * Sets up the message for sending.
619
-     *
620
-     * @param  EE_message $message the message object that contains details about the message.
621
-     * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
622
-     *
623
-     * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
624
-     *              added to EE_Error.
625
-     *              true = message sent successfully
626
-     *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
627
-     *              Throwing a SendMessageException means the message failed sending and cannot be retried.
628
-     *
629
-     * @throws SendMessageException
630
-     */
631
-    final public function send_message($message, EE_message_type $message_type)
632
-    {
633
-        try {
634
-            $this->_validate_and_setup($message);
635
-            $this->_incoming_message_type = $message_type;
636
-            $response = $this->_send_message();
637
-            if ($response instanceof WP_Error) {
638
-                EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
639
-                $response = false;
640
-            }
641
-        } catch (\Exception $e) {
642
-            // convert to an instance of SendMessageException
643
-            throw new SendMessageException($e->getMessage());
644
-        }
645
-        return $response;
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * Sets up and returns message preview
652
-     * @param  EE_Message $message incoming message object
653
-     * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
654
-     * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
655
-     * @return string          return the message html content
656
-     */
657
-    public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
658
-    {
659
-        $this->_validate_and_setup($message);
660
-
661
-        $this->_incoming_message_type = $message_type;
662
-
663
-        if ($send) {
664
-            // are we overriding any existing template fields?
665
-            $settings = apply_filters(
666
-                'FHEE__EE_messenger__get_preview__messenger_test_settings',
667
-                $this->get_existing_test_settings(),
668
-                $this,
669
-                $send,
670
-                $message,
671
-                $message_type
672
-            );
673
-            if (! empty($settings)) {
674
-                foreach ($settings as $field => $value) {
675
-                    $this->_set_template_value($field, $value);
676
-                }
677
-            }
678
-        }
679
-
680
-        // enqueue preview js so that any links/buttons on the page are disabled.
681
-        if (! $send) {
682
-            // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
683
-            // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
684
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
685
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
686
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
687
-        }
688
-
689
-        return $send ? $this->_send_message() : $this->_preview();
690
-    }
691
-
692
-
693
-
694
-
695
-    /**
696
-     * Callback for enqueue_scripts so that we setup the preview script for all previews.
697
-     *
698
-     * @since 4.5.0
699
-     *
700
-     * @return void
701
-     */
702
-    public function add_preview_script()
703
-    {
704
-        // error message
705
-        EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
706
-            __('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')
707
-        );
708
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
709
-        wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
710
-        wp_enqueue_script('ee-messages-preview-js');
711
-    }
712
-
713
-
714
-
715
-
716
-    /**
717
-     * simply validates the incoming message object and then sets up the properties for the messenger
718
-     * @param  EE_Message $message
719
-     * @throws EE_Error
720
-     */
721
-    protected function _validate_and_setup(EE_Message $message)
722
-    {
723
-        $template_pack = $message->get_template_pack();
724
-        $variation = $message->get_template_pack_variation();
725
-
726
-        // verify we have the required template pack value on the $message object.
727
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
728
-            throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
729
-        }
730
-
731
-        $this->_tmp_pack = $template_pack;
732
-
733
-        $this->_variation = $variation ? $variation : 'default';
734
-
735
-        $template_fields = $this->get_template_fields();
736
-
737
-        foreach ($template_fields as $template => $value) {
738
-            if ($template !== 'extra') {
739
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
740
-                $message_template_value = $column_value ? $column_value : null;
741
-                $this->_set_template_value($template, $message_template_value);
742
-            }
743
-        }
744
-    }
745
-
746
-
747
-
748
-    /**
749
-     * Utility method for child classes to get the contents of a template file and return
750
-     *
751
-     * We're assuming the child messenger class has already setup template args!
752
-     * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
753
-     * @return string
754
-     * @throws \EE_Error
755
-     */
756
-    protected function _get_main_template($preview = false)
757
-    {
758
-        $type = $preview ? 'preview' : 'main';
759
-
760
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
761
-
762
-        // check file exists and is readable
763
-        if (!is_readable($wrapper_template)) {
764
-            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));
765
-        }
766
-
767
-        // add message type to template args
768
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
769
-
770
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
771
-    }
772
-
773
-
774
-
775
-    /**
776
-     * set the _test_settings_fields property
777
-     *
778
-     * @access protected
779
-     * @return void
780
-     */
781
-    protected function _set_test_settings_fields()
782
-    {
783
-        $this->_test_settings_fields = array();
784
-    }
785
-
786
-
787
-
788
-    /**
789
-     * return the _test_settings_fields property
790
-     * @return array
791
-     */
792
-    public function get_test_settings_fields()
793
-    {
794
-        return $this->_test_settings_fields;
795
-    }
796
-
797
-
798
-
799
-
800
-    /**
801
-     * This just returns any existing test settings that might be saved in the database
802
-     *
803
-     * @access public
804
-     * @return array
805
-     */
806
-    public function get_existing_test_settings()
807
-    {
808
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
809
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
810
-        $settings = $Message_Resource_Manager->get_active_messengers_option();
811
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
812
-    }
813
-
814
-
815
-
816
-    /**
817
-     * All this does is set the existing test settings (in the db) for the messenger
818
-     *
819
-     * @access public
820
-     * @param $settings
821
-     * @return bool success/fail
822
-     */
823
-    public function set_existing_test_settings($settings)
824
-    {
825
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
826
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
827
-        $existing = $Message_Resource_Manager->get_active_messengers_option();
828
-        $existing[ $this->name ]['test_settings'] = $settings;
829
-        return $Message_Resource_Manager->update_active_messengers_option($existing);
830
-    }
831
-
832
-
833
-
834
-    /**
835
-     * This just returns the field label for a given field setup in the _template_fields property.
836
-     *
837
-     * @since   4.3.0
838
-     *
839
-     * @param string $field The field to retrieve the label for
840
-     * @return string             The label
841
-     */
842
-    public function get_field_label($field)
843
-    {
844
-        // first let's see if the field requests is in the top level array.
845
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
846
-            return $this->_template[ $field ]['label'];
847
-        }
848
-
849
-        // 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.
850
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
851
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
852
-        }
853
-
854
-        // now it's possible this field may just be existing in any of the extra array items.
855
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
856
-            foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
857
-                if (!is_array($subfields)) {
858
-                    continue;
859
-                }
860
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
861
-                    return $subfields[ $field ]['label'];
862
-                }
863
-            }
864
-        }
865
-
866
-        // if we made it here then there's no label set so let's just return the $field.
867
-        return $field;
868
-    }
869
-
870
-
871
-
872
-
873
-    /**
874
-     * 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).
875
-     *
876
-     * @since 4.5.0
877
-     *
878
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
879
-     *
880
-     * @return void
881
-     */
882
-    public function do_secondary_messenger_hooks($sending_messenger_name)
883
-    {
884
-        return;
885
-    }
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 = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url('admin.php'));
560
+				$create_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url('admin.php'));
561
+				$st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
562
+				$st_args['mt_slug'] = $mtpg->message_type();
563
+				$st_args['messenger_slug'] = $this->name;
564
+				$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');
565
+				// 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).
566
+				$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>';
567
+				$st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
568
+				$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>' : '';
569
+				$selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
570
+			}
571
+		}
572
+
573
+		// if no selectors present then get out.
574
+		if (empty($selector_rows)) {
575
+			return '';
576
+		}
577
+
578
+		$template_args['selector_rows'] = $selector_rows;
579
+		return EEH_Template::display_template($template_wrapper_path, $template_args, true);
580
+	}
581
+
582
+
583
+
584
+
585
+
586
+
587
+	/**
588
+	 * get_template_fields
589
+	 *
590
+	 * @access public
591
+	 * @return array $this->_template_fields
592
+	 */
593
+	public function get_template_fields()
594
+	{
595
+		$template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
596
+		$template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
597
+		return $template_fields;
598
+	}
599
+
600
+
601
+
602
+
603
+	/** SETUP METHODS **/
604
+	/**
605
+	 * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
606
+	 * @param string $item
607
+	 * @param mixed $value
608
+	 */
609
+	protected function _set_template_value($item, $value)
610
+	{
611
+		if (array_key_exists($item, $this->_template_fields)) {
612
+			$prop = '_' . $item;
613
+			$this->{$prop}= $value;
614
+		}
615
+	}
616
+
617
+	/**
618
+	 * Sets up the message for sending.
619
+	 *
620
+	 * @param  EE_message $message the message object that contains details about the message.
621
+	 * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
622
+	 *
623
+	 * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
624
+	 *              added to EE_Error.
625
+	 *              true = message sent successfully
626
+	 *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
627
+	 *              Throwing a SendMessageException means the message failed sending and cannot be retried.
628
+	 *
629
+	 * @throws SendMessageException
630
+	 */
631
+	final public function send_message($message, EE_message_type $message_type)
632
+	{
633
+		try {
634
+			$this->_validate_and_setup($message);
635
+			$this->_incoming_message_type = $message_type;
636
+			$response = $this->_send_message();
637
+			if ($response instanceof WP_Error) {
638
+				EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
639
+				$response = false;
640
+			}
641
+		} catch (\Exception $e) {
642
+			// convert to an instance of SendMessageException
643
+			throw new SendMessageException($e->getMessage());
644
+		}
645
+		return $response;
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * Sets up and returns message preview
652
+	 * @param  EE_Message $message incoming message object
653
+	 * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
654
+	 * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
655
+	 * @return string          return the message html content
656
+	 */
657
+	public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
658
+	{
659
+		$this->_validate_and_setup($message);
660
+
661
+		$this->_incoming_message_type = $message_type;
662
+
663
+		if ($send) {
664
+			// are we overriding any existing template fields?
665
+			$settings = apply_filters(
666
+				'FHEE__EE_messenger__get_preview__messenger_test_settings',
667
+				$this->get_existing_test_settings(),
668
+				$this,
669
+				$send,
670
+				$message,
671
+				$message_type
672
+			);
673
+			if (! empty($settings)) {
674
+				foreach ($settings as $field => $value) {
675
+					$this->_set_template_value($field, $value);
676
+				}
677
+			}
678
+		}
679
+
680
+		// enqueue preview js so that any links/buttons on the page are disabled.
681
+		if (! $send) {
682
+			// the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
683
+			// it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
684
+			add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
685
+			add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
686
+			add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
687
+		}
688
+
689
+		return $send ? $this->_send_message() : $this->_preview();
690
+	}
691
+
692
+
693
+
694
+
695
+	/**
696
+	 * Callback for enqueue_scripts so that we setup the preview script for all previews.
697
+	 *
698
+	 * @since 4.5.0
699
+	 *
700
+	 * @return void
701
+	 */
702
+	public function add_preview_script()
703
+	{
704
+		// error message
705
+		EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
706
+			__('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')
707
+		);
708
+		wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
709
+		wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
710
+		wp_enqueue_script('ee-messages-preview-js');
711
+	}
712
+
713
+
714
+
715
+
716
+	/**
717
+	 * simply validates the incoming message object and then sets up the properties for the messenger
718
+	 * @param  EE_Message $message
719
+	 * @throws EE_Error
720
+	 */
721
+	protected function _validate_and_setup(EE_Message $message)
722
+	{
723
+		$template_pack = $message->get_template_pack();
724
+		$variation = $message->get_template_pack_variation();
725
+
726
+		// verify we have the required template pack value on the $message object.
727
+		if (! $template_pack instanceof EE_Messages_Template_Pack) {
728
+			throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
729
+		}
730
+
731
+		$this->_tmp_pack = $template_pack;
732
+
733
+		$this->_variation = $variation ? $variation : 'default';
734
+
735
+		$template_fields = $this->get_template_fields();
736
+
737
+		foreach ($template_fields as $template => $value) {
738
+			if ($template !== 'extra') {
739
+				$column_value = $message->get_field_or_extra_meta('MSG_' . $template);
740
+				$message_template_value = $column_value ? $column_value : null;
741
+				$this->_set_template_value($template, $message_template_value);
742
+			}
743
+		}
744
+	}
745
+
746
+
747
+
748
+	/**
749
+	 * Utility method for child classes to get the contents of a template file and return
750
+	 *
751
+	 * We're assuming the child messenger class has already setup template args!
752
+	 * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
753
+	 * @return string
754
+	 * @throws \EE_Error
755
+	 */
756
+	protected function _get_main_template($preview = false)
757
+	{
758
+		$type = $preview ? 'preview' : 'main';
759
+
760
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
761
+
762
+		// check file exists and is readable
763
+		if (!is_readable($wrapper_template)) {
764
+			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));
765
+		}
766
+
767
+		// add message type to template args
768
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
769
+
770
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
771
+	}
772
+
773
+
774
+
775
+	/**
776
+	 * set the _test_settings_fields property
777
+	 *
778
+	 * @access protected
779
+	 * @return void
780
+	 */
781
+	protected function _set_test_settings_fields()
782
+	{
783
+		$this->_test_settings_fields = array();
784
+	}
785
+
786
+
787
+
788
+	/**
789
+	 * return the _test_settings_fields property
790
+	 * @return array
791
+	 */
792
+	public function get_test_settings_fields()
793
+	{
794
+		return $this->_test_settings_fields;
795
+	}
796
+
797
+
798
+
799
+
800
+	/**
801
+	 * This just returns any existing test settings that might be saved in the database
802
+	 *
803
+	 * @access public
804
+	 * @return array
805
+	 */
806
+	public function get_existing_test_settings()
807
+	{
808
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
809
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
810
+		$settings = $Message_Resource_Manager->get_active_messengers_option();
811
+		return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
812
+	}
813
+
814
+
815
+
816
+	/**
817
+	 * All this does is set the existing test settings (in the db) for the messenger
818
+	 *
819
+	 * @access public
820
+	 * @param $settings
821
+	 * @return bool success/fail
822
+	 */
823
+	public function set_existing_test_settings($settings)
824
+	{
825
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
826
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
827
+		$existing = $Message_Resource_Manager->get_active_messengers_option();
828
+		$existing[ $this->name ]['test_settings'] = $settings;
829
+		return $Message_Resource_Manager->update_active_messengers_option($existing);
830
+	}
831
+
832
+
833
+
834
+	/**
835
+	 * This just returns the field label for a given field setup in the _template_fields property.
836
+	 *
837
+	 * @since   4.3.0
838
+	 *
839
+	 * @param string $field The field to retrieve the label for
840
+	 * @return string             The label
841
+	 */
842
+	public function get_field_label($field)
843
+	{
844
+		// first let's see if the field requests is in the top level array.
845
+		if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
846
+			return $this->_template[ $field ]['label'];
847
+		}
848
+
849
+		// 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.
850
+		if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
851
+			return $this->_template_fields['extra'][ $field ]['main']['label'];
852
+		}
853
+
854
+		// now it's possible this field may just be existing in any of the extra array items.
855
+		if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
856
+			foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
857
+				if (!is_array($subfields)) {
858
+					continue;
859
+				}
860
+				if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
861
+					return $subfields[ $field ]['label'];
862
+				}
863
+			}
864
+		}
865
+
866
+		// if we made it here then there's no label set so let's just return the $field.
867
+		return $field;
868
+	}
869
+
870
+
871
+
872
+
873
+	/**
874
+	 * 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).
875
+	 *
876
+	 * @since 4.5.0
877
+	 *
878
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
879
+	 *
880
+	 * @return void
881
+	 */
882
+	public function do_secondary_messenger_hooks($sending_messenger_name)
883
+	{
884
+		return;
885
+	}
886 886
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 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,44 +528,44 @@  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
                 }
557 557
                 // if there is no $default_value then we set it as the global
558 558
                 $default_value = empty($default_value) ? $mtpgID : $default_value;
559
-                $edit_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url('admin.php'));
560
-                $create_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url('admin.php'));
559
+                $edit_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value), admin_url('admin.php'));
560
+                $create_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value), admin_url('admin.php'));
561 561
                 $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
562 562
                 $st_args['mt_slug'] = $mtpg->message_type();
563 563
                 $st_args['messenger_slug'] = $this->name;
564
-                $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');
564
+                $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');
565 565
                 // 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).
566
-                $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>';
566
+                $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>';
567 567
                 $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
568
-                $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>' : '';
568
+                $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>' : '';
569 569
                 $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
570 570
             }
571 571
         }
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
      */
593 593
     public function get_template_fields()
594 594
     {
595
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
595
+        $template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this);
596 596
         $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
597 597
         return $template_fields;
598 598
     }
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
     protected function _set_template_value($item, $value)
610 610
     {
611 611
         if (array_key_exists($item, $this->_template_fields)) {
612
-            $prop = '_' . $item;
613
-            $this->{$prop}= $value;
612
+            $prop = '_'.$item;
613
+            $this->{$prop} = $value;
614 614
         }
615 615
     }
616 616
 
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
                 $message,
671 671
                 $message_type
672 672
             );
673
-            if (! empty($settings)) {
673
+            if ( ! empty($settings)) {
674 674
                 foreach ($settings as $field => $value) {
675 675
                     $this->_set_template_value($field, $value);
676 676
                 }
@@ -678,12 +678,12 @@  discard block
 block discarded – undo
678 678
         }
679 679
 
680 680
         // enqueue preview js so that any links/buttons on the page are disabled.
681
-        if (! $send) {
681
+        if ( ! $send) {
682 682
             // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
683 683
             // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
684
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
685
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
686
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
684
+            add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10);
685
+            add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10);
686
+            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10);
687 687
         }
688 688
 
689 689
         return $send ? $this->_send_message() : $this->_preview();
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
         EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
706 706
             __('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')
707 707
         );
708
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
708
+        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
709 709
         wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
710 710
         wp_enqueue_script('ee-messages-preview-js');
711 711
     }
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
         $variation = $message->get_template_pack_variation();
725 725
 
726 726
         // verify we have the required template pack value on the $message object.
727
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
727
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack) {
728 728
             throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
729 729
         }
730 730
 
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
 
737 737
         foreach ($template_fields as $template => $value) {
738 738
             if ($template !== 'extra') {
739
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
739
+                $column_value = $message->get_field_or_extra_meta('MSG_'.$template);
740 740
                 $message_template_value = $column_value ? $column_value : null;
741 741
                 $this->_set_template_value($template, $message_template_value);
742 742
             }
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
         $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
761 761
 
762 762
         // check file exists and is readable
763
-        if (!is_readable($wrapper_template)) {
763
+        if ( ! is_readable($wrapper_template)) {
764 764
             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));
765 765
         }
766 766
 
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
809 809
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
810 810
         $settings = $Message_Resource_Manager->get_active_messengers_option();
811
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
811
+        return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array();
812 812
     }
813 813
 
814 814
 
@@ -825,7 +825,7 @@  discard block
 block discarded – undo
825 825
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
826 826
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
827 827
         $existing = $Message_Resource_Manager->get_active_messengers_option();
828
-        $existing[ $this->name ]['test_settings'] = $settings;
828
+        $existing[$this->name]['test_settings'] = $settings;
829 829
         return $Message_Resource_Manager->update_active_messengers_option($existing);
830 830
     }
831 831
 
@@ -842,23 +842,23 @@  discard block
 block discarded – undo
842 842
     public function get_field_label($field)
843 843
     {
844 844
         // first let's see if the field requests is in the top level array.
845
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
846
-            return $this->_template[ $field ]['label'];
845
+        if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label'])) {
846
+            return $this->_template[$field]['label'];
847 847
         }
848 848
 
849 849
         // 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.
850
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
851
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
850
+        if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label'])) {
851
+            return $this->_template_fields['extra'][$field]['main']['label'];
852 852
         }
853 853
 
854 854
         // now it's possible this field may just be existing in any of the extra array items.
855
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
855
+        if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
856 856
             foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
857
-                if (!is_array($subfields)) {
857
+                if ( ! is_array($subfields)) {
858 858
                     continue;
859 859
                 }
860
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
861
-                    return $subfields[ $field ]['label'];
860
+                if (isset($subfields[$field]) && ! empty($subfields[$field]['label'])) {
861
+                    return $subfields[$field]['label'];
862 862
                 }
863 863
             }
864 864
         }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT.core.php 2 patches
Indentation   +1451 added lines, -1451 removed lines patch added patch discarded remove patch
@@ -27,476 +27,476 @@  discard block
 block discarded – undo
27 27
 {
28 28
 
29 29
 
30
-    /**
31
-     * This gets set in _setup_cpt
32
-     * It will contain the object for the custom post type.
33
-     *
34
-     * @var EE_CPT_Base
35
-     */
36
-    protected $_cpt_object;
37
-
38
-
39
-    /**
40
-     * a boolean flag to set whether the current route is a cpt route or not.
41
-     *
42
-     * @var bool
43
-     */
44
-    protected $_cpt_route = false;
45
-
46
-
47
-    /**
48
-     * This property allows cpt classes to define multiple routes as cpt routes.
49
-     * //in this array we define what the custom post type for this route is.
50
-     * array(
51
-     * 'route_name' => 'custom_post_type_slug'
52
-     * )
53
-     *
54
-     * @var array
55
-     */
56
-    protected $_cpt_routes = array();
57
-
58
-
59
-    /**
60
-     * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
-     * in this format:
62
-     * array(
63
-     * 'post_type_slug' => 'edit_route'
64
-     * )
65
-     *
66
-     * @var array
67
-     */
68
-    protected $_cpt_edit_routes = array();
69
-
70
-
71
-    /**
72
-     * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
73
-     * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
74
-     * _cpt_model_names property should be in the following format: array(
75
-     * 'route_defined_by_action_param' => 'Model_Name')
76
-     *
77
-     * @var array $_cpt_model_names
78
-     */
79
-    protected $_cpt_model_names = array();
80
-
81
-
82
-    /**
83
-     * @var EE_CPT_Base
84
-     */
85
-    protected $_cpt_model_obj = false;
86
-
87
-
88
-    /**
89
-     * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
90
-     * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
91
-     * the _register_autosave_containers() method so that we don't override any other containers already registered.
92
-     * Registration of containers should be done before load_page_dependencies() is run.
93
-     *
94
-     * @var array()
95
-     */
96
-    protected $_autosave_containers = array();
97
-    protected $_autosave_fields = array();
98
-
99
-    /**
100
-     * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
101
-     * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
102
-     *
103
-     * @var array
104
-     */
105
-    protected $_pagenow_map;
106
-
107
-
108
-    /**
109
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
110
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
111
-     * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
112
-     * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
113
-     * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
114
-     *
115
-     * @access protected
116
-     * @abstract
117
-     * @param  string      $post_id The ID of the cpt that was saved (so you can link relationally)
118
-     * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
119
-     * @return void
120
-     */
121
-    abstract protected function _insert_update_cpt_item($post_id, $post);
122
-
123
-
124
-    /**
125
-     * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
126
-     *
127
-     * @abstract
128
-     * @access public
129
-     * @param  string $post_id The ID of the cpt that was trashed
130
-     * @return void
131
-     */
132
-    abstract public function trash_cpt_item($post_id);
133
-
134
-
135
-    /**
136
-     * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
137
-     *
138
-     * @param  string $post_id theID of the cpt that was untrashed
139
-     * @return void
140
-     */
141
-    abstract public function restore_cpt_item($post_id);
142
-
143
-
144
-    /**
145
-     * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
146
-     * from the db
147
-     *
148
-     * @param  string $post_id the ID of the cpt that was deleted
149
-     * @return void
150
-     */
151
-    abstract public function delete_cpt_item($post_id);
152
-
153
-
154
-    /**
155
-     * Just utilizing the method EE_Admin exposes for doing things before page setup.
156
-     *
157
-     * @access protected
158
-     * @return void
159
-     */
160
-    protected function _before_page_setup()
161
-    {
162
-        $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
163
-        $this->_cpt_routes = array_merge(
164
-            array(
165
-                'create_new' => $this->page_slug,
166
-                'edit'       => $this->page_slug,
167
-                'trash'      => $this->page_slug,
168
-            ),
169
-            $this->_cpt_routes
170
-        );
171
-        // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
172
-        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ])
173
-            ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ])
174
-            : get_post_type_object($page);
175
-        // tweak pagenow for page loading.
176
-        if (! $this->_pagenow_map) {
177
-            $this->_pagenow_map = array(
178
-                'create_new' => 'post-new.php',
179
-                'edit'       => 'post.php',
180
-                'trash'      => 'post.php',
181
-            );
182
-        }
183
-        add_action('current_screen', array($this, 'modify_pagenow'));
184
-        // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
185
-        // get current page from autosave
186
-        $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
187
-            ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
188
-            : null;
189
-        $this->_current_page = isset($this->_req_data['current_page'])
190
-            ? $this->_req_data['current_page']
191
-            : $current_page;
192
-        // autosave... make sure its only for the correct page
193
-        // if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
194
-        // setup autosave ajax hook
195
-        // add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
196
-        // }
197
-    }
198
-
199
-
200
-    /**
201
-     * Simply ensure that we simulate the correct post route for cpt screens
202
-     *
203
-     * @param WP_Screen $current_screen
204
-     * @return void
205
-     */
206
-    public function modify_pagenow($current_screen)
207
-    {
208
-        global $pagenow, $hook_suffix;
209
-        // possibly reset pagenow.
210
-        if (! empty($this->_req_data['page'])
211
-            && $this->_req_data['page'] == $this->page_slug
212
-            && ! empty($this->_req_data['action'])
213
-            && isset($this->_pagenow_map[ $this->_req_data['action'] ])
214
-        ) {
215
-            $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ];
216
-            $hook_suffix = $pagenow;
217
-        }
218
-    }
219
-
220
-
221
-    /**
222
-     * This method is used to register additional autosave containers to the _autosave_containers property.
223
-     *
224
-     * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
225
-     *       automatically register the id for the post metabox as a container.
226
-     * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
227
-     *                    you would send along the id of a metabox container.
228
-     * @return void
229
-     */
230
-    protected function _register_autosave_containers($ids)
231
-    {
232
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
233
-    }
234
-
235
-
236
-    /**
237
-     * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
238
-     * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
239
-     */
240
-    protected function _set_autosave_containers()
241
-    {
242
-        global $wp_meta_boxes;
243
-        $containers = array();
244
-        if (empty($wp_meta_boxes)) {
245
-            return;
246
-        }
247
-        $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array();
248
-        foreach ($current_metaboxes as $box_context) {
249
-            foreach ($box_context as $box_details) {
250
-                foreach ($box_details as $box) {
251
-                    if (is_array($box['callback'])
252
-                        && (
253
-                            $box['callback'][0] instanceof EE_Admin_Page
254
-                            || $box['callback'][0] instanceof EE_Admin_Hooks
255
-                        )
256
-                    ) {
257
-                        $containers[] = $box['id'];
258
-                    }
259
-                }
260
-            }
261
-        }
262
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
263
-        // add hidden inputs container
264
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
265
-    }
266
-
267
-
268
-    protected function _load_autosave_scripts_styles()
269
-    {
270
-        /*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 );
30
+	/**
31
+	 * This gets set in _setup_cpt
32
+	 * It will contain the object for the custom post type.
33
+	 *
34
+	 * @var EE_CPT_Base
35
+	 */
36
+	protected $_cpt_object;
37
+
38
+
39
+	/**
40
+	 * a boolean flag to set whether the current route is a cpt route or not.
41
+	 *
42
+	 * @var bool
43
+	 */
44
+	protected $_cpt_route = false;
45
+
46
+
47
+	/**
48
+	 * This property allows cpt classes to define multiple routes as cpt routes.
49
+	 * //in this array we define what the custom post type for this route is.
50
+	 * array(
51
+	 * 'route_name' => 'custom_post_type_slug'
52
+	 * )
53
+	 *
54
+	 * @var array
55
+	 */
56
+	protected $_cpt_routes = array();
57
+
58
+
59
+	/**
60
+	 * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
+	 * in this format:
62
+	 * array(
63
+	 * 'post_type_slug' => 'edit_route'
64
+	 * )
65
+	 *
66
+	 * @var array
67
+	 */
68
+	protected $_cpt_edit_routes = array();
69
+
70
+
71
+	/**
72
+	 * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
73
+	 * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
74
+	 * _cpt_model_names property should be in the following format: array(
75
+	 * 'route_defined_by_action_param' => 'Model_Name')
76
+	 *
77
+	 * @var array $_cpt_model_names
78
+	 */
79
+	protected $_cpt_model_names = array();
80
+
81
+
82
+	/**
83
+	 * @var EE_CPT_Base
84
+	 */
85
+	protected $_cpt_model_obj = false;
86
+
87
+
88
+	/**
89
+	 * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
90
+	 * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
91
+	 * the _register_autosave_containers() method so that we don't override any other containers already registered.
92
+	 * Registration of containers should be done before load_page_dependencies() is run.
93
+	 *
94
+	 * @var array()
95
+	 */
96
+	protected $_autosave_containers = array();
97
+	protected $_autosave_fields = array();
98
+
99
+	/**
100
+	 * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
101
+	 * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
102
+	 *
103
+	 * @var array
104
+	 */
105
+	protected $_pagenow_map;
106
+
107
+
108
+	/**
109
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
110
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
111
+	 * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
112
+	 * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
113
+	 * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
114
+	 *
115
+	 * @access protected
116
+	 * @abstract
117
+	 * @param  string      $post_id The ID of the cpt that was saved (so you can link relationally)
118
+	 * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
119
+	 * @return void
120
+	 */
121
+	abstract protected function _insert_update_cpt_item($post_id, $post);
122
+
123
+
124
+	/**
125
+	 * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
126
+	 *
127
+	 * @abstract
128
+	 * @access public
129
+	 * @param  string $post_id The ID of the cpt that was trashed
130
+	 * @return void
131
+	 */
132
+	abstract public function trash_cpt_item($post_id);
133
+
134
+
135
+	/**
136
+	 * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
137
+	 *
138
+	 * @param  string $post_id theID of the cpt that was untrashed
139
+	 * @return void
140
+	 */
141
+	abstract public function restore_cpt_item($post_id);
142
+
143
+
144
+	/**
145
+	 * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
146
+	 * from the db
147
+	 *
148
+	 * @param  string $post_id the ID of the cpt that was deleted
149
+	 * @return void
150
+	 */
151
+	abstract public function delete_cpt_item($post_id);
152
+
153
+
154
+	/**
155
+	 * Just utilizing the method EE_Admin exposes for doing things before page setup.
156
+	 *
157
+	 * @access protected
158
+	 * @return void
159
+	 */
160
+	protected function _before_page_setup()
161
+	{
162
+		$page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
163
+		$this->_cpt_routes = array_merge(
164
+			array(
165
+				'create_new' => $this->page_slug,
166
+				'edit'       => $this->page_slug,
167
+				'trash'      => $this->page_slug,
168
+			),
169
+			$this->_cpt_routes
170
+		);
171
+		// let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
172
+		$this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ])
173
+			? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ])
174
+			: get_post_type_object($page);
175
+		// tweak pagenow for page loading.
176
+		if (! $this->_pagenow_map) {
177
+			$this->_pagenow_map = array(
178
+				'create_new' => 'post-new.php',
179
+				'edit'       => 'post.php',
180
+				'trash'      => 'post.php',
181
+			);
182
+		}
183
+		add_action('current_screen', array($this, 'modify_pagenow'));
184
+		// TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
185
+		// get current page from autosave
186
+		$current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
187
+			? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
188
+			: null;
189
+		$this->_current_page = isset($this->_req_data['current_page'])
190
+			? $this->_req_data['current_page']
191
+			: $current_page;
192
+		// autosave... make sure its only for the correct page
193
+		// if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
194
+		// setup autosave ajax hook
195
+		// add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
196
+		// }
197
+	}
198
+
199
+
200
+	/**
201
+	 * Simply ensure that we simulate the correct post route for cpt screens
202
+	 *
203
+	 * @param WP_Screen $current_screen
204
+	 * @return void
205
+	 */
206
+	public function modify_pagenow($current_screen)
207
+	{
208
+		global $pagenow, $hook_suffix;
209
+		// possibly reset pagenow.
210
+		if (! empty($this->_req_data['page'])
211
+			&& $this->_req_data['page'] == $this->page_slug
212
+			&& ! empty($this->_req_data['action'])
213
+			&& isset($this->_pagenow_map[ $this->_req_data['action'] ])
214
+		) {
215
+			$pagenow = $this->_pagenow_map[ $this->_req_data['action'] ];
216
+			$hook_suffix = $pagenow;
217
+		}
218
+	}
219
+
220
+
221
+	/**
222
+	 * This method is used to register additional autosave containers to the _autosave_containers property.
223
+	 *
224
+	 * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
225
+	 *       automatically register the id for the post metabox as a container.
226
+	 * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
227
+	 *                    you would send along the id of a metabox container.
228
+	 * @return void
229
+	 */
230
+	protected function _register_autosave_containers($ids)
231
+	{
232
+		$this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
233
+	}
234
+
235
+
236
+	/**
237
+	 * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
238
+	 * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
239
+	 */
240
+	protected function _set_autosave_containers()
241
+	{
242
+		global $wp_meta_boxes;
243
+		$containers = array();
244
+		if (empty($wp_meta_boxes)) {
245
+			return;
246
+		}
247
+		$current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array();
248
+		foreach ($current_metaboxes as $box_context) {
249
+			foreach ($box_context as $box_details) {
250
+				foreach ($box_details as $box) {
251
+					if (is_array($box['callback'])
252
+						&& (
253
+							$box['callback'][0] instanceof EE_Admin_Page
254
+							|| $box['callback'][0] instanceof EE_Admin_Hooks
255
+						)
256
+					) {
257
+						$containers[] = $box['id'];
258
+					}
259
+				}
260
+			}
261
+		}
262
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
263
+		// add hidden inputs container
264
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
265
+	}
266
+
267
+
268
+	protected function _load_autosave_scripts_styles()
269
+	{
270
+		/*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 );
271 271
         wp_enqueue_script('cpt-autosave');/**/ // todo re-enable when we start doing autosave again in 4.2
272 272
 
273
-        // filter _autosave_containers
274
-        $containers = apply_filters(
275
-            'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
276
-            $this->_autosave_containers,
277
-            $this
278
-        );
279
-        $containers = apply_filters(
280
-            'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
281
-            $containers,
282
-            $this
283
-        );
284
-
285
-        wp_localize_script(
286
-            'event_editor_js',
287
-            'EE_AUTOSAVE_IDS',
288
-            $containers
289
-        ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
290
-
291
-        $unsaved_data_msg = array(
292
-            'eventmsg'     => sprintf(
293
-                wp_strip_all_tags(
294
-                    __(
295
-                        "The changes you made to this %s will be lost if you navigate away from this page.",
296
-                        'event_espresso'
297
-                    )
298
-                ),
299
-                $this->_cpt_object->labels->singular_name
300
-            ),
301
-            'inputChanged' => 0,
302
-        );
303
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
304
-    }
305
-
306
-
307
-    public function load_page_dependencies()
308
-    {
309
-        try {
310
-            $this->_load_page_dependencies();
311
-        } catch (EE_Error $e) {
312
-            $e->get_error();
313
-        }
314
-    }
315
-
316
-
317
-    /**
318
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
319
-     *
320
-     * @access protected
321
-     * @return void
322
-     */
323
-    protected function _load_page_dependencies()
324
-    {
325
-        // we only add stuff if this is a cpt_route!
326
-        if (! $this->_cpt_route) {
327
-            parent::_load_page_dependencies();
328
-            return;
329
-        }
330
-        // now let's do some automatic filters into the wp_system
331
-        // and we'll check to make sure the CHILD class
332
-        // automatically has the required methods in place.
333
-        // the following filters are for setting all the redirects
334
-        // on DEFAULT WP custom post type actions
335
-        // let's add a hidden input to the post-edit form
336
-        // so we know when we have to trigger our custom redirects!
337
-        // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
338
-        add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
339
-        // inject our Admin page nav tabs...
340
-        // let's make sure the nav tabs are set if they aren't already
341
-        // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
342
-        add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
343
-        // modify the post_updated messages array
344
-        add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
345
-        // add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
346
-        // cpts use the same format for shortlinks as posts!
347
-        add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
348
-        // This basically allows us to change the title of the "publish" metabox area
349
-        // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
350
-        if (! empty($this->_labels['publishbox'])) {
351
-            $box_label = is_array($this->_labels['publishbox'])
352
-                         && isset($this->_labels['publishbox'][ $this->_req_action ])
353
-                ? $this->_labels['publishbox'][ $this->_req_action ]
354
-                : $this->_labels['publishbox'];
355
-            add_meta_box(
356
-                'submitdiv',
357
-                $box_label,
358
-                'post_submit_meta_box',
359
-                $this->_cpt_routes[ $this->_req_action ],
360
-                'side',
361
-                'core'
362
-            );
363
-        }
364
-        // let's add page_templates metabox if this cpt added support for it.
365
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
366
-            add_meta_box(
367
-                'page_templates',
368
-                __('Page Template', 'event_espresso'),
369
-                array($this, 'page_template_meta_box'),
370
-                $this->_cpt_routes[ $this->_req_action ],
371
-                'side',
372
-                'default'
373
-            );
374
-        }
375
-        // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
376
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
377
-            add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
378
-        }
379
-        // add preview button
380
-        add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
381
-        // insert our own post_stati dropdown
382
-        add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
383
-        // This allows adding additional information to the publish post submitbox on the wp post edit form
384
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
385
-            add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
386
-        }
387
-        // This allows for adding additional stuff after the title field on the wp post edit form.
388
-        // This is also before the wp_editor for post description field.
389
-        if (method_exists($this, 'edit_form_after_title')) {
390
-            add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
391
-        }
392
-        /**
393
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
394
-         */
395
-        add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
396
-        parent::_load_page_dependencies();
397
-        // notice we are ALSO going to load the pagenow hook set for this route
398
-        // (see _before_page_setup for the reset of the pagenow global ).
399
-        // This is for any plugins that are doing things properly
400
-        // and hooking into the load page hook for core wp cpt routes.
401
-        global $pagenow;
402
-        do_action('load-' . $pagenow);
403
-        $this->modify_current_screen();
404
-        add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
405
-        // we route REALLY early.
406
-        try {
407
-            $this->_route_admin_request();
408
-        } catch (EE_Error $e) {
409
-            $e->get_error();
410
-        }
411
-    }
412
-
413
-
414
-    /**
415
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
416
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
417
-     * route instead.
418
-     *
419
-     * @param string $good_protocol_url The escaped url.
420
-     * @param string $original_url      The original url.
421
-     * @param string $_context          The context sent to the esc_url method.
422
-     * @return string possibly a new url for our route.
423
-     */
424
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
425
-    {
426
-        $routes_to_match = array(
427
-            0 => array(
428
-                'edit.php?post_type=espresso_attendees',
429
-                'admin.php?page=espresso_registrations&action=contact_list',
430
-            ),
431
-            1 => array(
432
-                'edit.php?post_type=' . $this->_cpt_object->name,
433
-                'admin.php?page=' . $this->_cpt_object->name,
434
-            ),
435
-        );
436
-        foreach ($routes_to_match as $route_matches) {
437
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
438
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
439
-            }
440
-        }
441
-        return $good_protocol_url;
442
-    }
443
-
444
-
445
-    /**
446
-     * Determine whether the current cpt supports page templates or not.
447
-     *
448
-     * @since %VER%
449
-     * @param string $cpt_name The cpt slug we're checking on.
450
-     * @return bool True supported, false not.
451
-     * @throws InvalidArgumentException
452
-     * @throws InvalidDataTypeException
453
-     * @throws InvalidInterfaceException
454
-     */
455
-    private function _supports_page_templates($cpt_name)
456
-    {
457
-        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
458
-        $custom_post_types = LoaderFactory::getLoader()->getShared(
459
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
460
-        );
461
-        $cpt_args = $custom_post_types->getDefinitions();
462
-        $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array();
463
-        $cpt_has_support = ! empty($cpt_args['page_templates']);
464
-
465
-        // if the installed version of WP is > 4.7 we do some additional checks.
466
-        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
467
-            $post_templates = wp_get_theme()->get_post_templates();
468
-            // if there are $post_templates for this cpt, then we return false for this method because
469
-            // that means we aren't going to load our page template manager and leave that up to the native
470
-            // cpt template manager.
471
-            $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
472
-        }
473
-
474
-        return $cpt_has_support;
475
-    }
476
-
477
-
478
-    /**
479
-     * Callback for the page_templates metabox selector.
480
-     *
481
-     * @since %VER%
482
-     * @return void
483
-     */
484
-    public function page_template_meta_box()
485
-    {
486
-        global $post;
487
-        $template = '';
488
-
489
-        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
490
-            $page_template_count = count(get_page_templates());
491
-        } else {
492
-            $page_template_count = count(get_page_templates($post));
493
-        };
494
-
495
-        if ($page_template_count) {
496
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
497
-            $template = ! empty($page_template) ? $page_template : '';
498
-        }
499
-        ?>
273
+		// filter _autosave_containers
274
+		$containers = apply_filters(
275
+			'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
276
+			$this->_autosave_containers,
277
+			$this
278
+		);
279
+		$containers = apply_filters(
280
+			'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
281
+			$containers,
282
+			$this
283
+		);
284
+
285
+		wp_localize_script(
286
+			'event_editor_js',
287
+			'EE_AUTOSAVE_IDS',
288
+			$containers
289
+		); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
290
+
291
+		$unsaved_data_msg = array(
292
+			'eventmsg'     => sprintf(
293
+				wp_strip_all_tags(
294
+					__(
295
+						"The changes you made to this %s will be lost if you navigate away from this page.",
296
+						'event_espresso'
297
+					)
298
+				),
299
+				$this->_cpt_object->labels->singular_name
300
+			),
301
+			'inputChanged' => 0,
302
+		);
303
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
304
+	}
305
+
306
+
307
+	public function load_page_dependencies()
308
+	{
309
+		try {
310
+			$this->_load_page_dependencies();
311
+		} catch (EE_Error $e) {
312
+			$e->get_error();
313
+		}
314
+	}
315
+
316
+
317
+	/**
318
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
319
+	 *
320
+	 * @access protected
321
+	 * @return void
322
+	 */
323
+	protected function _load_page_dependencies()
324
+	{
325
+		// we only add stuff if this is a cpt_route!
326
+		if (! $this->_cpt_route) {
327
+			parent::_load_page_dependencies();
328
+			return;
329
+		}
330
+		// now let's do some automatic filters into the wp_system
331
+		// and we'll check to make sure the CHILD class
332
+		// automatically has the required methods in place.
333
+		// the following filters are for setting all the redirects
334
+		// on DEFAULT WP custom post type actions
335
+		// let's add a hidden input to the post-edit form
336
+		// so we know when we have to trigger our custom redirects!
337
+		// Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
338
+		add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
339
+		// inject our Admin page nav tabs...
340
+		// let's make sure the nav tabs are set if they aren't already
341
+		// if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
342
+		add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
343
+		// modify the post_updated messages array
344
+		add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
345
+		// add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
346
+		// cpts use the same format for shortlinks as posts!
347
+		add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
348
+		// This basically allows us to change the title of the "publish" metabox area
349
+		// on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
350
+		if (! empty($this->_labels['publishbox'])) {
351
+			$box_label = is_array($this->_labels['publishbox'])
352
+						 && isset($this->_labels['publishbox'][ $this->_req_action ])
353
+				? $this->_labels['publishbox'][ $this->_req_action ]
354
+				: $this->_labels['publishbox'];
355
+			add_meta_box(
356
+				'submitdiv',
357
+				$box_label,
358
+				'post_submit_meta_box',
359
+				$this->_cpt_routes[ $this->_req_action ],
360
+				'side',
361
+				'core'
362
+			);
363
+		}
364
+		// let's add page_templates metabox if this cpt added support for it.
365
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
366
+			add_meta_box(
367
+				'page_templates',
368
+				__('Page Template', 'event_espresso'),
369
+				array($this, 'page_template_meta_box'),
370
+				$this->_cpt_routes[ $this->_req_action ],
371
+				'side',
372
+				'default'
373
+			);
374
+		}
375
+		// this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
376
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
377
+			add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
378
+		}
379
+		// add preview button
380
+		add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
381
+		// insert our own post_stati dropdown
382
+		add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
383
+		// This allows adding additional information to the publish post submitbox on the wp post edit form
384
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
385
+			add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
386
+		}
387
+		// This allows for adding additional stuff after the title field on the wp post edit form.
388
+		// This is also before the wp_editor for post description field.
389
+		if (method_exists($this, 'edit_form_after_title')) {
390
+			add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
391
+		}
392
+		/**
393
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
394
+		 */
395
+		add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
396
+		parent::_load_page_dependencies();
397
+		// notice we are ALSO going to load the pagenow hook set for this route
398
+		// (see _before_page_setup for the reset of the pagenow global ).
399
+		// This is for any plugins that are doing things properly
400
+		// and hooking into the load page hook for core wp cpt routes.
401
+		global $pagenow;
402
+		do_action('load-' . $pagenow);
403
+		$this->modify_current_screen();
404
+		add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
405
+		// we route REALLY early.
406
+		try {
407
+			$this->_route_admin_request();
408
+		} catch (EE_Error $e) {
409
+			$e->get_error();
410
+		}
411
+	}
412
+
413
+
414
+	/**
415
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
416
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
417
+	 * route instead.
418
+	 *
419
+	 * @param string $good_protocol_url The escaped url.
420
+	 * @param string $original_url      The original url.
421
+	 * @param string $_context          The context sent to the esc_url method.
422
+	 * @return string possibly a new url for our route.
423
+	 */
424
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
425
+	{
426
+		$routes_to_match = array(
427
+			0 => array(
428
+				'edit.php?post_type=espresso_attendees',
429
+				'admin.php?page=espresso_registrations&action=contact_list',
430
+			),
431
+			1 => array(
432
+				'edit.php?post_type=' . $this->_cpt_object->name,
433
+				'admin.php?page=' . $this->_cpt_object->name,
434
+			),
435
+		);
436
+		foreach ($routes_to_match as $route_matches) {
437
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
438
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
439
+			}
440
+		}
441
+		return $good_protocol_url;
442
+	}
443
+
444
+
445
+	/**
446
+	 * Determine whether the current cpt supports page templates or not.
447
+	 *
448
+	 * @since %VER%
449
+	 * @param string $cpt_name The cpt slug we're checking on.
450
+	 * @return bool True supported, false not.
451
+	 * @throws InvalidArgumentException
452
+	 * @throws InvalidDataTypeException
453
+	 * @throws InvalidInterfaceException
454
+	 */
455
+	private function _supports_page_templates($cpt_name)
456
+	{
457
+		/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
458
+		$custom_post_types = LoaderFactory::getLoader()->getShared(
459
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
460
+		);
461
+		$cpt_args = $custom_post_types->getDefinitions();
462
+		$cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array();
463
+		$cpt_has_support = ! empty($cpt_args['page_templates']);
464
+
465
+		// if the installed version of WP is > 4.7 we do some additional checks.
466
+		if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
467
+			$post_templates = wp_get_theme()->get_post_templates();
468
+			// if there are $post_templates for this cpt, then we return false for this method because
469
+			// that means we aren't going to load our page template manager and leave that up to the native
470
+			// cpt template manager.
471
+			$cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
472
+		}
473
+
474
+		return $cpt_has_support;
475
+	}
476
+
477
+
478
+	/**
479
+	 * Callback for the page_templates metabox selector.
480
+	 *
481
+	 * @since %VER%
482
+	 * @return void
483
+	 */
484
+	public function page_template_meta_box()
485
+	{
486
+		global $post;
487
+		$template = '';
488
+
489
+		if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
490
+			$page_template_count = count(get_page_templates());
491
+		} else {
492
+			$page_template_count = count(get_page_templates($post));
493
+		};
494
+
495
+		if ($page_template_count) {
496
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
497
+			$template = ! empty($page_template) ? $page_template : '';
498
+		}
499
+		?>
500 500
         <p><strong><?php _e('Template', 'event_espresso') ?></strong></p>
501 501
         <label class="screen-reader-text" for="page_template"><?php _e('Page Template', 'event_espresso') ?></label><select
502 502
         name="page_template" id="page_template">
@@ -504,471 +504,471 @@  discard block
 block discarded – undo
504 504
         <?php page_template_dropdown($template); ?>
505 505
     </select>
506 506
         <?php
507
-    }
508
-
509
-
510
-    /**
511
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
512
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
513
-     *
514
-     * @param  string $return    the current html
515
-     * @param  int    $id        the post id for the page
516
-     * @param  string $new_title What the title is
517
-     * @param  string $new_slug  what the slug is
518
-     * @return string            The new html string for the permalink area
519
-     */
520
-    public function preview_button_html($return, $id, $new_title, $new_slug)
521
-    {
522
-        $post = get_post($id);
523
-        if ('publish' !== get_post_status($post)) {
524
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
525
-                       . get_preview_post_link($id)
526
-                       . '" class="button button-small">'
527
-                       . __('Preview', 'event_espresso')
528
-                       . '</a></span>'
529
-                       . "\n";
530
-        }
531
-        return $return;
532
-    }
533
-
534
-
535
-    /**
536
-     * add our custom post stati dropdown on the wp post page for this cpt
537
-     *
538
-     * @return void
539
-     */
540
-    public function custom_post_stati_dropdown()
541
-    {
542
-
543
-        $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
544
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
545
-            ? $statuses[ $this->_cpt_model_obj->status() ]
546
-            : '';
547
-        $template_args = array(
548
-            'cur_status'            => $this->_cpt_model_obj->status(),
549
-            'statuses'              => $statuses,
550
-            'cur_status_label'      => $cur_status_label,
551
-            'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
552
-        );
553
-        // we'll add a trash post status (WP doesn't add one for some reason)
554
-        if ($this->_cpt_model_obj->status() === 'trash') {
555
-            $template_args['cur_status_label'] = __('Trashed', 'event_espresso');
556
-            $statuses['trash'] = __('Trashed', 'event_espresso');
557
-            $template_args['statuses'] = $statuses;
558
-        }
559
-
560
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
561
-        EEH_Template::display_template($template, $template_args);
562
-    }
563
-
564
-
565
-    public function setup_autosave_hooks()
566
-    {
567
-        $this->_set_autosave_containers();
568
-        $this->_load_autosave_scripts_styles();
569
-    }
570
-
571
-
572
-    /**
573
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
574
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
575
-     * for the nonce in here, but then this method looks for two things:
576
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
577
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
578
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
579
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
580
-     * template args.
581
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
582
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
583
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
584
-     *    $this->_template_args['data']['items'] = array(
585
-     *        'event-datetime-ids' => '1,2,3';
586
-     *    );
587
-     *    Keep in mind the following things:
588
-     *    - "where" index is for the input with the id as that string.
589
-     *    - "what" index is what will be used for the value of that input.
590
-     *
591
-     * @return void
592
-     */
593
-    public function do_extra_autosave_stuff()
594
-    {
595
-        // next let's check for the autosave nonce (we'll use _verify_nonce )
596
-        $nonce = isset($this->_req_data['autosavenonce'])
597
-            ? $this->_req_data['autosavenonce']
598
-            : null;
599
-        $this->_verify_nonce($nonce, 'autosave');
600
-        // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
601
-        if (! defined('DOING_AUTOSAVE')) {
602
-            define('DOING_AUTOSAVE', true);
603
-        }
604
-        // if we made it here then the nonce checked out.  Let's run our methods and actions
605
-        $autosave = "_ee_autosave_{$this->_current_view}";
606
-        if (method_exists($this, $autosave)) {
607
-            $this->$autosave();
608
-        } else {
609
-            $this->_template_args['success'] = true;
610
-        }
611
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
612
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
613
-        // now let's return json
614
-        $this->_return_json();
615
-    }
616
-
617
-
618
-    /**
619
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
620
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
621
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
622
-     *
623
-     * @access protected
624
-     * @throws EE_Error
625
-     * @return void
626
-     */
627
-    protected function _extend_page_config_for_cpt()
628
-    {
629
-        // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
630
-        if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
631
-            return;
632
-        }
633
-        // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
634
-        if (! empty($this->_cpt_object)) {
635
-            $this->_page_routes = array_merge(
636
-                array(
637
-                    'create_new' => '_create_new_cpt_item',
638
-                    'edit'       => '_edit_cpt_item',
639
-                ),
640
-                $this->_page_routes
641
-            );
642
-            $this->_page_config = array_merge(
643
-                array(
644
-                    'create_new' => array(
645
-                        'nav'           => array(
646
-                            'label' => $this->_cpt_object->labels->add_new_item,
647
-                            'order' => 5,
648
-                        ),
649
-                        'require_nonce' => false,
650
-                    ),
651
-                    'edit'       => array(
652
-                        'nav'           => array(
653
-                            'label'      => $this->_cpt_object->labels->edit_item,
654
-                            'order'      => 5,
655
-                            'persistent' => false,
656
-                            'url'        => '',
657
-                        ),
658
-                        'require_nonce' => false,
659
-                    ),
660
-                ),
661
-                $this->_page_config
662
-            );
663
-        }
664
-        // load the next section only if this is a matching cpt route as set in the cpt routes array.
665
-        if (! isset($this->_cpt_routes[ $this->_req_action ])) {
666
-            return;
667
-        }
668
-        $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false;
669
-        // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
670
-        if (empty($this->_cpt_object)) {
671
-            $msg = sprintf(
672
-                __(
673
-                    '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).',
674
-                    'event_espresso'
675
-                ),
676
-                $this->page_slug,
677
-                $this->_req_action,
678
-                get_class($this)
679
-            );
680
-            throw new EE_Error($msg);
681
-        }
682
-        if ($this->_cpt_route) {
683
-            $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
684
-            $this->_set_model_object($id);
685
-        }
686
-    }
687
-
688
-
689
-    /**
690
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
691
-     *
692
-     * @access protected
693
-     * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
694
-     * @param bool   $ignore_route_check
695
-     * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
696
-     * @throws EE_Error
697
-     * @throws InvalidArgumentException
698
-     * @throws InvalidDataTypeException
699
-     * @throws InvalidInterfaceException
700
-     * @throws ReflectionException
701
-     */
702
-    protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
703
-    {
704
-        $model = null;
705
-        if (empty($this->_cpt_model_names)
706
-            || (
707
-                ! $ignore_route_check
708
-                && ! isset($this->_cpt_routes[ $this->_req_action ])
709
-            ) || (
710
-                $this->_cpt_model_obj instanceof EE_CPT_Base
711
-                && $this->_cpt_model_obj->ID() === $id
712
-            )
713
-        ) {
714
-            // 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.
715
-            return;
716
-        }
717
-        // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
718
-        if ($ignore_route_check) {
719
-            $post_type = get_post_type($id);
720
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
721
-            $custom_post_types = LoaderFactory::getLoader()->getShared(
722
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
723
-            );
724
-            $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
725
-            if (isset($model_names[ $post_type ])) {
726
-                $model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
727
-            }
728
-        } else {
729
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
730
-        }
731
-        if ($model instanceof EEM_Base) {
732
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
733
-        }
734
-        do_action(
735
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
736
-            $this->_cpt_model_obj,
737
-            $req_type
738
-        );
739
-    }
740
-
741
-
742
-    /**
743
-     * admin_init_global
744
-     * This runs all the code that we want executed within the WP admin_init hook.
745
-     * This method executes for ALL EE Admin pages.
746
-     *
747
-     * @access public
748
-     * @return void
749
-     */
750
-    public function admin_init_global()
751
-    {
752
-        $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
753
-        // its possible this is a new save so let's catch that instead
754
-        $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
755
-        $post_type = $post ? $post->post_type : false;
756
-        $current_route = isset($this->_req_data['current_route'])
757
-            ? $this->_req_data['current_route']
758
-            : 'shouldneverwork';
759
-        $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
760
-            ? $this->_cpt_routes[ $current_route ]
761
-            : '';
762
-        add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
763
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
764
-        if ($post_type === $route_to_check) {
765
-            add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
766
-        }
767
-        // now let's filter redirect if we're on a revision page and the revision is for an event CPT.
768
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
769
-        if (! empty($revision)) {
770
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
771
-            // doing a restore?
772
-            if (! empty($action) && $action === 'restore') {
773
-                // get post for revision
774
-                $rev_post = get_post($revision);
775
-                $rev_parent = get_post($rev_post->post_parent);
776
-                // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
777
-                if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
778
-                    add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
779
-                    // restores of revisions
780
-                    add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
781
-                }
782
-            }
783
-        }
784
-        // 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!
785
-        if ($post_type && $post_type === $route_to_check) {
786
-            // $post_id, $post
787
-            add_action('save_post', array($this, 'insert_update'), 10, 3);
788
-            // $post_id
789
-            add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
790
-            add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
791
-            add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
792
-            add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
793
-        }
794
-    }
795
-
796
-
797
-    /**
798
-     * Callback for the WordPress trashed_post hook.
799
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
800
-     *
801
-     * @param int $post_id
802
-     * @throws \EE_Error
803
-     */
804
-    public function before_trash_cpt_item($post_id)
805
-    {
806
-        $this->_set_model_object($post_id, true, 'trash');
807
-        // if our cpt object isn't existent then get out immediately.
808
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
809
-            return;
810
-        }
811
-        $this->trash_cpt_item($post_id);
812
-    }
813
-
814
-
815
-    /**
816
-     * Callback for the WordPress untrashed_post hook.
817
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
818
-     *
819
-     * @param $post_id
820
-     * @throws \EE_Error
821
-     */
822
-    public function before_restore_cpt_item($post_id)
823
-    {
824
-        $this->_set_model_object($post_id, true, 'restore');
825
-        // if our cpt object isn't existent then get out immediately.
826
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
827
-            return;
828
-        }
829
-        $this->restore_cpt_item($post_id);
830
-    }
831
-
832
-
833
-    /**
834
-     * Callback for the WordPress after_delete_post hook.
835
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
836
-     *
837
-     * @param $post_id
838
-     * @throws \EE_Error
839
-     */
840
-    public function before_delete_cpt_item($post_id)
841
-    {
842
-        $this->_set_model_object($post_id, true, 'delete');
843
-        // if our cpt object isn't existent then get out immediately.
844
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
845
-            return;
846
-        }
847
-        $this->delete_cpt_item($post_id);
848
-    }
849
-
850
-
851
-    /**
852
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
853
-     * accordingly.
854
-     *
855
-     * @access public
856
-     * @throws EE_Error
857
-     * @return void
858
-     */
859
-    public function verify_cpt_object()
860
-    {
861
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
862
-        // verify event object
863
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
864
-            throw new EE_Error(
865
-                sprintf(
866
-                    __(
867
-                        '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',
868
-                        'event_espresso'
869
-                    ),
870
-                    $label
871
-                )
872
-            );
873
-        }
874
-        // if auto-draft then throw an error
875
-        if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
876
-            EE_Error::overwrite_errors();
877
-            EE_Error::add_error(
878
-                sprintf(
879
-                    __(
880
-                        '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.',
881
-                        'event_espresso'
882
-                    ),
883
-                    $label
884
-                ),
885
-                __FILE__,
886
-                __FUNCTION__,
887
-                __LINE__
888
-            );
889
-        }
890
-    }
891
-
892
-
893
-    /**
894
-     * admin_footer_scripts_global
895
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
896
-     * will apply on ALL EE_Admin pages.
897
-     *
898
-     * @access public
899
-     * @return void
900
-     */
901
-    public function admin_footer_scripts_global()
902
-    {
903
-        $this->_add_admin_page_ajax_loading_img();
904
-        $this->_add_admin_page_overlay();
905
-    }
906
-
907
-
908
-    /**
909
-     * add in any global scripts for cpt routes
910
-     *
911
-     * @return void
912
-     */
913
-    public function load_global_scripts_styles()
914
-    {
915
-        parent::load_global_scripts_styles();
916
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
917
-            // setup custom post status object for localize script but only if we've got a cpt object
918
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
919
-            if (! empty($statuses)) {
920
-                // get ALL statuses!
921
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
922
-                // setup object
923
-                $ee_cpt_statuses = array();
924
-                foreach ($statuses as $status => $label) {
925
-                    $ee_cpt_statuses[ $status ] = array(
926
-                        'label'      => $label,
927
-                        'save_label' => sprintf(
928
-                            wp_strip_all_tags(__('Save as %s', 'event_espresso')),
929
-                            $label
930
-                        ),
931
-                    );
932
-                }
933
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
934
-            }
935
-        }
936
-    }
937
-
938
-
939
-    /**
940
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
941
-     * insert/updates
942
-     *
943
-     * @param  int     $post_id ID of post being updated
944
-     * @param  WP_Post $post    Post object from WP
945
-     * @param  bool    $update  Whether this is an update or a new save.
946
-     * @return void
947
-     * @throws \EE_Error
948
-     */
949
-    public function insert_update($post_id, $post, $update)
950
-    {
951
-        // make sure that if this is a revision OR trash action that we don't do any updates!
952
-        if (isset($this->_req_data['action'])
953
-            && (
954
-                $this->_req_data['action'] === 'restore'
955
-                || $this->_req_data['action'] === 'trash'
956
-            )
957
-        ) {
958
-            return;
959
-        }
960
-        $this->_set_model_object($post_id, true, 'insert_update');
961
-        // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
962
-        if ($update
963
-            && (
964
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
965
-                || $this->_cpt_model_obj->ID() !== $post_id
966
-            )
967
-        ) {
968
-            return;
969
-        }
970
-        // check for autosave and update our req_data property accordingly.
971
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
507
+	}
508
+
509
+
510
+	/**
511
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
512
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
513
+	 *
514
+	 * @param  string $return    the current html
515
+	 * @param  int    $id        the post id for the page
516
+	 * @param  string $new_title What the title is
517
+	 * @param  string $new_slug  what the slug is
518
+	 * @return string            The new html string for the permalink area
519
+	 */
520
+	public function preview_button_html($return, $id, $new_title, $new_slug)
521
+	{
522
+		$post = get_post($id);
523
+		if ('publish' !== get_post_status($post)) {
524
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
525
+					   . get_preview_post_link($id)
526
+					   . '" class="button button-small">'
527
+					   . __('Preview', 'event_espresso')
528
+					   . '</a></span>'
529
+					   . "\n";
530
+		}
531
+		return $return;
532
+	}
533
+
534
+
535
+	/**
536
+	 * add our custom post stati dropdown on the wp post page for this cpt
537
+	 *
538
+	 * @return void
539
+	 */
540
+	public function custom_post_stati_dropdown()
541
+	{
542
+
543
+		$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
544
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
545
+			? $statuses[ $this->_cpt_model_obj->status() ]
546
+			: '';
547
+		$template_args = array(
548
+			'cur_status'            => $this->_cpt_model_obj->status(),
549
+			'statuses'              => $statuses,
550
+			'cur_status_label'      => $cur_status_label,
551
+			'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
552
+		);
553
+		// we'll add a trash post status (WP doesn't add one for some reason)
554
+		if ($this->_cpt_model_obj->status() === 'trash') {
555
+			$template_args['cur_status_label'] = __('Trashed', 'event_espresso');
556
+			$statuses['trash'] = __('Trashed', 'event_espresso');
557
+			$template_args['statuses'] = $statuses;
558
+		}
559
+
560
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
561
+		EEH_Template::display_template($template, $template_args);
562
+	}
563
+
564
+
565
+	public function setup_autosave_hooks()
566
+	{
567
+		$this->_set_autosave_containers();
568
+		$this->_load_autosave_scripts_styles();
569
+	}
570
+
571
+
572
+	/**
573
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
574
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
575
+	 * for the nonce in here, but then this method looks for two things:
576
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
577
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
578
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
579
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
580
+	 * template args.
581
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
582
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
583
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
584
+	 *    $this->_template_args['data']['items'] = array(
585
+	 *        'event-datetime-ids' => '1,2,3';
586
+	 *    );
587
+	 *    Keep in mind the following things:
588
+	 *    - "where" index is for the input with the id as that string.
589
+	 *    - "what" index is what will be used for the value of that input.
590
+	 *
591
+	 * @return void
592
+	 */
593
+	public function do_extra_autosave_stuff()
594
+	{
595
+		// next let's check for the autosave nonce (we'll use _verify_nonce )
596
+		$nonce = isset($this->_req_data['autosavenonce'])
597
+			? $this->_req_data['autosavenonce']
598
+			: null;
599
+		$this->_verify_nonce($nonce, 'autosave');
600
+		// make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
601
+		if (! defined('DOING_AUTOSAVE')) {
602
+			define('DOING_AUTOSAVE', true);
603
+		}
604
+		// if we made it here then the nonce checked out.  Let's run our methods and actions
605
+		$autosave = "_ee_autosave_{$this->_current_view}";
606
+		if (method_exists($this, $autosave)) {
607
+			$this->$autosave();
608
+		} else {
609
+			$this->_template_args['success'] = true;
610
+		}
611
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
612
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
613
+		// now let's return json
614
+		$this->_return_json();
615
+	}
616
+
617
+
618
+	/**
619
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
620
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
621
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
622
+	 *
623
+	 * @access protected
624
+	 * @throws EE_Error
625
+	 * @return void
626
+	 */
627
+	protected function _extend_page_config_for_cpt()
628
+	{
629
+		// before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
630
+		if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
631
+			return;
632
+		}
633
+		// set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
634
+		if (! empty($this->_cpt_object)) {
635
+			$this->_page_routes = array_merge(
636
+				array(
637
+					'create_new' => '_create_new_cpt_item',
638
+					'edit'       => '_edit_cpt_item',
639
+				),
640
+				$this->_page_routes
641
+			);
642
+			$this->_page_config = array_merge(
643
+				array(
644
+					'create_new' => array(
645
+						'nav'           => array(
646
+							'label' => $this->_cpt_object->labels->add_new_item,
647
+							'order' => 5,
648
+						),
649
+						'require_nonce' => false,
650
+					),
651
+					'edit'       => array(
652
+						'nav'           => array(
653
+							'label'      => $this->_cpt_object->labels->edit_item,
654
+							'order'      => 5,
655
+							'persistent' => false,
656
+							'url'        => '',
657
+						),
658
+						'require_nonce' => false,
659
+					),
660
+				),
661
+				$this->_page_config
662
+			);
663
+		}
664
+		// load the next section only if this is a matching cpt route as set in the cpt routes array.
665
+		if (! isset($this->_cpt_routes[ $this->_req_action ])) {
666
+			return;
667
+		}
668
+		$this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false;
669
+		// add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
670
+		if (empty($this->_cpt_object)) {
671
+			$msg = sprintf(
672
+				__(
673
+					'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).',
674
+					'event_espresso'
675
+				),
676
+				$this->page_slug,
677
+				$this->_req_action,
678
+				get_class($this)
679
+			);
680
+			throw new EE_Error($msg);
681
+		}
682
+		if ($this->_cpt_route) {
683
+			$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
684
+			$this->_set_model_object($id);
685
+		}
686
+	}
687
+
688
+
689
+	/**
690
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
691
+	 *
692
+	 * @access protected
693
+	 * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
694
+	 * @param bool   $ignore_route_check
695
+	 * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
696
+	 * @throws EE_Error
697
+	 * @throws InvalidArgumentException
698
+	 * @throws InvalidDataTypeException
699
+	 * @throws InvalidInterfaceException
700
+	 * @throws ReflectionException
701
+	 */
702
+	protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
703
+	{
704
+		$model = null;
705
+		if (empty($this->_cpt_model_names)
706
+			|| (
707
+				! $ignore_route_check
708
+				&& ! isset($this->_cpt_routes[ $this->_req_action ])
709
+			) || (
710
+				$this->_cpt_model_obj instanceof EE_CPT_Base
711
+				&& $this->_cpt_model_obj->ID() === $id
712
+			)
713
+		) {
714
+			// 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.
715
+			return;
716
+		}
717
+		// if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
718
+		if ($ignore_route_check) {
719
+			$post_type = get_post_type($id);
720
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
721
+			$custom_post_types = LoaderFactory::getLoader()->getShared(
722
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
723
+			);
724
+			$model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
725
+			if (isset($model_names[ $post_type ])) {
726
+				$model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
727
+			}
728
+		} else {
729
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
730
+		}
731
+		if ($model instanceof EEM_Base) {
732
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
733
+		}
734
+		do_action(
735
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
736
+			$this->_cpt_model_obj,
737
+			$req_type
738
+		);
739
+	}
740
+
741
+
742
+	/**
743
+	 * admin_init_global
744
+	 * This runs all the code that we want executed within the WP admin_init hook.
745
+	 * This method executes for ALL EE Admin pages.
746
+	 *
747
+	 * @access public
748
+	 * @return void
749
+	 */
750
+	public function admin_init_global()
751
+	{
752
+		$post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
753
+		// its possible this is a new save so let's catch that instead
754
+		$post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
755
+		$post_type = $post ? $post->post_type : false;
756
+		$current_route = isset($this->_req_data['current_route'])
757
+			? $this->_req_data['current_route']
758
+			: 'shouldneverwork';
759
+		$route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
760
+			? $this->_cpt_routes[ $current_route ]
761
+			: '';
762
+		add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
763
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
764
+		if ($post_type === $route_to_check) {
765
+			add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
766
+		}
767
+		// now let's filter redirect if we're on a revision page and the revision is for an event CPT.
768
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
769
+		if (! empty($revision)) {
770
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
771
+			// doing a restore?
772
+			if (! empty($action) && $action === 'restore') {
773
+				// get post for revision
774
+				$rev_post = get_post($revision);
775
+				$rev_parent = get_post($rev_post->post_parent);
776
+				// only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
777
+				if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
778
+					add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
779
+					// restores of revisions
780
+					add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
781
+				}
782
+			}
783
+		}
784
+		// 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!
785
+		if ($post_type && $post_type === $route_to_check) {
786
+			// $post_id, $post
787
+			add_action('save_post', array($this, 'insert_update'), 10, 3);
788
+			// $post_id
789
+			add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
790
+			add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
791
+			add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
792
+			add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
793
+		}
794
+	}
795
+
796
+
797
+	/**
798
+	 * Callback for the WordPress trashed_post hook.
799
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
800
+	 *
801
+	 * @param int $post_id
802
+	 * @throws \EE_Error
803
+	 */
804
+	public function before_trash_cpt_item($post_id)
805
+	{
806
+		$this->_set_model_object($post_id, true, 'trash');
807
+		// if our cpt object isn't existent then get out immediately.
808
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
809
+			return;
810
+		}
811
+		$this->trash_cpt_item($post_id);
812
+	}
813
+
814
+
815
+	/**
816
+	 * Callback for the WordPress untrashed_post hook.
817
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
818
+	 *
819
+	 * @param $post_id
820
+	 * @throws \EE_Error
821
+	 */
822
+	public function before_restore_cpt_item($post_id)
823
+	{
824
+		$this->_set_model_object($post_id, true, 'restore');
825
+		// if our cpt object isn't existent then get out immediately.
826
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
827
+			return;
828
+		}
829
+		$this->restore_cpt_item($post_id);
830
+	}
831
+
832
+
833
+	/**
834
+	 * Callback for the WordPress after_delete_post hook.
835
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
836
+	 *
837
+	 * @param $post_id
838
+	 * @throws \EE_Error
839
+	 */
840
+	public function before_delete_cpt_item($post_id)
841
+	{
842
+		$this->_set_model_object($post_id, true, 'delete');
843
+		// if our cpt object isn't existent then get out immediately.
844
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
845
+			return;
846
+		}
847
+		$this->delete_cpt_item($post_id);
848
+	}
849
+
850
+
851
+	/**
852
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
853
+	 * accordingly.
854
+	 *
855
+	 * @access public
856
+	 * @throws EE_Error
857
+	 * @return void
858
+	 */
859
+	public function verify_cpt_object()
860
+	{
861
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
862
+		// verify event object
863
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
864
+			throw new EE_Error(
865
+				sprintf(
866
+					__(
867
+						'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',
868
+						'event_espresso'
869
+					),
870
+					$label
871
+				)
872
+			);
873
+		}
874
+		// if auto-draft then throw an error
875
+		if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
876
+			EE_Error::overwrite_errors();
877
+			EE_Error::add_error(
878
+				sprintf(
879
+					__(
880
+						'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.',
881
+						'event_espresso'
882
+					),
883
+					$label
884
+				),
885
+				__FILE__,
886
+				__FUNCTION__,
887
+				__LINE__
888
+			);
889
+		}
890
+	}
891
+
892
+
893
+	/**
894
+	 * admin_footer_scripts_global
895
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
896
+	 * will apply on ALL EE_Admin pages.
897
+	 *
898
+	 * @access public
899
+	 * @return void
900
+	 */
901
+	public function admin_footer_scripts_global()
902
+	{
903
+		$this->_add_admin_page_ajax_loading_img();
904
+		$this->_add_admin_page_overlay();
905
+	}
906
+
907
+
908
+	/**
909
+	 * add in any global scripts for cpt routes
910
+	 *
911
+	 * @return void
912
+	 */
913
+	public function load_global_scripts_styles()
914
+	{
915
+		parent::load_global_scripts_styles();
916
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
917
+			// setup custom post status object for localize script but only if we've got a cpt object
918
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
919
+			if (! empty($statuses)) {
920
+				// get ALL statuses!
921
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
922
+				// setup object
923
+				$ee_cpt_statuses = array();
924
+				foreach ($statuses as $status => $label) {
925
+					$ee_cpt_statuses[ $status ] = array(
926
+						'label'      => $label,
927
+						'save_label' => sprintf(
928
+							wp_strip_all_tags(__('Save as %s', 'event_espresso')),
929
+							$label
930
+						),
931
+					);
932
+				}
933
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
934
+			}
935
+		}
936
+	}
937
+
938
+
939
+	/**
940
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
941
+	 * insert/updates
942
+	 *
943
+	 * @param  int     $post_id ID of post being updated
944
+	 * @param  WP_Post $post    Post object from WP
945
+	 * @param  bool    $update  Whether this is an update or a new save.
946
+	 * @return void
947
+	 * @throws \EE_Error
948
+	 */
949
+	public function insert_update($post_id, $post, $update)
950
+	{
951
+		// make sure that if this is a revision OR trash action that we don't do any updates!
952
+		if (isset($this->_req_data['action'])
953
+			&& (
954
+				$this->_req_data['action'] === 'restore'
955
+				|| $this->_req_data['action'] === 'trash'
956
+			)
957
+		) {
958
+			return;
959
+		}
960
+		$this->_set_model_object($post_id, true, 'insert_update');
961
+		// if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
962
+		if ($update
963
+			&& (
964
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
965
+				|| $this->_cpt_model_obj->ID() !== $post_id
966
+			)
967
+		) {
968
+			return;
969
+		}
970
+		// check for autosave and update our req_data property accordingly.
971
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
972 972
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
973 973
 
974 974
                 foreach ( (array) $values as $key => $value ) {
@@ -978,532 +978,532 @@  discard block
 block discarded – undo
978 978
 
979 979
         }/**/ // TODO reactivate after autosave is implemented in 4.2
980 980
 
981
-        // take care of updating any selected page_template IF this cpt supports it.
982
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
983
-            // wp version aware.
984
-            if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
985
-                $page_templates = wp_get_theme()->get_page_templates();
986
-            } else {
987
-                $post->page_template = $this->_req_data['page_template'];
988
-                $page_templates = wp_get_theme()->get_page_templates($post);
989
-            }
990
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) {
991
-                EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
992
-            } else {
993
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
994
-            }
995
-        }
996
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
997
-            return;
998
-        } //TODO we'll remove this after reimplementing autosave in 4.2
999
-        $this->_insert_update_cpt_item($post_id, $post);
1000
-    }
1001
-
1002
-
1003
-    /**
1004
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
1005
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
1006
-     * so we don't have to check for our CPT.
1007
-     *
1008
-     * @param  int $post_id ID of the post
1009
-     * @return void
1010
-     */
1011
-    public function dont_permanently_delete_ee_cpts($post_id)
1012
-    {
1013
-        // only do this if we're actually processing one of our CPTs
1014
-        // if our cpt object isn't existent then get out immediately.
1015
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1016
-            return;
1017
-        }
1018
-        delete_post_meta($post_id, '_wp_trash_meta_status');
1019
-        delete_post_meta($post_id, '_wp_trash_meta_time');
1020
-        // our cpts may have comments so let's take care of that too
1021
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1022
-    }
1023
-
1024
-
1025
-    /**
1026
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1027
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1028
-     * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1029
-     *
1030
-     * @param  int $post_id     ID of cpt item
1031
-     * @param  int $revision_id ID of revision being restored
1032
-     * @return void
1033
-     */
1034
-    public function restore_revision($post_id, $revision_id)
1035
-    {
1036
-        $this->_restore_cpt_item($post_id, $revision_id);
1037
-        // global action
1038
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1039
-        // class specific action so you can limit hooking into a specific page.
1040
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1041
-    }
1042
-
1043
-
1044
-    /**
1045
-     * @see restore_revision() for details
1046
-     * @param  int $post_id     ID of cpt item
1047
-     * @param  int $revision_id ID of revision for item
1048
-     * @return void
1049
-     */
1050
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
1051
-
1052
-
1053
-    /**
1054
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
1055
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1056
-     * To fix we have to reset the current_screen using the page_slug
1057
-     * (which is identical - or should be - to our registered_post_type id.)
1058
-     * Also, since the core WP file loads the admin_header.php for WP
1059
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1060
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1061
-     *
1062
-     * @return void
1063
-     */
1064
-    public function modify_current_screen()
1065
-    {
1066
-        // ONLY do this if the current page_route IS a cpt route
1067
-        if (! $this->_cpt_route) {
1068
-            return;
1069
-        }
1070
-        // routing things REALLY early b/c this is a cpt admin page
1071
-        set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1072
-        $this->_current_screen = get_current_screen();
1073
-        $this->_current_screen->base = 'event-espresso';
1074
-        $this->_add_help_tabs(); // we make sure we add any help tabs back in!
1075
-        /*try {
981
+		// take care of updating any selected page_template IF this cpt supports it.
982
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
983
+			// wp version aware.
984
+			if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
985
+				$page_templates = wp_get_theme()->get_page_templates();
986
+			} else {
987
+				$post->page_template = $this->_req_data['page_template'];
988
+				$page_templates = wp_get_theme()->get_page_templates($post);
989
+			}
990
+			if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) {
991
+				EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
992
+			} else {
993
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
994
+			}
995
+		}
996
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
997
+			return;
998
+		} //TODO we'll remove this after reimplementing autosave in 4.2
999
+		$this->_insert_update_cpt_item($post_id, $post);
1000
+	}
1001
+
1002
+
1003
+	/**
1004
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
1005
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
1006
+	 * so we don't have to check for our CPT.
1007
+	 *
1008
+	 * @param  int $post_id ID of the post
1009
+	 * @return void
1010
+	 */
1011
+	public function dont_permanently_delete_ee_cpts($post_id)
1012
+	{
1013
+		// only do this if we're actually processing one of our CPTs
1014
+		// if our cpt object isn't existent then get out immediately.
1015
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1016
+			return;
1017
+		}
1018
+		delete_post_meta($post_id, '_wp_trash_meta_status');
1019
+		delete_post_meta($post_id, '_wp_trash_meta_time');
1020
+		// our cpts may have comments so let's take care of that too
1021
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1022
+	}
1023
+
1024
+
1025
+	/**
1026
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1027
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1028
+	 * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1029
+	 *
1030
+	 * @param  int $post_id     ID of cpt item
1031
+	 * @param  int $revision_id ID of revision being restored
1032
+	 * @return void
1033
+	 */
1034
+	public function restore_revision($post_id, $revision_id)
1035
+	{
1036
+		$this->_restore_cpt_item($post_id, $revision_id);
1037
+		// global action
1038
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1039
+		// class specific action so you can limit hooking into a specific page.
1040
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1041
+	}
1042
+
1043
+
1044
+	/**
1045
+	 * @see restore_revision() for details
1046
+	 * @param  int $post_id     ID of cpt item
1047
+	 * @param  int $revision_id ID of revision for item
1048
+	 * @return void
1049
+	 */
1050
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
1051
+
1052
+
1053
+	/**
1054
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
1055
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1056
+	 * To fix we have to reset the current_screen using the page_slug
1057
+	 * (which is identical - or should be - to our registered_post_type id.)
1058
+	 * Also, since the core WP file loads the admin_header.php for WP
1059
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1060
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1061
+	 *
1062
+	 * @return void
1063
+	 */
1064
+	public function modify_current_screen()
1065
+	{
1066
+		// ONLY do this if the current page_route IS a cpt route
1067
+		if (! $this->_cpt_route) {
1068
+			return;
1069
+		}
1070
+		// routing things REALLY early b/c this is a cpt admin page
1071
+		set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1072
+		$this->_current_screen = get_current_screen();
1073
+		$this->_current_screen->base = 'event-espresso';
1074
+		$this->_add_help_tabs(); // we make sure we add any help tabs back in!
1075
+		/*try {
1076 1076
             $this->_route_admin_request();
1077 1077
         } catch ( EE_Error $e ) {
1078 1078
             $e->get_error();
1079 1079
         }/**/
1080
-    }
1081
-
1082
-
1083
-    /**
1084
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1085
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1086
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1087
-     * default to be.
1088
-     *
1089
-     * @param string $title The new title (or existing if there is no editor_title defined)
1090
-     * @return string
1091
-     */
1092
-    public function add_custom_editor_default_title($title)
1093
-    {
1094
-        return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1095
-            ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1096
-            : $title;
1097
-    }
1098
-
1099
-
1100
-    /**
1101
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1102
-     *
1103
-     * @param string $shortlink   The already generated shortlink
1104
-     * @param int    $id          Post ID for this item
1105
-     * @param string $context     The context for the link
1106
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1107
-     * @return string
1108
-     */
1109
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1110
-    {
1111
-        if (! empty($id) && get_option('permalink_structure') !== '') {
1112
-            $post = get_post($id);
1113
-            if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1114
-                $shortlink = home_url('?p=' . $post->ID);
1115
-            }
1116
-        }
1117
-        return $shortlink;
1118
-    }
1119
-
1120
-
1121
-    /**
1122
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1123
-     * already run in modify_current_screen())
1124
-     *
1125
-     * @return void
1126
-     */
1127
-    public function route_admin_request()
1128
-    {
1129
-        if ($this->_cpt_route) {
1130
-            return;
1131
-        }
1132
-        try {
1133
-            $this->_route_admin_request();
1134
-        } catch (EE_Error $e) {
1135
-            $e->get_error();
1136
-        }
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1142
-     *
1143
-     * @return void
1144
-     */
1145
-    public function cpt_post_form_hidden_input()
1146
-    {
1147
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1148
-        // we're also going to add the route value and the current page so we can direct autosave parsing correctly
1149
-        echo '<div id="ee-cpt-hidden-inputs">';
1150
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1151
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1152
-        echo '</div>';
1153
-    }
1154
-
1155
-
1156
-    /**
1157
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1158
-     *
1159
-     * @param  string $location Original location url
1160
-     * @param  int    $status   Status for http header
1161
-     * @return string           new (or original) url to redirect to.
1162
-     */
1163
-    public function revision_redirect($location, $status)
1164
-    {
1165
-        // get revision
1166
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1167
-        // can't do anything without revision so let's get out if not present
1168
-        if (empty($rev_id)) {
1169
-            return $location;
1170
-        }
1171
-        // get rev_post_data
1172
-        $rev = get_post($rev_id);
1173
-        $admin_url = $this->_admin_base_url;
1174
-        $query_args = array(
1175
-            'action'   => 'edit',
1176
-            'post'     => $rev->post_parent,
1177
-            'revision' => $rev_id,
1178
-            'message'  => 5,
1179
-        );
1180
-        $this->_process_notices($query_args, true);
1181
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1182
-    }
1183
-
1184
-
1185
-    /**
1186
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1187
-     *
1188
-     * @param  string $link    the original generated link
1189
-     * @param  int    $id      post id
1190
-     * @param  string $context optional, defaults to display.  How to write the '&'
1191
-     * @return string          the link
1192
-     */
1193
-    public function modify_edit_post_link($link, $id, $context)
1194
-    {
1195
-        $post = get_post($id);
1196
-        if (! isset($this->_req_data['action'])
1197
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1198
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1199
-        ) {
1200
-            return $link;
1201
-        }
1202
-        $query_args = array(
1203
-            'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1204
-                ? $this->_cpt_edit_routes[ $post->post_type ]
1205
-                : 'edit',
1206
-            'post'   => $id,
1207
-        );
1208
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1209
-    }
1210
-
1211
-
1212
-    /**
1213
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1214
-     * our routes.
1215
-     *
1216
-     * @param  string $delete_link  original delete link
1217
-     * @param  int    $post_id      id of cpt object
1218
-     * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1219
-     * @return string new delete link
1220
-     * @throws EE_Error
1221
-     */
1222
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1223
-    {
1224
-        $post = get_post($post_id);
1225
-
1226
-        if (empty($this->_req_data['action'])
1227
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1228
-            || ! $post instanceof WP_Post
1229
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1230
-        ) {
1231
-            return $delete_link;
1232
-        }
1233
-        $this->_set_model_object($post->ID, true);
1234
-
1235
-        // returns something like `trash_event` or `trash_attendee` or `trash_venue`
1236
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1237
-
1238
-        return EE_Admin_Page::add_query_args_and_nonce(
1239
-            array(
1240
-                'page'   => $this->_req_data['page'],
1241
-                'action' => $action,
1242
-                $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1243
-                         => $post->ID,
1244
-            ),
1245
-            admin_url()
1246
-        );
1247
-    }
1248
-
1249
-
1250
-    /**
1251
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1252
-     * so that we can hijack the default redirect locations for wp custom post types
1253
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1254
-     *
1255
-     * @param  string $location This is the incoming currently set redirect location
1256
-     * @param  string $post_id  This is the 'ID' value of the wp_posts table
1257
-     * @return string           the new location to redirect to
1258
-     */
1259
-    public function cpt_post_location_redirect($location, $post_id)
1260
-    {
1261
-        // we DO have a match so let's setup the url
1262
-        // we have to get the post to determine our route
1263
-        $post = get_post($post_id);
1264
-        $edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1265
-        // shared query_args
1266
-        $query_args = array('action' => $edit_route, 'post' => $post_id);
1267
-        $admin_url = $this->_admin_base_url;
1268
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1269
-            $status = get_post_status($post_id);
1270
-            if (isset($this->_req_data['publish'])) {
1271
-                switch ($status) {
1272
-                    case 'pending':
1273
-                        $message = 8;
1274
-                        break;
1275
-                    case 'future':
1276
-                        $message = 9;
1277
-                        break;
1278
-                    default:
1279
-                        $message = 6;
1280
-                }
1281
-            } else {
1282
-                $message = 'draft' === $status ? 10 : 1;
1283
-            }
1284
-        } elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1285
-            $message = 2;
1286
-        } elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1287
-            $message = 3;
1288
-        } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1289
-            $message = 7;
1290
-        } else {
1291
-            $message = 4;
1292
-        }
1293
-        // change the message if the post type is not viewable on the frontend
1294
-        $this->_cpt_object = get_post_type_object($post->post_type);
1295
-        $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1296
-        $query_args = array_merge(array('message' => $message), $query_args);
1297
-        $this->_process_notices($query_args, true);
1298
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1299
-    }
1300
-
1301
-
1302
-    /**
1303
-     * This method is called to inject nav tabs on core WP cpt pages
1304
-     *
1305
-     * @access public
1306
-     * @return void
1307
-     */
1308
-    public function inject_nav_tabs()
1309
-    {
1310
-        // can we hijack and insert the nav_tabs?
1311
-        $nav_tabs = $this->_get_main_nav_tabs();
1312
-        // first close off existing form tag
1313
-        $html = '>';
1314
-        $html .= $nav_tabs;
1315
-        // now let's handle the remaining tag ( missing ">" is CORRECT )
1316
-        $html .= '<span></span';
1317
-        echo $html;
1318
-    }
1319
-
1320
-
1321
-    /**
1322
-     * This just sets up the post update messages when an update form is loaded
1323
-     *
1324
-     * @access public
1325
-     * @param  array $messages the original messages array
1326
-     * @return array           the new messages array
1327
-     */
1328
-    public function post_update_messages($messages)
1329
-    {
1330
-        global $post;
1331
-        $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1332
-        $id = empty($id) && is_object($post) ? $post->ID : null;
1333
-        /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1080
+	}
1081
+
1082
+
1083
+	/**
1084
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1085
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1086
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1087
+	 * default to be.
1088
+	 *
1089
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1090
+	 * @return string
1091
+	 */
1092
+	public function add_custom_editor_default_title($title)
1093
+	{
1094
+		return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1095
+			? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1096
+			: $title;
1097
+	}
1098
+
1099
+
1100
+	/**
1101
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1102
+	 *
1103
+	 * @param string $shortlink   The already generated shortlink
1104
+	 * @param int    $id          Post ID for this item
1105
+	 * @param string $context     The context for the link
1106
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1107
+	 * @return string
1108
+	 */
1109
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1110
+	{
1111
+		if (! empty($id) && get_option('permalink_structure') !== '') {
1112
+			$post = get_post($id);
1113
+			if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1114
+				$shortlink = home_url('?p=' . $post->ID);
1115
+			}
1116
+		}
1117
+		return $shortlink;
1118
+	}
1119
+
1120
+
1121
+	/**
1122
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1123
+	 * already run in modify_current_screen())
1124
+	 *
1125
+	 * @return void
1126
+	 */
1127
+	public function route_admin_request()
1128
+	{
1129
+		if ($this->_cpt_route) {
1130
+			return;
1131
+		}
1132
+		try {
1133
+			$this->_route_admin_request();
1134
+		} catch (EE_Error $e) {
1135
+			$e->get_error();
1136
+		}
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1142
+	 *
1143
+	 * @return void
1144
+	 */
1145
+	public function cpt_post_form_hidden_input()
1146
+	{
1147
+		echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1148
+		// we're also going to add the route value and the current page so we can direct autosave parsing correctly
1149
+		echo '<div id="ee-cpt-hidden-inputs">';
1150
+		echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1151
+		echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1152
+		echo '</div>';
1153
+	}
1154
+
1155
+
1156
+	/**
1157
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1158
+	 *
1159
+	 * @param  string $location Original location url
1160
+	 * @param  int    $status   Status for http header
1161
+	 * @return string           new (or original) url to redirect to.
1162
+	 */
1163
+	public function revision_redirect($location, $status)
1164
+	{
1165
+		// get revision
1166
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1167
+		// can't do anything without revision so let's get out if not present
1168
+		if (empty($rev_id)) {
1169
+			return $location;
1170
+		}
1171
+		// get rev_post_data
1172
+		$rev = get_post($rev_id);
1173
+		$admin_url = $this->_admin_base_url;
1174
+		$query_args = array(
1175
+			'action'   => 'edit',
1176
+			'post'     => $rev->post_parent,
1177
+			'revision' => $rev_id,
1178
+			'message'  => 5,
1179
+		);
1180
+		$this->_process_notices($query_args, true);
1181
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1182
+	}
1183
+
1184
+
1185
+	/**
1186
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1187
+	 *
1188
+	 * @param  string $link    the original generated link
1189
+	 * @param  int    $id      post id
1190
+	 * @param  string $context optional, defaults to display.  How to write the '&'
1191
+	 * @return string          the link
1192
+	 */
1193
+	public function modify_edit_post_link($link, $id, $context)
1194
+	{
1195
+		$post = get_post($id);
1196
+		if (! isset($this->_req_data['action'])
1197
+			|| ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1198
+			|| $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1199
+		) {
1200
+			return $link;
1201
+		}
1202
+		$query_args = array(
1203
+			'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1204
+				? $this->_cpt_edit_routes[ $post->post_type ]
1205
+				: 'edit',
1206
+			'post'   => $id,
1207
+		);
1208
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1209
+	}
1210
+
1211
+
1212
+	/**
1213
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1214
+	 * our routes.
1215
+	 *
1216
+	 * @param  string $delete_link  original delete link
1217
+	 * @param  int    $post_id      id of cpt object
1218
+	 * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1219
+	 * @return string new delete link
1220
+	 * @throws EE_Error
1221
+	 */
1222
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1223
+	{
1224
+		$post = get_post($post_id);
1225
+
1226
+		if (empty($this->_req_data['action'])
1227
+			|| ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1228
+			|| ! $post instanceof WP_Post
1229
+			|| $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1230
+		) {
1231
+			return $delete_link;
1232
+		}
1233
+		$this->_set_model_object($post->ID, true);
1234
+
1235
+		// returns something like `trash_event` or `trash_attendee` or `trash_venue`
1236
+		$action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1237
+
1238
+		return EE_Admin_Page::add_query_args_and_nonce(
1239
+			array(
1240
+				'page'   => $this->_req_data['page'],
1241
+				'action' => $action,
1242
+				$this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1243
+						 => $post->ID,
1244
+			),
1245
+			admin_url()
1246
+		);
1247
+	}
1248
+
1249
+
1250
+	/**
1251
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1252
+	 * so that we can hijack the default redirect locations for wp custom post types
1253
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1254
+	 *
1255
+	 * @param  string $location This is the incoming currently set redirect location
1256
+	 * @param  string $post_id  This is the 'ID' value of the wp_posts table
1257
+	 * @return string           the new location to redirect to
1258
+	 */
1259
+	public function cpt_post_location_redirect($location, $post_id)
1260
+	{
1261
+		// we DO have a match so let's setup the url
1262
+		// we have to get the post to determine our route
1263
+		$post = get_post($post_id);
1264
+		$edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1265
+		// shared query_args
1266
+		$query_args = array('action' => $edit_route, 'post' => $post_id);
1267
+		$admin_url = $this->_admin_base_url;
1268
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1269
+			$status = get_post_status($post_id);
1270
+			if (isset($this->_req_data['publish'])) {
1271
+				switch ($status) {
1272
+					case 'pending':
1273
+						$message = 8;
1274
+						break;
1275
+					case 'future':
1276
+						$message = 9;
1277
+						break;
1278
+					default:
1279
+						$message = 6;
1280
+				}
1281
+			} else {
1282
+				$message = 'draft' === $status ? 10 : 1;
1283
+			}
1284
+		} elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1285
+			$message = 2;
1286
+		} elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1287
+			$message = 3;
1288
+		} elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1289
+			$message = 7;
1290
+		} else {
1291
+			$message = 4;
1292
+		}
1293
+		// change the message if the post type is not viewable on the frontend
1294
+		$this->_cpt_object = get_post_type_object($post->post_type);
1295
+		$message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1296
+		$query_args = array_merge(array('message' => $message), $query_args);
1297
+		$this->_process_notices($query_args, true);
1298
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1299
+	}
1300
+
1301
+
1302
+	/**
1303
+	 * This method is called to inject nav tabs on core WP cpt pages
1304
+	 *
1305
+	 * @access public
1306
+	 * @return void
1307
+	 */
1308
+	public function inject_nav_tabs()
1309
+	{
1310
+		// can we hijack and insert the nav_tabs?
1311
+		$nav_tabs = $this->_get_main_nav_tabs();
1312
+		// first close off existing form tag
1313
+		$html = '>';
1314
+		$html .= $nav_tabs;
1315
+		// now let's handle the remaining tag ( missing ">" is CORRECT )
1316
+		$html .= '<span></span';
1317
+		echo $html;
1318
+	}
1319
+
1320
+
1321
+	/**
1322
+	 * This just sets up the post update messages when an update form is loaded
1323
+	 *
1324
+	 * @access public
1325
+	 * @param  array $messages the original messages array
1326
+	 * @return array           the new messages array
1327
+	 */
1328
+	public function post_update_messages($messages)
1329
+	{
1330
+		global $post;
1331
+		$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1332
+		$id = empty($id) && is_object($post) ? $post->ID : null;
1333
+		/*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1334 1334
 
1335 1335
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1336
-        $messages[ $post->post_type ] = array(
1337
-            0  => '', // Unused. Messages start at index 1.
1338
-            1  => sprintf(
1339
-                __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1340
-                $this->_cpt_object->labels->singular_name,
1341
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1342
-                '</a>'
1343
-            ),
1344
-            2  => __('Custom field updated', 'event_espresso'),
1345
-            3  => __('Custom field deleted.', 'event_espresso'),
1346
-            4  => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1347
-            5  => isset($_GET['revision']) ? sprintf(
1348
-                __('%s restored to revision from %s', 'event_espresso'),
1349
-                $this->_cpt_object->labels->singular_name,
1350
-                wp_post_revision_title((int) $_GET['revision'], false)
1351
-            )
1352
-                : false,
1353
-            6  => sprintf(
1354
-                __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1355
-                $this->_cpt_object->labels->singular_name,
1356
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1357
-                '</a>'
1358
-            ),
1359
-            7  => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1360
-            8  => sprintf(
1361
-                __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1362
-                $this->_cpt_object->labels->singular_name,
1363
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1364
-                '</a>'
1365
-            ),
1366
-            9  => sprintf(
1367
-                __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1368
-                $this->_cpt_object->labels->singular_name,
1369
-                '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1370
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1371
-                '</a>'
1372
-            ),
1373
-            10 => sprintf(
1374
-                __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1375
-                $this->_cpt_object->labels->singular_name,
1376
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1377
-                '</a>'
1378
-            ),
1379
-        );
1380
-        return $messages;
1381
-    }
1382
-
1383
-
1384
-    /**
1385
-     * default method for the 'create_new' route for cpt admin pages.
1386
-     * For reference what to include in here, see wp-admin/post-new.php
1387
-     *
1388
-     * @access  protected
1389
-     * @return void
1390
-     */
1391
-    protected function _create_new_cpt_item()
1392
-    {
1393
-        // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1394
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1395
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1396
-        $post_type_object = $this->_cpt_object;
1397
-        $title = $post_type_object->labels->add_new_item;
1398
-        $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1399
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1400
-        // modify the default editor title field with default title.
1401
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1402
-        $this->loadEditorTemplate(true);
1403
-    }
1404
-
1405
-
1406
-    /**
1407
-     * Enqueues auto-save and loads the editor template
1408
-     *
1409
-     * @param bool $creating
1410
-     */
1411
-    private function loadEditorTemplate($creating = true)
1412
-    {
1413
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1414
-        // these vars are used by the template
1415
-        $editing = true;
1416
-        $post_ID = $post->ID;
1417
-        if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1418
-            // only enqueue autosave when creating event (necessary to get permalink/url generated)
1419
-            // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1420
-            if ($creating) {
1421
-                wp_enqueue_script('autosave');
1422
-            } else {
1423
-                if (isset($this->_cpt_routes[ $this->_req_data['action'] ])
1424
-                    && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1425
-                ) {
1426
-                    $create_new_action = apply_filters(
1427
-                        'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1428
-                        'create_new',
1429
-                        $this
1430
-                    );
1431
-                    $post_new_file = EE_Admin_Page::add_query_args_and_nonce(
1432
-                        array(
1433
-                            'action' => $create_new_action,
1434
-                            'page'   => $this->page_slug,
1435
-                        ),
1436
-                        'admin.php'
1437
-                    );
1438
-                }
1439
-            }
1440
-            include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1441
-        }
1442
-    }
1443
-
1444
-
1445
-    public function add_new_admin_page_global()
1446
-    {
1447
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1448
-        ?>
1336
+		$messages[ $post->post_type ] = array(
1337
+			0  => '', // Unused. Messages start at index 1.
1338
+			1  => sprintf(
1339
+				__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1340
+				$this->_cpt_object->labels->singular_name,
1341
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1342
+				'</a>'
1343
+			),
1344
+			2  => __('Custom field updated', 'event_espresso'),
1345
+			3  => __('Custom field deleted.', 'event_espresso'),
1346
+			4  => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1347
+			5  => isset($_GET['revision']) ? sprintf(
1348
+				__('%s restored to revision from %s', 'event_espresso'),
1349
+				$this->_cpt_object->labels->singular_name,
1350
+				wp_post_revision_title((int) $_GET['revision'], false)
1351
+			)
1352
+				: false,
1353
+			6  => sprintf(
1354
+				__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1355
+				$this->_cpt_object->labels->singular_name,
1356
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1357
+				'</a>'
1358
+			),
1359
+			7  => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1360
+			8  => sprintf(
1361
+				__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1362
+				$this->_cpt_object->labels->singular_name,
1363
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1364
+				'</a>'
1365
+			),
1366
+			9  => sprintf(
1367
+				__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1368
+				$this->_cpt_object->labels->singular_name,
1369
+				'<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1370
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1371
+				'</a>'
1372
+			),
1373
+			10 => sprintf(
1374
+				__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1375
+				$this->_cpt_object->labels->singular_name,
1376
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1377
+				'</a>'
1378
+			),
1379
+		);
1380
+		return $messages;
1381
+	}
1382
+
1383
+
1384
+	/**
1385
+	 * default method for the 'create_new' route for cpt admin pages.
1386
+	 * For reference what to include in here, see wp-admin/post-new.php
1387
+	 *
1388
+	 * @access  protected
1389
+	 * @return void
1390
+	 */
1391
+	protected function _create_new_cpt_item()
1392
+	{
1393
+		// gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1394
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1395
+		$post_type = $this->_cpt_routes[ $this->_req_action ];
1396
+		$post_type_object = $this->_cpt_object;
1397
+		$title = $post_type_object->labels->add_new_item;
1398
+		$post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1399
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1400
+		// modify the default editor title field with default title.
1401
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1402
+		$this->loadEditorTemplate(true);
1403
+	}
1404
+
1405
+
1406
+	/**
1407
+	 * Enqueues auto-save and loads the editor template
1408
+	 *
1409
+	 * @param bool $creating
1410
+	 */
1411
+	private function loadEditorTemplate($creating = true)
1412
+	{
1413
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1414
+		// these vars are used by the template
1415
+		$editing = true;
1416
+		$post_ID = $post->ID;
1417
+		if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1418
+			// only enqueue autosave when creating event (necessary to get permalink/url generated)
1419
+			// otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1420
+			if ($creating) {
1421
+				wp_enqueue_script('autosave');
1422
+			} else {
1423
+				if (isset($this->_cpt_routes[ $this->_req_data['action'] ])
1424
+					&& ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1425
+				) {
1426
+					$create_new_action = apply_filters(
1427
+						'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1428
+						'create_new',
1429
+						$this
1430
+					);
1431
+					$post_new_file = EE_Admin_Page::add_query_args_and_nonce(
1432
+						array(
1433
+							'action' => $create_new_action,
1434
+							'page'   => $this->page_slug,
1435
+						),
1436
+						'admin.php'
1437
+					);
1438
+				}
1439
+			}
1440
+			include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1441
+		}
1442
+	}
1443
+
1444
+
1445
+	public function add_new_admin_page_global()
1446
+	{
1447
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1448
+		?>
1449 1449
         <script type="text/javascript">
1450 1450
             adminpage = '<?php echo $admin_page; ?>';
1451 1451
         </script>
1452 1452
         <?php
1453
-    }
1454
-
1455
-
1456
-    /**
1457
-     * default method for the 'edit' route for cpt admin pages
1458
-     * For reference on what to put in here, refer to wp-admin/post.php
1459
-     *
1460
-     * @access protected
1461
-     * @return string   template for edit cpt form
1462
-     */
1463
-    protected function _edit_cpt_item()
1464
-    {
1465
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1466
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1467
-        $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1468
-        if (empty($post)) {
1469
-            wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?', 'event_espresso'));
1470
-        }
1471
-        if (! empty($_GET['get-post-lock'])) {
1472
-            wp_set_post_lock($post_id);
1473
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1474
-            exit();
1475
-        }
1476
-
1477
-        // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1478
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1479
-        $post_type_object = $this->_cpt_object;
1480
-
1481
-        if (! wp_check_post_lock($post->ID)) {
1482
-            wp_set_post_lock($post->ID);
1483
-        }
1484
-        add_action('admin_footer', '_admin_notice_post_locked');
1485
-        if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1486
-            wp_enqueue_script('admin-comments');
1487
-            enqueue_comment_hotkeys_js();
1488
-        }
1489
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1490
-        // modify the default editor title field with default title.
1491
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1492
-        $this->loadEditorTemplate(false);
1493
-    }
1494
-
1495
-
1496
-
1497
-    /**
1498
-     * some getters
1499
-     */
1500
-    /**
1501
-     * This returns the protected _cpt_model_obj property
1502
-     *
1503
-     * @return EE_CPT_Base
1504
-     */
1505
-    public function get_cpt_model_obj()
1506
-    {
1507
-        return $this->_cpt_model_obj;
1508
-    }
1453
+	}
1454
+
1455
+
1456
+	/**
1457
+	 * default method for the 'edit' route for cpt admin pages
1458
+	 * For reference on what to put in here, refer to wp-admin/post.php
1459
+	 *
1460
+	 * @access protected
1461
+	 * @return string   template for edit cpt form
1462
+	 */
1463
+	protected function _edit_cpt_item()
1464
+	{
1465
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1466
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1467
+		$post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1468
+		if (empty($post)) {
1469
+			wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?', 'event_espresso'));
1470
+		}
1471
+		if (! empty($_GET['get-post-lock'])) {
1472
+			wp_set_post_lock($post_id);
1473
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1474
+			exit();
1475
+		}
1476
+
1477
+		// template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1478
+		$post_type = $this->_cpt_routes[ $this->_req_action ];
1479
+		$post_type_object = $this->_cpt_object;
1480
+
1481
+		if (! wp_check_post_lock($post->ID)) {
1482
+			wp_set_post_lock($post->ID);
1483
+		}
1484
+		add_action('admin_footer', '_admin_notice_post_locked');
1485
+		if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1486
+			wp_enqueue_script('admin-comments');
1487
+			enqueue_comment_hotkeys_js();
1488
+		}
1489
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1490
+		// modify the default editor title field with default title.
1491
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1492
+		$this->loadEditorTemplate(false);
1493
+	}
1494
+
1495
+
1496
+
1497
+	/**
1498
+	 * some getters
1499
+	 */
1500
+	/**
1501
+	 * This returns the protected _cpt_model_obj property
1502
+	 *
1503
+	 * @return EE_CPT_Base
1504
+	 */
1505
+	public function get_cpt_model_obj()
1506
+	{
1507
+		return $this->_cpt_model_obj;
1508
+	}
1509 1509
 }
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
             $this->_cpt_routes
170 170
         );
171 171
         // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
172
-        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ])
173
-            ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ])
172
+        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
173
+            ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
174 174
             : get_post_type_object($page);
175 175
         // tweak pagenow for page loading.
176
-        if (! $this->_pagenow_map) {
176
+        if ( ! $this->_pagenow_map) {
177 177
             $this->_pagenow_map = array(
178 178
                 'create_new' => 'post-new.php',
179 179
                 'edit'       => 'post.php',
@@ -207,12 +207,12 @@  discard block
 block discarded – undo
207 207
     {
208 208
         global $pagenow, $hook_suffix;
209 209
         // possibly reset pagenow.
210
-        if (! empty($this->_req_data['page'])
210
+        if ( ! empty($this->_req_data['page'])
211 211
             && $this->_req_data['page'] == $this->page_slug
212 212
             && ! empty($this->_req_data['action'])
213
-            && isset($this->_pagenow_map[ $this->_req_data['action'] ])
213
+            && isset($this->_pagenow_map[$this->_req_data['action']])
214 214
         ) {
215
-            $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ];
215
+            $pagenow = $this->_pagenow_map[$this->_req_data['action']];
216 216
             $hook_suffix = $pagenow;
217 217
         }
218 218
     }
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
         if (empty($wp_meta_boxes)) {
245 245
             return;
246 246
         }
247
-        $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array();
247
+        $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
248 248
         foreach ($current_metaboxes as $box_context) {
249 249
             foreach ($box_context as $box_details) {
250 250
                 foreach ($box_details as $box) {
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
             $this
278 278
         );
279 279
         $containers = apply_filters(
280
-            'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
280
+            'FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers',
281 281
             $containers,
282 282
             $this
283 283
         );
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
     protected function _load_page_dependencies()
324 324
     {
325 325
         // we only add stuff if this is a cpt_route!
326
-        if (! $this->_cpt_route) {
326
+        if ( ! $this->_cpt_route) {
327 327
             parent::_load_page_dependencies();
328 328
             return;
329 329
         }
@@ -347,16 +347,16 @@  discard block
 block discarded – undo
347 347
         add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
348 348
         // This basically allows us to change the title of the "publish" metabox area
349 349
         // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
350
-        if (! empty($this->_labels['publishbox'])) {
350
+        if ( ! empty($this->_labels['publishbox'])) {
351 351
             $box_label = is_array($this->_labels['publishbox'])
352
-                         && isset($this->_labels['publishbox'][ $this->_req_action ])
353
-                ? $this->_labels['publishbox'][ $this->_req_action ]
352
+                         && isset($this->_labels['publishbox'][$this->_req_action])
353
+                ? $this->_labels['publishbox'][$this->_req_action]
354 354
                 : $this->_labels['publishbox'];
355 355
             add_meta_box(
356 356
                 'submitdiv',
357 357
                 $box_label,
358 358
                 'post_submit_meta_box',
359
-                $this->_cpt_routes[ $this->_req_action ],
359
+                $this->_cpt_routes[$this->_req_action],
360 360
                 'side',
361 361
                 'core'
362 362
             );
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
                 'page_templates',
368 368
                 __('Page Template', 'event_espresso'),
369 369
                 array($this, 'page_template_meta_box'),
370
-                $this->_cpt_routes[ $this->_req_action ],
370
+                $this->_cpt_routes[$this->_req_action],
371 371
                 'side',
372 372
                 'default'
373 373
             );
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
         // This is for any plugins that are doing things properly
400 400
         // and hooking into the load page hook for core wp cpt routes.
401 401
         global $pagenow;
402
-        do_action('load-' . $pagenow);
402
+        do_action('load-'.$pagenow);
403 403
         $this->modify_current_screen();
404 404
         add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
405 405
         // we route REALLY early.
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
                 'admin.php?page=espresso_registrations&action=contact_list',
430 430
             ),
431 431
             1 => array(
432
-                'edit.php?post_type=' . $this->_cpt_object->name,
433
-                'admin.php?page=' . $this->_cpt_object->name,
432
+                'edit.php?post_type='.$this->_cpt_object->name,
433
+                'admin.php?page='.$this->_cpt_object->name,
434 434
             ),
435 435
         );
436 436
         foreach ($routes_to_match as $route_matches) {
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
             'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
460 460
         );
461 461
         $cpt_args = $custom_post_types->getDefinitions();
462
-        $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array();
462
+        $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
463 463
         $cpt_has_support = ! empty($cpt_args['page_templates']);
464 464
 
465 465
         // if the installed version of WP is > 4.7 we do some additional checks.
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
             // if there are $post_templates for this cpt, then we return false for this method because
469 469
             // that means we aren't going to load our page template manager and leave that up to the native
470 470
             // cpt template manager.
471
-            $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
471
+            $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
472 472
         }
473 473
 
474 474
         return $cpt_has_support;
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
 
543 543
         $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
544 544
         $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
545
-            ? $statuses[ $this->_cpt_model_obj->status() ]
545
+            ? $statuses[$this->_cpt_model_obj->status()]
546 546
             : '';
547 547
         $template_args = array(
548 548
             'cur_status'            => $this->_cpt_model_obj->status(),
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
             $template_args['statuses'] = $statuses;
558 558
         }
559 559
 
560
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
560
+        $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php';
561 561
         EEH_Template::display_template($template, $template_args);
562 562
     }
563 563
 
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
             : null;
599 599
         $this->_verify_nonce($nonce, 'autosave');
600 600
         // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
601
-        if (! defined('DOING_AUTOSAVE')) {
601
+        if ( ! defined('DOING_AUTOSAVE')) {
602 602
             define('DOING_AUTOSAVE', true);
603 603
         }
604 604
         // if we made it here then the nonce checked out.  Let's run our methods and actions
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
             $this->_template_args['success'] = true;
610 610
         }
611 611
         do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
612
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
612
+        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this);
613 613
         // now let's return json
614 614
         $this->_return_json();
615 615
     }
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
             return;
632 632
         }
633 633
         // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
634
-        if (! empty($this->_cpt_object)) {
634
+        if ( ! empty($this->_cpt_object)) {
635 635
             $this->_page_routes = array_merge(
636 636
                 array(
637 637
                     'create_new' => '_create_new_cpt_item',
@@ -662,10 +662,10 @@  discard block
 block discarded – undo
662 662
             );
663 663
         }
664 664
         // load the next section only if this is a matching cpt route as set in the cpt routes array.
665
-        if (! isset($this->_cpt_routes[ $this->_req_action ])) {
665
+        if ( ! isset($this->_cpt_routes[$this->_req_action])) {
666 666
             return;
667 667
         }
668
-        $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false;
668
+        $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
669 669
         // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
670 670
         if (empty($this->_cpt_object)) {
671 671
             $msg = sprintf(
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
         if (empty($this->_cpt_model_names)
706 706
             || (
707 707
                 ! $ignore_route_check
708
-                && ! isset($this->_cpt_routes[ $this->_req_action ])
708
+                && ! isset($this->_cpt_routes[$this->_req_action])
709 709
             ) || (
710 710
                 $this->_cpt_model_obj instanceof EE_CPT_Base
711 711
                 && $this->_cpt_model_obj->ID() === $id
@@ -722,11 +722,11 @@  discard block
 block discarded – undo
722 722
                 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
723 723
             );
724 724
             $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
725
-            if (isset($model_names[ $post_type ])) {
726
-                $model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
725
+            if (isset($model_names[$post_type])) {
726
+                $model = EE_Registry::instance()->load_model($model_names[$post_type]);
727 727
             }
728 728
         } else {
729
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
729
+            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
730 730
         }
731 731
         if ($model instanceof EEM_Base) {
732 732
             $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
@@ -756,8 +756,8 @@  discard block
 block discarded – undo
756 756
         $current_route = isset($this->_req_data['current_route'])
757 757
             ? $this->_req_data['current_route']
758 758
             : 'shouldneverwork';
759
-        $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
760
-            ? $this->_cpt_routes[ $current_route ]
759
+        $route_to_check = $post_type && isset($this->_cpt_routes[$current_route])
760
+            ? $this->_cpt_routes[$current_route]
761 761
             : '';
762 762
         add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
763 763
         add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
@@ -766,10 +766,10 @@  discard block
 block discarded – undo
766 766
         }
767 767
         // now let's filter redirect if we're on a revision page and the revision is for an event CPT.
768 768
         $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
769
-        if (! empty($revision)) {
769
+        if ( ! empty($revision)) {
770 770
             $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
771 771
             // doing a restore?
772
-            if (! empty($action) && $action === 'restore') {
772
+            if ( ! empty($action) && $action === 'restore') {
773 773
                 // get post for revision
774 774
                 $rev_post = get_post($revision);
775 775
                 $rev_parent = get_post($rev_post->post_parent);
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
     {
806 806
         $this->_set_model_object($post_id, true, 'trash');
807 807
         // if our cpt object isn't existent then get out immediately.
808
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
808
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
809 809
             return;
810 810
         }
811 811
         $this->trash_cpt_item($post_id);
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
     {
824 824
         $this->_set_model_object($post_id, true, 'restore');
825 825
         // if our cpt object isn't existent then get out immediately.
826
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
826
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
827 827
             return;
828 828
         }
829 829
         $this->restore_cpt_item($post_id);
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
     {
842 842
         $this->_set_model_object($post_id, true, 'delete');
843 843
         // if our cpt object isn't existent then get out immediately.
844
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
844
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
845 845
             return;
846 846
         }
847 847
         $this->delete_cpt_item($post_id);
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
     {
861 861
         $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
862 862
         // verify event object
863
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
863
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
864 864
             throw new EE_Error(
865 865
                 sprintf(
866 866
                     __(
@@ -916,13 +916,13 @@  discard block
 block discarded – undo
916 916
         if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
917 917
             // setup custom post status object for localize script but only if we've got a cpt object
918 918
             $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
919
-            if (! empty($statuses)) {
919
+            if ( ! empty($statuses)) {
920 920
                 // get ALL statuses!
921 921
                 $statuses = $this->_cpt_model_obj->get_all_post_statuses();
922 922
                 // setup object
923 923
                 $ee_cpt_statuses = array();
924 924
                 foreach ($statuses as $status => $label) {
925
-                    $ee_cpt_statuses[ $status ] = array(
925
+                    $ee_cpt_statuses[$status] = array(
926 926
                         'label'      => $label,
927 927
                         'save_label' => sprintf(
928 928
                             wp_strip_all_tags(__('Save as %s', 'event_espresso')),
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
                 $post->page_template = $this->_req_data['page_template'];
988 988
                 $page_templates = wp_get_theme()->get_page_templates($post);
989 989
             }
990
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) {
990
+            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
991 991
                 EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
992 992
             } else {
993 993
                 update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
     {
1013 1013
         // only do this if we're actually processing one of our CPTs
1014 1014
         // if our cpt object isn't existent then get out immediately.
1015
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1015
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1016 1016
             return;
1017 1017
         }
1018 1018
         delete_post_meta($post_id, '_wp_trash_meta_status');
@@ -1037,7 +1037,7 @@  discard block
 block discarded – undo
1037 1037
         // global action
1038 1038
         do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1039 1039
         // class specific action so you can limit hooking into a specific page.
1040
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1040
+        do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id);
1041 1041
     }
1042 1042
 
1043 1043
 
@@ -1064,11 +1064,11 @@  discard block
 block discarded – undo
1064 1064
     public function modify_current_screen()
1065 1065
     {
1066 1066
         // ONLY do this if the current page_route IS a cpt route
1067
-        if (! $this->_cpt_route) {
1067
+        if ( ! $this->_cpt_route) {
1068 1068
             return;
1069 1069
         }
1070 1070
         // routing things REALLY early b/c this is a cpt admin page
1071
-        set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1071
+        set_current_screen($this->_cpt_routes[$this->_req_action]);
1072 1072
         $this->_current_screen = get_current_screen();
1073 1073
         $this->_current_screen->base = 'event-espresso';
1074 1074
         $this->_add_help_tabs(); // we make sure we add any help tabs back in!
@@ -1091,8 +1091,8 @@  discard block
 block discarded – undo
1091 1091
      */
1092 1092
     public function add_custom_editor_default_title($title)
1093 1093
     {
1094
-        return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1095
-            ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1094
+        return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1095
+            ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1096 1096
             : $title;
1097 1097
     }
1098 1098
 
@@ -1108,10 +1108,10 @@  discard block
 block discarded – undo
1108 1108
      */
1109 1109
     public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1110 1110
     {
1111
-        if (! empty($id) && get_option('permalink_structure') !== '') {
1111
+        if ( ! empty($id) && get_option('permalink_structure') !== '') {
1112 1112
             $post = get_post($id);
1113 1113
             if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1114
-                $shortlink = home_url('?p=' . $post->ID);
1114
+                $shortlink = home_url('?p='.$post->ID);
1115 1115
             }
1116 1116
         }
1117 1117
         return $shortlink;
@@ -1144,11 +1144,11 @@  discard block
 block discarded – undo
1144 1144
      */
1145 1145
     public function cpt_post_form_hidden_input()
1146 1146
     {
1147
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1147
+        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />';
1148 1148
         // we're also going to add the route value and the current page so we can direct autosave parsing correctly
1149 1149
         echo '<div id="ee-cpt-hidden-inputs">';
1150
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1151
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1150
+        echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />';
1151
+        echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />';
1152 1152
         echo '</div>';
1153 1153
     }
1154 1154
 
@@ -1193,15 +1193,15 @@  discard block
 block discarded – undo
1193 1193
     public function modify_edit_post_link($link, $id, $context)
1194 1194
     {
1195 1195
         $post = get_post($id);
1196
-        if (! isset($this->_req_data['action'])
1197
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1198
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1196
+        if ( ! isset($this->_req_data['action'])
1197
+            || ! isset($this->_cpt_routes[$this->_req_data['action']])
1198
+            || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1199 1199
         ) {
1200 1200
             return $link;
1201 1201
         }
1202 1202
         $query_args = array(
1203
-            'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1204
-                ? $this->_cpt_edit_routes[ $post->post_type ]
1203
+            'action' => isset($this->_cpt_edit_routes[$post->post_type])
1204
+                ? $this->_cpt_edit_routes[$post->post_type]
1205 1205
                 : 'edit',
1206 1206
             'post'   => $id,
1207 1207
         );
@@ -1224,16 +1224,16 @@  discard block
 block discarded – undo
1224 1224
         $post = get_post($post_id);
1225 1225
 
1226 1226
         if (empty($this->_req_data['action'])
1227
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1227
+            || ! isset($this->_cpt_routes[$this->_req_data['action']])
1228 1228
             || ! $post instanceof WP_Post
1229
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1229
+            || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1230 1230
         ) {
1231 1231
             return $delete_link;
1232 1232
         }
1233 1233
         $this->_set_model_object($post->ID, true);
1234 1234
 
1235 1235
         // returns something like `trash_event` or `trash_attendee` or `trash_venue`
1236
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1236
+        $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1237 1237
 
1238 1238
         return EE_Admin_Page::add_query_args_and_nonce(
1239 1239
             array(
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
         // we DO have a match so let's setup the url
1262 1262
         // we have to get the post to determine our route
1263 1263
         $post = get_post($post_id);
1264
-        $edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1264
+        $edit_route = $this->_cpt_edit_routes[$post->post_type];
1265 1265
         // shared query_args
1266 1266
         $query_args = array('action' => $edit_route, 'post' => $post_id);
1267 1267
         $admin_url = $this->_admin_base_url;
@@ -1333,12 +1333,12 @@  discard block
 block discarded – undo
1333 1333
         /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1334 1334
 
1335 1335
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1336
-        $messages[ $post->post_type ] = array(
1336
+        $messages[$post->post_type] = array(
1337 1337
             0  => '', // Unused. Messages start at index 1.
1338 1338
             1  => sprintf(
1339 1339
                 __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1340 1340
                 $this->_cpt_object->labels->singular_name,
1341
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1341
+                '<a href="'.esc_url(get_permalink($id)).'">',
1342 1342
                 '</a>'
1343 1343
             ),
1344 1344
             2  => __('Custom field updated', 'event_espresso'),
@@ -1353,27 +1353,27 @@  discard block
 block discarded – undo
1353 1353
             6  => sprintf(
1354 1354
                 __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1355 1355
                 $this->_cpt_object->labels->singular_name,
1356
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1356
+                '<a href="'.esc_url(get_permalink($id)).'">',
1357 1357
                 '</a>'
1358 1358
             ),
1359 1359
             7  => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1360 1360
             8  => sprintf(
1361 1361
                 __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1362 1362
                 $this->_cpt_object->labels->singular_name,
1363
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1363
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">',
1364 1364
                 '</a>'
1365 1365
             ),
1366 1366
             9  => sprintf(
1367 1367
                 __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1368 1368
                 $this->_cpt_object->labels->singular_name,
1369
-                '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1370
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1369
+                '<strong>'.date_i18n('M j, Y @ G:i', strtotime($post->post_date)).'</strong>',
1370
+                '<a target="_blank" href="'.esc_url(get_permalink($id)),
1371 1371
                 '</a>'
1372 1372
             ),
1373 1373
             10 => sprintf(
1374 1374
                 __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1375 1375
                 $this->_cpt_object->labels->singular_name,
1376
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1376
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1377 1377
                 '</a>'
1378 1378
             ),
1379 1379
         );
@@ -1392,10 +1392,10 @@  discard block
 block discarded – undo
1392 1392
     {
1393 1393
         // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1394 1394
         global $post, $title, $is_IE, $post_type, $post_type_object;
1395
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1395
+        $post_type = $this->_cpt_routes[$this->_req_action];
1396 1396
         $post_type_object = $this->_cpt_object;
1397 1397
         $title = $post_type_object->labels->add_new_item;
1398
-        $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1398
+        $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1399 1399
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1400 1400
         // modify the default editor title field with default title.
1401 1401
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
@@ -1420,8 +1420,8 @@  discard block
 block discarded – undo
1420 1420
             if ($creating) {
1421 1421
                 wp_enqueue_script('autosave');
1422 1422
             } else {
1423
-                if (isset($this->_cpt_routes[ $this->_req_data['action'] ])
1424
-                    && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1423
+                if (isset($this->_cpt_routes[$this->_req_data['action']])
1424
+                    && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1425 1425
                 ) {
1426 1426
                     $create_new_action = apply_filters(
1427 1427
                         'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
@@ -1437,7 +1437,7 @@  discard block
 block discarded – undo
1437 1437
                     );
1438 1438
                 }
1439 1439
             }
1440
-            include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1440
+            include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1441 1441
         }
1442 1442
     }
1443 1443
 
@@ -1468,21 +1468,21 @@  discard block
 block discarded – undo
1468 1468
         if (empty($post)) {
1469 1469
             wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?', 'event_espresso'));
1470 1470
         }
1471
-        if (! empty($_GET['get-post-lock'])) {
1471
+        if ( ! empty($_GET['get-post-lock'])) {
1472 1472
             wp_set_post_lock($post_id);
1473 1473
             wp_redirect(get_edit_post_link($post_id, 'url'));
1474 1474
             exit();
1475 1475
         }
1476 1476
 
1477 1477
         // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1478
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1478
+        $post_type = $this->_cpt_routes[$this->_req_action];
1479 1479
         $post_type_object = $this->_cpt_object;
1480 1480
 
1481
-        if (! wp_check_post_lock($post->ID)) {
1481
+        if ( ! wp_check_post_lock($post->ID)) {
1482 1482
             wp_set_post_lock($post->ID);
1483 1483
         }
1484 1484
         add_action('admin_footer', '_admin_notice_post_locked');
1485
-        if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1485
+        if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1486 1486
             wp_enqueue_script('admin-comments');
1487 1487
             enqueue_comment_hotkeys_js();
1488 1488
         }
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.
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +4046 added lines, -4046 removed lines patch added patch discarded remove patch
@@ -17,4113 +17,4113 @@
 block discarded – undo
17 17
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @var LoaderInterface $loader
22
-     */
23
-    protected $loader;
20
+	/**
21
+	 * @var LoaderInterface $loader
22
+	 */
23
+	protected $loader;
24 24
 
25
-    // set in _init_page_props()
26
-    public $page_slug;
25
+	// set in _init_page_props()
26
+	public $page_slug;
27 27
 
28
-    public $page_label;
28
+	public $page_label;
29 29
 
30
-    public $page_folder;
30
+	public $page_folder;
31 31
 
32
-    // set in define_page_props()
33
-    protected $_admin_base_url;
32
+	// set in define_page_props()
33
+	protected $_admin_base_url;
34 34
 
35
-    protected $_admin_base_path;
35
+	protected $_admin_base_path;
36 36
 
37
-    protected $_admin_page_title;
37
+	protected $_admin_page_title;
38 38
 
39
-    protected $_labels;
39
+	protected $_labels;
40 40
 
41 41
 
42
-    // set early within EE_Admin_Init
43
-    protected $_wp_page_slug;
42
+	// set early within EE_Admin_Init
43
+	protected $_wp_page_slug;
44 44
 
45
-    // navtabs
46
-    protected $_nav_tabs;
45
+	// navtabs
46
+	protected $_nav_tabs;
47 47
 
48
-    protected $_default_nav_tab_name;
48
+	protected $_default_nav_tab_name;
49 49
 
50
-    /**
51
-     * @var array $_help_tour
52
-     */
53
-    protected $_help_tour = array();
50
+	/**
51
+	 * @var array $_help_tour
52
+	 */
53
+	protected $_help_tour = array();
54 54
 
55 55
 
56
-    // template variables (used by templates)
57
-    protected $_template_path;
56
+	// template variables (used by templates)
57
+	protected $_template_path;
58 58
 
59
-    protected $_column_template_path;
59
+	protected $_column_template_path;
60 60
 
61
-    /**
62
-     * @var array $_template_args
63
-     */
64
-    protected $_template_args = array();
61
+	/**
62
+	 * @var array $_template_args
63
+	 */
64
+	protected $_template_args = array();
65 65
 
66
-    /**
67
-     * this will hold the list table object for a given view.
68
-     *
69
-     * @var EE_Admin_List_Table $_list_table_object
70
-     */
71
-    protected $_list_table_object;
66
+	/**
67
+	 * this will hold the list table object for a given view.
68
+	 *
69
+	 * @var EE_Admin_List_Table $_list_table_object
70
+	 */
71
+	protected $_list_table_object;
72 72
 
73
-    // bools
74
-    protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states.
73
+	// bools
74
+	protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states.
75 75
 
76
-    protected $_routing;
76
+	protected $_routing;
77 77
 
78
-    // list table args
79
-    protected $_view;
78
+	// list table args
79
+	protected $_view;
80 80
 
81
-    protected $_views;
81
+	protected $_views;
82 82
 
83 83
 
84
-    // action => method pairs used for routing incoming requests
85
-    protected $_page_routes;
84
+	// action => method pairs used for routing incoming requests
85
+	protected $_page_routes;
86 86
 
87
-    /**
88
-     * @var array $_page_config
89
-     */
90
-    protected $_page_config;
87
+	/**
88
+	 * @var array $_page_config
89
+	 */
90
+	protected $_page_config;
91 91
 
92
-    /**
93
-     * the current page route and route config
94
-     *
95
-     * @var string $_route
96
-     */
97
-    protected $_route;
92
+	/**
93
+	 * the current page route and route config
94
+	 *
95
+	 * @var string $_route
96
+	 */
97
+	protected $_route;
98 98
 
99
-    /**
100
-     * @var string $_cpt_route
101
-     */
102
-    protected $_cpt_route;
99
+	/**
100
+	 * @var string $_cpt_route
101
+	 */
102
+	protected $_cpt_route;
103 103
 
104
-    /**
105
-     * @var array $_route_config
106
-     */
107
-    protected $_route_config;
108
-
109
-    /**
110
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
111
-     * actions.
112
-     *
113
-     * @since 4.6.x
114
-     * @var array.
115
-     */
116
-    protected $_default_route_query_args;
117
-
118
-    // set via request page and action args.
119
-    protected $_current_page;
120
-
121
-    protected $_current_view;
122
-
123
-    protected $_current_page_view_url;
124
-
125
-    // sanitized request action (and nonce)
126
-
127
-    /**
128
-     * @var string $_req_action
129
-     */
130
-    protected $_req_action;
131
-
132
-    /**
133
-     * @var string $_req_nonce
134
-     */
135
-    protected $_req_nonce;
136
-
137
-    // search related
138
-    protected $_search_btn_label;
139
-
140
-    protected $_search_box_callback;
141
-
142
-    /**
143
-     * WP Current Screen object
144
-     *
145
-     * @var WP_Screen
146
-     */
147
-    protected $_current_screen;
148
-
149
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
150
-    protected $_hook_obj;
151
-
152
-    // for holding incoming request data
153
-    protected $_req_data;
154
-
155
-    // yes / no array for admin form fields
156
-    protected $_yes_no_values = array();
157
-
158
-    // some default things shared by all child classes
159
-    protected $_default_espresso_metaboxes;
160
-
161
-    /**
162
-     *    EE_Registry Object
163
-     *
164
-     * @var    EE_Registry
165
-     */
166
-    protected $EE = null;
167
-
168
-
169
-    /**
170
-     * This is just a property that flags whether the given route is a caffeinated route or not.
171
-     *
172
-     * @var boolean
173
-     */
174
-    protected $_is_caf = false;
175
-
176
-
177
-    /**
178
-     * @Constructor
179
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
180
-     * @throws EE_Error
181
-     * @throws InvalidArgumentException
182
-     * @throws ReflectionException
183
-     * @throws InvalidDataTypeException
184
-     * @throws InvalidInterfaceException
185
-     */
186
-    public function __construct($routing = true)
187
-    {
188
-        $this->loader = LoaderFactory::getLoader();
189
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
190
-            $this->_is_caf = true;
191
-        }
192
-        $this->_yes_no_values = array(
193
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
194
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
195
-        );
196
-        // set the _req_data property.
197
-        $this->_req_data = array_merge($_GET, $_POST);
198
-        // routing enabled?
199
-        $this->_routing = $routing;
200
-        // set initial page props (child method)
201
-        $this->_init_page_props();
202
-        // set global defaults
203
-        $this->_set_defaults();
204
-        // set early because incoming requests could be ajax related and we need to register those hooks.
205
-        $this->_global_ajax_hooks();
206
-        $this->_ajax_hooks();
207
-        // other_page_hooks have to be early too.
208
-        $this->_do_other_page_hooks();
209
-        // This just allows us to have extending classes do something specific
210
-        // before the parent constructor runs _page_setup().
211
-        if (method_exists($this, '_before_page_setup')) {
212
-            $this->_before_page_setup();
213
-        }
214
-        // set up page dependencies
215
-        $this->_page_setup();
216
-    }
217
-
218
-
219
-    /**
220
-     * _init_page_props
221
-     * Child classes use to set at least the following properties:
222
-     * $page_slug.
223
-     * $page_label.
224
-     *
225
-     * @abstract
226
-     * @return void
227
-     */
228
-    abstract protected function _init_page_props();
229
-
230
-
231
-    /**
232
-     * _ajax_hooks
233
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
234
-     * Note: within the ajax callback methods.
235
-     *
236
-     * @abstract
237
-     * @return void
238
-     */
239
-    abstract protected function _ajax_hooks();
240
-
241
-
242
-    /**
243
-     * _define_page_props
244
-     * child classes define page properties in here.  Must include at least:
245
-     * $_admin_base_url = base_url for all admin pages
246
-     * $_admin_page_title = default admin_page_title for admin pages
247
-     * $_labels = array of default labels for various automatically generated elements:
248
-     *    array(
249
-     *        'buttons' => array(
250
-     *            'add' => esc_html__('label for add new button'),
251
-     *            'edit' => esc_html__('label for edit button'),
252
-     *            'delete' => esc_html__('label for delete button')
253
-     *            )
254
-     *        )
255
-     *
256
-     * @abstract
257
-     * @return void
258
-     */
259
-    abstract protected function _define_page_props();
260
-
261
-
262
-    /**
263
-     * _set_page_routes
264
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
265
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
266
-     * have a 'default' route. Here's the format
267
-     * $this->_page_routes = array(
268
-     *        'default' => array(
269
-     *            'func' => '_default_method_handling_route',
270
-     *            'args' => array('array','of','args'),
271
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
272
-     *            ajax request, backend processing)
273
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
274
-     *            headers route after.  The string you enter here should match the defined route reference for a
275
-     *            headers sent route.
276
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
277
-     *            this route.
278
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
279
-     *            checks).
280
-     *        ),
281
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
282
-     *        handling method.
283
-     *        )
284
-     * )
285
-     *
286
-     * @abstract
287
-     * @return void
288
-     */
289
-    abstract protected function _set_page_routes();
290
-
291
-
292
-    /**
293
-     * _set_page_config
294
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
295
-     * array corresponds to the page_route for the loaded page. Format:
296
-     * $this->_page_config = array(
297
-     *        'default' => array(
298
-     *            'labels' => array(
299
-     *                'buttons' => array(
300
-     *                    'add' => esc_html__('label for adding item'),
301
-     *                    'edit' => esc_html__('label for editing item'),
302
-     *                    'delete' => esc_html__('label for deleting item')
303
-     *                ),
304
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
305
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
306
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
307
-     *            _define_page_props() method
308
-     *            'nav' => array(
309
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
310
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
311
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
312
-     *                'order' => 10, //required to indicate tab position.
313
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
314
-     *                displayed then add this parameter.
315
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
316
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
317
-     *            metaboxes set for eventespresso admin pages.
318
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
319
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
320
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
321
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
322
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
323
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
324
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
325
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
326
-     *            want to display.
327
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
328
-     *                'tab_id' => array(
329
-     *                    'title' => 'tab_title',
330
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
331
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
332
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
333
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
334
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
335
-     *                    attempt to use the callback which should match the name of a method in the class
336
-     *                    ),
337
-     *                'tab2_id' => array(
338
-     *                    'title' => 'tab2 title',
339
-     *                    'filename' => 'file_name_2'
340
-     *                    'callback' => 'callback_method_for_content',
341
-     *                 ),
342
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
343
-     *            help tab area on an admin page. @link
344
-     *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
345
-     *            'help_tour' => array(
346
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
347
-     *                in a folder for this admin page named "help_tours", a file name matching the key given here
348
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
349
-     *            ),
350
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
351
-     *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
352
-     *            just set
353
-     *            'require_nonce' to FALSE
354
-     *            )
355
-     * )
356
-     *
357
-     * @abstract
358
-     * @return void
359
-     */
360
-    abstract protected function _set_page_config();
361
-
362
-
363
-
364
-
365
-
366
-    /** end sample help_tour methods **/
367
-    /**
368
-     * _add_screen_options
369
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
370
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
371
-     * to a particular view.
372
-     *
373
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
374
-     *         see also WP_Screen object documents...
375
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
376
-     * @abstract
377
-     * @return void
378
-     */
379
-    abstract protected function _add_screen_options();
380
-
381
-
382
-    /**
383
-     * _add_feature_pointers
384
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
385
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
386
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
387
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
388
-     * extended) also see:
389
-     *
390
-     * @link   http://eamann.com/tech/wordpress-portland/
391
-     * @abstract
392
-     * @return void
393
-     */
394
-    abstract protected function _add_feature_pointers();
395
-
396
-
397
-    /**
398
-     * load_scripts_styles
399
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
400
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
401
-     * scripts/styles per view by putting them in a dynamic function in this format
402
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
403
-     *
404
-     * @abstract
405
-     * @return void
406
-     */
407
-    abstract public function load_scripts_styles();
408
-
409
-
410
-    /**
411
-     * admin_init
412
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
413
-     * all pages/views loaded by child class.
414
-     *
415
-     * @abstract
416
-     * @return void
417
-     */
418
-    abstract public function admin_init();
419
-
420
-
421
-    /**
422
-     * admin_notices
423
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
424
-     * all pages/views loaded by child class.
425
-     *
426
-     * @abstract
427
-     * @return void
428
-     */
429
-    abstract public function admin_notices();
430
-
431
-
432
-    /**
433
-     * admin_footer_scripts
434
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
435
-     * will apply to all pages/views loaded by child class.
436
-     *
437
-     * @return void
438
-     */
439
-    abstract public function admin_footer_scripts();
440
-
441
-
442
-    /**
443
-     * admin_footer
444
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
445
-     * apply to all pages/views loaded by child class.
446
-     *
447
-     * @return void
448
-     */
449
-    public function admin_footer()
450
-    {
451
-    }
452
-
453
-
454
-    /**
455
-     * _global_ajax_hooks
456
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
457
-     * Note: within the ajax callback methods.
458
-     *
459
-     * @abstract
460
-     * @return void
461
-     */
462
-    protected function _global_ajax_hooks()
463
-    {
464
-        // for lazy loading of metabox content
465
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
466
-    }
467
-
468
-
469
-    public function ajax_metabox_content()
470
-    {
471
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
472
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
473
-        self::cached_rss_display($contentid, $url);
474
-        wp_die();
475
-    }
476
-
477
-
478
-    /**
479
-     * _page_setup
480
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
481
-     * doesn't match the object.
482
-     *
483
-     * @final
484
-     * @return void
485
-     * @throws EE_Error
486
-     * @throws InvalidArgumentException
487
-     * @throws ReflectionException
488
-     * @throws InvalidDataTypeException
489
-     * @throws InvalidInterfaceException
490
-     */
491
-    final protected function _page_setup()
492
-    {
493
-        // requires?
494
-        // admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
495
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
496
-        // next verify if we need to load anything...
497
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
498
-        $this->page_folder = strtolower(
499
-            str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
500
-        );
501
-        global $ee_menu_slugs;
502
-        $ee_menu_slugs = (array) $ee_menu_slugs;
503
-        if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) {
504
-            return;
505
-        }
506
-        // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
507
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
508
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
509
-                ? $this->_req_data['action2']
510
-                : $this->_req_data['action'];
511
-        }
512
-        // then set blank or -1 action values to 'default'
513
-        $this->_req_action = isset($this->_req_data['action'])
514
-                             && ! empty($this->_req_data['action'])
515
-                             && $this->_req_data['action'] !== '-1'
516
-            ? sanitize_key($this->_req_data['action'])
517
-            : 'default';
518
-        // if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
519
-        //  This covers cases where we're coming in from a list table that isn't on the default route.
520
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
521
-            ? $this->_req_data['route'] : $this->_req_action;
522
-        // however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
523
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route'])
524
-            ? $this->_req_data['route']
525
-            : $this->_req_action;
526
-        $this->_current_view = $this->_req_action;
527
-        $this->_req_nonce = $this->_req_action . '_nonce';
528
-        $this->_define_page_props();
529
-        $this->_current_page_view_url = add_query_arg(
530
-            array('page' => $this->_current_page, 'action' => $this->_current_view),
531
-            $this->_admin_base_url
532
-        );
533
-        // default things
534
-        $this->_default_espresso_metaboxes = array(
535
-            '_espresso_news_post_box',
536
-            '_espresso_links_post_box',
537
-            '_espresso_ratings_request',
538
-            '_espresso_sponsors_post_box',
539
-        );
540
-        // set page configs
541
-        $this->_set_page_routes();
542
-        $this->_set_page_config();
543
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
544
-        if (isset($this->_req_data['wp_referer'])) {
545
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
546
-        }
547
-        // for caffeinated and other extended functionality.
548
-        //  If there is a _extend_page_config method
549
-        // then let's run that to modify the all the various page configuration arrays
550
-        if (method_exists($this, '_extend_page_config')) {
551
-            $this->_extend_page_config();
552
-        }
553
-        // for CPT and other extended functionality.
554
-        // If there is an _extend_page_config_for_cpt
555
-        // then let's run that to modify all the various page configuration arrays.
556
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
557
-            $this->_extend_page_config_for_cpt();
558
-        }
559
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
560
-        $this->_page_routes = apply_filters(
561
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
562
-            $this->_page_routes,
563
-            $this
564
-        );
565
-        $this->_page_config = apply_filters(
566
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
567
-            $this->_page_config,
568
-            $this
569
-        );
570
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
571
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
572
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
573
-            add_action(
574
-                'AHEE__EE_Admin_Page__route_admin_request',
575
-                array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
576
-                10,
577
-                2
578
-            );
579
-        }
580
-        // next route only if routing enabled
581
-        if ($this->_routing && ! defined('DOING_AJAX')) {
582
-            $this->_verify_routes();
583
-            // next let's just check user_access and kill if no access
584
-            $this->check_user_access();
585
-            if ($this->_is_UI_request) {
586
-                // admin_init stuff - global, all views for this page class, specific view
587
-                add_action('admin_init', array($this, 'admin_init'), 10);
588
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
589
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
590
-                }
591
-            } else {
592
-                // hijack regular WP loading and route admin request immediately
593
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
594
-                $this->route_admin_request();
595
-            }
596
-        }
597
-    }
598
-
599
-
600
-    /**
601
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
602
-     *
603
-     * @return void
604
-     * @throws ReflectionException
605
-     * @throws EE_Error
606
-     */
607
-    private function _do_other_page_hooks()
608
-    {
609
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
610
-        foreach ($registered_pages as $page) {
611
-            // now let's setup the file name and class that should be present
612
-            $classname = str_replace('.class.php', '', $page);
613
-            // autoloaders should take care of loading file
614
-            if (! class_exists($classname)) {
615
-                $error_msg[] = sprintf(
616
-                    esc_html__(
617
-                        'Something went wrong with loading the %s admin hooks page.',
618
-                        'event_espresso'
619
-                    ),
620
-                    $page
621
-                );
622
-                $error_msg[] = $error_msg[0]
623
-                               . "\r\n"
624
-                               . sprintf(
625
-                                   esc_html__(
626
-                                       'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
627
-                                       'event_espresso'
628
-                                   ),
629
-                                   $page,
630
-                                   '<br />',
631
-                                   '<strong>' . $classname . '</strong>'
632
-                               );
633
-                throw new EE_Error(implode('||', $error_msg));
634
-            }
635
-            $a = new ReflectionClass($classname);
636
-            // notice we are passing the instance of this class to the hook object.
637
-            $hookobj[] = $a->newInstance($this);
638
-        }
639
-    }
640
-
641
-
642
-    public function load_page_dependencies()
643
-    {
644
-        try {
645
-            $this->_load_page_dependencies();
646
-        } catch (EE_Error $e) {
647
-            $e->get_error();
648
-        }
649
-    }
650
-
651
-
652
-    /**
653
-     * load_page_dependencies
654
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
655
-     *
656
-     * @return void
657
-     * @throws DomainException
658
-     * @throws EE_Error
659
-     * @throws InvalidArgumentException
660
-     * @throws InvalidDataTypeException
661
-     * @throws InvalidInterfaceException
662
-     * @throws ReflectionException
663
-     */
664
-    protected function _load_page_dependencies()
665
-    {
666
-        // let's set the current_screen and screen options to override what WP set
667
-        $this->_current_screen = get_current_screen();
668
-        // load admin_notices - global, page class, and view specific
669
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
670
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
671
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
672
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
673
-        }
674
-        // load network admin_notices - global, page class, and view specific
675
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
676
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
677
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
678
-        }
679
-        // this will save any per_page screen options if they are present
680
-        $this->_set_per_page_screen_options();
681
-        // setup list table properties
682
-        $this->_set_list_table();
683
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
684
-        // However in some cases the metaboxes will need to be added within a route handling callback.
685
-        $this->_add_registered_meta_boxes();
686
-        $this->_add_screen_columns();
687
-        // add screen options - global, page child class, and view specific
688
-        $this->_add_global_screen_options();
689
-        $this->_add_screen_options();
690
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
691
-        if (method_exists($this, $add_screen_options)) {
692
-            $this->{$add_screen_options}();
693
-        }
694
-        // add help tab(s) and tours- set via page_config and qtips.
695
-        $this->_add_help_tour();
696
-        $this->_add_help_tabs();
697
-        $this->_add_qtips();
698
-        // add feature_pointers - global, page child class, and view specific
699
-        $this->_add_feature_pointers();
700
-        $this->_add_global_feature_pointers();
701
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
702
-        if (method_exists($this, $add_feature_pointer)) {
703
-            $this->{$add_feature_pointer}();
704
-        }
705
-        // enqueue scripts/styles - global, page class, and view specific
706
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
707
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
708
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
709
-            add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
710
-        }
711
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
712
-        // admin_print_footer_scripts - global, page child class, and view specific.
713
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
714
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
715
-        // is a good use case. Notice the late priority we're giving these
716
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
717
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
718
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
719
-            add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
720
-        }
721
-        // admin footer scripts
722
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
723
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
724
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
725
-            add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
726
-        }
727
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
728
-        // targeted hook
729
-        do_action(
730
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
731
-        );
732
-    }
733
-
734
-
735
-    /**
736
-     * _set_defaults
737
-     * This sets some global defaults for class properties.
738
-     */
739
-    private function _set_defaults()
740
-    {
741
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
742
-        $this->_event = $this->_template_path = $this->_column_template_path = null;
743
-        $this->_nav_tabs = $this->_views = $this->_page_routes = array();
744
-        $this->_page_config = $this->_default_route_query_args = array();
745
-        $this->_default_nav_tab_name = 'overview';
746
-        // init template args
747
-        $this->_template_args = array(
748
-            'admin_page_header'  => '',
749
-            'admin_page_content' => '',
750
-            'post_body_content'  => '',
751
-            'before_list_table'  => '',
752
-            'after_list_table'   => '',
753
-        );
754
-    }
755
-
756
-
757
-    /**
758
-     * route_admin_request
759
-     *
760
-     * @see    _route_admin_request()
761
-     * @return exception|void error
762
-     * @throws InvalidArgumentException
763
-     * @throws InvalidInterfaceException
764
-     * @throws InvalidDataTypeException
765
-     * @throws EE_Error
766
-     * @throws ReflectionException
767
-     */
768
-    public function route_admin_request()
769
-    {
770
-        try {
771
-            $this->_route_admin_request();
772
-        } catch (EE_Error $e) {
773
-            $e->get_error();
774
-        }
775
-    }
776
-
777
-
778
-    public function set_wp_page_slug($wp_page_slug)
779
-    {
780
-        $this->_wp_page_slug = $wp_page_slug;
781
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
782
-        if (is_network_admin()) {
783
-            $this->_wp_page_slug .= '-network';
784
-        }
785
-    }
786
-
787
-
788
-    /**
789
-     * _verify_routes
790
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
791
-     * we know if we need to drop out.
792
-     *
793
-     * @return bool
794
-     * @throws EE_Error
795
-     */
796
-    protected function _verify_routes()
797
-    {
798
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
799
-        if (! $this->_current_page && ! defined('DOING_AJAX')) {
800
-            return false;
801
-        }
802
-        $this->_route = false;
803
-        // check that the page_routes array is not empty
804
-        if (empty($this->_page_routes)) {
805
-            // user error msg
806
-            $error_msg = sprintf(
807
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
808
-                $this->_admin_page_title
809
-            );
810
-            // developer error msg
811
-            $error_msg .= '||' . $error_msg
812
-                          . esc_html__(
813
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
814
-                              'event_espresso'
815
-                          );
816
-            throw new EE_Error($error_msg);
817
-        }
818
-        // and that the requested page route exists
819
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
820
-            $this->_route = $this->_page_routes[ $this->_req_action ];
821
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
822
-                ? $this->_page_config[ $this->_req_action ] : array();
823
-        } else {
824
-            // user error msg
825
-            $error_msg = sprintf(
826
-                esc_html__(
827
-                    'The requested page route does not exist for the %s admin page.',
828
-                    'event_espresso'
829
-                ),
830
-                $this->_admin_page_title
831
-            );
832
-            // developer error msg
833
-            $error_msg .= '||' . $error_msg
834
-                          . sprintf(
835
-                              esc_html__(
836
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
837
-                                  'event_espresso'
838
-                              ),
839
-                              $this->_req_action
840
-                          );
841
-            throw new EE_Error($error_msg);
842
-        }
843
-        // and that a default route exists
844
-        if (! array_key_exists('default', $this->_page_routes)) {
845
-            // user error msg
846
-            $error_msg = sprintf(
847
-                esc_html__(
848
-                    'A default page route has not been set for the % admin page.',
849
-                    'event_espresso'
850
-                ),
851
-                $this->_admin_page_title
852
-            );
853
-            // developer error msg
854
-            $error_msg .= '||' . $error_msg
855
-                          . esc_html__(
856
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
857
-                              'event_espresso'
858
-                          );
859
-            throw new EE_Error($error_msg);
860
-        }
861
-        // first lets' catch if the UI request has EVER been set.
862
-        if ($this->_is_UI_request === null) {
863
-            // lets set if this is a UI request or not.
864
-            $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
865
-            // wait a minute... we might have a noheader in the route array
866
-            $this->_is_UI_request = is_array($this->_route)
867
-                                    && isset($this->_route['noheader'])
868
-                                    && $this->_route['noheader'] ? false : $this->_is_UI_request;
869
-        }
870
-        $this->_set_current_labels();
871
-        return true;
872
-    }
873
-
874
-
875
-    /**
876
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
877
-     *
878
-     * @param  string $route the route name we're verifying
879
-     * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
880
-     * @throws EE_Error
881
-     */
882
-    protected function _verify_route($route)
883
-    {
884
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
885
-            return true;
886
-        }
887
-        // user error msg
888
-        $error_msg = sprintf(
889
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
890
-            $this->_admin_page_title
891
-        );
892
-        // developer error msg
893
-        $error_msg .= '||' . $error_msg
894
-                      . sprintf(
895
-                          esc_html__(
896
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
897
-                              'event_espresso'
898
-                          ),
899
-                          $route
900
-                      );
901
-        throw new EE_Error($error_msg);
902
-    }
903
-
904
-
905
-    /**
906
-     * perform nonce verification
907
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
908
-     * using this method (and save retyping!)
909
-     *
910
-     * @param  string $nonce     The nonce sent
911
-     * @param  string $nonce_ref The nonce reference string (name0)
912
-     * @return void
913
-     * @throws EE_Error
914
-     */
915
-    protected function _verify_nonce($nonce, $nonce_ref)
916
-    {
917
-        // verify nonce against expected value
918
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
919
-            // these are not the droids you are looking for !!!
920
-            $msg = sprintf(
921
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
922
-                '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
923
-                '</a>'
924
-            );
925
-            if (WP_DEBUG) {
926
-                $msg .= "\n  "
927
-                        . sprintf(
928
-                            esc_html__(
929
-                                'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
930
-                                'event_espresso'
931
-                            ),
932
-                            __CLASS__
933
-                        );
934
-            }
935
-            if (! defined('DOING_AJAX')) {
936
-                wp_die($msg);
937
-            } else {
938
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
939
-                $this->_return_json();
940
-            }
941
-        }
942
-    }
943
-
944
-
945
-    /**
946
-     * _route_admin_request()
947
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
948
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
949
-     * in the page routes and then will try to load the corresponding method.
950
-     *
951
-     * @return void
952
-     * @throws EE_Error
953
-     * @throws InvalidArgumentException
954
-     * @throws InvalidDataTypeException
955
-     * @throws InvalidInterfaceException
956
-     * @throws ReflectionException
957
-     */
958
-    protected function _route_admin_request()
959
-    {
960
-        if (! $this->_is_UI_request) {
961
-            $this->_verify_routes();
962
-        }
963
-        $nonce_check = isset($this->_route_config['require_nonce'])
964
-            ? $this->_route_config['require_nonce']
965
-            : true;
966
-        if ($this->_req_action !== 'default' && $nonce_check) {
967
-            // set nonce from post data
968
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
969
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ])
970
-                : '';
971
-            $this->_verify_nonce($nonce, $this->_req_nonce);
972
-        }
973
-        // set the nav_tabs array but ONLY if this is  UI_request
974
-        if ($this->_is_UI_request) {
975
-            $this->_set_nav_tabs();
976
-        }
977
-        // grab callback function
978
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
979
-        // check if callback has args
980
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
981
-        $error_msg = '';
982
-        // action right before calling route
983
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
984
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
985
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
986
-        }
987
-        // right before calling the route, let's remove _wp_http_referer from the
988
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
989
-        $_SERVER['REQUEST_URI'] = remove_query_arg(
990
-            '_wp_http_referer',
991
-            wp_unslash($_SERVER['REQUEST_URI'])
992
-        );
993
-        if (! empty($func)) {
994
-            if (is_array($func)) {
995
-                list($class, $method) = $func;
996
-            } elseif (strpos($func, '::') !== false) {
997
-                list($class, $method) = explode('::', $func);
998
-            } else {
999
-                $class = $this;
1000
-                $method = $func;
1001
-            }
1002
-            if (! (is_object($class) && $class === $this)) {
1003
-                // send along this admin page object for access by addons.
1004
-                $args['admin_page_object'] = $this;
1005
-            }
1006
-            if (// is it a method on a class that doesn't work?
1007
-                (
1008
-                    (
1009
-                        method_exists($class, $method)
1010
-                        && call_user_func_array(array($class, $method), $args) === false
1011
-                    )
1012
-                    && (
1013
-                        // is it a standalone function that doesn't work?
1014
-                        function_exists($method)
1015
-                        && call_user_func_array(
1016
-                            $func,
1017
-                            array_merge(array('admin_page_object' => $this), $args)
1018
-                        ) === false
1019
-                    )
1020
-                )
1021
-                || (
1022
-                    // is it neither a class method NOR a standalone function?
1023
-                    ! method_exists($class, $method)
1024
-                    && ! function_exists($method)
1025
-                )
1026
-            ) {
1027
-                // user error msg
1028
-                $error_msg = esc_html__(
1029
-                    'An error occurred. The  requested page route could not be found.',
1030
-                    'event_espresso'
1031
-                );
1032
-                // developer error msg
1033
-                $error_msg .= '||';
1034
-                $error_msg .= sprintf(
1035
-                    esc_html__(
1036
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1037
-                        'event_espresso'
1038
-                    ),
1039
-                    $method
1040
-                );
1041
-            }
1042
-            if (! empty($error_msg)) {
1043
-                throw new EE_Error($error_msg);
1044
-            }
1045
-        }
1046
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1047
-        // then we need to reset the routing properties to the new route.
1048
-        // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1049
-        if ($this->_is_UI_request === false
1050
-            && is_array($this->_route)
1051
-            && ! empty($this->_route['headers_sent_route'])
1052
-        ) {
1053
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1054
-        }
1055
-    }
1056
-
1057
-
1058
-    /**
1059
-     * This method just allows the resetting of page properties in the case where a no headers
1060
-     * route redirects to a headers route in its route config.
1061
-     *
1062
-     * @since   4.3.0
1063
-     * @param  string $new_route New (non header) route to redirect to.
1064
-     * @return   void
1065
-     * @throws ReflectionException
1066
-     * @throws InvalidArgumentException
1067
-     * @throws InvalidInterfaceException
1068
-     * @throws InvalidDataTypeException
1069
-     * @throws EE_Error
1070
-     */
1071
-    protected function _reset_routing_properties($new_route)
1072
-    {
1073
-        $this->_is_UI_request = true;
1074
-        // now we set the current route to whatever the headers_sent_route is set at
1075
-        $this->_req_data['action'] = $new_route;
1076
-        // rerun page setup
1077
-        $this->_page_setup();
1078
-    }
1079
-
1080
-
1081
-    /**
1082
-     * _add_query_arg
1083
-     * adds nonce to array of arguments then calls WP add_query_arg function
1084
-     *(internally just uses EEH_URL's function with the same name)
1085
-     *
1086
-     * @param array  $args
1087
-     * @param string $url
1088
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1089
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1090
-     *                                        Example usage: If the current page is:
1091
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1092
-     *                                        &action=default&event_id=20&month_range=March%202015
1093
-     *                                        &_wpnonce=5467821
1094
-     *                                        and you call:
1095
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1096
-     *                                        array(
1097
-     *                                        'action' => 'resend_something',
1098
-     *                                        'page=>espresso_registrations'
1099
-     *                                        ),
1100
-     *                                        $some_url,
1101
-     *                                        true
1102
-     *                                        );
1103
-     *                                        It will produce a url in this structure:
1104
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1105
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1106
-     *                                        month_range]=March%202015
1107
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1108
-     * @return string
1109
-     */
1110
-    public static function add_query_args_and_nonce(
1111
-        $args = array(),
1112
-        $url = false,
1113
-        $sticky = false,
1114
-        $exclude_nonce = false
1115
-    ) {
1116
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1117
-        if ($sticky) {
1118
-            $request = $_REQUEST;
1119
-            unset($request['_wp_http_referer']);
1120
-            unset($request['wp_referer']);
1121
-            foreach ($request as $key => $value) {
1122
-                // do not add nonces
1123
-                if (strpos($key, 'nonce') !== false) {
1124
-                    continue;
1125
-                }
1126
-                $args[ 'wp_referer[' . $key . ']' ] = $value;
1127
-            }
1128
-        }
1129
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1130
-    }
1131
-
1132
-
1133
-    /**
1134
-     * This returns a generated link that will load the related help tab.
1135
-     *
1136
-     * @param  string $help_tab_id the id for the connected help tab
1137
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1138
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1139
-     * @uses EEH_Template::get_help_tab_link()
1140
-     * @return string              generated link
1141
-     */
1142
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1143
-    {
1144
-        return EEH_Template::get_help_tab_link(
1145
-            $help_tab_id,
1146
-            $this->page_slug,
1147
-            $this->_req_action,
1148
-            $icon_style,
1149
-            $help_text
1150
-        );
1151
-    }
1152
-
1153
-
1154
-    /**
1155
-     * _add_help_tabs
1156
-     * Note child classes define their help tabs within the page_config array.
1157
-     *
1158
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1159
-     * @return void
1160
-     * @throws DomainException
1161
-     * @throws EE_Error
1162
-     */
1163
-    protected function _add_help_tabs()
1164
-    {
1165
-        $tour_buttons = '';
1166
-        if (isset($this->_page_config[ $this->_req_action ])) {
1167
-            $config = $this->_page_config[ $this->_req_action ];
1168
-            // is there a help tour for the current route?  if there is let's setup the tour buttons
1169
-            if (isset($this->_help_tour[ $this->_req_action ])) {
1170
-                $tb = array();
1171
-                $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1172
-                foreach ($this->_help_tour['tours'] as $tour) {
1173
-                    // if this is the end tour then we don't need to setup a button
1174
-                    if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1175
-                        continue;
1176
-                    }
1177
-                    $tb[] = '<button id="trigger-tour-'
1178
-                            . $tour->get_slug()
1179
-                            . '" class="button-primary trigger-ee-help-tour">'
1180
-                            . $tour->get_label()
1181
-                            . '</button>';
1182
-                }
1183
-                $tour_buttons .= implode('<br />', $tb);
1184
-                $tour_buttons .= '</div></div>';
1185
-            }
1186
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1187
-            if (is_array($config) && isset($config['help_sidebar'])) {
1188
-                // check that the callback given is valid
1189
-                if (! method_exists($this, $config['help_sidebar'])) {
1190
-                    throw new EE_Error(
1191
-                        sprintf(
1192
-                            esc_html__(
1193
-                                'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1194
-                                'event_espresso'
1195
-                            ),
1196
-                            $config['help_sidebar'],
1197
-                            get_class($this)
1198
-                        )
1199
-                    );
1200
-                }
1201
-                $content = apply_filters(
1202
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1203
-                    $this->{$config['help_sidebar']}()
1204
-                );
1205
-                $content .= $tour_buttons; // add help tour buttons.
1206
-                // do we have any help tours setup?  Cause if we do we want to add the buttons
1207
-                $this->_current_screen->set_help_sidebar($content);
1208
-            }
1209
-            // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar.
1210
-            if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1211
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1212
-            }
1213
-            // handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1214
-            if (! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1215
-                $_ht['id'] = $this->page_slug;
1216
-                $_ht['title'] = esc_html__('Help Tours', 'event_espresso');
1217
-                $_ht['content'] = '<p>'
1218
-                                  . esc_html__(
1219
-                                      'The buttons to the right allow you to start/restart any help tours available for this page',
1220
-                                      'event_espresso'
1221
-                                  ) . '</p>';
1222
-                $this->_current_screen->add_help_tab($_ht);
1223
-            }
1224
-            if (! isset($config['help_tabs'])) {
1225
-                return;
1226
-            } //no help tabs for this route
1227
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1228
-                // we're here so there ARE help tabs!
1229
-                // make sure we've got what we need
1230
-                if (! isset($cfg['title'])) {
1231
-                    throw new EE_Error(
1232
-                        esc_html__(
1233
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1234
-                            'event_espresso'
1235
-                        )
1236
-                    );
1237
-                }
1238
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1239
-                    throw new EE_Error(
1240
-                        esc_html__(
1241
-                            'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1242
-                            'event_espresso'
1243
-                        )
1244
-                    );
1245
-                }
1246
-                // first priority goes to content.
1247
-                if (! empty($cfg['content'])) {
1248
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1249
-                    // second priority goes to filename
1250
-                } elseif (! empty($cfg['filename'])) {
1251
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1252
-                    // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1253
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1254
-                                                             . basename($this->_get_dir())
1255
-                                                             . '/help_tabs/'
1256
-                                                             . $cfg['filename']
1257
-                                                             . '.help_tab.php' : $file_path;
1258
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1259
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1260
-                        EE_Error::add_error(
1261
-                            sprintf(
1262
-                                esc_html__(
1263
-                                    'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1264
-                                    'event_espresso'
1265
-                                ),
1266
-                                $tab_id,
1267
-                                key($config),
1268
-                                $file_path
1269
-                            ),
1270
-                            __FILE__,
1271
-                            __FUNCTION__,
1272
-                            __LINE__
1273
-                        );
1274
-                        return;
1275
-                    }
1276
-                    $template_args['admin_page_obj'] = $this;
1277
-                    $content = EEH_Template::display_template(
1278
-                        $file_path,
1279
-                        $template_args,
1280
-                        true
1281
-                    );
1282
-                } else {
1283
-                    $content = '';
1284
-                }
1285
-                // check if callback is valid
1286
-                if (empty($content) && (
1287
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1288
-                    )
1289
-                ) {
1290
-                    EE_Error::add_error(
1291
-                        sprintf(
1292
-                            esc_html__(
1293
-                                'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1294
-                                'event_espresso'
1295
-                            ),
1296
-                            $cfg['title']
1297
-                        ),
1298
-                        __FILE__,
1299
-                        __FUNCTION__,
1300
-                        __LINE__
1301
-                    );
1302
-                    return;
1303
-                }
1304
-                // setup config array for help tab method
1305
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1306
-                $_ht = array(
1307
-                    'id'       => $id,
1308
-                    'title'    => $cfg['title'],
1309
-                    'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1310
-                    'content'  => $content,
1311
-                );
1312
-                $this->_current_screen->add_help_tab($_ht);
1313
-            }
1314
-        }
1315
-    }
1316
-
1317
-
1318
-    /**
1319
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1320
-     * an array with properties for setting up usage of the joyride plugin
1321
-     *
1322
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1323
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1324
-     *         _set_page_config() comments
1325
-     * @return void
1326
-     * @throws EE_Error
1327
-     * @throws InvalidArgumentException
1328
-     * @throws InvalidDataTypeException
1329
-     * @throws InvalidInterfaceException
1330
-     */
1331
-    protected function _add_help_tour()
1332
-    {
1333
-        $tours = array();
1334
-        $this->_help_tour = array();
1335
-        // exit early if help tours are turned off globally
1336
-        if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1337
-            || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1338
-        ) {
1339
-            return;
1340
-        }
1341
-        // loop through _page_config to find any help_tour defined
1342
-        foreach ($this->_page_config as $route => $config) {
1343
-            // we're only going to set things up for this route
1344
-            if ($route !== $this->_req_action) {
1345
-                continue;
1346
-            }
1347
-            if (isset($config['help_tour'])) {
1348
-                foreach ($config['help_tour'] as $tour) {
1349
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1350
-                    // let's see if we can get that file...
1351
-                    // if not its possible this is a decaf route not set in caffeinated
1352
-                    // so lets try and get the caffeinated equivalent
1353
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1354
-                                                             . basename($this->_get_dir())
1355
-                                                             . '/help_tours/'
1356
-                                                             . $tour
1357
-                                                             . '.class.php' : $file_path;
1358
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1359
-                    if (! is_readable($file_path)) {
1360
-                        EE_Error::add_error(
1361
-                            sprintf(
1362
-                                esc_html__(
1363
-                                    'The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling',
1364
-                                    'event_espresso'
1365
-                                ),
1366
-                                $file_path,
1367
-                                $tour
1368
-                            ),
1369
-                            __FILE__,
1370
-                            __FUNCTION__,
1371
-                            __LINE__
1372
-                        );
1373
-                        return;
1374
-                    }
1375
-                    require_once $file_path;
1376
-                    if (! class_exists($tour)) {
1377
-                        $error_msg[] = sprintf(
1378
-                            esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1379
-                            $tour
1380
-                        );
1381
-                        $error_msg[] = $error_msg[0] . "\r\n"
1382
-                                       . sprintf(
1383
-                                           esc_html__(
1384
-                                               'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1385
-                                               'event_espresso'
1386
-                                           ),
1387
-                                           $tour,
1388
-                                           '<br />',
1389
-                                           $tour,
1390
-                                           $this->_req_action,
1391
-                                           get_class($this)
1392
-                                       );
1393
-                        throw new EE_Error(implode('||', $error_msg));
1394
-                    }
1395
-                    $tour_obj = new $tour($this->_is_caf);
1396
-                    $tours[] = $tour_obj;
1397
-                    $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1398
-                }
1399
-                // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1400
-                $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1401
-                $tours[] = $end_stop_tour;
1402
-                $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1403
-            }
1404
-        }
1405
-        if (! empty($tours)) {
1406
-            $this->_help_tour['tours'] = $tours;
1407
-        }
1408
-        // that's it!  Now that the $_help_tours property is set (or not)
1409
-        // the scripts and html should be taken care of automatically.
1410
-    }
1411
-
1412
-
1413
-    /**
1414
-     * This simply sets up any qtips that have been defined in the page config
1415
-     *
1416
-     * @return void
1417
-     */
1418
-    protected function _add_qtips()
1419
-    {
1420
-        if (isset($this->_route_config['qtips'])) {
1421
-            $qtips = (array) $this->_route_config['qtips'];
1422
-            // load qtip loader
1423
-            $path = array(
1424
-                $this->_get_dir() . '/qtips/',
1425
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1426
-            );
1427
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1428
-        }
1429
-    }
1430
-
1431
-
1432
-    /**
1433
-     * _set_nav_tabs
1434
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1435
-     * wish to add additional tabs or modify accordingly.
1436
-     *
1437
-     * @return void
1438
-     * @throws InvalidArgumentException
1439
-     * @throws InvalidInterfaceException
1440
-     * @throws InvalidDataTypeException
1441
-     */
1442
-    protected function _set_nav_tabs()
1443
-    {
1444
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1445
-        $i = 0;
1446
-        foreach ($this->_page_config as $slug => $config) {
1447
-            if (! is_array($config)
1448
-                || (
1449
-                    is_array($config)
1450
-                    && (
1451
-                        (isset($config['nav']) && ! $config['nav'])
1452
-                        || ! isset($config['nav'])
1453
-                    )
1454
-                )
1455
-            ) {
1456
-                continue;
1457
-            }
1458
-            // no nav tab for this config
1459
-            // check for persistent flag
1460
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1461
-                // nav tab is only to appear when route requested.
1462
-                continue;
1463
-            }
1464
-            if (! $this->check_user_access($slug, true)) {
1465
-                // no nav tab because current user does not have access.
1466
-                continue;
1467
-            }
1468
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1469
-            $this->_nav_tabs[ $slug ] = array(
1470
-                'url'       => isset($config['nav']['url'])
1471
-                    ? $config['nav']['url']
1472
-                    : self::add_query_args_and_nonce(
1473
-                        array('action' => $slug),
1474
-                        $this->_admin_base_url
1475
-                    ),
1476
-                'link_text' => isset($config['nav']['label'])
1477
-                    ? $config['nav']['label']
1478
-                    : ucwords(
1479
-                        str_replace('_', ' ', $slug)
1480
-                    ),
1481
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1482
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1483
-            );
1484
-            $i++;
1485
-        }
1486
-        // if $this->_nav_tabs is empty then lets set the default
1487
-        if (empty($this->_nav_tabs)) {
1488
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = array(
1489
-                'url'       => $this->_admin_base_url,
1490
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1491
-                'css_class' => 'nav-tab-active',
1492
-                'order'     => 10,
1493
-            );
1494
-        }
1495
-        // now let's sort the tabs according to order
1496
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1497
-    }
1498
-
1499
-
1500
-    /**
1501
-     * _set_current_labels
1502
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1503
-     * property array
1504
-     *
1505
-     * @return void
1506
-     */
1507
-    private function _set_current_labels()
1508
-    {
1509
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1510
-            foreach ($this->_route_config['labels'] as $label => $text) {
1511
-                if (is_array($text)) {
1512
-                    foreach ($text as $sublabel => $subtext) {
1513
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1514
-                    }
1515
-                } else {
1516
-                    $this->_labels[ $label ] = $text;
1517
-                }
1518
-            }
1519
-        }
1520
-    }
1521
-
1522
-
1523
-    /**
1524
-     *        verifies user access for this admin page
1525
-     *
1526
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1527
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1528
-     *                               return false if verify fail.
1529
-     * @return bool
1530
-     * @throws InvalidArgumentException
1531
-     * @throws InvalidDataTypeException
1532
-     * @throws InvalidInterfaceException
1533
-     */
1534
-    public function check_user_access($route_to_check = '', $verify_only = false)
1535
-    {
1536
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1537
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1538
-        $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1539
-                      && is_array(
1540
-                          $this->_page_routes[ $route_to_check ]
1541
-                      )
1542
-                      && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1543
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1544
-        if (empty($capability) && empty($route_to_check)) {
1545
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1546
-                : $this->_route['capability'];
1547
-        } else {
1548
-            $capability = empty($capability) ? 'manage_options' : $capability;
1549
-        }
1550
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1551
-        if (! defined('DOING_AJAX')
1552
-            && (
1553
-                ! function_exists('is_admin')
1554
-                || ! EE_Registry::instance()->CAP->current_user_can(
1555
-                    $capability,
1556
-                    $this->page_slug
1557
-                    . '_'
1558
-                    . $route_to_check,
1559
-                    $id
1560
-                )
1561
-            )
1562
-        ) {
1563
-            if ($verify_only) {
1564
-                return false;
1565
-            }
1566
-            if (is_user_logged_in()) {
1567
-                wp_die(__('You do not have access to this route.', 'event_espresso'));
1568
-            } else {
1569
-                return false;
1570
-            }
1571
-        }
1572
-        return true;
1573
-    }
1574
-
1575
-
1576
-    /**
1577
-     * admin_init_global
1578
-     * This runs all the code that we want executed within the WP admin_init hook.
1579
-     * This method executes for ALL EE Admin pages.
1580
-     *
1581
-     * @return void
1582
-     */
1583
-    public function admin_init_global()
1584
-    {
1585
-    }
1586
-
1587
-
1588
-    /**
1589
-     * wp_loaded_global
1590
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1591
-     * EE_Admin page and will execute on every EE Admin Page load
1592
-     *
1593
-     * @return void
1594
-     */
1595
-    public function wp_loaded()
1596
-    {
1597
-    }
1598
-
1599
-
1600
-    /**
1601
-     * admin_notices
1602
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1603
-     * ALL EE_Admin pages.
1604
-     *
1605
-     * @return void
1606
-     */
1607
-    public function admin_notices_global()
1608
-    {
1609
-        $this->_display_no_javascript_warning();
1610
-        $this->_display_espresso_notices();
1611
-    }
1612
-
1613
-
1614
-    public function network_admin_notices_global()
1615
-    {
1616
-        $this->_display_no_javascript_warning();
1617
-        $this->_display_espresso_notices();
1618
-    }
1619
-
1620
-
1621
-    /**
1622
-     * admin_footer_scripts_global
1623
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1624
-     * will apply on ALL EE_Admin pages.
1625
-     *
1626
-     * @return void
1627
-     */
1628
-    public function admin_footer_scripts_global()
1629
-    {
1630
-        $this->_add_admin_page_ajax_loading_img();
1631
-        $this->_add_admin_page_overlay();
1632
-        // if metaboxes are present we need to add the nonce field
1633
-        if (isset($this->_route_config['metaboxes'])
1634
-            || isset($this->_route_config['list_table'])
1635
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1636
-        ) {
1637
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1638
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1639
-        }
1640
-    }
1641
-
1642
-
1643
-    /**
1644
-     * admin_footer_global
1645
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1646
-     * ALL EE_Admin Pages.
1647
-     *
1648
-     * @return void
1649
-     * @throws EE_Error
1650
-     */
1651
-    public function admin_footer_global()
1652
-    {
1653
-        // dialog container for dialog helper
1654
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1655
-        $d_cont .= '<div class="ee-notices"></div>';
1656
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1657
-        $d_cont .= '</div>';
1658
-        echo $d_cont;
1659
-        // help tour stuff?
1660
-        if (isset($this->_help_tour[ $this->_req_action ])) {
1661
-            echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1662
-        }
1663
-        // current set timezone for timezone js
1664
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1665
-    }
1666
-
1667
-
1668
-    /**
1669
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1670
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1671
-     * help popups then in your templates or your content you set "triggers" for the content using the
1672
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1673
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1674
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1675
-     * for the
1676
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1677
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1678
-     *    'help_trigger_id' => array(
1679
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1680
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1681
-     *    )
1682
-     * );
1683
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1684
-     *
1685
-     * @param array $help_array
1686
-     * @param bool  $display
1687
-     * @return string content
1688
-     * @throws DomainException
1689
-     * @throws EE_Error
1690
-     */
1691
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1692
-    {
1693
-        $content = '';
1694
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1695
-        // loop through the array and setup content
1696
-        foreach ($help_array as $trigger => $help) {
1697
-            // make sure the array is setup properly
1698
-            if (! isset($help['title']) || ! isset($help['content'])) {
1699
-                throw new EE_Error(
1700
-                    esc_html__(
1701
-                        'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1702
-                        'event_espresso'
1703
-                    )
1704
-                );
1705
-            }
1706
-            // we're good so let'd setup the template vars and then assign parsed template content to our content.
1707
-            $template_args = array(
1708
-                'help_popup_id'      => $trigger,
1709
-                'help_popup_title'   => $help['title'],
1710
-                'help_popup_content' => $help['content'],
1711
-            );
1712
-            $content .= EEH_Template::display_template(
1713
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1714
-                $template_args,
1715
-                true
1716
-            );
1717
-        }
1718
-        if ($display) {
1719
-            echo $content;
1720
-            return '';
1721
-        }
1722
-        return $content;
1723
-    }
1724
-
1725
-
1726
-    /**
1727
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1728
-     *
1729
-     * @return array properly formatted array for help popup content
1730
-     * @throws EE_Error
1731
-     */
1732
-    private function _get_help_content()
1733
-    {
1734
-        // what is the method we're looking for?
1735
-        $method_name = '_help_popup_content_' . $this->_req_action;
1736
-        // if method doesn't exist let's get out.
1737
-        if (! method_exists($this, $method_name)) {
1738
-            return array();
1739
-        }
1740
-        // k we're good to go let's retrieve the help array
1741
-        $help_array = call_user_func(array($this, $method_name));
1742
-        // make sure we've got an array!
1743
-        if (! is_array($help_array)) {
1744
-            throw new EE_Error(
1745
-                esc_html__(
1746
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1747
-                    'event_espresso'
1748
-                )
1749
-            );
1750
-        }
1751
-        return $help_array;
1752
-    }
1753
-
1754
-
1755
-    /**
1756
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1757
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1758
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1759
-     *
1760
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1761
-     * @param boolean $display    if false then we return the trigger string
1762
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1763
-     * @return string
1764
-     * @throws DomainException
1765
-     * @throws EE_Error
1766
-     */
1767
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1768
-    {
1769
-        if (defined('DOING_AJAX')) {
1770
-            return '';
1771
-        }
1772
-        // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1773
-        $help_array = $this->_get_help_content();
1774
-        $help_content = '';
1775
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1776
-            $help_array[ $trigger_id ] = array(
1777
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1778
-                'content' => esc_html__(
1779
-                    'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1780
-                    'event_espresso'
1781
-                ),
1782
-            );
1783
-            $help_content = $this->_set_help_popup_content($help_array, false);
1784
-        }
1785
-        // let's setup the trigger
1786
-        $content = '<a class="ee-dialog" href="?height='
1787
-                   . $dimensions[0]
1788
-                   . '&width='
1789
-                   . $dimensions[1]
1790
-                   . '&inlineId='
1791
-                   . $trigger_id
1792
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1793
-        $content .= $help_content;
1794
-        if ($display) {
1795
-            echo $content;
1796
-            return '';
1797
-        }
1798
-        return $content;
1799
-    }
1800
-
1801
-
1802
-    /**
1803
-     * _add_global_screen_options
1804
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1805
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1806
-     *
1807
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1808
-     *         see also WP_Screen object documents...
1809
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1810
-     * @abstract
1811
-     * @return void
1812
-     */
1813
-    private function _add_global_screen_options()
1814
-    {
1815
-    }
1816
-
1817
-
1818
-    /**
1819
-     * _add_global_feature_pointers
1820
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1821
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1822
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1823
-     *
1824
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1825
-     *         extended) also see:
1826
-     * @link   http://eamann.com/tech/wordpress-portland/
1827
-     * @abstract
1828
-     * @return void
1829
-     */
1830
-    private function _add_global_feature_pointers()
1831
-    {
1832
-    }
1833
-
1834
-
1835
-    /**
1836
-     * load_global_scripts_styles
1837
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1838
-     *
1839
-     * @return void
1840
-     * @throws EE_Error
1841
-     */
1842
-    public function load_global_scripts_styles()
1843
-    {
1844
-        /** STYLES **/
1845
-        // add debugging styles
1846
-        if (WP_DEBUG) {
1847
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1848
-        }
1849
-        // register all styles
1850
-        wp_register_style(
1851
-            'espresso-ui-theme',
1852
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1853
-            array(),
1854
-            EVENT_ESPRESSO_VERSION
1855
-        );
1856
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1857
-        // helpers styles
1858
-        wp_register_style(
1859
-            'ee-text-links',
1860
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1861
-            array(),
1862
-            EVENT_ESPRESSO_VERSION
1863
-        );
1864
-        /** SCRIPTS **/
1865
-        // register all scripts
1866
-        wp_register_script(
1867
-            'ee-dialog',
1868
-            EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1869
-            array('jquery', 'jquery-ui-draggable'),
1870
-            EVENT_ESPRESSO_VERSION,
1871
-            true
1872
-        );
1873
-        wp_register_script(
1874
-            'ee_admin_js',
1875
-            EE_ADMIN_URL . 'assets/ee-admin-page.js',
1876
-            array('espresso_core', 'ee-parse-uri', 'ee-dialog'),
1877
-            EVENT_ESPRESSO_VERSION,
1878
-            true
1879
-        );
1880
-        wp_register_script(
1881
-            'jquery-ui-timepicker-addon',
1882
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1883
-            array('jquery-ui-datepicker', 'jquery-ui-slider'),
1884
-            EVENT_ESPRESSO_VERSION,
1885
-            true
1886
-        );
1887
-        add_filter('FHEE_load_joyride', '__return_true');
1888
-        // script for sorting tables
1889
-        wp_register_script(
1890
-            'espresso_ajax_table_sorting',
1891
-            EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1892
-            array('ee_admin_js', 'jquery-ui-sortable'),
1893
-            EVENT_ESPRESSO_VERSION,
1894
-            true
1895
-        );
1896
-        // script for parsing uri's
1897
-        wp_register_script(
1898
-            'ee-parse-uri',
1899
-            EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1900
-            array(),
1901
-            EVENT_ESPRESSO_VERSION,
1902
-            true
1903
-        );
1904
-        // and parsing associative serialized form elements
1905
-        wp_register_script(
1906
-            'ee-serialize-full-array',
1907
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1908
-            array('jquery'),
1909
-            EVENT_ESPRESSO_VERSION,
1910
-            true
1911
-        );
1912
-        // helpers scripts
1913
-        wp_register_script(
1914
-            'ee-text-links',
1915
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1916
-            array('jquery'),
1917
-            EVENT_ESPRESSO_VERSION,
1918
-            true
1919
-        );
1920
-        wp_register_script(
1921
-            'ee-moment-core',
1922
-            EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1923
-            array(),
1924
-            EVENT_ESPRESSO_VERSION,
1925
-            true
1926
-        );
1927
-        wp_register_script(
1928
-            'ee-moment',
1929
-            EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1930
-            array('ee-moment-core'),
1931
-            EVENT_ESPRESSO_VERSION,
1932
-            true
1933
-        );
1934
-        wp_register_script(
1935
-            'ee-datepicker',
1936
-            EE_ADMIN_URL . 'assets/ee-datepicker.js',
1937
-            array('jquery-ui-timepicker-addon', 'ee-moment'),
1938
-            EVENT_ESPRESSO_VERSION,
1939
-            true
1940
-        );
1941
-        // google charts
1942
-        wp_register_script(
1943
-            'google-charts',
1944
-            'https://www.gstatic.com/charts/loader.js',
1945
-            array(),
1946
-            EVENT_ESPRESSO_VERSION,
1947
-            false
1948
-        );
1949
-        // ENQUEUE ALL BASICS BY DEFAULT
1950
-        wp_enqueue_style('ee-admin-css');
1951
-        wp_enqueue_script('ee_admin_js');
1952
-        wp_enqueue_script('ee-accounting');
1953
-        wp_enqueue_script('jquery-validate');
1954
-        // taking care of metaboxes
1955
-        if (empty($this->_cpt_route)
1956
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1957
-        ) {
1958
-            wp_enqueue_script('dashboard');
1959
-        }
1960
-        // LOCALIZED DATA
1961
-        // localize script for ajax lazy loading
1962
-        $lazy_loader_container_ids = apply_filters(
1963
-            'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1964
-            array('espresso_news_post_box_content')
1965
-        );
1966
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1967
-        /**
1968
-         * help tour stuff
1969
-         */
1970
-        if (! empty($this->_help_tour)) {
1971
-            // register the js for kicking things off
1972
-            wp_enqueue_script(
1973
-                'ee-help-tour',
1974
-                EE_ADMIN_URL . 'assets/ee-help-tour.js',
1975
-                array('jquery-joyride'),
1976
-                EVENT_ESPRESSO_VERSION,
1977
-                true
1978
-            );
1979
-            $tours = array();
1980
-            // setup tours for the js tour object
1981
-            foreach ($this->_help_tour['tours'] as $tour) {
1982
-                if ($tour instanceof EE_Help_Tour) {
1983
-                    $tours[] = array(
1984
-                        'id'      => $tour->get_slug(),
1985
-                        'options' => $tour->get_options(),
1986
-                    );
1987
-                }
1988
-            }
1989
-            wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1990
-            // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1991
-        }
1992
-    }
1993
-
1994
-
1995
-    /**
1996
-     *        admin_footer_scripts_eei18n_js_strings
1997
-     *
1998
-     * @return        void
1999
-     */
2000
-    public function admin_footer_scripts_eei18n_js_strings()
2001
-    {
2002
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
2003
-        EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
2004
-            __(
2005
-                'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
2006
-                'event_espresso'
2007
-            )
2008
-        );
2009
-        EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso'));
2010
-        EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso'));
2011
-        EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso'));
2012
-        EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso'));
2013
-        EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso'));
2014
-        EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso'));
2015
-        EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso'));
2016
-        EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso'));
2017
-        EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso'));
2018
-        EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso'));
2019
-        EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso'));
2020
-        EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso'));
2021
-        EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso'));
2022
-        EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso'));
2023
-        EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso'));
2024
-        EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso'));
2025
-        EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso'));
2026
-        EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso'));
2027
-        EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso'));
2028
-        EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso'));
2029
-        EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso'));
2030
-        EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso'));
2031
-        EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso'));
2032
-        EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso'));
2033
-        EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso'));
2034
-        EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso'));
2035
-        EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
2036
-        EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
2037
-        EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso'));
2038
-        EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso'));
2039
-        EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso'));
2040
-        EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso'));
2041
-        EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso'));
2042
-        EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso'));
2043
-        EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso'));
2044
-        EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso'));
2045
-        EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso'));
2046
-        EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso'));
2047
-    }
2048
-
2049
-
2050
-    /**
2051
-     *        load enhanced xdebug styles for ppl with failing eyesight
2052
-     *
2053
-     * @return        void
2054
-     */
2055
-    public function add_xdebug_style()
2056
-    {
2057
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2058
-    }
2059
-
2060
-
2061
-    /************************/
2062
-    /** LIST TABLE METHODS **/
2063
-    /************************/
2064
-    /**
2065
-     * this sets up the list table if the current view requires it.
2066
-     *
2067
-     * @return void
2068
-     * @throws EE_Error
2069
-     */
2070
-    protected function _set_list_table()
2071
-    {
2072
-        // first is this a list_table view?
2073
-        if (! isset($this->_route_config['list_table'])) {
2074
-            return;
2075
-        } //not a list_table view so get out.
2076
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
2077
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2078
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2079
-            // user error msg
2080
-            $error_msg = esc_html__(
2081
-                'An error occurred. The requested list table views could not be found.',
2082
-                'event_espresso'
2083
-            );
2084
-            // developer error msg
2085
-            $error_msg .= '||'
2086
-                          . sprintf(
2087
-                              esc_html__(
2088
-                                  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2089
-                                  'event_espresso'
2090
-                              ),
2091
-                              $this->_req_action,
2092
-                              $list_table_view
2093
-                          );
2094
-            throw new EE_Error($error_msg);
2095
-        }
2096
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2097
-        $this->_views = apply_filters(
2098
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2099
-            $this->_views
2100
-        );
2101
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2102
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2103
-        $this->_set_list_table_view();
2104
-        $this->_set_list_table_object();
2105
-    }
2106
-
2107
-
2108
-    /**
2109
-     * set current view for List Table
2110
-     *
2111
-     * @return void
2112
-     */
2113
-    protected function _set_list_table_view()
2114
-    {
2115
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2116
-        // looking at active items or dumpster diving ?
2117
-        if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2118
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2119
-        } else {
2120
-            $this->_view = sanitize_key($this->_req_data['status']);
2121
-        }
2122
-    }
2123
-
2124
-
2125
-    /**
2126
-     * _set_list_table_object
2127
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2128
-     *
2129
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2130
-     * @throws \InvalidArgumentException
2131
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2132
-     * @throws EE_Error
2133
-     * @throws InvalidInterfaceException
2134
-     */
2135
-    protected function _set_list_table_object()
2136
-    {
2137
-        if (isset($this->_route_config['list_table'])) {
2138
-            if (! class_exists($this->_route_config['list_table'])) {
2139
-                throw new EE_Error(
2140
-                    sprintf(
2141
-                        esc_html__(
2142
-                            'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2143
-                            'event_espresso'
2144
-                        ),
2145
-                        $this->_route_config['list_table'],
2146
-                        get_class($this)
2147
-                    )
2148
-                );
2149
-            }
2150
-            $this->_list_table_object = $this->loader->getShared(
2151
-                $this->_route_config['list_table'],
2152
-                array($this)
2153
-            );
2154
-        }
2155
-    }
2156
-
2157
-
2158
-    /**
2159
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2160
-     *
2161
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2162
-     *                                                    urls.  The array should be indexed by the view it is being
2163
-     *                                                    added to.
2164
-     * @return array
2165
-     */
2166
-    public function get_list_table_view_RLs($extra_query_args = array())
2167
-    {
2168
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2169
-        if (empty($this->_views)) {
2170
-            $this->_views = array();
2171
-        }
2172
-        // cycle thru views
2173
-        foreach ($this->_views as $key => $view) {
2174
-            $query_args = array();
2175
-            // check for current view
2176
-            $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : '';
2177
-            $query_args['action'] = $this->_req_action;
2178
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2179
-            $query_args['status'] = $view['slug'];
2180
-            // merge any other arguments sent in.
2181
-            if (isset($extra_query_args[ $view['slug'] ])) {
2182
-                $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2183
-            }
2184
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2185
-        }
2186
-        return $this->_views;
2187
-    }
2188
-
2189
-
2190
-    /**
2191
-     * _entries_per_page_dropdown
2192
-     * generates a drop down box for selecting the number of visible rows in an admin page list table
2193
-     *
2194
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2195
-     *         WP does it.
2196
-     * @param int $max_entries total number of rows in the table
2197
-     * @return string
2198
-     */
2199
-    protected function _entries_per_page_dropdown($max_entries = 0)
2200
-    {
2201
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2202
-        $values = array(10, 25, 50, 100);
2203
-        $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2204
-        if ($max_entries) {
2205
-            $values[] = $max_entries;
2206
-            sort($values);
2207
-        }
2208
-        $entries_per_page_dropdown = '
104
+	/**
105
+	 * @var array $_route_config
106
+	 */
107
+	protected $_route_config;
108
+
109
+	/**
110
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
111
+	 * actions.
112
+	 *
113
+	 * @since 4.6.x
114
+	 * @var array.
115
+	 */
116
+	protected $_default_route_query_args;
117
+
118
+	// set via request page and action args.
119
+	protected $_current_page;
120
+
121
+	protected $_current_view;
122
+
123
+	protected $_current_page_view_url;
124
+
125
+	// sanitized request action (and nonce)
126
+
127
+	/**
128
+	 * @var string $_req_action
129
+	 */
130
+	protected $_req_action;
131
+
132
+	/**
133
+	 * @var string $_req_nonce
134
+	 */
135
+	protected $_req_nonce;
136
+
137
+	// search related
138
+	protected $_search_btn_label;
139
+
140
+	protected $_search_box_callback;
141
+
142
+	/**
143
+	 * WP Current Screen object
144
+	 *
145
+	 * @var WP_Screen
146
+	 */
147
+	protected $_current_screen;
148
+
149
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
150
+	protected $_hook_obj;
151
+
152
+	// for holding incoming request data
153
+	protected $_req_data;
154
+
155
+	// yes / no array for admin form fields
156
+	protected $_yes_no_values = array();
157
+
158
+	// some default things shared by all child classes
159
+	protected $_default_espresso_metaboxes;
160
+
161
+	/**
162
+	 *    EE_Registry Object
163
+	 *
164
+	 * @var    EE_Registry
165
+	 */
166
+	protected $EE = null;
167
+
168
+
169
+	/**
170
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
171
+	 *
172
+	 * @var boolean
173
+	 */
174
+	protected $_is_caf = false;
175
+
176
+
177
+	/**
178
+	 * @Constructor
179
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
180
+	 * @throws EE_Error
181
+	 * @throws InvalidArgumentException
182
+	 * @throws ReflectionException
183
+	 * @throws InvalidDataTypeException
184
+	 * @throws InvalidInterfaceException
185
+	 */
186
+	public function __construct($routing = true)
187
+	{
188
+		$this->loader = LoaderFactory::getLoader();
189
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
190
+			$this->_is_caf = true;
191
+		}
192
+		$this->_yes_no_values = array(
193
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
194
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
195
+		);
196
+		// set the _req_data property.
197
+		$this->_req_data = array_merge($_GET, $_POST);
198
+		// routing enabled?
199
+		$this->_routing = $routing;
200
+		// set initial page props (child method)
201
+		$this->_init_page_props();
202
+		// set global defaults
203
+		$this->_set_defaults();
204
+		// set early because incoming requests could be ajax related and we need to register those hooks.
205
+		$this->_global_ajax_hooks();
206
+		$this->_ajax_hooks();
207
+		// other_page_hooks have to be early too.
208
+		$this->_do_other_page_hooks();
209
+		// This just allows us to have extending classes do something specific
210
+		// before the parent constructor runs _page_setup().
211
+		if (method_exists($this, '_before_page_setup')) {
212
+			$this->_before_page_setup();
213
+		}
214
+		// set up page dependencies
215
+		$this->_page_setup();
216
+	}
217
+
218
+
219
+	/**
220
+	 * _init_page_props
221
+	 * Child classes use to set at least the following properties:
222
+	 * $page_slug.
223
+	 * $page_label.
224
+	 *
225
+	 * @abstract
226
+	 * @return void
227
+	 */
228
+	abstract protected function _init_page_props();
229
+
230
+
231
+	/**
232
+	 * _ajax_hooks
233
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
234
+	 * Note: within the ajax callback methods.
235
+	 *
236
+	 * @abstract
237
+	 * @return void
238
+	 */
239
+	abstract protected function _ajax_hooks();
240
+
241
+
242
+	/**
243
+	 * _define_page_props
244
+	 * child classes define page properties in here.  Must include at least:
245
+	 * $_admin_base_url = base_url for all admin pages
246
+	 * $_admin_page_title = default admin_page_title for admin pages
247
+	 * $_labels = array of default labels for various automatically generated elements:
248
+	 *    array(
249
+	 *        'buttons' => array(
250
+	 *            'add' => esc_html__('label for add new button'),
251
+	 *            'edit' => esc_html__('label for edit button'),
252
+	 *            'delete' => esc_html__('label for delete button')
253
+	 *            )
254
+	 *        )
255
+	 *
256
+	 * @abstract
257
+	 * @return void
258
+	 */
259
+	abstract protected function _define_page_props();
260
+
261
+
262
+	/**
263
+	 * _set_page_routes
264
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
265
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
266
+	 * have a 'default' route. Here's the format
267
+	 * $this->_page_routes = array(
268
+	 *        'default' => array(
269
+	 *            'func' => '_default_method_handling_route',
270
+	 *            'args' => array('array','of','args'),
271
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
272
+	 *            ajax request, backend processing)
273
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
274
+	 *            headers route after.  The string you enter here should match the defined route reference for a
275
+	 *            headers sent route.
276
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
277
+	 *            this route.
278
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
279
+	 *            checks).
280
+	 *        ),
281
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
282
+	 *        handling method.
283
+	 *        )
284
+	 * )
285
+	 *
286
+	 * @abstract
287
+	 * @return void
288
+	 */
289
+	abstract protected function _set_page_routes();
290
+
291
+
292
+	/**
293
+	 * _set_page_config
294
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
295
+	 * array corresponds to the page_route for the loaded page. Format:
296
+	 * $this->_page_config = array(
297
+	 *        'default' => array(
298
+	 *            'labels' => array(
299
+	 *                'buttons' => array(
300
+	 *                    'add' => esc_html__('label for adding item'),
301
+	 *                    'edit' => esc_html__('label for editing item'),
302
+	 *                    'delete' => esc_html__('label for deleting item')
303
+	 *                ),
304
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
305
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
306
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
307
+	 *            _define_page_props() method
308
+	 *            'nav' => array(
309
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
310
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
311
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
312
+	 *                'order' => 10, //required to indicate tab position.
313
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
314
+	 *                displayed then add this parameter.
315
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
316
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
317
+	 *            metaboxes set for eventespresso admin pages.
318
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
319
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
320
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
321
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
322
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
323
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
324
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
325
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
326
+	 *            want to display.
327
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
328
+	 *                'tab_id' => array(
329
+	 *                    'title' => 'tab_title',
330
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
331
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
332
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
333
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
334
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
335
+	 *                    attempt to use the callback which should match the name of a method in the class
336
+	 *                    ),
337
+	 *                'tab2_id' => array(
338
+	 *                    'title' => 'tab2 title',
339
+	 *                    'filename' => 'file_name_2'
340
+	 *                    'callback' => 'callback_method_for_content',
341
+	 *                 ),
342
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
343
+	 *            help tab area on an admin page. @link
344
+	 *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
345
+	 *            'help_tour' => array(
346
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
347
+	 *                in a folder for this admin page named "help_tours", a file name matching the key given here
348
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
349
+	 *            ),
350
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
351
+	 *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
352
+	 *            just set
353
+	 *            'require_nonce' to FALSE
354
+	 *            )
355
+	 * )
356
+	 *
357
+	 * @abstract
358
+	 * @return void
359
+	 */
360
+	abstract protected function _set_page_config();
361
+
362
+
363
+
364
+
365
+
366
+	/** end sample help_tour methods **/
367
+	/**
368
+	 * _add_screen_options
369
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
370
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
371
+	 * to a particular view.
372
+	 *
373
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
374
+	 *         see also WP_Screen object documents...
375
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
376
+	 * @abstract
377
+	 * @return void
378
+	 */
379
+	abstract protected function _add_screen_options();
380
+
381
+
382
+	/**
383
+	 * _add_feature_pointers
384
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
385
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
386
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
387
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
388
+	 * extended) also see:
389
+	 *
390
+	 * @link   http://eamann.com/tech/wordpress-portland/
391
+	 * @abstract
392
+	 * @return void
393
+	 */
394
+	abstract protected function _add_feature_pointers();
395
+
396
+
397
+	/**
398
+	 * load_scripts_styles
399
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
400
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
401
+	 * scripts/styles per view by putting them in a dynamic function in this format
402
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
403
+	 *
404
+	 * @abstract
405
+	 * @return void
406
+	 */
407
+	abstract public function load_scripts_styles();
408
+
409
+
410
+	/**
411
+	 * admin_init
412
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
413
+	 * all pages/views loaded by child class.
414
+	 *
415
+	 * @abstract
416
+	 * @return void
417
+	 */
418
+	abstract public function admin_init();
419
+
420
+
421
+	/**
422
+	 * admin_notices
423
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
424
+	 * all pages/views loaded by child class.
425
+	 *
426
+	 * @abstract
427
+	 * @return void
428
+	 */
429
+	abstract public function admin_notices();
430
+
431
+
432
+	/**
433
+	 * admin_footer_scripts
434
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
435
+	 * will apply to all pages/views loaded by child class.
436
+	 *
437
+	 * @return void
438
+	 */
439
+	abstract public function admin_footer_scripts();
440
+
441
+
442
+	/**
443
+	 * admin_footer
444
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
445
+	 * apply to all pages/views loaded by child class.
446
+	 *
447
+	 * @return void
448
+	 */
449
+	public function admin_footer()
450
+	{
451
+	}
452
+
453
+
454
+	/**
455
+	 * _global_ajax_hooks
456
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
457
+	 * Note: within the ajax callback methods.
458
+	 *
459
+	 * @abstract
460
+	 * @return void
461
+	 */
462
+	protected function _global_ajax_hooks()
463
+	{
464
+		// for lazy loading of metabox content
465
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
466
+	}
467
+
468
+
469
+	public function ajax_metabox_content()
470
+	{
471
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
472
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
473
+		self::cached_rss_display($contentid, $url);
474
+		wp_die();
475
+	}
476
+
477
+
478
+	/**
479
+	 * _page_setup
480
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
481
+	 * doesn't match the object.
482
+	 *
483
+	 * @final
484
+	 * @return void
485
+	 * @throws EE_Error
486
+	 * @throws InvalidArgumentException
487
+	 * @throws ReflectionException
488
+	 * @throws InvalidDataTypeException
489
+	 * @throws InvalidInterfaceException
490
+	 */
491
+	final protected function _page_setup()
492
+	{
493
+		// requires?
494
+		// admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
495
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
496
+		// next verify if we need to load anything...
497
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
498
+		$this->page_folder = strtolower(
499
+			str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
500
+		);
501
+		global $ee_menu_slugs;
502
+		$ee_menu_slugs = (array) $ee_menu_slugs;
503
+		if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) {
504
+			return;
505
+		}
506
+		// becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
507
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
508
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
509
+				? $this->_req_data['action2']
510
+				: $this->_req_data['action'];
511
+		}
512
+		// then set blank or -1 action values to 'default'
513
+		$this->_req_action = isset($this->_req_data['action'])
514
+							 && ! empty($this->_req_data['action'])
515
+							 && $this->_req_data['action'] !== '-1'
516
+			? sanitize_key($this->_req_data['action'])
517
+			: 'default';
518
+		// if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
519
+		//  This covers cases where we're coming in from a list table that isn't on the default route.
520
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
521
+			? $this->_req_data['route'] : $this->_req_action;
522
+		// however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
523
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route'])
524
+			? $this->_req_data['route']
525
+			: $this->_req_action;
526
+		$this->_current_view = $this->_req_action;
527
+		$this->_req_nonce = $this->_req_action . '_nonce';
528
+		$this->_define_page_props();
529
+		$this->_current_page_view_url = add_query_arg(
530
+			array('page' => $this->_current_page, 'action' => $this->_current_view),
531
+			$this->_admin_base_url
532
+		);
533
+		// default things
534
+		$this->_default_espresso_metaboxes = array(
535
+			'_espresso_news_post_box',
536
+			'_espresso_links_post_box',
537
+			'_espresso_ratings_request',
538
+			'_espresso_sponsors_post_box',
539
+		);
540
+		// set page configs
541
+		$this->_set_page_routes();
542
+		$this->_set_page_config();
543
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
544
+		if (isset($this->_req_data['wp_referer'])) {
545
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
546
+		}
547
+		// for caffeinated and other extended functionality.
548
+		//  If there is a _extend_page_config method
549
+		// then let's run that to modify the all the various page configuration arrays
550
+		if (method_exists($this, '_extend_page_config')) {
551
+			$this->_extend_page_config();
552
+		}
553
+		// for CPT and other extended functionality.
554
+		// If there is an _extend_page_config_for_cpt
555
+		// then let's run that to modify all the various page configuration arrays.
556
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
557
+			$this->_extend_page_config_for_cpt();
558
+		}
559
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
560
+		$this->_page_routes = apply_filters(
561
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
562
+			$this->_page_routes,
563
+			$this
564
+		);
565
+		$this->_page_config = apply_filters(
566
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
567
+			$this->_page_config,
568
+			$this
569
+		);
570
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
571
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
572
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
573
+			add_action(
574
+				'AHEE__EE_Admin_Page__route_admin_request',
575
+				array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
576
+				10,
577
+				2
578
+			);
579
+		}
580
+		// next route only if routing enabled
581
+		if ($this->_routing && ! defined('DOING_AJAX')) {
582
+			$this->_verify_routes();
583
+			// next let's just check user_access and kill if no access
584
+			$this->check_user_access();
585
+			if ($this->_is_UI_request) {
586
+				// admin_init stuff - global, all views for this page class, specific view
587
+				add_action('admin_init', array($this, 'admin_init'), 10);
588
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
589
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
590
+				}
591
+			} else {
592
+				// hijack regular WP loading and route admin request immediately
593
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
594
+				$this->route_admin_request();
595
+			}
596
+		}
597
+	}
598
+
599
+
600
+	/**
601
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
602
+	 *
603
+	 * @return void
604
+	 * @throws ReflectionException
605
+	 * @throws EE_Error
606
+	 */
607
+	private function _do_other_page_hooks()
608
+	{
609
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
610
+		foreach ($registered_pages as $page) {
611
+			// now let's setup the file name and class that should be present
612
+			$classname = str_replace('.class.php', '', $page);
613
+			// autoloaders should take care of loading file
614
+			if (! class_exists($classname)) {
615
+				$error_msg[] = sprintf(
616
+					esc_html__(
617
+						'Something went wrong with loading the %s admin hooks page.',
618
+						'event_espresso'
619
+					),
620
+					$page
621
+				);
622
+				$error_msg[] = $error_msg[0]
623
+							   . "\r\n"
624
+							   . sprintf(
625
+								   esc_html__(
626
+									   'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
627
+									   'event_espresso'
628
+								   ),
629
+								   $page,
630
+								   '<br />',
631
+								   '<strong>' . $classname . '</strong>'
632
+							   );
633
+				throw new EE_Error(implode('||', $error_msg));
634
+			}
635
+			$a = new ReflectionClass($classname);
636
+			// notice we are passing the instance of this class to the hook object.
637
+			$hookobj[] = $a->newInstance($this);
638
+		}
639
+	}
640
+
641
+
642
+	public function load_page_dependencies()
643
+	{
644
+		try {
645
+			$this->_load_page_dependencies();
646
+		} catch (EE_Error $e) {
647
+			$e->get_error();
648
+		}
649
+	}
650
+
651
+
652
+	/**
653
+	 * load_page_dependencies
654
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
655
+	 *
656
+	 * @return void
657
+	 * @throws DomainException
658
+	 * @throws EE_Error
659
+	 * @throws InvalidArgumentException
660
+	 * @throws InvalidDataTypeException
661
+	 * @throws InvalidInterfaceException
662
+	 * @throws ReflectionException
663
+	 */
664
+	protected function _load_page_dependencies()
665
+	{
666
+		// let's set the current_screen and screen options to override what WP set
667
+		$this->_current_screen = get_current_screen();
668
+		// load admin_notices - global, page class, and view specific
669
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
670
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
671
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
672
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
673
+		}
674
+		// load network admin_notices - global, page class, and view specific
675
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
676
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
677
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
678
+		}
679
+		// this will save any per_page screen options if they are present
680
+		$this->_set_per_page_screen_options();
681
+		// setup list table properties
682
+		$this->_set_list_table();
683
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
684
+		// However in some cases the metaboxes will need to be added within a route handling callback.
685
+		$this->_add_registered_meta_boxes();
686
+		$this->_add_screen_columns();
687
+		// add screen options - global, page child class, and view specific
688
+		$this->_add_global_screen_options();
689
+		$this->_add_screen_options();
690
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
691
+		if (method_exists($this, $add_screen_options)) {
692
+			$this->{$add_screen_options}();
693
+		}
694
+		// add help tab(s) and tours- set via page_config and qtips.
695
+		$this->_add_help_tour();
696
+		$this->_add_help_tabs();
697
+		$this->_add_qtips();
698
+		// add feature_pointers - global, page child class, and view specific
699
+		$this->_add_feature_pointers();
700
+		$this->_add_global_feature_pointers();
701
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
702
+		if (method_exists($this, $add_feature_pointer)) {
703
+			$this->{$add_feature_pointer}();
704
+		}
705
+		// enqueue scripts/styles - global, page class, and view specific
706
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
707
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
708
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
709
+			add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
710
+		}
711
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
712
+		// admin_print_footer_scripts - global, page child class, and view specific.
713
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
714
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
715
+		// is a good use case. Notice the late priority we're giving these
716
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
717
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
718
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
719
+			add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
720
+		}
721
+		// admin footer scripts
722
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
723
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
724
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
725
+			add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
726
+		}
727
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
728
+		// targeted hook
729
+		do_action(
730
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
731
+		);
732
+	}
733
+
734
+
735
+	/**
736
+	 * _set_defaults
737
+	 * This sets some global defaults for class properties.
738
+	 */
739
+	private function _set_defaults()
740
+	{
741
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
742
+		$this->_event = $this->_template_path = $this->_column_template_path = null;
743
+		$this->_nav_tabs = $this->_views = $this->_page_routes = array();
744
+		$this->_page_config = $this->_default_route_query_args = array();
745
+		$this->_default_nav_tab_name = 'overview';
746
+		// init template args
747
+		$this->_template_args = array(
748
+			'admin_page_header'  => '',
749
+			'admin_page_content' => '',
750
+			'post_body_content'  => '',
751
+			'before_list_table'  => '',
752
+			'after_list_table'   => '',
753
+		);
754
+	}
755
+
756
+
757
+	/**
758
+	 * route_admin_request
759
+	 *
760
+	 * @see    _route_admin_request()
761
+	 * @return exception|void error
762
+	 * @throws InvalidArgumentException
763
+	 * @throws InvalidInterfaceException
764
+	 * @throws InvalidDataTypeException
765
+	 * @throws EE_Error
766
+	 * @throws ReflectionException
767
+	 */
768
+	public function route_admin_request()
769
+	{
770
+		try {
771
+			$this->_route_admin_request();
772
+		} catch (EE_Error $e) {
773
+			$e->get_error();
774
+		}
775
+	}
776
+
777
+
778
+	public function set_wp_page_slug($wp_page_slug)
779
+	{
780
+		$this->_wp_page_slug = $wp_page_slug;
781
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
782
+		if (is_network_admin()) {
783
+			$this->_wp_page_slug .= '-network';
784
+		}
785
+	}
786
+
787
+
788
+	/**
789
+	 * _verify_routes
790
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
791
+	 * we know if we need to drop out.
792
+	 *
793
+	 * @return bool
794
+	 * @throws EE_Error
795
+	 */
796
+	protected function _verify_routes()
797
+	{
798
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
799
+		if (! $this->_current_page && ! defined('DOING_AJAX')) {
800
+			return false;
801
+		}
802
+		$this->_route = false;
803
+		// check that the page_routes array is not empty
804
+		if (empty($this->_page_routes)) {
805
+			// user error msg
806
+			$error_msg = sprintf(
807
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
808
+				$this->_admin_page_title
809
+			);
810
+			// developer error msg
811
+			$error_msg .= '||' . $error_msg
812
+						  . esc_html__(
813
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
814
+							  'event_espresso'
815
+						  );
816
+			throw new EE_Error($error_msg);
817
+		}
818
+		// and that the requested page route exists
819
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
820
+			$this->_route = $this->_page_routes[ $this->_req_action ];
821
+			$this->_route_config = isset($this->_page_config[ $this->_req_action ])
822
+				? $this->_page_config[ $this->_req_action ] : array();
823
+		} else {
824
+			// user error msg
825
+			$error_msg = sprintf(
826
+				esc_html__(
827
+					'The requested page route does not exist for the %s admin page.',
828
+					'event_espresso'
829
+				),
830
+				$this->_admin_page_title
831
+			);
832
+			// developer error msg
833
+			$error_msg .= '||' . $error_msg
834
+						  . sprintf(
835
+							  esc_html__(
836
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
837
+								  'event_espresso'
838
+							  ),
839
+							  $this->_req_action
840
+						  );
841
+			throw new EE_Error($error_msg);
842
+		}
843
+		// and that a default route exists
844
+		if (! array_key_exists('default', $this->_page_routes)) {
845
+			// user error msg
846
+			$error_msg = sprintf(
847
+				esc_html__(
848
+					'A default page route has not been set for the % admin page.',
849
+					'event_espresso'
850
+				),
851
+				$this->_admin_page_title
852
+			);
853
+			// developer error msg
854
+			$error_msg .= '||' . $error_msg
855
+						  . esc_html__(
856
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
857
+							  'event_espresso'
858
+						  );
859
+			throw new EE_Error($error_msg);
860
+		}
861
+		// first lets' catch if the UI request has EVER been set.
862
+		if ($this->_is_UI_request === null) {
863
+			// lets set if this is a UI request or not.
864
+			$this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
865
+			// wait a minute... we might have a noheader in the route array
866
+			$this->_is_UI_request = is_array($this->_route)
867
+									&& isset($this->_route['noheader'])
868
+									&& $this->_route['noheader'] ? false : $this->_is_UI_request;
869
+		}
870
+		$this->_set_current_labels();
871
+		return true;
872
+	}
873
+
874
+
875
+	/**
876
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
877
+	 *
878
+	 * @param  string $route the route name we're verifying
879
+	 * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
880
+	 * @throws EE_Error
881
+	 */
882
+	protected function _verify_route($route)
883
+	{
884
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
885
+			return true;
886
+		}
887
+		// user error msg
888
+		$error_msg = sprintf(
889
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
890
+			$this->_admin_page_title
891
+		);
892
+		// developer error msg
893
+		$error_msg .= '||' . $error_msg
894
+					  . sprintf(
895
+						  esc_html__(
896
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
897
+							  'event_espresso'
898
+						  ),
899
+						  $route
900
+					  );
901
+		throw new EE_Error($error_msg);
902
+	}
903
+
904
+
905
+	/**
906
+	 * perform nonce verification
907
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
908
+	 * using this method (and save retyping!)
909
+	 *
910
+	 * @param  string $nonce     The nonce sent
911
+	 * @param  string $nonce_ref The nonce reference string (name0)
912
+	 * @return void
913
+	 * @throws EE_Error
914
+	 */
915
+	protected function _verify_nonce($nonce, $nonce_ref)
916
+	{
917
+		// verify nonce against expected value
918
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
919
+			// these are not the droids you are looking for !!!
920
+			$msg = sprintf(
921
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
922
+				'<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
923
+				'</a>'
924
+			);
925
+			if (WP_DEBUG) {
926
+				$msg .= "\n  "
927
+						. sprintf(
928
+							esc_html__(
929
+								'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
930
+								'event_espresso'
931
+							),
932
+							__CLASS__
933
+						);
934
+			}
935
+			if (! defined('DOING_AJAX')) {
936
+				wp_die($msg);
937
+			} else {
938
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
939
+				$this->_return_json();
940
+			}
941
+		}
942
+	}
943
+
944
+
945
+	/**
946
+	 * _route_admin_request()
947
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
948
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
949
+	 * in the page routes and then will try to load the corresponding method.
950
+	 *
951
+	 * @return void
952
+	 * @throws EE_Error
953
+	 * @throws InvalidArgumentException
954
+	 * @throws InvalidDataTypeException
955
+	 * @throws InvalidInterfaceException
956
+	 * @throws ReflectionException
957
+	 */
958
+	protected function _route_admin_request()
959
+	{
960
+		if (! $this->_is_UI_request) {
961
+			$this->_verify_routes();
962
+		}
963
+		$nonce_check = isset($this->_route_config['require_nonce'])
964
+			? $this->_route_config['require_nonce']
965
+			: true;
966
+		if ($this->_req_action !== 'default' && $nonce_check) {
967
+			// set nonce from post data
968
+			$nonce = isset($this->_req_data[ $this->_req_nonce ])
969
+				? sanitize_text_field($this->_req_data[ $this->_req_nonce ])
970
+				: '';
971
+			$this->_verify_nonce($nonce, $this->_req_nonce);
972
+		}
973
+		// set the nav_tabs array but ONLY if this is  UI_request
974
+		if ($this->_is_UI_request) {
975
+			$this->_set_nav_tabs();
976
+		}
977
+		// grab callback function
978
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
979
+		// check if callback has args
980
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
981
+		$error_msg = '';
982
+		// action right before calling route
983
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
984
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
985
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
986
+		}
987
+		// right before calling the route, let's remove _wp_http_referer from the
988
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
989
+		$_SERVER['REQUEST_URI'] = remove_query_arg(
990
+			'_wp_http_referer',
991
+			wp_unslash($_SERVER['REQUEST_URI'])
992
+		);
993
+		if (! empty($func)) {
994
+			if (is_array($func)) {
995
+				list($class, $method) = $func;
996
+			} elseif (strpos($func, '::') !== false) {
997
+				list($class, $method) = explode('::', $func);
998
+			} else {
999
+				$class = $this;
1000
+				$method = $func;
1001
+			}
1002
+			if (! (is_object($class) && $class === $this)) {
1003
+				// send along this admin page object for access by addons.
1004
+				$args['admin_page_object'] = $this;
1005
+			}
1006
+			if (// is it a method on a class that doesn't work?
1007
+				(
1008
+					(
1009
+						method_exists($class, $method)
1010
+						&& call_user_func_array(array($class, $method), $args) === false
1011
+					)
1012
+					&& (
1013
+						// is it a standalone function that doesn't work?
1014
+						function_exists($method)
1015
+						&& call_user_func_array(
1016
+							$func,
1017
+							array_merge(array('admin_page_object' => $this), $args)
1018
+						) === false
1019
+					)
1020
+				)
1021
+				|| (
1022
+					// is it neither a class method NOR a standalone function?
1023
+					! method_exists($class, $method)
1024
+					&& ! function_exists($method)
1025
+				)
1026
+			) {
1027
+				// user error msg
1028
+				$error_msg = esc_html__(
1029
+					'An error occurred. The  requested page route could not be found.',
1030
+					'event_espresso'
1031
+				);
1032
+				// developer error msg
1033
+				$error_msg .= '||';
1034
+				$error_msg .= sprintf(
1035
+					esc_html__(
1036
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1037
+						'event_espresso'
1038
+					),
1039
+					$method
1040
+				);
1041
+			}
1042
+			if (! empty($error_msg)) {
1043
+				throw new EE_Error($error_msg);
1044
+			}
1045
+		}
1046
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1047
+		// then we need to reset the routing properties to the new route.
1048
+		// now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1049
+		if ($this->_is_UI_request === false
1050
+			&& is_array($this->_route)
1051
+			&& ! empty($this->_route['headers_sent_route'])
1052
+		) {
1053
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1054
+		}
1055
+	}
1056
+
1057
+
1058
+	/**
1059
+	 * This method just allows the resetting of page properties in the case where a no headers
1060
+	 * route redirects to a headers route in its route config.
1061
+	 *
1062
+	 * @since   4.3.0
1063
+	 * @param  string $new_route New (non header) route to redirect to.
1064
+	 * @return   void
1065
+	 * @throws ReflectionException
1066
+	 * @throws InvalidArgumentException
1067
+	 * @throws InvalidInterfaceException
1068
+	 * @throws InvalidDataTypeException
1069
+	 * @throws EE_Error
1070
+	 */
1071
+	protected function _reset_routing_properties($new_route)
1072
+	{
1073
+		$this->_is_UI_request = true;
1074
+		// now we set the current route to whatever the headers_sent_route is set at
1075
+		$this->_req_data['action'] = $new_route;
1076
+		// rerun page setup
1077
+		$this->_page_setup();
1078
+	}
1079
+
1080
+
1081
+	/**
1082
+	 * _add_query_arg
1083
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1084
+	 *(internally just uses EEH_URL's function with the same name)
1085
+	 *
1086
+	 * @param array  $args
1087
+	 * @param string $url
1088
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1089
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1090
+	 *                                        Example usage: If the current page is:
1091
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1092
+	 *                                        &action=default&event_id=20&month_range=March%202015
1093
+	 *                                        &_wpnonce=5467821
1094
+	 *                                        and you call:
1095
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1096
+	 *                                        array(
1097
+	 *                                        'action' => 'resend_something',
1098
+	 *                                        'page=>espresso_registrations'
1099
+	 *                                        ),
1100
+	 *                                        $some_url,
1101
+	 *                                        true
1102
+	 *                                        );
1103
+	 *                                        It will produce a url in this structure:
1104
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1105
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1106
+	 *                                        month_range]=March%202015
1107
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1108
+	 * @return string
1109
+	 */
1110
+	public static function add_query_args_and_nonce(
1111
+		$args = array(),
1112
+		$url = false,
1113
+		$sticky = false,
1114
+		$exclude_nonce = false
1115
+	) {
1116
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1117
+		if ($sticky) {
1118
+			$request = $_REQUEST;
1119
+			unset($request['_wp_http_referer']);
1120
+			unset($request['wp_referer']);
1121
+			foreach ($request as $key => $value) {
1122
+				// do not add nonces
1123
+				if (strpos($key, 'nonce') !== false) {
1124
+					continue;
1125
+				}
1126
+				$args[ 'wp_referer[' . $key . ']' ] = $value;
1127
+			}
1128
+		}
1129
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1130
+	}
1131
+
1132
+
1133
+	/**
1134
+	 * This returns a generated link that will load the related help tab.
1135
+	 *
1136
+	 * @param  string $help_tab_id the id for the connected help tab
1137
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1138
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1139
+	 * @uses EEH_Template::get_help_tab_link()
1140
+	 * @return string              generated link
1141
+	 */
1142
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1143
+	{
1144
+		return EEH_Template::get_help_tab_link(
1145
+			$help_tab_id,
1146
+			$this->page_slug,
1147
+			$this->_req_action,
1148
+			$icon_style,
1149
+			$help_text
1150
+		);
1151
+	}
1152
+
1153
+
1154
+	/**
1155
+	 * _add_help_tabs
1156
+	 * Note child classes define their help tabs within the page_config array.
1157
+	 *
1158
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1159
+	 * @return void
1160
+	 * @throws DomainException
1161
+	 * @throws EE_Error
1162
+	 */
1163
+	protected function _add_help_tabs()
1164
+	{
1165
+		$tour_buttons = '';
1166
+		if (isset($this->_page_config[ $this->_req_action ])) {
1167
+			$config = $this->_page_config[ $this->_req_action ];
1168
+			// is there a help tour for the current route?  if there is let's setup the tour buttons
1169
+			if (isset($this->_help_tour[ $this->_req_action ])) {
1170
+				$tb = array();
1171
+				$tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1172
+				foreach ($this->_help_tour['tours'] as $tour) {
1173
+					// if this is the end tour then we don't need to setup a button
1174
+					if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1175
+						continue;
1176
+					}
1177
+					$tb[] = '<button id="trigger-tour-'
1178
+							. $tour->get_slug()
1179
+							. '" class="button-primary trigger-ee-help-tour">'
1180
+							. $tour->get_label()
1181
+							. '</button>';
1182
+				}
1183
+				$tour_buttons .= implode('<br />', $tb);
1184
+				$tour_buttons .= '</div></div>';
1185
+			}
1186
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1187
+			if (is_array($config) && isset($config['help_sidebar'])) {
1188
+				// check that the callback given is valid
1189
+				if (! method_exists($this, $config['help_sidebar'])) {
1190
+					throw new EE_Error(
1191
+						sprintf(
1192
+							esc_html__(
1193
+								'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1194
+								'event_espresso'
1195
+							),
1196
+							$config['help_sidebar'],
1197
+							get_class($this)
1198
+						)
1199
+					);
1200
+				}
1201
+				$content = apply_filters(
1202
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1203
+					$this->{$config['help_sidebar']}()
1204
+				);
1205
+				$content .= $tour_buttons; // add help tour buttons.
1206
+				// do we have any help tours setup?  Cause if we do we want to add the buttons
1207
+				$this->_current_screen->set_help_sidebar($content);
1208
+			}
1209
+			// if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar.
1210
+			if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1211
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1212
+			}
1213
+			// handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1214
+			if (! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1215
+				$_ht['id'] = $this->page_slug;
1216
+				$_ht['title'] = esc_html__('Help Tours', 'event_espresso');
1217
+				$_ht['content'] = '<p>'
1218
+								  . esc_html__(
1219
+									  'The buttons to the right allow you to start/restart any help tours available for this page',
1220
+									  'event_espresso'
1221
+								  ) . '</p>';
1222
+				$this->_current_screen->add_help_tab($_ht);
1223
+			}
1224
+			if (! isset($config['help_tabs'])) {
1225
+				return;
1226
+			} //no help tabs for this route
1227
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1228
+				// we're here so there ARE help tabs!
1229
+				// make sure we've got what we need
1230
+				if (! isset($cfg['title'])) {
1231
+					throw new EE_Error(
1232
+						esc_html__(
1233
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1234
+							'event_espresso'
1235
+						)
1236
+					);
1237
+				}
1238
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1239
+					throw new EE_Error(
1240
+						esc_html__(
1241
+							'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1242
+							'event_espresso'
1243
+						)
1244
+					);
1245
+				}
1246
+				// first priority goes to content.
1247
+				if (! empty($cfg['content'])) {
1248
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1249
+					// second priority goes to filename
1250
+				} elseif (! empty($cfg['filename'])) {
1251
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1252
+					// it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1253
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1254
+															 . basename($this->_get_dir())
1255
+															 . '/help_tabs/'
1256
+															 . $cfg['filename']
1257
+															 . '.help_tab.php' : $file_path;
1258
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1259
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1260
+						EE_Error::add_error(
1261
+							sprintf(
1262
+								esc_html__(
1263
+									'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1264
+									'event_espresso'
1265
+								),
1266
+								$tab_id,
1267
+								key($config),
1268
+								$file_path
1269
+							),
1270
+							__FILE__,
1271
+							__FUNCTION__,
1272
+							__LINE__
1273
+						);
1274
+						return;
1275
+					}
1276
+					$template_args['admin_page_obj'] = $this;
1277
+					$content = EEH_Template::display_template(
1278
+						$file_path,
1279
+						$template_args,
1280
+						true
1281
+					);
1282
+				} else {
1283
+					$content = '';
1284
+				}
1285
+				// check if callback is valid
1286
+				if (empty($content) && (
1287
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1288
+					)
1289
+				) {
1290
+					EE_Error::add_error(
1291
+						sprintf(
1292
+							esc_html__(
1293
+								'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1294
+								'event_espresso'
1295
+							),
1296
+							$cfg['title']
1297
+						),
1298
+						__FILE__,
1299
+						__FUNCTION__,
1300
+						__LINE__
1301
+					);
1302
+					return;
1303
+				}
1304
+				// setup config array for help tab method
1305
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1306
+				$_ht = array(
1307
+					'id'       => $id,
1308
+					'title'    => $cfg['title'],
1309
+					'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1310
+					'content'  => $content,
1311
+				);
1312
+				$this->_current_screen->add_help_tab($_ht);
1313
+			}
1314
+		}
1315
+	}
1316
+
1317
+
1318
+	/**
1319
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1320
+	 * an array with properties for setting up usage of the joyride plugin
1321
+	 *
1322
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1323
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1324
+	 *         _set_page_config() comments
1325
+	 * @return void
1326
+	 * @throws EE_Error
1327
+	 * @throws InvalidArgumentException
1328
+	 * @throws InvalidDataTypeException
1329
+	 * @throws InvalidInterfaceException
1330
+	 */
1331
+	protected function _add_help_tour()
1332
+	{
1333
+		$tours = array();
1334
+		$this->_help_tour = array();
1335
+		// exit early if help tours are turned off globally
1336
+		if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1337
+			|| ! EE_Registry::instance()->CFG->admin->help_tour_activation
1338
+		) {
1339
+			return;
1340
+		}
1341
+		// loop through _page_config to find any help_tour defined
1342
+		foreach ($this->_page_config as $route => $config) {
1343
+			// we're only going to set things up for this route
1344
+			if ($route !== $this->_req_action) {
1345
+				continue;
1346
+			}
1347
+			if (isset($config['help_tour'])) {
1348
+				foreach ($config['help_tour'] as $tour) {
1349
+					$file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1350
+					// let's see if we can get that file...
1351
+					// if not its possible this is a decaf route not set in caffeinated
1352
+					// so lets try and get the caffeinated equivalent
1353
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1354
+															 . basename($this->_get_dir())
1355
+															 . '/help_tours/'
1356
+															 . $tour
1357
+															 . '.class.php' : $file_path;
1358
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1359
+					if (! is_readable($file_path)) {
1360
+						EE_Error::add_error(
1361
+							sprintf(
1362
+								esc_html__(
1363
+									'The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling',
1364
+									'event_espresso'
1365
+								),
1366
+								$file_path,
1367
+								$tour
1368
+							),
1369
+							__FILE__,
1370
+							__FUNCTION__,
1371
+							__LINE__
1372
+						);
1373
+						return;
1374
+					}
1375
+					require_once $file_path;
1376
+					if (! class_exists($tour)) {
1377
+						$error_msg[] = sprintf(
1378
+							esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1379
+							$tour
1380
+						);
1381
+						$error_msg[] = $error_msg[0] . "\r\n"
1382
+									   . sprintf(
1383
+										   esc_html__(
1384
+											   'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1385
+											   'event_espresso'
1386
+										   ),
1387
+										   $tour,
1388
+										   '<br />',
1389
+										   $tour,
1390
+										   $this->_req_action,
1391
+										   get_class($this)
1392
+									   );
1393
+						throw new EE_Error(implode('||', $error_msg));
1394
+					}
1395
+					$tour_obj = new $tour($this->_is_caf);
1396
+					$tours[] = $tour_obj;
1397
+					$this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1398
+				}
1399
+				// let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1400
+				$end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1401
+				$tours[] = $end_stop_tour;
1402
+				$this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1403
+			}
1404
+		}
1405
+		if (! empty($tours)) {
1406
+			$this->_help_tour['tours'] = $tours;
1407
+		}
1408
+		// that's it!  Now that the $_help_tours property is set (or not)
1409
+		// the scripts and html should be taken care of automatically.
1410
+	}
1411
+
1412
+
1413
+	/**
1414
+	 * This simply sets up any qtips that have been defined in the page config
1415
+	 *
1416
+	 * @return void
1417
+	 */
1418
+	protected function _add_qtips()
1419
+	{
1420
+		if (isset($this->_route_config['qtips'])) {
1421
+			$qtips = (array) $this->_route_config['qtips'];
1422
+			// load qtip loader
1423
+			$path = array(
1424
+				$this->_get_dir() . '/qtips/',
1425
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1426
+			);
1427
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1428
+		}
1429
+	}
1430
+
1431
+
1432
+	/**
1433
+	 * _set_nav_tabs
1434
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1435
+	 * wish to add additional tabs or modify accordingly.
1436
+	 *
1437
+	 * @return void
1438
+	 * @throws InvalidArgumentException
1439
+	 * @throws InvalidInterfaceException
1440
+	 * @throws InvalidDataTypeException
1441
+	 */
1442
+	protected function _set_nav_tabs()
1443
+	{
1444
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1445
+		$i = 0;
1446
+		foreach ($this->_page_config as $slug => $config) {
1447
+			if (! is_array($config)
1448
+				|| (
1449
+					is_array($config)
1450
+					&& (
1451
+						(isset($config['nav']) && ! $config['nav'])
1452
+						|| ! isset($config['nav'])
1453
+					)
1454
+				)
1455
+			) {
1456
+				continue;
1457
+			}
1458
+			// no nav tab for this config
1459
+			// check for persistent flag
1460
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1461
+				// nav tab is only to appear when route requested.
1462
+				continue;
1463
+			}
1464
+			if (! $this->check_user_access($slug, true)) {
1465
+				// no nav tab because current user does not have access.
1466
+				continue;
1467
+			}
1468
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1469
+			$this->_nav_tabs[ $slug ] = array(
1470
+				'url'       => isset($config['nav']['url'])
1471
+					? $config['nav']['url']
1472
+					: self::add_query_args_and_nonce(
1473
+						array('action' => $slug),
1474
+						$this->_admin_base_url
1475
+					),
1476
+				'link_text' => isset($config['nav']['label'])
1477
+					? $config['nav']['label']
1478
+					: ucwords(
1479
+						str_replace('_', ' ', $slug)
1480
+					),
1481
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1482
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1483
+			);
1484
+			$i++;
1485
+		}
1486
+		// if $this->_nav_tabs is empty then lets set the default
1487
+		if (empty($this->_nav_tabs)) {
1488
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = array(
1489
+				'url'       => $this->_admin_base_url,
1490
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1491
+				'css_class' => 'nav-tab-active',
1492
+				'order'     => 10,
1493
+			);
1494
+		}
1495
+		// now let's sort the tabs according to order
1496
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1497
+	}
1498
+
1499
+
1500
+	/**
1501
+	 * _set_current_labels
1502
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1503
+	 * property array
1504
+	 *
1505
+	 * @return void
1506
+	 */
1507
+	private function _set_current_labels()
1508
+	{
1509
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1510
+			foreach ($this->_route_config['labels'] as $label => $text) {
1511
+				if (is_array($text)) {
1512
+					foreach ($text as $sublabel => $subtext) {
1513
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1514
+					}
1515
+				} else {
1516
+					$this->_labels[ $label ] = $text;
1517
+				}
1518
+			}
1519
+		}
1520
+	}
1521
+
1522
+
1523
+	/**
1524
+	 *        verifies user access for this admin page
1525
+	 *
1526
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1527
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1528
+	 *                               return false if verify fail.
1529
+	 * @return bool
1530
+	 * @throws InvalidArgumentException
1531
+	 * @throws InvalidDataTypeException
1532
+	 * @throws InvalidInterfaceException
1533
+	 */
1534
+	public function check_user_access($route_to_check = '', $verify_only = false)
1535
+	{
1536
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1537
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1538
+		$capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1539
+					  && is_array(
1540
+						  $this->_page_routes[ $route_to_check ]
1541
+					  )
1542
+					  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1543
+			? $this->_page_routes[ $route_to_check ]['capability'] : null;
1544
+		if (empty($capability) && empty($route_to_check)) {
1545
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1546
+				: $this->_route['capability'];
1547
+		} else {
1548
+			$capability = empty($capability) ? 'manage_options' : $capability;
1549
+		}
1550
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1551
+		if (! defined('DOING_AJAX')
1552
+			&& (
1553
+				! function_exists('is_admin')
1554
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1555
+					$capability,
1556
+					$this->page_slug
1557
+					. '_'
1558
+					. $route_to_check,
1559
+					$id
1560
+				)
1561
+			)
1562
+		) {
1563
+			if ($verify_only) {
1564
+				return false;
1565
+			}
1566
+			if (is_user_logged_in()) {
1567
+				wp_die(__('You do not have access to this route.', 'event_espresso'));
1568
+			} else {
1569
+				return false;
1570
+			}
1571
+		}
1572
+		return true;
1573
+	}
1574
+
1575
+
1576
+	/**
1577
+	 * admin_init_global
1578
+	 * This runs all the code that we want executed within the WP admin_init hook.
1579
+	 * This method executes for ALL EE Admin pages.
1580
+	 *
1581
+	 * @return void
1582
+	 */
1583
+	public function admin_init_global()
1584
+	{
1585
+	}
1586
+
1587
+
1588
+	/**
1589
+	 * wp_loaded_global
1590
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1591
+	 * EE_Admin page and will execute on every EE Admin Page load
1592
+	 *
1593
+	 * @return void
1594
+	 */
1595
+	public function wp_loaded()
1596
+	{
1597
+	}
1598
+
1599
+
1600
+	/**
1601
+	 * admin_notices
1602
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1603
+	 * ALL EE_Admin pages.
1604
+	 *
1605
+	 * @return void
1606
+	 */
1607
+	public function admin_notices_global()
1608
+	{
1609
+		$this->_display_no_javascript_warning();
1610
+		$this->_display_espresso_notices();
1611
+	}
1612
+
1613
+
1614
+	public function network_admin_notices_global()
1615
+	{
1616
+		$this->_display_no_javascript_warning();
1617
+		$this->_display_espresso_notices();
1618
+	}
1619
+
1620
+
1621
+	/**
1622
+	 * admin_footer_scripts_global
1623
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1624
+	 * will apply on ALL EE_Admin pages.
1625
+	 *
1626
+	 * @return void
1627
+	 */
1628
+	public function admin_footer_scripts_global()
1629
+	{
1630
+		$this->_add_admin_page_ajax_loading_img();
1631
+		$this->_add_admin_page_overlay();
1632
+		// if metaboxes are present we need to add the nonce field
1633
+		if (isset($this->_route_config['metaboxes'])
1634
+			|| isset($this->_route_config['list_table'])
1635
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1636
+		) {
1637
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1638
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1639
+		}
1640
+	}
1641
+
1642
+
1643
+	/**
1644
+	 * admin_footer_global
1645
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1646
+	 * ALL EE_Admin Pages.
1647
+	 *
1648
+	 * @return void
1649
+	 * @throws EE_Error
1650
+	 */
1651
+	public function admin_footer_global()
1652
+	{
1653
+		// dialog container for dialog helper
1654
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1655
+		$d_cont .= '<div class="ee-notices"></div>';
1656
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1657
+		$d_cont .= '</div>';
1658
+		echo $d_cont;
1659
+		// help tour stuff?
1660
+		if (isset($this->_help_tour[ $this->_req_action ])) {
1661
+			echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1662
+		}
1663
+		// current set timezone for timezone js
1664
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1665
+	}
1666
+
1667
+
1668
+	/**
1669
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1670
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1671
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1672
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1673
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1674
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1675
+	 * for the
1676
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1677
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1678
+	 *    'help_trigger_id' => array(
1679
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1680
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1681
+	 *    )
1682
+	 * );
1683
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1684
+	 *
1685
+	 * @param array $help_array
1686
+	 * @param bool  $display
1687
+	 * @return string content
1688
+	 * @throws DomainException
1689
+	 * @throws EE_Error
1690
+	 */
1691
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1692
+	{
1693
+		$content = '';
1694
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1695
+		// loop through the array and setup content
1696
+		foreach ($help_array as $trigger => $help) {
1697
+			// make sure the array is setup properly
1698
+			if (! isset($help['title']) || ! isset($help['content'])) {
1699
+				throw new EE_Error(
1700
+					esc_html__(
1701
+						'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1702
+						'event_espresso'
1703
+					)
1704
+				);
1705
+			}
1706
+			// we're good so let'd setup the template vars and then assign parsed template content to our content.
1707
+			$template_args = array(
1708
+				'help_popup_id'      => $trigger,
1709
+				'help_popup_title'   => $help['title'],
1710
+				'help_popup_content' => $help['content'],
1711
+			);
1712
+			$content .= EEH_Template::display_template(
1713
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1714
+				$template_args,
1715
+				true
1716
+			);
1717
+		}
1718
+		if ($display) {
1719
+			echo $content;
1720
+			return '';
1721
+		}
1722
+		return $content;
1723
+	}
1724
+
1725
+
1726
+	/**
1727
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1728
+	 *
1729
+	 * @return array properly formatted array for help popup content
1730
+	 * @throws EE_Error
1731
+	 */
1732
+	private function _get_help_content()
1733
+	{
1734
+		// what is the method we're looking for?
1735
+		$method_name = '_help_popup_content_' . $this->_req_action;
1736
+		// if method doesn't exist let's get out.
1737
+		if (! method_exists($this, $method_name)) {
1738
+			return array();
1739
+		}
1740
+		// k we're good to go let's retrieve the help array
1741
+		$help_array = call_user_func(array($this, $method_name));
1742
+		// make sure we've got an array!
1743
+		if (! is_array($help_array)) {
1744
+			throw new EE_Error(
1745
+				esc_html__(
1746
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1747
+					'event_espresso'
1748
+				)
1749
+			);
1750
+		}
1751
+		return $help_array;
1752
+	}
1753
+
1754
+
1755
+	/**
1756
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1757
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1758
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1759
+	 *
1760
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1761
+	 * @param boolean $display    if false then we return the trigger string
1762
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1763
+	 * @return string
1764
+	 * @throws DomainException
1765
+	 * @throws EE_Error
1766
+	 */
1767
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1768
+	{
1769
+		if (defined('DOING_AJAX')) {
1770
+			return '';
1771
+		}
1772
+		// let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1773
+		$help_array = $this->_get_help_content();
1774
+		$help_content = '';
1775
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1776
+			$help_array[ $trigger_id ] = array(
1777
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1778
+				'content' => esc_html__(
1779
+					'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1780
+					'event_espresso'
1781
+				),
1782
+			);
1783
+			$help_content = $this->_set_help_popup_content($help_array, false);
1784
+		}
1785
+		// let's setup the trigger
1786
+		$content = '<a class="ee-dialog" href="?height='
1787
+				   . $dimensions[0]
1788
+				   . '&width='
1789
+				   . $dimensions[1]
1790
+				   . '&inlineId='
1791
+				   . $trigger_id
1792
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1793
+		$content .= $help_content;
1794
+		if ($display) {
1795
+			echo $content;
1796
+			return '';
1797
+		}
1798
+		return $content;
1799
+	}
1800
+
1801
+
1802
+	/**
1803
+	 * _add_global_screen_options
1804
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1805
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1806
+	 *
1807
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1808
+	 *         see also WP_Screen object documents...
1809
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1810
+	 * @abstract
1811
+	 * @return void
1812
+	 */
1813
+	private function _add_global_screen_options()
1814
+	{
1815
+	}
1816
+
1817
+
1818
+	/**
1819
+	 * _add_global_feature_pointers
1820
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1821
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1822
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1823
+	 *
1824
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1825
+	 *         extended) also see:
1826
+	 * @link   http://eamann.com/tech/wordpress-portland/
1827
+	 * @abstract
1828
+	 * @return void
1829
+	 */
1830
+	private function _add_global_feature_pointers()
1831
+	{
1832
+	}
1833
+
1834
+
1835
+	/**
1836
+	 * load_global_scripts_styles
1837
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1838
+	 *
1839
+	 * @return void
1840
+	 * @throws EE_Error
1841
+	 */
1842
+	public function load_global_scripts_styles()
1843
+	{
1844
+		/** STYLES **/
1845
+		// add debugging styles
1846
+		if (WP_DEBUG) {
1847
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1848
+		}
1849
+		// register all styles
1850
+		wp_register_style(
1851
+			'espresso-ui-theme',
1852
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1853
+			array(),
1854
+			EVENT_ESPRESSO_VERSION
1855
+		);
1856
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1857
+		// helpers styles
1858
+		wp_register_style(
1859
+			'ee-text-links',
1860
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1861
+			array(),
1862
+			EVENT_ESPRESSO_VERSION
1863
+		);
1864
+		/** SCRIPTS **/
1865
+		// register all scripts
1866
+		wp_register_script(
1867
+			'ee-dialog',
1868
+			EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1869
+			array('jquery', 'jquery-ui-draggable'),
1870
+			EVENT_ESPRESSO_VERSION,
1871
+			true
1872
+		);
1873
+		wp_register_script(
1874
+			'ee_admin_js',
1875
+			EE_ADMIN_URL . 'assets/ee-admin-page.js',
1876
+			array('espresso_core', 'ee-parse-uri', 'ee-dialog'),
1877
+			EVENT_ESPRESSO_VERSION,
1878
+			true
1879
+		);
1880
+		wp_register_script(
1881
+			'jquery-ui-timepicker-addon',
1882
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1883
+			array('jquery-ui-datepicker', 'jquery-ui-slider'),
1884
+			EVENT_ESPRESSO_VERSION,
1885
+			true
1886
+		);
1887
+		add_filter('FHEE_load_joyride', '__return_true');
1888
+		// script for sorting tables
1889
+		wp_register_script(
1890
+			'espresso_ajax_table_sorting',
1891
+			EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1892
+			array('ee_admin_js', 'jquery-ui-sortable'),
1893
+			EVENT_ESPRESSO_VERSION,
1894
+			true
1895
+		);
1896
+		// script for parsing uri's
1897
+		wp_register_script(
1898
+			'ee-parse-uri',
1899
+			EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1900
+			array(),
1901
+			EVENT_ESPRESSO_VERSION,
1902
+			true
1903
+		);
1904
+		// and parsing associative serialized form elements
1905
+		wp_register_script(
1906
+			'ee-serialize-full-array',
1907
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1908
+			array('jquery'),
1909
+			EVENT_ESPRESSO_VERSION,
1910
+			true
1911
+		);
1912
+		// helpers scripts
1913
+		wp_register_script(
1914
+			'ee-text-links',
1915
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1916
+			array('jquery'),
1917
+			EVENT_ESPRESSO_VERSION,
1918
+			true
1919
+		);
1920
+		wp_register_script(
1921
+			'ee-moment-core',
1922
+			EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1923
+			array(),
1924
+			EVENT_ESPRESSO_VERSION,
1925
+			true
1926
+		);
1927
+		wp_register_script(
1928
+			'ee-moment',
1929
+			EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1930
+			array('ee-moment-core'),
1931
+			EVENT_ESPRESSO_VERSION,
1932
+			true
1933
+		);
1934
+		wp_register_script(
1935
+			'ee-datepicker',
1936
+			EE_ADMIN_URL . 'assets/ee-datepicker.js',
1937
+			array('jquery-ui-timepicker-addon', 'ee-moment'),
1938
+			EVENT_ESPRESSO_VERSION,
1939
+			true
1940
+		);
1941
+		// google charts
1942
+		wp_register_script(
1943
+			'google-charts',
1944
+			'https://www.gstatic.com/charts/loader.js',
1945
+			array(),
1946
+			EVENT_ESPRESSO_VERSION,
1947
+			false
1948
+		);
1949
+		// ENQUEUE ALL BASICS BY DEFAULT
1950
+		wp_enqueue_style('ee-admin-css');
1951
+		wp_enqueue_script('ee_admin_js');
1952
+		wp_enqueue_script('ee-accounting');
1953
+		wp_enqueue_script('jquery-validate');
1954
+		// taking care of metaboxes
1955
+		if (empty($this->_cpt_route)
1956
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1957
+		) {
1958
+			wp_enqueue_script('dashboard');
1959
+		}
1960
+		// LOCALIZED DATA
1961
+		// localize script for ajax lazy loading
1962
+		$lazy_loader_container_ids = apply_filters(
1963
+			'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1964
+			array('espresso_news_post_box_content')
1965
+		);
1966
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1967
+		/**
1968
+		 * help tour stuff
1969
+		 */
1970
+		if (! empty($this->_help_tour)) {
1971
+			// register the js for kicking things off
1972
+			wp_enqueue_script(
1973
+				'ee-help-tour',
1974
+				EE_ADMIN_URL . 'assets/ee-help-tour.js',
1975
+				array('jquery-joyride'),
1976
+				EVENT_ESPRESSO_VERSION,
1977
+				true
1978
+			);
1979
+			$tours = array();
1980
+			// setup tours for the js tour object
1981
+			foreach ($this->_help_tour['tours'] as $tour) {
1982
+				if ($tour instanceof EE_Help_Tour) {
1983
+					$tours[] = array(
1984
+						'id'      => $tour->get_slug(),
1985
+						'options' => $tour->get_options(),
1986
+					);
1987
+				}
1988
+			}
1989
+			wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1990
+			// admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1991
+		}
1992
+	}
1993
+
1994
+
1995
+	/**
1996
+	 *        admin_footer_scripts_eei18n_js_strings
1997
+	 *
1998
+	 * @return        void
1999
+	 */
2000
+	public function admin_footer_scripts_eei18n_js_strings()
2001
+	{
2002
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
2003
+		EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
2004
+			__(
2005
+				'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
2006
+				'event_espresso'
2007
+			)
2008
+		);
2009
+		EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso'));
2010
+		EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso'));
2011
+		EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso'));
2012
+		EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso'));
2013
+		EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso'));
2014
+		EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso'));
2015
+		EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso'));
2016
+		EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso'));
2017
+		EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso'));
2018
+		EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso'));
2019
+		EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso'));
2020
+		EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso'));
2021
+		EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso'));
2022
+		EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso'));
2023
+		EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso'));
2024
+		EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso'));
2025
+		EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso'));
2026
+		EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso'));
2027
+		EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso'));
2028
+		EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso'));
2029
+		EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso'));
2030
+		EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso'));
2031
+		EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso'));
2032
+		EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso'));
2033
+		EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso'));
2034
+		EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso'));
2035
+		EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
2036
+		EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
2037
+		EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso'));
2038
+		EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso'));
2039
+		EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso'));
2040
+		EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso'));
2041
+		EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso'));
2042
+		EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso'));
2043
+		EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso'));
2044
+		EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso'));
2045
+		EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso'));
2046
+		EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso'));
2047
+	}
2048
+
2049
+
2050
+	/**
2051
+	 *        load enhanced xdebug styles for ppl with failing eyesight
2052
+	 *
2053
+	 * @return        void
2054
+	 */
2055
+	public function add_xdebug_style()
2056
+	{
2057
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2058
+	}
2059
+
2060
+
2061
+	/************************/
2062
+	/** LIST TABLE METHODS **/
2063
+	/************************/
2064
+	/**
2065
+	 * this sets up the list table if the current view requires it.
2066
+	 *
2067
+	 * @return void
2068
+	 * @throws EE_Error
2069
+	 */
2070
+	protected function _set_list_table()
2071
+	{
2072
+		// first is this a list_table view?
2073
+		if (! isset($this->_route_config['list_table'])) {
2074
+			return;
2075
+		} //not a list_table view so get out.
2076
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
2077
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
2078
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2079
+			// user error msg
2080
+			$error_msg = esc_html__(
2081
+				'An error occurred. The requested list table views could not be found.',
2082
+				'event_espresso'
2083
+			);
2084
+			// developer error msg
2085
+			$error_msg .= '||'
2086
+						  . sprintf(
2087
+							  esc_html__(
2088
+								  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2089
+								  'event_espresso'
2090
+							  ),
2091
+							  $this->_req_action,
2092
+							  $list_table_view
2093
+						  );
2094
+			throw new EE_Error($error_msg);
2095
+		}
2096
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2097
+		$this->_views = apply_filters(
2098
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2099
+			$this->_views
2100
+		);
2101
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2102
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2103
+		$this->_set_list_table_view();
2104
+		$this->_set_list_table_object();
2105
+	}
2106
+
2107
+
2108
+	/**
2109
+	 * set current view for List Table
2110
+	 *
2111
+	 * @return void
2112
+	 */
2113
+	protected function _set_list_table_view()
2114
+	{
2115
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2116
+		// looking at active items or dumpster diving ?
2117
+		if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2118
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2119
+		} else {
2120
+			$this->_view = sanitize_key($this->_req_data['status']);
2121
+		}
2122
+	}
2123
+
2124
+
2125
+	/**
2126
+	 * _set_list_table_object
2127
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2128
+	 *
2129
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2130
+	 * @throws \InvalidArgumentException
2131
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2132
+	 * @throws EE_Error
2133
+	 * @throws InvalidInterfaceException
2134
+	 */
2135
+	protected function _set_list_table_object()
2136
+	{
2137
+		if (isset($this->_route_config['list_table'])) {
2138
+			if (! class_exists($this->_route_config['list_table'])) {
2139
+				throw new EE_Error(
2140
+					sprintf(
2141
+						esc_html__(
2142
+							'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2143
+							'event_espresso'
2144
+						),
2145
+						$this->_route_config['list_table'],
2146
+						get_class($this)
2147
+					)
2148
+				);
2149
+			}
2150
+			$this->_list_table_object = $this->loader->getShared(
2151
+				$this->_route_config['list_table'],
2152
+				array($this)
2153
+			);
2154
+		}
2155
+	}
2156
+
2157
+
2158
+	/**
2159
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2160
+	 *
2161
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2162
+	 *                                                    urls.  The array should be indexed by the view it is being
2163
+	 *                                                    added to.
2164
+	 * @return array
2165
+	 */
2166
+	public function get_list_table_view_RLs($extra_query_args = array())
2167
+	{
2168
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2169
+		if (empty($this->_views)) {
2170
+			$this->_views = array();
2171
+		}
2172
+		// cycle thru views
2173
+		foreach ($this->_views as $key => $view) {
2174
+			$query_args = array();
2175
+			// check for current view
2176
+			$this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : '';
2177
+			$query_args['action'] = $this->_req_action;
2178
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2179
+			$query_args['status'] = $view['slug'];
2180
+			// merge any other arguments sent in.
2181
+			if (isset($extra_query_args[ $view['slug'] ])) {
2182
+				$query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2183
+			}
2184
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2185
+		}
2186
+		return $this->_views;
2187
+	}
2188
+
2189
+
2190
+	/**
2191
+	 * _entries_per_page_dropdown
2192
+	 * generates a drop down box for selecting the number of visible rows in an admin page list table
2193
+	 *
2194
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2195
+	 *         WP does it.
2196
+	 * @param int $max_entries total number of rows in the table
2197
+	 * @return string
2198
+	 */
2199
+	protected function _entries_per_page_dropdown($max_entries = 0)
2200
+	{
2201
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2202
+		$values = array(10, 25, 50, 100);
2203
+		$per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2204
+		if ($max_entries) {
2205
+			$values[] = $max_entries;
2206
+			sort($values);
2207
+		}
2208
+		$entries_per_page_dropdown = '
2209 2209
 			<div id="entries-per-page-dv" class="alignleft actions">
2210 2210
 				<label class="hide-if-no-js">
2211 2211
 					Show
2212 2212
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2213
-        foreach ($values as $value) {
2214
-            if ($value < $max_entries) {
2215
-                $selected = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2216
-                $entries_per_page_dropdown .= '
2213
+		foreach ($values as $value) {
2214
+			if ($value < $max_entries) {
2215
+				$selected = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2216
+				$entries_per_page_dropdown .= '
2217 2217
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2218
-            }
2219
-        }
2220
-        $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2221
-        $entries_per_page_dropdown .= '
2218
+			}
2219
+		}
2220
+		$selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2221
+		$entries_per_page_dropdown .= '
2222 2222
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2223
-        $entries_per_page_dropdown .= '
2223
+		$entries_per_page_dropdown .= '
2224 2224
 					</select>
2225 2225
 					entries
2226 2226
 				</label>
2227 2227
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2228 2228
 			</div>
2229 2229
 		';
2230
-        return $entries_per_page_dropdown;
2231
-    }
2232
-
2233
-
2234
-    /**
2235
-     *        _set_search_attributes
2236
-     *
2237
-     * @return        void
2238
-     */
2239
-    public function _set_search_attributes()
2240
-    {
2241
-        $this->_template_args['search']['btn_label'] = sprintf(
2242
-            esc_html__('Search %s', 'event_espresso'),
2243
-            empty($this->_search_btn_label) ? $this->page_label
2244
-                : $this->_search_btn_label
2245
-        );
2246
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
2247
-    }
2248
-
2249
-
2250
-
2251
-    /*** END LIST TABLE METHODS **/
2252
-
2253
-
2254
-    /**
2255
-     * _add_registered_metaboxes
2256
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2257
-     *
2258
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2259
-     * @return void
2260
-     * @throws EE_Error
2261
-     */
2262
-    private function _add_registered_meta_boxes()
2263
-    {
2264
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2265
-        // we only add meta boxes if the page_route calls for it
2266
-        if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2267
-            && is_array(
2268
-                $this->_route_config['metaboxes']
2269
-            )
2270
-        ) {
2271
-            // this simply loops through the callbacks provided
2272
-            // and checks if there is a corresponding callback registered by the child
2273
-            // if there is then we go ahead and process the metabox loader.
2274
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2275
-                // first check for Closures
2276
-                if ($metabox_callback instanceof Closure) {
2277
-                    $result = $metabox_callback();
2278
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2279
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2280
-                } else {
2281
-                    $result = call_user_func(array($this, &$metabox_callback));
2282
-                }
2283
-                if ($result === false) {
2284
-                    // user error msg
2285
-                    $error_msg = esc_html__(
2286
-                        'An error occurred. The  requested metabox could not be found.',
2287
-                        'event_espresso'
2288
-                    );
2289
-                    // developer error msg
2290
-                    $error_msg .= '||'
2291
-                                  . sprintf(
2292
-                                      esc_html__(
2293
-                                          'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2294
-                                          'event_espresso'
2295
-                                      ),
2296
-                                      $metabox_callback
2297
-                                  );
2298
-                    throw new EE_Error($error_msg);
2299
-                }
2300
-            }
2301
-        }
2302
-    }
2303
-
2304
-
2305
-    /**
2306
-     * _add_screen_columns
2307
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2308
-     * the dynamic column template and we'll setup the column options for the page.
2309
-     *
2310
-     * @return void
2311
-     */
2312
-    private function _add_screen_columns()
2313
-    {
2314
-        if (is_array($this->_route_config)
2315
-            && isset($this->_route_config['columns'])
2316
-            && is_array($this->_route_config['columns'])
2317
-            && count($this->_route_config['columns']) === 2
2318
-        ) {
2319
-            add_screen_option(
2320
-                'layout_columns',
2321
-                array(
2322
-                    'max'     => (int) $this->_route_config['columns'][0],
2323
-                    'default' => (int) $this->_route_config['columns'][1],
2324
-                )
2325
-            );
2326
-            $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
2327
-            $screen_id = $this->_current_screen->id;
2328
-            $screen_columns = (int) get_user_option("screen_layout_{$screen_id}");
2329
-            $total_columns = ! empty($screen_columns)
2330
-                ? $screen_columns
2331
-                : $this->_route_config['columns'][1];
2332
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2333
-            $this->_template_args['current_page'] = $this->_wp_page_slug;
2334
-            $this->_template_args['screen'] = $this->_current_screen;
2335
-            $this->_column_template_path = EE_ADMIN_TEMPLATE
2336
-                                           . 'admin_details_metabox_column_wrapper.template.php';
2337
-            // finally if we don't have has_metaboxes set in the route config
2338
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2339
-            $this->_route_config['has_metaboxes'] = true;
2340
-        }
2341
-    }
2342
-
2343
-
2344
-
2345
-    /** GLOBALLY AVAILABLE METABOXES **/
2346
-
2347
-
2348
-    /**
2349
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2350
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2351
-     * these get loaded on.
2352
-     */
2353
-    private function _espresso_news_post_box()
2354
-    {
2355
-        $news_box_title = apply_filters(
2356
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2357
-            esc_html__('New @ Event Espresso', 'event_espresso')
2358
-        );
2359
-        add_meta_box(
2360
-            'espresso_news_post_box',
2361
-            $news_box_title,
2362
-            array(
2363
-                $this,
2364
-                'espresso_news_post_box',
2365
-            ),
2366
-            $this->_wp_page_slug,
2367
-            'side'
2368
-        );
2369
-    }
2370
-
2371
-
2372
-    /**
2373
-     * Code for setting up espresso ratings request metabox.
2374
-     */
2375
-    protected function _espresso_ratings_request()
2376
-    {
2377
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2378
-            return;
2379
-        }
2380
-        $ratings_box_title = apply_filters(
2381
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2382
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2383
-        );
2384
-        add_meta_box(
2385
-            'espresso_ratings_request',
2386
-            $ratings_box_title,
2387
-            array(
2388
-                $this,
2389
-                'espresso_ratings_request',
2390
-            ),
2391
-            $this->_wp_page_slug,
2392
-            'side'
2393
-        );
2394
-    }
2395
-
2396
-
2397
-    /**
2398
-     * Code for setting up espresso ratings request metabox content.
2399
-     *
2400
-     * @throws DomainException
2401
-     */
2402
-    public function espresso_ratings_request()
2403
-    {
2404
-        EEH_Template::display_template(
2405
-            EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2406
-            array()
2407
-        );
2408
-    }
2409
-
2410
-
2411
-    public static function cached_rss_display($rss_id, $url)
2412
-    {
2413
-        $loading = '<p class="widget-loading hide-if-no-js">'
2414
-                   . __('Loading&#8230;', 'event_espresso')
2415
-                   . '</p><p class="hide-if-js">'
2416
-                   . esc_html__('This widget requires JavaScript.', 'event_espresso')
2417
-                   . '</p>';
2418
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
2419
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2420
-        $post = '</div>' . "\n";
2421
-        $cache_key = 'ee_rss_' . md5($rss_id);
2422
-        $output = get_transient($cache_key);
2423
-        if ($output !== false) {
2424
-            echo $pre . $output . $post;
2425
-            return true;
2426
-        }
2427
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2428
-            echo $pre . $loading . $post;
2429
-            return false;
2430
-        }
2431
-        ob_start();
2432
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2433
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2434
-        return true;
2435
-    }
2436
-
2437
-
2438
-    public function espresso_news_post_box()
2439
-    {
2440
-        ?>
2230
+		return $entries_per_page_dropdown;
2231
+	}
2232
+
2233
+
2234
+	/**
2235
+	 *        _set_search_attributes
2236
+	 *
2237
+	 * @return        void
2238
+	 */
2239
+	public function _set_search_attributes()
2240
+	{
2241
+		$this->_template_args['search']['btn_label'] = sprintf(
2242
+			esc_html__('Search %s', 'event_espresso'),
2243
+			empty($this->_search_btn_label) ? $this->page_label
2244
+				: $this->_search_btn_label
2245
+		);
2246
+		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
2247
+	}
2248
+
2249
+
2250
+
2251
+	/*** END LIST TABLE METHODS **/
2252
+
2253
+
2254
+	/**
2255
+	 * _add_registered_metaboxes
2256
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2257
+	 *
2258
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2259
+	 * @return void
2260
+	 * @throws EE_Error
2261
+	 */
2262
+	private function _add_registered_meta_boxes()
2263
+	{
2264
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2265
+		// we only add meta boxes if the page_route calls for it
2266
+		if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2267
+			&& is_array(
2268
+				$this->_route_config['metaboxes']
2269
+			)
2270
+		) {
2271
+			// this simply loops through the callbacks provided
2272
+			// and checks if there is a corresponding callback registered by the child
2273
+			// if there is then we go ahead and process the metabox loader.
2274
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2275
+				// first check for Closures
2276
+				if ($metabox_callback instanceof Closure) {
2277
+					$result = $metabox_callback();
2278
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2279
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2280
+				} else {
2281
+					$result = call_user_func(array($this, &$metabox_callback));
2282
+				}
2283
+				if ($result === false) {
2284
+					// user error msg
2285
+					$error_msg = esc_html__(
2286
+						'An error occurred. The  requested metabox could not be found.',
2287
+						'event_espresso'
2288
+					);
2289
+					// developer error msg
2290
+					$error_msg .= '||'
2291
+								  . sprintf(
2292
+									  esc_html__(
2293
+										  'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2294
+										  'event_espresso'
2295
+									  ),
2296
+									  $metabox_callback
2297
+								  );
2298
+					throw new EE_Error($error_msg);
2299
+				}
2300
+			}
2301
+		}
2302
+	}
2303
+
2304
+
2305
+	/**
2306
+	 * _add_screen_columns
2307
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2308
+	 * the dynamic column template and we'll setup the column options for the page.
2309
+	 *
2310
+	 * @return void
2311
+	 */
2312
+	private function _add_screen_columns()
2313
+	{
2314
+		if (is_array($this->_route_config)
2315
+			&& isset($this->_route_config['columns'])
2316
+			&& is_array($this->_route_config['columns'])
2317
+			&& count($this->_route_config['columns']) === 2
2318
+		) {
2319
+			add_screen_option(
2320
+				'layout_columns',
2321
+				array(
2322
+					'max'     => (int) $this->_route_config['columns'][0],
2323
+					'default' => (int) $this->_route_config['columns'][1],
2324
+				)
2325
+			);
2326
+			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
2327
+			$screen_id = $this->_current_screen->id;
2328
+			$screen_columns = (int) get_user_option("screen_layout_{$screen_id}");
2329
+			$total_columns = ! empty($screen_columns)
2330
+				? $screen_columns
2331
+				: $this->_route_config['columns'][1];
2332
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2333
+			$this->_template_args['current_page'] = $this->_wp_page_slug;
2334
+			$this->_template_args['screen'] = $this->_current_screen;
2335
+			$this->_column_template_path = EE_ADMIN_TEMPLATE
2336
+										   . 'admin_details_metabox_column_wrapper.template.php';
2337
+			// finally if we don't have has_metaboxes set in the route config
2338
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2339
+			$this->_route_config['has_metaboxes'] = true;
2340
+		}
2341
+	}
2342
+
2343
+
2344
+
2345
+	/** GLOBALLY AVAILABLE METABOXES **/
2346
+
2347
+
2348
+	/**
2349
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2350
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2351
+	 * these get loaded on.
2352
+	 */
2353
+	private function _espresso_news_post_box()
2354
+	{
2355
+		$news_box_title = apply_filters(
2356
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2357
+			esc_html__('New @ Event Espresso', 'event_espresso')
2358
+		);
2359
+		add_meta_box(
2360
+			'espresso_news_post_box',
2361
+			$news_box_title,
2362
+			array(
2363
+				$this,
2364
+				'espresso_news_post_box',
2365
+			),
2366
+			$this->_wp_page_slug,
2367
+			'side'
2368
+		);
2369
+	}
2370
+
2371
+
2372
+	/**
2373
+	 * Code for setting up espresso ratings request metabox.
2374
+	 */
2375
+	protected function _espresso_ratings_request()
2376
+	{
2377
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2378
+			return;
2379
+		}
2380
+		$ratings_box_title = apply_filters(
2381
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2382
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2383
+		);
2384
+		add_meta_box(
2385
+			'espresso_ratings_request',
2386
+			$ratings_box_title,
2387
+			array(
2388
+				$this,
2389
+				'espresso_ratings_request',
2390
+			),
2391
+			$this->_wp_page_slug,
2392
+			'side'
2393
+		);
2394
+	}
2395
+
2396
+
2397
+	/**
2398
+	 * Code for setting up espresso ratings request metabox content.
2399
+	 *
2400
+	 * @throws DomainException
2401
+	 */
2402
+	public function espresso_ratings_request()
2403
+	{
2404
+		EEH_Template::display_template(
2405
+			EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2406
+			array()
2407
+		);
2408
+	}
2409
+
2410
+
2411
+	public static function cached_rss_display($rss_id, $url)
2412
+	{
2413
+		$loading = '<p class="widget-loading hide-if-no-js">'
2414
+				   . __('Loading&#8230;', 'event_espresso')
2415
+				   . '</p><p class="hide-if-js">'
2416
+				   . esc_html__('This widget requires JavaScript.', 'event_espresso')
2417
+				   . '</p>';
2418
+		$pre = '<div class="espresso-rss-display">' . "\n\t";
2419
+		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2420
+		$post = '</div>' . "\n";
2421
+		$cache_key = 'ee_rss_' . md5($rss_id);
2422
+		$output = get_transient($cache_key);
2423
+		if ($output !== false) {
2424
+			echo $pre . $output . $post;
2425
+			return true;
2426
+		}
2427
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2428
+			echo $pre . $loading . $post;
2429
+			return false;
2430
+		}
2431
+		ob_start();
2432
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2433
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2434
+		return true;
2435
+	}
2436
+
2437
+
2438
+	public function espresso_news_post_box()
2439
+	{
2440
+		?>
2441 2441
         <div class="padding">
2442 2442
             <div id="espresso_news_post_box_content" class="infolinks">
2443 2443
                 <?php
2444
-                // Get RSS Feed(s)
2445
-                self::cached_rss_display(
2446
-                    'espresso_news_post_box_content',
2447
-                    urlencode(
2448
-                        apply_filters(
2449
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2450
-                            'http://eventespresso.com/feed/'
2451
-                        )
2452
-                    )
2453
-                );
2454
-                ?>
2444
+				// Get RSS Feed(s)
2445
+				self::cached_rss_display(
2446
+					'espresso_news_post_box_content',
2447
+					urlencode(
2448
+						apply_filters(
2449
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2450
+							'http://eventespresso.com/feed/'
2451
+						)
2452
+					)
2453
+				);
2454
+				?>
2455 2455
             </div>
2456 2456
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2457 2457
         </div>
2458 2458
         <?php
2459
-    }
2460
-
2461
-
2462
-    private function _espresso_links_post_box()
2463
-    {
2464
-        // Hiding until we actually have content to put in here...
2465
-        // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2466
-    }
2467
-
2468
-
2469
-    public function espresso_links_post_box()
2470
-    {
2471
-        // Hiding until we actually have content to put in here...
2472
-        // EEH_Template::display_template(
2473
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2474
-        // );
2475
-    }
2476
-
2477
-
2478
-    protected function _espresso_sponsors_post_box()
2479
-    {
2480
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2481
-            add_meta_box(
2482
-                'espresso_sponsors_post_box',
2483
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2484
-                array($this, 'espresso_sponsors_post_box'),
2485
-                $this->_wp_page_slug,
2486
-                'side'
2487
-            );
2488
-        }
2489
-    }
2490
-
2491
-
2492
-    public function espresso_sponsors_post_box()
2493
-    {
2494
-        EEH_Template::display_template(
2495
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2496
-        );
2497
-    }
2498
-
2499
-
2500
-    private function _publish_post_box()
2501
-    {
2502
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2503
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2504
-        // then we'll use that for the metabox label.
2505
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2506
-        if (! empty($this->_labels['publishbox'])) {
2507
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2508
-                : $this->_labels['publishbox'];
2509
-        } else {
2510
-            $box_label = esc_html__('Publish', 'event_espresso');
2511
-        }
2512
-        $box_label = apply_filters(
2513
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2514
-            $box_label,
2515
-            $this->_req_action,
2516
-            $this
2517
-        );
2518
-        add_meta_box(
2519
-            $meta_box_ref,
2520
-            $box_label,
2521
-            array($this, 'editor_overview'),
2522
-            $this->_current_screen->id,
2523
-            'side',
2524
-            'high'
2525
-        );
2526
-    }
2527
-
2528
-
2529
-    public function editor_overview()
2530
-    {
2531
-        // if we have extra content set let's add it in if not make sure its empty
2532
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2533
-            ? $this->_template_args['publish_box_extra_content']
2534
-            : '';
2535
-        echo EEH_Template::display_template(
2536
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2537
-            $this->_template_args,
2538
-            true
2539
-        );
2540
-    }
2541
-
2542
-
2543
-    /** end of globally available metaboxes section **/
2544
-
2545
-
2546
-    /**
2547
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2548
-     * protected method.
2549
-     *
2550
-     * @see   $this->_set_publish_post_box_vars for param details
2551
-     * @since 4.6.0
2552
-     * @param string $name
2553
-     * @param int    $id
2554
-     * @param bool   $delete
2555
-     * @param string $save_close_redirect_URL
2556
-     * @param bool   $both_btns
2557
-     * @throws EE_Error
2558
-     * @throws InvalidArgumentException
2559
-     * @throws InvalidDataTypeException
2560
-     * @throws InvalidInterfaceException
2561
-     */
2562
-    public function set_publish_post_box_vars(
2563
-        $name = '',
2564
-        $id = 0,
2565
-        $delete = false,
2566
-        $save_close_redirect_URL = '',
2567
-        $both_btns = true
2568
-    ) {
2569
-        $this->_set_publish_post_box_vars(
2570
-            $name,
2571
-            $id,
2572
-            $delete,
2573
-            $save_close_redirect_URL,
2574
-            $both_btns
2575
-        );
2576
-    }
2577
-
2578
-
2579
-    /**
2580
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2581
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2582
-     * save, and save and close buttons to work properly, then you will want to include a
2583
-     * values for the name and id arguments.
2584
-     *
2585
-     * @todo  Add in validation for name/id arguments.
2586
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2587
-     * @param    int     $id                      id attached to the item published
2588
-     * @param    string  $delete                  page route callback for the delete action
2589
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2590
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2591
-     *                                            the Save button
2592
-     * @throws EE_Error
2593
-     * @throws InvalidArgumentException
2594
-     * @throws InvalidDataTypeException
2595
-     * @throws InvalidInterfaceException
2596
-     */
2597
-    protected function _set_publish_post_box_vars(
2598
-        $name = '',
2599
-        $id = 0,
2600
-        $delete = '',
2601
-        $save_close_redirect_URL = '',
2602
-        $both_btns = true
2603
-    ) {
2604
-        // if Save & Close, use a custom redirect URL or default to the main page?
2605
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2606
-            ? $save_close_redirect_URL
2607
-            : $this->_admin_base_url;
2608
-        // create the Save & Close and Save buttons
2609
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2610
-        // if we have extra content set let's add it in if not make sure its empty
2611
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2612
-            ? $this->_template_args['publish_box_extra_content']
2613
-            : '';
2614
-        if ($delete && ! empty($id)) {
2615
-            // make sure we have a default if just true is sent.
2616
-            $delete = ! empty($delete) ? $delete : 'delete';
2617
-            $delete_link_args = array($name => $id);
2618
-            $delete = $this->get_action_link_or_button(
2619
-                $delete,
2620
-                $delete,
2621
-                $delete_link_args,
2622
-                'submitdelete deletion',
2623
-                '',
2624
-                false
2625
-            );
2626
-        }
2627
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2628
-        if (! empty($name) && ! empty($id)) {
2629
-            $hidden_field_arr[ $name ] = array(
2630
-                'type'  => 'hidden',
2631
-                'value' => $id,
2632
-            );
2633
-            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2634
-        } else {
2635
-            $hf = '';
2636
-        }
2637
-        // add hidden field
2638
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2639
-            ? $hf[ $name ]['field']
2640
-            : $hf;
2641
-    }
2642
-
2643
-
2644
-    /**
2645
-     * displays an error message to ppl who have javascript disabled
2646
-     *
2647
-     * @return void
2648
-     */
2649
-    private function _display_no_javascript_warning()
2650
-    {
2651
-        ?>
2459
+	}
2460
+
2461
+
2462
+	private function _espresso_links_post_box()
2463
+	{
2464
+		// Hiding until we actually have content to put in here...
2465
+		// add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2466
+	}
2467
+
2468
+
2469
+	public function espresso_links_post_box()
2470
+	{
2471
+		// Hiding until we actually have content to put in here...
2472
+		// EEH_Template::display_template(
2473
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2474
+		// );
2475
+	}
2476
+
2477
+
2478
+	protected function _espresso_sponsors_post_box()
2479
+	{
2480
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2481
+			add_meta_box(
2482
+				'espresso_sponsors_post_box',
2483
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2484
+				array($this, 'espresso_sponsors_post_box'),
2485
+				$this->_wp_page_slug,
2486
+				'side'
2487
+			);
2488
+		}
2489
+	}
2490
+
2491
+
2492
+	public function espresso_sponsors_post_box()
2493
+	{
2494
+		EEH_Template::display_template(
2495
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2496
+		);
2497
+	}
2498
+
2499
+
2500
+	private function _publish_post_box()
2501
+	{
2502
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2503
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2504
+		// then we'll use that for the metabox label.
2505
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2506
+		if (! empty($this->_labels['publishbox'])) {
2507
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2508
+				: $this->_labels['publishbox'];
2509
+		} else {
2510
+			$box_label = esc_html__('Publish', 'event_espresso');
2511
+		}
2512
+		$box_label = apply_filters(
2513
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2514
+			$box_label,
2515
+			$this->_req_action,
2516
+			$this
2517
+		);
2518
+		add_meta_box(
2519
+			$meta_box_ref,
2520
+			$box_label,
2521
+			array($this, 'editor_overview'),
2522
+			$this->_current_screen->id,
2523
+			'side',
2524
+			'high'
2525
+		);
2526
+	}
2527
+
2528
+
2529
+	public function editor_overview()
2530
+	{
2531
+		// if we have extra content set let's add it in if not make sure its empty
2532
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2533
+			? $this->_template_args['publish_box_extra_content']
2534
+			: '';
2535
+		echo EEH_Template::display_template(
2536
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2537
+			$this->_template_args,
2538
+			true
2539
+		);
2540
+	}
2541
+
2542
+
2543
+	/** end of globally available metaboxes section **/
2544
+
2545
+
2546
+	/**
2547
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2548
+	 * protected method.
2549
+	 *
2550
+	 * @see   $this->_set_publish_post_box_vars for param details
2551
+	 * @since 4.6.0
2552
+	 * @param string $name
2553
+	 * @param int    $id
2554
+	 * @param bool   $delete
2555
+	 * @param string $save_close_redirect_URL
2556
+	 * @param bool   $both_btns
2557
+	 * @throws EE_Error
2558
+	 * @throws InvalidArgumentException
2559
+	 * @throws InvalidDataTypeException
2560
+	 * @throws InvalidInterfaceException
2561
+	 */
2562
+	public function set_publish_post_box_vars(
2563
+		$name = '',
2564
+		$id = 0,
2565
+		$delete = false,
2566
+		$save_close_redirect_URL = '',
2567
+		$both_btns = true
2568
+	) {
2569
+		$this->_set_publish_post_box_vars(
2570
+			$name,
2571
+			$id,
2572
+			$delete,
2573
+			$save_close_redirect_URL,
2574
+			$both_btns
2575
+		);
2576
+	}
2577
+
2578
+
2579
+	/**
2580
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2581
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2582
+	 * save, and save and close buttons to work properly, then you will want to include a
2583
+	 * values for the name and id arguments.
2584
+	 *
2585
+	 * @todo  Add in validation for name/id arguments.
2586
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2587
+	 * @param    int     $id                      id attached to the item published
2588
+	 * @param    string  $delete                  page route callback for the delete action
2589
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2590
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2591
+	 *                                            the Save button
2592
+	 * @throws EE_Error
2593
+	 * @throws InvalidArgumentException
2594
+	 * @throws InvalidDataTypeException
2595
+	 * @throws InvalidInterfaceException
2596
+	 */
2597
+	protected function _set_publish_post_box_vars(
2598
+		$name = '',
2599
+		$id = 0,
2600
+		$delete = '',
2601
+		$save_close_redirect_URL = '',
2602
+		$both_btns = true
2603
+	) {
2604
+		// if Save & Close, use a custom redirect URL or default to the main page?
2605
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2606
+			? $save_close_redirect_URL
2607
+			: $this->_admin_base_url;
2608
+		// create the Save & Close and Save buttons
2609
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2610
+		// if we have extra content set let's add it in if not make sure its empty
2611
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2612
+			? $this->_template_args['publish_box_extra_content']
2613
+			: '';
2614
+		if ($delete && ! empty($id)) {
2615
+			// make sure we have a default if just true is sent.
2616
+			$delete = ! empty($delete) ? $delete : 'delete';
2617
+			$delete_link_args = array($name => $id);
2618
+			$delete = $this->get_action_link_or_button(
2619
+				$delete,
2620
+				$delete,
2621
+				$delete_link_args,
2622
+				'submitdelete deletion',
2623
+				'',
2624
+				false
2625
+			);
2626
+		}
2627
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2628
+		if (! empty($name) && ! empty($id)) {
2629
+			$hidden_field_arr[ $name ] = array(
2630
+				'type'  => 'hidden',
2631
+				'value' => $id,
2632
+			);
2633
+			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2634
+		} else {
2635
+			$hf = '';
2636
+		}
2637
+		// add hidden field
2638
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2639
+			? $hf[ $name ]['field']
2640
+			: $hf;
2641
+	}
2642
+
2643
+
2644
+	/**
2645
+	 * displays an error message to ppl who have javascript disabled
2646
+	 *
2647
+	 * @return void
2648
+	 */
2649
+	private function _display_no_javascript_warning()
2650
+	{
2651
+		?>
2652 2652
         <noscript>
2653 2653
             <div id="no-js-message" class="error">
2654 2654
                 <p style="font-size:1.3em;">
2655 2655
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2656 2656
                     <?php esc_html_e(
2657
-                        'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2658
-                        'event_espresso'
2659
-                    ); ?>
2657
+						'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2658
+						'event_espresso'
2659
+					); ?>
2660 2660
                 </p>
2661 2661
             </div>
2662 2662
         </noscript>
2663 2663
         <?php
2664
-    }
2665
-
2666
-
2667
-    /**
2668
-     * displays espresso success and/or error notices
2669
-     *
2670
-     * @return void
2671
-     */
2672
-    private function _display_espresso_notices()
2673
-    {
2674
-        $notices = $this->_get_transient(true);
2675
-        echo stripslashes($notices);
2676
-    }
2677
-
2678
-
2679
-    /**
2680
-     * spinny things pacify the masses
2681
-     *
2682
-     * @return void
2683
-     */
2684
-    protected function _add_admin_page_ajax_loading_img()
2685
-    {
2686
-        ?>
2664
+	}
2665
+
2666
+
2667
+	/**
2668
+	 * displays espresso success and/or error notices
2669
+	 *
2670
+	 * @return void
2671
+	 */
2672
+	private function _display_espresso_notices()
2673
+	{
2674
+		$notices = $this->_get_transient(true);
2675
+		echo stripslashes($notices);
2676
+	}
2677
+
2678
+
2679
+	/**
2680
+	 * spinny things pacify the masses
2681
+	 *
2682
+	 * @return void
2683
+	 */
2684
+	protected function _add_admin_page_ajax_loading_img()
2685
+	{
2686
+		?>
2687 2687
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2688 2688
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2689
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2689
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2690 2690
         </div>
2691 2691
         <?php
2692
-    }
2692
+	}
2693 2693
 
2694 2694
 
2695
-    /**
2696
-     * add admin page overlay for modal boxes
2697
-     *
2698
-     * @return void
2699
-     */
2700
-    protected function _add_admin_page_overlay()
2701
-    {
2702
-        ?>
2695
+	/**
2696
+	 * add admin page overlay for modal boxes
2697
+	 *
2698
+	 * @return void
2699
+	 */
2700
+	protected function _add_admin_page_overlay()
2701
+	{
2702
+		?>
2703 2703
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2704 2704
         <?php
2705
-    }
2706
-
2707
-
2708
-    /**
2709
-     * facade for add_meta_box
2710
-     *
2711
-     * @param string  $action        where the metabox get's displayed
2712
-     * @param string  $title         Title of Metabox (output in metabox header)
2713
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2714
-     *                               instead of the one created in here.
2715
-     * @param array   $callback_args an array of args supplied for the metabox
2716
-     * @param string  $column        what metabox column
2717
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2718
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2719
-     *                               created but just set our own callback for wp's add_meta_box.
2720
-     * @throws \DomainException
2721
-     */
2722
-    public function _add_admin_page_meta_box(
2723
-        $action,
2724
-        $title,
2725
-        $callback,
2726
-        $callback_args,
2727
-        $column = 'normal',
2728
-        $priority = 'high',
2729
-        $create_func = true
2730
-    ) {
2731
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2732
-        // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2733
-        if (empty($callback_args) && $create_func) {
2734
-            $callback_args = array(
2735
-                'template_path' => $this->_template_path,
2736
-                'template_args' => $this->_template_args,
2737
-            );
2738
-        }
2739
-        // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2740
-        $call_back_func = $create_func
2741
-            ? function ($post, $metabox) {
2742
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2743
-                echo EEH_Template::display_template(
2744
-                    $metabox['args']['template_path'],
2745
-                    $metabox['args']['template_args'],
2746
-                    true
2747
-                );
2748
-            }
2749
-            : $callback;
2750
-        add_meta_box(
2751
-            str_replace('_', '-', $action) . '-mbox',
2752
-            $title,
2753
-            $call_back_func,
2754
-            $this->_wp_page_slug,
2755
-            $column,
2756
-            $priority,
2757
-            $callback_args
2758
-        );
2759
-    }
2760
-
2761
-
2762
-    /**
2763
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2764
-     *
2765
-     * @throws DomainException
2766
-     * @throws EE_Error
2767
-     */
2768
-    public function display_admin_page_with_metabox_columns()
2769
-    {
2770
-        $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2771
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2772
-            $this->_column_template_path,
2773
-            $this->_template_args,
2774
-            true
2775
-        );
2776
-        // the final wrapper
2777
-        $this->admin_page_wrapper();
2778
-    }
2779
-
2780
-
2781
-    /**
2782
-     * generates  HTML wrapper for an admin details page
2783
-     *
2784
-     * @return void
2785
-     * @throws EE_Error
2786
-     * @throws DomainException
2787
-     */
2788
-    public function display_admin_page_with_sidebar()
2789
-    {
2790
-        $this->_display_admin_page(true);
2791
-    }
2792
-
2793
-
2794
-    /**
2795
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2796
-     *
2797
-     * @return void
2798
-     * @throws EE_Error
2799
-     * @throws DomainException
2800
-     */
2801
-    public function display_admin_page_with_no_sidebar()
2802
-    {
2803
-        $this->_display_admin_page();
2804
-    }
2805
-
2806
-
2807
-    /**
2808
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2809
-     *
2810
-     * @return void
2811
-     * @throws EE_Error
2812
-     * @throws DomainException
2813
-     */
2814
-    public function display_about_admin_page()
2815
-    {
2816
-        $this->_display_admin_page(false, true);
2817
-    }
2818
-
2819
-
2820
-    /**
2821
-     * display_admin_page
2822
-     * contains the code for actually displaying an admin page
2823
-     *
2824
-     * @param  boolean $sidebar true with sidebar, false without
2825
-     * @param  boolean $about   use the about admin wrapper instead of the default.
2826
-     * @return void
2827
-     * @throws DomainException
2828
-     * @throws EE_Error
2829
-     */
2830
-    private function _display_admin_page($sidebar = false, $about = false)
2831
-    {
2832
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2833
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2834
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2835
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2836
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2837
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2838
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2839
-            ? 'poststuff'
2840
-            : 'espresso-default-admin';
2841
-        $template_path = $sidebar
2842
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2843
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2844
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2845
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2846
-        }
2847
-        $template_path = ! empty($this->_column_template_path)
2848
-            ? $this->_column_template_path : $template_path;
2849
-        $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content'])
2850
-            ? $this->_template_args['admin_page_content']
2851
-            : '';
2852
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2853
-            ? $this->_template_args['before_admin_page_content']
2854
-            : '';
2855
-        $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content'])
2856
-            ? $this->_template_args['after_admin_page_content']
2857
-            : '';
2858
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2859
-            $template_path,
2860
-            $this->_template_args,
2861
-            true
2862
-        );
2863
-        // the final template wrapper
2864
-        $this->admin_page_wrapper($about);
2865
-    }
2866
-
2867
-
2868
-    /**
2869
-     * This is used to display caf preview pages.
2870
-     *
2871
-     * @since 4.3.2
2872
-     * @param string $utm_campaign_source what is the key used for google analytics link
2873
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2874
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2875
-     * @return void
2876
-     * @throws DomainException
2877
-     * @throws EE_Error
2878
-     * @throws InvalidArgumentException
2879
-     * @throws InvalidDataTypeException
2880
-     * @throws InvalidInterfaceException
2881
-     */
2882
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2883
-    {
2884
-        // let's generate a default preview action button if there isn't one already present.
2885
-        $this->_labels['buttons']['buy_now'] = esc_html__(
2886
-            'Upgrade to Event Espresso 4 Right Now',
2887
-            'event_espresso'
2888
-        );
2889
-        $buy_now_url = add_query_arg(
2890
-            array(
2891
-                'ee_ver'       => 'ee4',
2892
-                'utm_source'   => 'ee4_plugin_admin',
2893
-                'utm_medium'   => 'link',
2894
-                'utm_campaign' => $utm_campaign_source,
2895
-                'utm_content'  => 'buy_now_button',
2896
-            ),
2897
-            'http://eventespresso.com/pricing/'
2898
-        );
2899
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2900
-            ? $this->get_action_link_or_button(
2901
-                '',
2902
-                'buy_now',
2903
-                array(),
2904
-                'button-primary button-large',
2905
-                $buy_now_url,
2906
-                true
2907
-            )
2908
-            : $this->_template_args['preview_action_button'];
2909
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2910
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2911
-            $this->_template_args,
2912
-            true
2913
-        );
2914
-        $this->_display_admin_page($display_sidebar);
2915
-    }
2916
-
2917
-
2918
-    /**
2919
-     * display_admin_list_table_page_with_sidebar
2920
-     * generates HTML wrapper for an admin_page with list_table
2921
-     *
2922
-     * @return void
2923
-     * @throws EE_Error
2924
-     * @throws DomainException
2925
-     */
2926
-    public function display_admin_list_table_page_with_sidebar()
2927
-    {
2928
-        $this->_display_admin_list_table_page(true);
2929
-    }
2930
-
2931
-
2932
-    /**
2933
-     * display_admin_list_table_page_with_no_sidebar
2934
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2935
-     *
2936
-     * @return void
2937
-     * @throws EE_Error
2938
-     * @throws DomainException
2939
-     */
2940
-    public function display_admin_list_table_page_with_no_sidebar()
2941
-    {
2942
-        $this->_display_admin_list_table_page();
2943
-    }
2944
-
2945
-
2946
-    /**
2947
-     * generates html wrapper for an admin_list_table page
2948
-     *
2949
-     * @param boolean $sidebar whether to display with sidebar or not.
2950
-     * @return void
2951
-     * @throws DomainException
2952
-     * @throws EE_Error
2953
-     */
2954
-    private function _display_admin_list_table_page($sidebar = false)
2955
-    {
2956
-        // setup search attributes
2957
-        $this->_set_search_attributes();
2958
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2959
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2960
-        $this->_template_args['table_url'] = defined('DOING_AJAX')
2961
-            ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2962
-            : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2963
-        $this->_template_args['list_table'] = $this->_list_table_object;
2964
-        $this->_template_args['current_route'] = $this->_req_action;
2965
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2966
-        $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2967
-        if (! empty($ajax_sorting_callback)) {
2968
-            $sortable_list_table_form_fields = wp_nonce_field(
2969
-                $ajax_sorting_callback . '_nonce',
2970
-                $ajax_sorting_callback . '_nonce',
2971
-                false,
2972
-                false
2973
-            );
2974
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2975
-                                                . $this->page_slug
2976
-                                                . '" />';
2977
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2978
-                                                . $ajax_sorting_callback
2979
-                                                . '" />';
2980
-        } else {
2981
-            $sortable_list_table_form_fields = '';
2982
-        }
2983
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2984
-        $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields'])
2985
-            ? $this->_template_args['list_table_hidden_fields']
2986
-            : '';
2987
-        $nonce_ref = $this->_req_action . '_nonce';
2988
-        $hidden_form_fields .= '<input type="hidden" name="'
2989
-                               . $nonce_ref
2990
-                               . '" value="'
2991
-                               . wp_create_nonce($nonce_ref)
2992
-                               . '">';
2993
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2994
-        // display message about search results?
2995
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2996
-            ? '<p class="ee-search-results">' . sprintf(
2997
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2998
-                trim($this->_req_data['s'], '%')
2999
-            ) . '</p>'
3000
-            : '';
3001
-        // filter before_list_table template arg
3002
-        $this->_template_args['before_list_table'] = apply_filters(
3003
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3004
-            $this->_template_args['before_list_table'],
3005
-            $this->page_slug,
3006
-            $this->_req_data,
3007
-            $this->_req_action
3008
-        );
3009
-        // convert to array and filter again
3010
-        // arrays are easier to inject new items in a specific location,
3011
-        // but would not be backwards compatible, so we have to add a new filter
3012
-        $this->_template_args['before_list_table'] = implode(
3013
-            " \n",
3014
-            (array) apply_filters(
3015
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3016
-                (array) $this->_template_args['before_list_table'],
3017
-                $this->page_slug,
3018
-                $this->_req_data,
3019
-                $this->_req_action
3020
-            )
3021
-        );
3022
-        // filter after_list_table template arg
3023
-        $this->_template_args['after_list_table'] = apply_filters(
3024
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3025
-            $this->_template_args['after_list_table'],
3026
-            $this->page_slug,
3027
-            $this->_req_data,
3028
-            $this->_req_action
3029
-        );
3030
-        // convert to array and filter again
3031
-        // arrays are easier to inject new items in a specific location,
3032
-        // but would not be backwards compatible, so we have to add a new filter
3033
-        $this->_template_args['after_list_table'] = implode(
3034
-            " \n",
3035
-            (array) apply_filters(
3036
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3037
-                (array) $this->_template_args['after_list_table'],
3038
-                $this->page_slug,
3039
-                $this->_req_data,
3040
-                $this->_req_action
3041
-            )
3042
-        );
3043
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3044
-            $template_path,
3045
-            $this->_template_args,
3046
-            true
3047
-        );
3048
-        // the final template wrapper
3049
-        if ($sidebar) {
3050
-            $this->display_admin_page_with_sidebar();
3051
-        } else {
3052
-            $this->display_admin_page_with_no_sidebar();
3053
-        }
3054
-    }
3055
-
3056
-
3057
-    /**
3058
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3059
-     * html string for the legend.
3060
-     * $items are expected in an array in the following format:
3061
-     * $legend_items = array(
3062
-     *        'item_id' => array(
3063
-     *            'icon' => 'http://url_to_icon_being_described.png',
3064
-     *            'desc' => esc_html__('localized description of item');
3065
-     *        )
3066
-     * );
3067
-     *
3068
-     * @param  array $items see above for format of array
3069
-     * @return string html string of legend
3070
-     * @throws DomainException
3071
-     */
3072
-    protected function _display_legend($items)
3073
-    {
3074
-        $this->_template_args['items'] = apply_filters(
3075
-            'FHEE__EE_Admin_Page___display_legend__items',
3076
-            (array) $items,
3077
-            $this
3078
-        );
3079
-        return EEH_Template::display_template(
3080
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3081
-            $this->_template_args,
3082
-            true
3083
-        );
3084
-    }
3085
-
3086
-
3087
-    /**
3088
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3089
-     * The returned json object is created from an array in the following format:
3090
-     * array(
3091
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3092
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
3093
-     *  'notices' => '', // - contains any EE_Error formatted notices
3094
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3095
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3096
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
3097
-     *  that might be included in here)
3098
-     * )
3099
-     * The json object is populated by whatever is set in the $_template_args property.
3100
-     *
3101
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3102
-     *                                 instead of displayed.
3103
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3104
-     * @return void
3105
-     * @throws EE_Error
3106
-     */
3107
-    protected function _return_json($sticky_notices = false, $notices_arguments = array())
3108
-    {
3109
-        // make sure any EE_Error notices have been handled.
3110
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
3111
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3112
-        unset($this->_template_args['data']);
3113
-        $json = array(
3114
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3115
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3116
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3117
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3118
-            'notices'   => EE_Error::get_notices(),
3119
-            'content'   => isset($this->_template_args['admin_page_content'])
3120
-                ? $this->_template_args['admin_page_content'] : '',
3121
-            'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3122
-            'isEEajax'  => true
3123
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3124
-        );
3125
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3126
-        if (null === error_get_last() || ! headers_sent()) {
3127
-            header('Content-Type: application/json; charset=UTF-8');
3128
-        }
3129
-        echo wp_json_encode($json);
3130
-        exit();
3131
-    }
3132
-
3133
-
3134
-    /**
3135
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3136
-     *
3137
-     * @return void
3138
-     * @throws EE_Error
3139
-     */
3140
-    public function return_json()
3141
-    {
3142
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3143
-            $this->_return_json();
3144
-        } else {
3145
-            throw new EE_Error(
3146
-                sprintf(
3147
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3148
-                    __FUNCTION__
3149
-                )
3150
-            );
3151
-        }
3152
-    }
3153
-
3154
-
3155
-    /**
3156
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3157
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3158
-     *
3159
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3160
-     */
3161
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3162
-    {
3163
-        $this->_hook_obj = $hook_obj;
3164
-    }
3165
-
3166
-
3167
-    /**
3168
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3169
-     *
3170
-     * @param  boolean $about whether to use the special about page wrapper or default.
3171
-     * @return void
3172
-     * @throws DomainException
3173
-     * @throws EE_Error
3174
-     */
3175
-    public function admin_page_wrapper($about = false)
3176
-    {
3177
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3178
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
3179
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
3180
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
3181
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3182
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3183
-            isset($this->_template_args['before_admin_page_content'])
3184
-                ? $this->_template_args['before_admin_page_content']
3185
-                : ''
3186
-        );
3187
-        $this->_template_args['after_admin_page_content'] = apply_filters(
3188
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3189
-            isset($this->_template_args['after_admin_page_content'])
3190
-                ? $this->_template_args['after_admin_page_content']
3191
-                : ''
3192
-        );
3193
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3194
-        // load settings page wrapper template
3195
-        $template_path = ! defined('DOING_AJAX')
3196
-            ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3197
-            : EE_ADMIN_TEMPLATE
3198
-              . 'admin_wrapper_ajax.template.php';
3199
-        // about page?
3200
-        $template_path = $about
3201
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3202
-            : $template_path;
3203
-        if (defined('DOING_AJAX')) {
3204
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3205
-                $template_path,
3206
-                $this->_template_args,
3207
-                true
3208
-            );
3209
-            $this->_return_json();
3210
-        } else {
3211
-            EEH_Template::display_template($template_path, $this->_template_args);
3212
-        }
3213
-    }
3214
-
3215
-
3216
-    /**
3217
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3218
-     *
3219
-     * @return string html
3220
-     * @throws EE_Error
3221
-     */
3222
-    protected function _get_main_nav_tabs()
3223
-    {
3224
-        // let's generate the html using the EEH_Tabbed_Content helper.
3225
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3226
-        // (rather than setting in the page_routes array)
3227
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3228
-    }
3229
-
3230
-
3231
-    /**
3232
-     *        sort nav tabs
3233
-     *
3234
-     * @param $a
3235
-     * @param $b
3236
-     * @return int
3237
-     */
3238
-    private function _sort_nav_tabs($a, $b)
3239
-    {
3240
-        if ($a['order'] === $b['order']) {
3241
-            return 0;
3242
-        }
3243
-        return ($a['order'] < $b['order']) ? -1 : 1;
3244
-    }
3245
-
3246
-
3247
-    /**
3248
-     *    generates HTML for the forms used on admin pages
3249
-     *
3250
-     * @param    array $input_vars - array of input field details
3251
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to
3252
-     *                             use)
3253
-     * @param bool     $id
3254
-     * @return string
3255
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3256
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3257
-     */
3258
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
3259
-    {
3260
-        $content = $generator === 'string'
3261
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3262
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3263
-        return $content;
3264
-    }
3265
-
3266
-
3267
-    /**
3268
-     * generates the "Save" and "Save & Close" buttons for edit forms
3269
-     *
3270
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3271
-     *                                   Close" button.
3272
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3273
-     *                                   'Save', [1] => 'save & close')
3274
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3275
-     *                                   via the "name" value in the button).  We can also use this to just dump
3276
-     *                                   default actions by submitting some other value.
3277
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3278
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3279
-     *                                   close (normal form handling).
3280
-     */
3281
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3282
-    {
3283
-        // make sure $text and $actions are in an array
3284
-        $text = (array) $text;
3285
-        $actions = (array) $actions;
3286
-        $referrer_url = empty($referrer)
3287
-            ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3288
-              . $_SERVER['REQUEST_URI']
3289
-              . '" />'
3290
-            : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3291
-              . $referrer
3292
-              . '" />';
3293
-        $button_text = ! empty($text)
3294
-            ? $text
3295
-            : array(
3296
-                esc_html__('Save', 'event_espresso'),
3297
-                esc_html__('Save and Close', 'event_espresso'),
3298
-            );
3299
-        $default_names = array('save', 'save_and_close');
3300
-        // add in a hidden index for the current page (so save and close redirects properly)
3301
-        $this->_template_args['save_buttons'] = $referrer_url;
3302
-        foreach ($button_text as $key => $button) {
3303
-            $ref = $default_names[ $key ];
3304
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3305
-                                                     . $ref
3306
-                                                     . '" value="'
3307
-                                                     . $button
3308
-                                                     . '" name="'
3309
-                                                     . (! empty($actions) ? $actions[ $key ] : $ref)
3310
-                                                     . '" id="'
3311
-                                                     . $this->_current_view . '_' . $ref
3312
-                                                     . '" />';
3313
-            if (! $both) {
3314
-                break;
3315
-            }
3316
-        }
3317
-    }
3318
-
3319
-
3320
-    /**
3321
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3322
-     *
3323
-     * @see   $this->_set_add_edit_form_tags() for details on params
3324
-     * @since 4.6.0
3325
-     * @param string $route
3326
-     * @param array  $additional_hidden_fields
3327
-     */
3328
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3329
-    {
3330
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3331
-    }
3332
-
3333
-
3334
-    /**
3335
-     * set form open and close tags on add/edit pages.
3336
-     *
3337
-     * @param string $route                    the route you want the form to direct to
3338
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3339
-     * @return void
3340
-     */
3341
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3342
-    {
3343
-        if (empty($route)) {
3344
-            $user_msg = esc_html__(
3345
-                'An error occurred. No action was set for this page\'s form.',
3346
-                'event_espresso'
3347
-            );
3348
-            $dev_msg = $user_msg . "\n"
3349
-                       . sprintf(
3350
-                           esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3351
-                           __FUNCTION__,
3352
-                           __CLASS__
3353
-                       );
3354
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3355
-        }
3356
-        // open form
3357
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3358
-                                                             . $this->_admin_base_url
3359
-                                                             . '" id="'
3360
-                                                             . $route
3361
-                                                             . '_event_form" >';
3362
-        // add nonce
3363
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3364
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3365
-        // add REQUIRED form action
3366
-        $hidden_fields = array(
3367
-            'action' => array('type' => 'hidden', 'value' => $route),
3368
-        );
3369
-        // merge arrays
3370
-        $hidden_fields = is_array($additional_hidden_fields)
3371
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3372
-            : $hidden_fields;
3373
-        // generate form fields
3374
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3375
-        // add fields to form
3376
-        foreach ((array) $form_fields as $field_name => $form_field) {
3377
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3378
-        }
3379
-        // close form
3380
-        $this->_template_args['after_admin_page_content'] = '</form>';
3381
-    }
3382
-
3383
-
3384
-    /**
3385
-     * Public Wrapper for _redirect_after_action() method since its
3386
-     * discovered it would be useful for external code to have access.
3387
-     *
3388
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3389
-     * @since 4.5.0
3390
-     * @param bool   $success
3391
-     * @param string $what
3392
-     * @param string $action_desc
3393
-     * @param array  $query_args
3394
-     * @param bool   $override_overwrite
3395
-     * @throws EE_Error
3396
-     */
3397
-    public function redirect_after_action(
3398
-        $success = false,
3399
-        $what = 'item',
3400
-        $action_desc = 'processed',
3401
-        $query_args = array(),
3402
-        $override_overwrite = false
3403
-    ) {
3404
-        $this->_redirect_after_action(
3405
-            $success,
3406
-            $what,
3407
-            $action_desc,
3408
-            $query_args,
3409
-            $override_overwrite
3410
-        );
3411
-    }
3412
-
3413
-
3414
-    /**
3415
-     * Helper method for merging existing request data with the returned redirect url.
3416
-     *
3417
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3418
-     * filters are still applied.
3419
-     *
3420
-     * @param array $new_route_data
3421
-     * @return array
3422
-     */
3423
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3424
-    {
3425
-        foreach ($this->_req_data as $ref => $value) {
3426
-            // unset nonces
3427
-            if (strpos($ref, 'nonce') !== false) {
3428
-                unset($this->_req_data[ $ref ]);
3429
-                continue;
3430
-            }
3431
-            // urlencode values.
3432
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3433
-            $this->_req_data[ $ref ] = $value;
3434
-        }
3435
-        return array_merge($this->_req_data, $new_route_data);
3436
-    }
3437
-
3438
-
3439
-    /**
3440
-     *    _redirect_after_action
3441
-     *
3442
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3443
-     * @param string $what               - what the action was performed on
3444
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3445
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3446
-     *                                   action is completed
3447
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3448
-     *                                   override this so that they show.
3449
-     * @return void
3450
-     * @throws EE_Error
3451
-     */
3452
-    protected function _redirect_after_action(
3453
-        $success = 0,
3454
-        $what = 'item',
3455
-        $action_desc = 'processed',
3456
-        $query_args = array(),
3457
-        $override_overwrite = false
3458
-    ) {
3459
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3460
-        // class name for actions/filters.
3461
-        $classname = get_class($this);
3462
-        // set redirect url.
3463
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3464
-        // otherwise we go with whatever is set as the _admin_base_url
3465
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3466
-        $notices = EE_Error::get_notices(false);
3467
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3468
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3469
-            EE_Error::overwrite_success();
3470
-        }
3471
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3472
-            // how many records affected ? more than one record ? or just one ?
3473
-            if ($success > 1) {
3474
-                // set plural msg
3475
-                EE_Error::add_success(
3476
-                    sprintf(
3477
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3478
-                        $what,
3479
-                        $action_desc
3480
-                    ),
3481
-                    __FILE__,
3482
-                    __FUNCTION__,
3483
-                    __LINE__
3484
-                );
3485
-            } elseif ($success === 1) {
3486
-                // set singular msg
3487
-                EE_Error::add_success(
3488
-                    sprintf(
3489
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3490
-                        $what,
3491
-                        $action_desc
3492
-                    ),
3493
-                    __FILE__,
3494
-                    __FUNCTION__,
3495
-                    __LINE__
3496
-                );
3497
-            }
3498
-        }
3499
-        // check that $query_args isn't something crazy
3500
-        if (! is_array($query_args)) {
3501
-            $query_args = array();
3502
-        }
3503
-        /**
3504
-         * Allow injecting actions before the query_args are modified for possible different
3505
-         * redirections on save and close actions
3506
-         *
3507
-         * @since 4.2.0
3508
-         * @param array $query_args       The original query_args array coming into the
3509
-         *                                method.
3510
-         */
3511
-        do_action(
3512
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3513
-            $query_args
3514
-        );
3515
-        // calculate where we're going (if we have a "save and close" button pushed)
3516
-        if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3517
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3518
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3519
-            // regenerate query args array from referrer URL
3520
-            parse_str($parsed_url['query'], $query_args);
3521
-            // correct page and action will be in the query args now
3522
-            $redirect_url = admin_url('admin.php');
3523
-        }
3524
-        // merge any default query_args set in _default_route_query_args property
3525
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3526
-            $args_to_merge = array();
3527
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3528
-                // is there a wp_referer array in our _default_route_query_args property?
3529
-                if ($query_param === 'wp_referer') {
3530
-                    $query_value = (array) $query_value;
3531
-                    foreach ($query_value as $reference => $value) {
3532
-                        if (strpos($reference, 'nonce') !== false) {
3533
-                            continue;
3534
-                        }
3535
-                        // finally we will override any arguments in the referer with
3536
-                        // what might be set on the _default_route_query_args array.
3537
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3538
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3539
-                        } else {
3540
-                            $args_to_merge[ $reference ] = urlencode($value);
3541
-                        }
3542
-                    }
3543
-                    continue;
3544
-                }
3545
-                $args_to_merge[ $query_param ] = $query_value;
3546
-            }
3547
-            // now let's merge these arguments but override with what was specifically sent in to the
3548
-            // redirect.
3549
-            $query_args = array_merge($args_to_merge, $query_args);
3550
-        }
3551
-        $this->_process_notices($query_args);
3552
-        // generate redirect url
3553
-        // if redirecting to anything other than the main page, add a nonce
3554
-        if (isset($query_args['action'])) {
3555
-            // manually generate wp_nonce and merge that with the query vars
3556
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3557
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3558
-        }
3559
-        // we're adding some hooks and filters in here for processing any things just before redirects
3560
-        // (example: an admin page has done an insert or update and we want to run something after that).
3561
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3562
-        $redirect_url = apply_filters(
3563
-            'FHEE_redirect_' . $classname . $this->_req_action,
3564
-            self::add_query_args_and_nonce($query_args, $redirect_url),
3565
-            $query_args
3566
-        );
3567
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3568
-        if (defined('DOING_AJAX')) {
3569
-            $default_data = array(
3570
-                'close'        => true,
3571
-                'redirect_url' => $redirect_url,
3572
-                'where'        => 'main',
3573
-                'what'         => 'append',
3574
-            );
3575
-            $this->_template_args['success'] = $success;
3576
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge(
3577
-                $default_data,
3578
-                $this->_template_args['data']
3579
-            ) : $default_data;
3580
-            $this->_return_json();
3581
-        }
3582
-        wp_safe_redirect($redirect_url);
3583
-        exit();
3584
-    }
3585
-
3586
-
3587
-    /**
3588
-     * process any notices before redirecting (or returning ajax request)
3589
-     * This method sets the $this->_template_args['notices'] attribute;
3590
-     *
3591
-     * @param  array $query_args        any query args that need to be used for notice transient ('action')
3592
-     * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and
3593
-     *                                  page_routes haven't been defined yet.
3594
-     * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we
3595
-     *                                  still save a transient for the notice.
3596
-     * @return void
3597
-     * @throws EE_Error
3598
-     */
3599
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3600
-    {
3601
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3602
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3603
-            $notices = EE_Error::get_notices(false);
3604
-            if (empty($this->_template_args['success'])) {
3605
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3606
-            }
3607
-            if (empty($this->_template_args['errors'])) {
3608
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3609
-            }
3610
-            if (empty($this->_template_args['attention'])) {
3611
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3612
-            }
3613
-        }
3614
-        $this->_template_args['notices'] = EE_Error::get_notices();
3615
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3616
-        if (! defined('DOING_AJAX') || $sticky_notices) {
3617
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3618
-            $this->_add_transient(
3619
-                $route,
3620
-                $this->_template_args['notices'],
3621
-                true,
3622
-                $skip_route_verify
3623
-            );
3624
-        }
3625
-    }
3626
-
3627
-
3628
-    /**
3629
-     * get_action_link_or_button
3630
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3631
-     *
3632
-     * @param string $action        use this to indicate which action the url is generated with.
3633
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3634
-     *                              property.
3635
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3636
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3637
-     * @param string $base_url      If this is not provided
3638
-     *                              the _admin_base_url will be used as the default for the button base_url.
3639
-     *                              Otherwise this value will be used.
3640
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3641
-     * @return string
3642
-     * @throws InvalidArgumentException
3643
-     * @throws InvalidInterfaceException
3644
-     * @throws InvalidDataTypeException
3645
-     * @throws EE_Error
3646
-     */
3647
-    public function get_action_link_or_button(
3648
-        $action,
3649
-        $type = 'add',
3650
-        $extra_request = array(),
3651
-        $class = 'button-primary',
3652
-        $base_url = '',
3653
-        $exclude_nonce = false
3654
-    ) {
3655
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3656
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3657
-            throw new EE_Error(
3658
-                sprintf(
3659
-                    esc_html__(
3660
-                        'There is no page route for given action for the button.  This action was given: %s',
3661
-                        'event_espresso'
3662
-                    ),
3663
-                    $action
3664
-                )
3665
-            );
3666
-        }
3667
-        if (! isset($this->_labels['buttons'][ $type ])) {
3668
-            throw new EE_Error(
3669
-                sprintf(
3670
-                    __(
3671
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3672
-                        'event_espresso'
3673
-                    ),
3674
-                    $type
3675
-                )
3676
-            );
3677
-        }
3678
-        // finally check user access for this button.
3679
-        $has_access = $this->check_user_access($action, true);
3680
-        if (! $has_access) {
3681
-            return '';
3682
-        }
3683
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
3684
-        $query_args = array(
3685
-            'action' => $action,
3686
-        );
3687
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3688
-        if (! empty($extra_request)) {
3689
-            $query_args = array_merge($extra_request, $query_args);
3690
-        }
3691
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3692
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3693
-    }
3694
-
3695
-
3696
-    /**
3697
-     * _per_page_screen_option
3698
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3699
-     *
3700
-     * @return void
3701
-     * @throws InvalidArgumentException
3702
-     * @throws InvalidInterfaceException
3703
-     * @throws InvalidDataTypeException
3704
-     */
3705
-    protected function _per_page_screen_option()
3706
-    {
3707
-        $option = 'per_page';
3708
-        $args = array(
3709
-            'label'   => apply_filters(
3710
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3711
-                $this->_admin_page_title,
3712
-                $this
3713
-            ),
3714
-            'default' => (int) apply_filters(
3715
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3716
-                20
3717
-            ),
3718
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3719
-        );
3720
-        // ONLY add the screen option if the user has access to it.
3721
-        if ($this->check_user_access($this->_current_view, true)) {
3722
-            add_screen_option($option, $args);
3723
-        }
3724
-    }
3725
-
3726
-
3727
-    /**
3728
-     * set_per_page_screen_option
3729
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3730
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3731
-     * admin_menu.
3732
-     *
3733
-     * @return void
3734
-     */
3735
-    private function _set_per_page_screen_options()
3736
-    {
3737
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3738
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3739
-            if (! $user = wp_get_current_user()) {
3740
-                return;
3741
-            }
3742
-            $option = $_POST['wp_screen_options']['option'];
3743
-            $value = $_POST['wp_screen_options']['value'];
3744
-            if ($option != sanitize_key($option)) {
3745
-                return;
3746
-            }
3747
-            $map_option = $option;
3748
-            $option = str_replace('-', '_', $option);
3749
-            switch ($map_option) {
3750
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3751
-                    $value = (int) $value;
3752
-                    $max_value = apply_filters(
3753
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3754
-                        999,
3755
-                        $this->_current_page,
3756
-                        $this->_current_view
3757
-                    );
3758
-                    if ($value < 1) {
3759
-                        return;
3760
-                    }
3761
-                    $value = min($value, $max_value);
3762
-                    break;
3763
-                default:
3764
-                    $value = apply_filters(
3765
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3766
-                        false,
3767
-                        $option,
3768
-                        $value
3769
-                    );
3770
-                    if (false === $value) {
3771
-                        return;
3772
-                    }
3773
-                    break;
3774
-            }
3775
-            update_user_meta($user->ID, $option, $value);
3776
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3777
-            exit;
3778
-        }
3779
-    }
3780
-
3781
-
3782
-    /**
3783
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3784
-     *
3785
-     * @param array $data array that will be assigned to template args.
3786
-     */
3787
-    public function set_template_args($data)
3788
-    {
3789
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3790
-    }
3791
-
3792
-
3793
-    /**
3794
-     * This makes available the WP transient system for temporarily moving data between routes
3795
-     *
3796
-     * @param string $route             the route that should receive the transient
3797
-     * @param array  $data              the data that gets sent
3798
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3799
-     *                                  normal route transient.
3800
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3801
-     *                                  when we are adding a transient before page_routes have been defined.
3802
-     * @return void
3803
-     * @throws EE_Error
3804
-     */
3805
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3806
-    {
3807
-        $user_id = get_current_user_id();
3808
-        if (! $skip_route_verify) {
3809
-            $this->_verify_route($route);
3810
-        }
3811
-        // now let's set the string for what kind of transient we're setting
3812
-        $transient = $notices
3813
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3814
-            : 'rte_tx_' . $route . '_' . $user_id;
3815
-        $data = $notices ? array('notices' => $data) : $data;
3816
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3817
-        $existing = is_multisite() && is_network_admin()
3818
-            ? get_site_transient($transient)
3819
-            : get_transient($transient);
3820
-        if ($existing) {
3821
-            $data = array_merge((array) $data, (array) $existing);
3822
-        }
3823
-        if (is_multisite() && is_network_admin()) {
3824
-            set_site_transient($transient, $data, 8);
3825
-        } else {
3826
-            set_transient($transient, $data, 8);
3827
-        }
3828
-    }
3829
-
3830
-
3831
-    /**
3832
-     * this retrieves the temporary transient that has been set for moving data between routes.
3833
-     *
3834
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3835
-     * @param string $route
3836
-     * @return mixed data
3837
-     */
3838
-    protected function _get_transient($notices = false, $route = '')
3839
-    {
3840
-        $user_id = get_current_user_id();
3841
-        $route = ! $route ? $this->_req_action : $route;
3842
-        $transient = $notices
3843
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3844
-            : 'rte_tx_' . $route . '_' . $user_id;
3845
-        $data = is_multisite() && is_network_admin()
3846
-            ? get_site_transient($transient)
3847
-            : get_transient($transient);
3848
-        // delete transient after retrieval (just in case it hasn't expired);
3849
-        if (is_multisite() && is_network_admin()) {
3850
-            delete_site_transient($transient);
3851
-        } else {
3852
-            delete_transient($transient);
3853
-        }
3854
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3855
-    }
3856
-
3857
-
3858
-    /**
3859
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3860
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3861
-     * default route callback on the EE_Admin page you want it run.)
3862
-     *
3863
-     * @return void
3864
-     */
3865
-    protected function _transient_garbage_collection()
3866
-    {
3867
-        global $wpdb;
3868
-        // retrieve all existing transients
3869
-        $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3870
-        if ($results = $wpdb->get_results($query)) {
3871
-            foreach ($results as $result) {
3872
-                $transient = str_replace('_transient_', '', $result->option_name);
3873
-                get_transient($transient);
3874
-                if (is_multisite() && is_network_admin()) {
3875
-                    get_site_transient($transient);
3876
-                }
3877
-            }
3878
-        }
3879
-    }
3880
-
3881
-
3882
-    /**
3883
-     * get_view
3884
-     *
3885
-     * @return string content of _view property
3886
-     */
3887
-    public function get_view()
3888
-    {
3889
-        return $this->_view;
3890
-    }
3891
-
3892
-
3893
-    /**
3894
-     * getter for the protected $_views property
3895
-     *
3896
-     * @return array
3897
-     */
3898
-    public function get_views()
3899
-    {
3900
-        return $this->_views;
3901
-    }
3902
-
3903
-
3904
-    /**
3905
-     * get_current_page
3906
-     *
3907
-     * @return string _current_page property value
3908
-     */
3909
-    public function get_current_page()
3910
-    {
3911
-        return $this->_current_page;
3912
-    }
3913
-
3914
-
3915
-    /**
3916
-     * get_current_view
3917
-     *
3918
-     * @return string _current_view property value
3919
-     */
3920
-    public function get_current_view()
3921
-    {
3922
-        return $this->_current_view;
3923
-    }
3924
-
3925
-
3926
-    /**
3927
-     * get_current_screen
3928
-     *
3929
-     * @return object The current WP_Screen object
3930
-     */
3931
-    public function get_current_screen()
3932
-    {
3933
-        return $this->_current_screen;
3934
-    }
3935
-
3936
-
3937
-    /**
3938
-     * get_current_page_view_url
3939
-     *
3940
-     * @return string This returns the url for the current_page_view.
3941
-     */
3942
-    public function get_current_page_view_url()
3943
-    {
3944
-        return $this->_current_page_view_url;
3945
-    }
3946
-
3947
-
3948
-    /**
3949
-     * just returns the _req_data property
3950
-     *
3951
-     * @return array
3952
-     */
3953
-    public function get_request_data()
3954
-    {
3955
-        return $this->_req_data;
3956
-    }
3957
-
3958
-
3959
-    /**
3960
-     * returns the _req_data protected property
3961
-     *
3962
-     * @return string
3963
-     */
3964
-    public function get_req_action()
3965
-    {
3966
-        return $this->_req_action;
3967
-    }
3968
-
3969
-
3970
-    /**
3971
-     * @return bool  value of $_is_caf property
3972
-     */
3973
-    public function is_caf()
3974
-    {
3975
-        return $this->_is_caf;
3976
-    }
3977
-
3978
-
3979
-    /**
3980
-     * @return mixed
3981
-     */
3982
-    public function default_espresso_metaboxes()
3983
-    {
3984
-        return $this->_default_espresso_metaboxes;
3985
-    }
3986
-
3987
-
3988
-    /**
3989
-     * @return mixed
3990
-     */
3991
-    public function admin_base_url()
3992
-    {
3993
-        return $this->_admin_base_url;
3994
-    }
3995
-
3996
-
3997
-    /**
3998
-     * @return mixed
3999
-     */
4000
-    public function wp_page_slug()
4001
-    {
4002
-        return $this->_wp_page_slug;
4003
-    }
4004
-
4005
-
4006
-    /**
4007
-     * updates  espresso configuration settings
4008
-     *
4009
-     * @param string                   $tab
4010
-     * @param EE_Config_Base|EE_Config $config
4011
-     * @param string                   $file file where error occurred
4012
-     * @param string                   $func function  where error occurred
4013
-     * @param string                   $line line no where error occurred
4014
-     * @return boolean
4015
-     */
4016
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4017
-    {
4018
-        // remove any options that are NOT going to be saved with the config settings.
4019
-        if (isset($config->core->ee_ueip_optin)) {
4020
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
4021
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4022
-            update_option('ee_ueip_has_notified', true);
4023
-        }
4024
-        // and save it (note we're also doing the network save here)
4025
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4026
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
4027
-        if ($config_saved && $net_saved) {
4028
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4029
-            return true;
4030
-        }
4031
-        EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4032
-        return false;
4033
-    }
4034
-
4035
-
4036
-    /**
4037
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4038
-     *
4039
-     * @return array
4040
-     */
4041
-    public function get_yes_no_values()
4042
-    {
4043
-        return $this->_yes_no_values;
4044
-    }
4045
-
4046
-
4047
-    protected function _get_dir()
4048
-    {
4049
-        $reflector = new ReflectionClass(get_class($this));
4050
-        return dirname($reflector->getFileName());
4051
-    }
4052
-
4053
-
4054
-    /**
4055
-     * A helper for getting a "next link".
4056
-     *
4057
-     * @param string $url   The url to link to
4058
-     * @param string $class The class to use.
4059
-     * @return string
4060
-     */
4061
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4062
-    {
4063
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4064
-    }
4065
-
4066
-
4067
-    /**
4068
-     * A helper for getting a "previous link".
4069
-     *
4070
-     * @param string $url   The url to link to
4071
-     * @param string $class The class to use.
4072
-     * @return string
4073
-     */
4074
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4075
-    {
4076
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4077
-    }
4078
-
4079
-
4080
-
4081
-
4082
-
4083
-
4084
-
4085
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4086
-
4087
-
4088
-    /**
4089
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4090
-     * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4091
-     * _req_data array.
4092
-     *
4093
-     * @return bool success/fail
4094
-     * @throws EE_Error
4095
-     * @throws InvalidArgumentException
4096
-     * @throws ReflectionException
4097
-     * @throws InvalidDataTypeException
4098
-     * @throws InvalidInterfaceException
4099
-     */
4100
-    protected function _process_resend_registration()
4101
-    {
4102
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4103
-        do_action(
4104
-            'AHEE__EE_Admin_Page___process_resend_registration',
4105
-            $this->_template_args['success'],
4106
-            $this->_req_data
4107
-        );
4108
-        return $this->_template_args['success'];
4109
-    }
4110
-
4111
-
4112
-    /**
4113
-     * This automatically processes any payment message notifications when manual payment has been applied.
4114
-     *
4115
-     * @param \EE_Payment $payment
4116
-     * @return bool success/fail
4117
-     */
4118
-    protected function _process_payment_notification(EE_Payment $payment)
4119
-    {
4120
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4121
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4122
-        $this->_template_args['success'] = apply_filters(
4123
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4124
-            false,
4125
-            $payment
4126
-        );
4127
-        return $this->_template_args['success'];
4128
-    }
2705
+	}
2706
+
2707
+
2708
+	/**
2709
+	 * facade for add_meta_box
2710
+	 *
2711
+	 * @param string  $action        where the metabox get's displayed
2712
+	 * @param string  $title         Title of Metabox (output in metabox header)
2713
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2714
+	 *                               instead of the one created in here.
2715
+	 * @param array   $callback_args an array of args supplied for the metabox
2716
+	 * @param string  $column        what metabox column
2717
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2718
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2719
+	 *                               created but just set our own callback for wp's add_meta_box.
2720
+	 * @throws \DomainException
2721
+	 */
2722
+	public function _add_admin_page_meta_box(
2723
+		$action,
2724
+		$title,
2725
+		$callback,
2726
+		$callback_args,
2727
+		$column = 'normal',
2728
+		$priority = 'high',
2729
+		$create_func = true
2730
+	) {
2731
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2732
+		// if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2733
+		if (empty($callback_args) && $create_func) {
2734
+			$callback_args = array(
2735
+				'template_path' => $this->_template_path,
2736
+				'template_args' => $this->_template_args,
2737
+			);
2738
+		}
2739
+		// if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2740
+		$call_back_func = $create_func
2741
+			? function ($post, $metabox) {
2742
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2743
+				echo EEH_Template::display_template(
2744
+					$metabox['args']['template_path'],
2745
+					$metabox['args']['template_args'],
2746
+					true
2747
+				);
2748
+			}
2749
+			: $callback;
2750
+		add_meta_box(
2751
+			str_replace('_', '-', $action) . '-mbox',
2752
+			$title,
2753
+			$call_back_func,
2754
+			$this->_wp_page_slug,
2755
+			$column,
2756
+			$priority,
2757
+			$callback_args
2758
+		);
2759
+	}
2760
+
2761
+
2762
+	/**
2763
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2764
+	 *
2765
+	 * @throws DomainException
2766
+	 * @throws EE_Error
2767
+	 */
2768
+	public function display_admin_page_with_metabox_columns()
2769
+	{
2770
+		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2771
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2772
+			$this->_column_template_path,
2773
+			$this->_template_args,
2774
+			true
2775
+		);
2776
+		// the final wrapper
2777
+		$this->admin_page_wrapper();
2778
+	}
2779
+
2780
+
2781
+	/**
2782
+	 * generates  HTML wrapper for an admin details page
2783
+	 *
2784
+	 * @return void
2785
+	 * @throws EE_Error
2786
+	 * @throws DomainException
2787
+	 */
2788
+	public function display_admin_page_with_sidebar()
2789
+	{
2790
+		$this->_display_admin_page(true);
2791
+	}
2792
+
2793
+
2794
+	/**
2795
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2796
+	 *
2797
+	 * @return void
2798
+	 * @throws EE_Error
2799
+	 * @throws DomainException
2800
+	 */
2801
+	public function display_admin_page_with_no_sidebar()
2802
+	{
2803
+		$this->_display_admin_page();
2804
+	}
2805
+
2806
+
2807
+	/**
2808
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2809
+	 *
2810
+	 * @return void
2811
+	 * @throws EE_Error
2812
+	 * @throws DomainException
2813
+	 */
2814
+	public function display_about_admin_page()
2815
+	{
2816
+		$this->_display_admin_page(false, true);
2817
+	}
2818
+
2819
+
2820
+	/**
2821
+	 * display_admin_page
2822
+	 * contains the code for actually displaying an admin page
2823
+	 *
2824
+	 * @param  boolean $sidebar true with sidebar, false without
2825
+	 * @param  boolean $about   use the about admin wrapper instead of the default.
2826
+	 * @return void
2827
+	 * @throws DomainException
2828
+	 * @throws EE_Error
2829
+	 */
2830
+	private function _display_admin_page($sidebar = false, $about = false)
2831
+	{
2832
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2833
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2834
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2835
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2836
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2837
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2838
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2839
+			? 'poststuff'
2840
+			: 'espresso-default-admin';
2841
+		$template_path = $sidebar
2842
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2843
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2844
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2845
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2846
+		}
2847
+		$template_path = ! empty($this->_column_template_path)
2848
+			? $this->_column_template_path : $template_path;
2849
+		$this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content'])
2850
+			? $this->_template_args['admin_page_content']
2851
+			: '';
2852
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2853
+			? $this->_template_args['before_admin_page_content']
2854
+			: '';
2855
+		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content'])
2856
+			? $this->_template_args['after_admin_page_content']
2857
+			: '';
2858
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2859
+			$template_path,
2860
+			$this->_template_args,
2861
+			true
2862
+		);
2863
+		// the final template wrapper
2864
+		$this->admin_page_wrapper($about);
2865
+	}
2866
+
2867
+
2868
+	/**
2869
+	 * This is used to display caf preview pages.
2870
+	 *
2871
+	 * @since 4.3.2
2872
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2873
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2874
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2875
+	 * @return void
2876
+	 * @throws DomainException
2877
+	 * @throws EE_Error
2878
+	 * @throws InvalidArgumentException
2879
+	 * @throws InvalidDataTypeException
2880
+	 * @throws InvalidInterfaceException
2881
+	 */
2882
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2883
+	{
2884
+		// let's generate a default preview action button if there isn't one already present.
2885
+		$this->_labels['buttons']['buy_now'] = esc_html__(
2886
+			'Upgrade to Event Espresso 4 Right Now',
2887
+			'event_espresso'
2888
+		);
2889
+		$buy_now_url = add_query_arg(
2890
+			array(
2891
+				'ee_ver'       => 'ee4',
2892
+				'utm_source'   => 'ee4_plugin_admin',
2893
+				'utm_medium'   => 'link',
2894
+				'utm_campaign' => $utm_campaign_source,
2895
+				'utm_content'  => 'buy_now_button',
2896
+			),
2897
+			'http://eventespresso.com/pricing/'
2898
+		);
2899
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2900
+			? $this->get_action_link_or_button(
2901
+				'',
2902
+				'buy_now',
2903
+				array(),
2904
+				'button-primary button-large',
2905
+				$buy_now_url,
2906
+				true
2907
+			)
2908
+			: $this->_template_args['preview_action_button'];
2909
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2910
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2911
+			$this->_template_args,
2912
+			true
2913
+		);
2914
+		$this->_display_admin_page($display_sidebar);
2915
+	}
2916
+
2917
+
2918
+	/**
2919
+	 * display_admin_list_table_page_with_sidebar
2920
+	 * generates HTML wrapper for an admin_page with list_table
2921
+	 *
2922
+	 * @return void
2923
+	 * @throws EE_Error
2924
+	 * @throws DomainException
2925
+	 */
2926
+	public function display_admin_list_table_page_with_sidebar()
2927
+	{
2928
+		$this->_display_admin_list_table_page(true);
2929
+	}
2930
+
2931
+
2932
+	/**
2933
+	 * display_admin_list_table_page_with_no_sidebar
2934
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2935
+	 *
2936
+	 * @return void
2937
+	 * @throws EE_Error
2938
+	 * @throws DomainException
2939
+	 */
2940
+	public function display_admin_list_table_page_with_no_sidebar()
2941
+	{
2942
+		$this->_display_admin_list_table_page();
2943
+	}
2944
+
2945
+
2946
+	/**
2947
+	 * generates html wrapper for an admin_list_table page
2948
+	 *
2949
+	 * @param boolean $sidebar whether to display with sidebar or not.
2950
+	 * @return void
2951
+	 * @throws DomainException
2952
+	 * @throws EE_Error
2953
+	 */
2954
+	private function _display_admin_list_table_page($sidebar = false)
2955
+	{
2956
+		// setup search attributes
2957
+		$this->_set_search_attributes();
2958
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2959
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2960
+		$this->_template_args['table_url'] = defined('DOING_AJAX')
2961
+			? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2962
+			: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2963
+		$this->_template_args['list_table'] = $this->_list_table_object;
2964
+		$this->_template_args['current_route'] = $this->_req_action;
2965
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2966
+		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2967
+		if (! empty($ajax_sorting_callback)) {
2968
+			$sortable_list_table_form_fields = wp_nonce_field(
2969
+				$ajax_sorting_callback . '_nonce',
2970
+				$ajax_sorting_callback . '_nonce',
2971
+				false,
2972
+				false
2973
+			);
2974
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2975
+												. $this->page_slug
2976
+												. '" />';
2977
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2978
+												. $ajax_sorting_callback
2979
+												. '" />';
2980
+		} else {
2981
+			$sortable_list_table_form_fields = '';
2982
+		}
2983
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2984
+		$hidden_form_fields = isset($this->_template_args['list_table_hidden_fields'])
2985
+			? $this->_template_args['list_table_hidden_fields']
2986
+			: '';
2987
+		$nonce_ref = $this->_req_action . '_nonce';
2988
+		$hidden_form_fields .= '<input type="hidden" name="'
2989
+							   . $nonce_ref
2990
+							   . '" value="'
2991
+							   . wp_create_nonce($nonce_ref)
2992
+							   . '">';
2993
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2994
+		// display message about search results?
2995
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2996
+			? '<p class="ee-search-results">' . sprintf(
2997
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2998
+				trim($this->_req_data['s'], '%')
2999
+			) . '</p>'
3000
+			: '';
3001
+		// filter before_list_table template arg
3002
+		$this->_template_args['before_list_table'] = apply_filters(
3003
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3004
+			$this->_template_args['before_list_table'],
3005
+			$this->page_slug,
3006
+			$this->_req_data,
3007
+			$this->_req_action
3008
+		);
3009
+		// convert to array and filter again
3010
+		// arrays are easier to inject new items in a specific location,
3011
+		// but would not be backwards compatible, so we have to add a new filter
3012
+		$this->_template_args['before_list_table'] = implode(
3013
+			" \n",
3014
+			(array) apply_filters(
3015
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3016
+				(array) $this->_template_args['before_list_table'],
3017
+				$this->page_slug,
3018
+				$this->_req_data,
3019
+				$this->_req_action
3020
+			)
3021
+		);
3022
+		// filter after_list_table template arg
3023
+		$this->_template_args['after_list_table'] = apply_filters(
3024
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3025
+			$this->_template_args['after_list_table'],
3026
+			$this->page_slug,
3027
+			$this->_req_data,
3028
+			$this->_req_action
3029
+		);
3030
+		// convert to array and filter again
3031
+		// arrays are easier to inject new items in a specific location,
3032
+		// but would not be backwards compatible, so we have to add a new filter
3033
+		$this->_template_args['after_list_table'] = implode(
3034
+			" \n",
3035
+			(array) apply_filters(
3036
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3037
+				(array) $this->_template_args['after_list_table'],
3038
+				$this->page_slug,
3039
+				$this->_req_data,
3040
+				$this->_req_action
3041
+			)
3042
+		);
3043
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3044
+			$template_path,
3045
+			$this->_template_args,
3046
+			true
3047
+		);
3048
+		// the final template wrapper
3049
+		if ($sidebar) {
3050
+			$this->display_admin_page_with_sidebar();
3051
+		} else {
3052
+			$this->display_admin_page_with_no_sidebar();
3053
+		}
3054
+	}
3055
+
3056
+
3057
+	/**
3058
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3059
+	 * html string for the legend.
3060
+	 * $items are expected in an array in the following format:
3061
+	 * $legend_items = array(
3062
+	 *        'item_id' => array(
3063
+	 *            'icon' => 'http://url_to_icon_being_described.png',
3064
+	 *            'desc' => esc_html__('localized description of item');
3065
+	 *        )
3066
+	 * );
3067
+	 *
3068
+	 * @param  array $items see above for format of array
3069
+	 * @return string html string of legend
3070
+	 * @throws DomainException
3071
+	 */
3072
+	protected function _display_legend($items)
3073
+	{
3074
+		$this->_template_args['items'] = apply_filters(
3075
+			'FHEE__EE_Admin_Page___display_legend__items',
3076
+			(array) $items,
3077
+			$this
3078
+		);
3079
+		return EEH_Template::display_template(
3080
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3081
+			$this->_template_args,
3082
+			true
3083
+		);
3084
+	}
3085
+
3086
+
3087
+	/**
3088
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3089
+	 * The returned json object is created from an array in the following format:
3090
+	 * array(
3091
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3092
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
3093
+	 *  'notices' => '', // - contains any EE_Error formatted notices
3094
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3095
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3096
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
3097
+	 *  that might be included in here)
3098
+	 * )
3099
+	 * The json object is populated by whatever is set in the $_template_args property.
3100
+	 *
3101
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3102
+	 *                                 instead of displayed.
3103
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3104
+	 * @return void
3105
+	 * @throws EE_Error
3106
+	 */
3107
+	protected function _return_json($sticky_notices = false, $notices_arguments = array())
3108
+	{
3109
+		// make sure any EE_Error notices have been handled.
3110
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
3111
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3112
+		unset($this->_template_args['data']);
3113
+		$json = array(
3114
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3115
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3116
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3117
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3118
+			'notices'   => EE_Error::get_notices(),
3119
+			'content'   => isset($this->_template_args['admin_page_content'])
3120
+				? $this->_template_args['admin_page_content'] : '',
3121
+			'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3122
+			'isEEajax'  => true
3123
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3124
+		);
3125
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3126
+		if (null === error_get_last() || ! headers_sent()) {
3127
+			header('Content-Type: application/json; charset=UTF-8');
3128
+		}
3129
+		echo wp_json_encode($json);
3130
+		exit();
3131
+	}
3132
+
3133
+
3134
+	/**
3135
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3136
+	 *
3137
+	 * @return void
3138
+	 * @throws EE_Error
3139
+	 */
3140
+	public function return_json()
3141
+	{
3142
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3143
+			$this->_return_json();
3144
+		} else {
3145
+			throw new EE_Error(
3146
+				sprintf(
3147
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3148
+					__FUNCTION__
3149
+				)
3150
+			);
3151
+		}
3152
+	}
3153
+
3154
+
3155
+	/**
3156
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3157
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3158
+	 *
3159
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3160
+	 */
3161
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3162
+	{
3163
+		$this->_hook_obj = $hook_obj;
3164
+	}
3165
+
3166
+
3167
+	/**
3168
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3169
+	 *
3170
+	 * @param  boolean $about whether to use the special about page wrapper or default.
3171
+	 * @return void
3172
+	 * @throws DomainException
3173
+	 * @throws EE_Error
3174
+	 */
3175
+	public function admin_page_wrapper($about = false)
3176
+	{
3177
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3178
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
3179
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
3180
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
3181
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3182
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3183
+			isset($this->_template_args['before_admin_page_content'])
3184
+				? $this->_template_args['before_admin_page_content']
3185
+				: ''
3186
+		);
3187
+		$this->_template_args['after_admin_page_content'] = apply_filters(
3188
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3189
+			isset($this->_template_args['after_admin_page_content'])
3190
+				? $this->_template_args['after_admin_page_content']
3191
+				: ''
3192
+		);
3193
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3194
+		// load settings page wrapper template
3195
+		$template_path = ! defined('DOING_AJAX')
3196
+			? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3197
+			: EE_ADMIN_TEMPLATE
3198
+			  . 'admin_wrapper_ajax.template.php';
3199
+		// about page?
3200
+		$template_path = $about
3201
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3202
+			: $template_path;
3203
+		if (defined('DOING_AJAX')) {
3204
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3205
+				$template_path,
3206
+				$this->_template_args,
3207
+				true
3208
+			);
3209
+			$this->_return_json();
3210
+		} else {
3211
+			EEH_Template::display_template($template_path, $this->_template_args);
3212
+		}
3213
+	}
3214
+
3215
+
3216
+	/**
3217
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3218
+	 *
3219
+	 * @return string html
3220
+	 * @throws EE_Error
3221
+	 */
3222
+	protected function _get_main_nav_tabs()
3223
+	{
3224
+		// let's generate the html using the EEH_Tabbed_Content helper.
3225
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3226
+		// (rather than setting in the page_routes array)
3227
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3228
+	}
3229
+
3230
+
3231
+	/**
3232
+	 *        sort nav tabs
3233
+	 *
3234
+	 * @param $a
3235
+	 * @param $b
3236
+	 * @return int
3237
+	 */
3238
+	private function _sort_nav_tabs($a, $b)
3239
+	{
3240
+		if ($a['order'] === $b['order']) {
3241
+			return 0;
3242
+		}
3243
+		return ($a['order'] < $b['order']) ? -1 : 1;
3244
+	}
3245
+
3246
+
3247
+	/**
3248
+	 *    generates HTML for the forms used on admin pages
3249
+	 *
3250
+	 * @param    array $input_vars - array of input field details
3251
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to
3252
+	 *                             use)
3253
+	 * @param bool     $id
3254
+	 * @return string
3255
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3256
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3257
+	 */
3258
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
3259
+	{
3260
+		$content = $generator === 'string'
3261
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3262
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3263
+		return $content;
3264
+	}
3265
+
3266
+
3267
+	/**
3268
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3269
+	 *
3270
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3271
+	 *                                   Close" button.
3272
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3273
+	 *                                   'Save', [1] => 'save & close')
3274
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3275
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3276
+	 *                                   default actions by submitting some other value.
3277
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3278
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3279
+	 *                                   close (normal form handling).
3280
+	 */
3281
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3282
+	{
3283
+		// make sure $text and $actions are in an array
3284
+		$text = (array) $text;
3285
+		$actions = (array) $actions;
3286
+		$referrer_url = empty($referrer)
3287
+			? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3288
+			  . $_SERVER['REQUEST_URI']
3289
+			  . '" />'
3290
+			: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3291
+			  . $referrer
3292
+			  . '" />';
3293
+		$button_text = ! empty($text)
3294
+			? $text
3295
+			: array(
3296
+				esc_html__('Save', 'event_espresso'),
3297
+				esc_html__('Save and Close', 'event_espresso'),
3298
+			);
3299
+		$default_names = array('save', 'save_and_close');
3300
+		// add in a hidden index for the current page (so save and close redirects properly)
3301
+		$this->_template_args['save_buttons'] = $referrer_url;
3302
+		foreach ($button_text as $key => $button) {
3303
+			$ref = $default_names[ $key ];
3304
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3305
+													 . $ref
3306
+													 . '" value="'
3307
+													 . $button
3308
+													 . '" name="'
3309
+													 . (! empty($actions) ? $actions[ $key ] : $ref)
3310
+													 . '" id="'
3311
+													 . $this->_current_view . '_' . $ref
3312
+													 . '" />';
3313
+			if (! $both) {
3314
+				break;
3315
+			}
3316
+		}
3317
+	}
3318
+
3319
+
3320
+	/**
3321
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3322
+	 *
3323
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3324
+	 * @since 4.6.0
3325
+	 * @param string $route
3326
+	 * @param array  $additional_hidden_fields
3327
+	 */
3328
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3329
+	{
3330
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3331
+	}
3332
+
3333
+
3334
+	/**
3335
+	 * set form open and close tags on add/edit pages.
3336
+	 *
3337
+	 * @param string $route                    the route you want the form to direct to
3338
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3339
+	 * @return void
3340
+	 */
3341
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3342
+	{
3343
+		if (empty($route)) {
3344
+			$user_msg = esc_html__(
3345
+				'An error occurred. No action was set for this page\'s form.',
3346
+				'event_espresso'
3347
+			);
3348
+			$dev_msg = $user_msg . "\n"
3349
+					   . sprintf(
3350
+						   esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3351
+						   __FUNCTION__,
3352
+						   __CLASS__
3353
+					   );
3354
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3355
+		}
3356
+		// open form
3357
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3358
+															 . $this->_admin_base_url
3359
+															 . '" id="'
3360
+															 . $route
3361
+															 . '_event_form" >';
3362
+		// add nonce
3363
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3364
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3365
+		// add REQUIRED form action
3366
+		$hidden_fields = array(
3367
+			'action' => array('type' => 'hidden', 'value' => $route),
3368
+		);
3369
+		// merge arrays
3370
+		$hidden_fields = is_array($additional_hidden_fields)
3371
+			? array_merge($hidden_fields, $additional_hidden_fields)
3372
+			: $hidden_fields;
3373
+		// generate form fields
3374
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3375
+		// add fields to form
3376
+		foreach ((array) $form_fields as $field_name => $form_field) {
3377
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3378
+		}
3379
+		// close form
3380
+		$this->_template_args['after_admin_page_content'] = '</form>';
3381
+	}
3382
+
3383
+
3384
+	/**
3385
+	 * Public Wrapper for _redirect_after_action() method since its
3386
+	 * discovered it would be useful for external code to have access.
3387
+	 *
3388
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3389
+	 * @since 4.5.0
3390
+	 * @param bool   $success
3391
+	 * @param string $what
3392
+	 * @param string $action_desc
3393
+	 * @param array  $query_args
3394
+	 * @param bool   $override_overwrite
3395
+	 * @throws EE_Error
3396
+	 */
3397
+	public function redirect_after_action(
3398
+		$success = false,
3399
+		$what = 'item',
3400
+		$action_desc = 'processed',
3401
+		$query_args = array(),
3402
+		$override_overwrite = false
3403
+	) {
3404
+		$this->_redirect_after_action(
3405
+			$success,
3406
+			$what,
3407
+			$action_desc,
3408
+			$query_args,
3409
+			$override_overwrite
3410
+		);
3411
+	}
3412
+
3413
+
3414
+	/**
3415
+	 * Helper method for merging existing request data with the returned redirect url.
3416
+	 *
3417
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3418
+	 * filters are still applied.
3419
+	 *
3420
+	 * @param array $new_route_data
3421
+	 * @return array
3422
+	 */
3423
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3424
+	{
3425
+		foreach ($this->_req_data as $ref => $value) {
3426
+			// unset nonces
3427
+			if (strpos($ref, 'nonce') !== false) {
3428
+				unset($this->_req_data[ $ref ]);
3429
+				continue;
3430
+			}
3431
+			// urlencode values.
3432
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3433
+			$this->_req_data[ $ref ] = $value;
3434
+		}
3435
+		return array_merge($this->_req_data, $new_route_data);
3436
+	}
3437
+
3438
+
3439
+	/**
3440
+	 *    _redirect_after_action
3441
+	 *
3442
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3443
+	 * @param string $what               - what the action was performed on
3444
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3445
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3446
+	 *                                   action is completed
3447
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3448
+	 *                                   override this so that they show.
3449
+	 * @return void
3450
+	 * @throws EE_Error
3451
+	 */
3452
+	protected function _redirect_after_action(
3453
+		$success = 0,
3454
+		$what = 'item',
3455
+		$action_desc = 'processed',
3456
+		$query_args = array(),
3457
+		$override_overwrite = false
3458
+	) {
3459
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3460
+		// class name for actions/filters.
3461
+		$classname = get_class($this);
3462
+		// set redirect url.
3463
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3464
+		// otherwise we go with whatever is set as the _admin_base_url
3465
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3466
+		$notices = EE_Error::get_notices(false);
3467
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3468
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3469
+			EE_Error::overwrite_success();
3470
+		}
3471
+		if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3472
+			// how many records affected ? more than one record ? or just one ?
3473
+			if ($success > 1) {
3474
+				// set plural msg
3475
+				EE_Error::add_success(
3476
+					sprintf(
3477
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3478
+						$what,
3479
+						$action_desc
3480
+					),
3481
+					__FILE__,
3482
+					__FUNCTION__,
3483
+					__LINE__
3484
+				);
3485
+			} elseif ($success === 1) {
3486
+				// set singular msg
3487
+				EE_Error::add_success(
3488
+					sprintf(
3489
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3490
+						$what,
3491
+						$action_desc
3492
+					),
3493
+					__FILE__,
3494
+					__FUNCTION__,
3495
+					__LINE__
3496
+				);
3497
+			}
3498
+		}
3499
+		// check that $query_args isn't something crazy
3500
+		if (! is_array($query_args)) {
3501
+			$query_args = array();
3502
+		}
3503
+		/**
3504
+		 * Allow injecting actions before the query_args are modified for possible different
3505
+		 * redirections on save and close actions
3506
+		 *
3507
+		 * @since 4.2.0
3508
+		 * @param array $query_args       The original query_args array coming into the
3509
+		 *                                method.
3510
+		 */
3511
+		do_action(
3512
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3513
+			$query_args
3514
+		);
3515
+		// calculate where we're going (if we have a "save and close" button pushed)
3516
+		if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3517
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3518
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3519
+			// regenerate query args array from referrer URL
3520
+			parse_str($parsed_url['query'], $query_args);
3521
+			// correct page and action will be in the query args now
3522
+			$redirect_url = admin_url('admin.php');
3523
+		}
3524
+		// merge any default query_args set in _default_route_query_args property
3525
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3526
+			$args_to_merge = array();
3527
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3528
+				// is there a wp_referer array in our _default_route_query_args property?
3529
+				if ($query_param === 'wp_referer') {
3530
+					$query_value = (array) $query_value;
3531
+					foreach ($query_value as $reference => $value) {
3532
+						if (strpos($reference, 'nonce') !== false) {
3533
+							continue;
3534
+						}
3535
+						// finally we will override any arguments in the referer with
3536
+						// what might be set on the _default_route_query_args array.
3537
+						if (isset($this->_default_route_query_args[ $reference ])) {
3538
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3539
+						} else {
3540
+							$args_to_merge[ $reference ] = urlencode($value);
3541
+						}
3542
+					}
3543
+					continue;
3544
+				}
3545
+				$args_to_merge[ $query_param ] = $query_value;
3546
+			}
3547
+			// now let's merge these arguments but override with what was specifically sent in to the
3548
+			// redirect.
3549
+			$query_args = array_merge($args_to_merge, $query_args);
3550
+		}
3551
+		$this->_process_notices($query_args);
3552
+		// generate redirect url
3553
+		// if redirecting to anything other than the main page, add a nonce
3554
+		if (isset($query_args['action'])) {
3555
+			// manually generate wp_nonce and merge that with the query vars
3556
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3557
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3558
+		}
3559
+		// we're adding some hooks and filters in here for processing any things just before redirects
3560
+		// (example: an admin page has done an insert or update and we want to run something after that).
3561
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3562
+		$redirect_url = apply_filters(
3563
+			'FHEE_redirect_' . $classname . $this->_req_action,
3564
+			self::add_query_args_and_nonce($query_args, $redirect_url),
3565
+			$query_args
3566
+		);
3567
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3568
+		if (defined('DOING_AJAX')) {
3569
+			$default_data = array(
3570
+				'close'        => true,
3571
+				'redirect_url' => $redirect_url,
3572
+				'where'        => 'main',
3573
+				'what'         => 'append',
3574
+			);
3575
+			$this->_template_args['success'] = $success;
3576
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge(
3577
+				$default_data,
3578
+				$this->_template_args['data']
3579
+			) : $default_data;
3580
+			$this->_return_json();
3581
+		}
3582
+		wp_safe_redirect($redirect_url);
3583
+		exit();
3584
+	}
3585
+
3586
+
3587
+	/**
3588
+	 * process any notices before redirecting (or returning ajax request)
3589
+	 * This method sets the $this->_template_args['notices'] attribute;
3590
+	 *
3591
+	 * @param  array $query_args        any query args that need to be used for notice transient ('action')
3592
+	 * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and
3593
+	 *                                  page_routes haven't been defined yet.
3594
+	 * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we
3595
+	 *                                  still save a transient for the notice.
3596
+	 * @return void
3597
+	 * @throws EE_Error
3598
+	 */
3599
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3600
+	{
3601
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3602
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3603
+			$notices = EE_Error::get_notices(false);
3604
+			if (empty($this->_template_args['success'])) {
3605
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3606
+			}
3607
+			if (empty($this->_template_args['errors'])) {
3608
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3609
+			}
3610
+			if (empty($this->_template_args['attention'])) {
3611
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3612
+			}
3613
+		}
3614
+		$this->_template_args['notices'] = EE_Error::get_notices();
3615
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3616
+		if (! defined('DOING_AJAX') || $sticky_notices) {
3617
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3618
+			$this->_add_transient(
3619
+				$route,
3620
+				$this->_template_args['notices'],
3621
+				true,
3622
+				$skip_route_verify
3623
+			);
3624
+		}
3625
+	}
3626
+
3627
+
3628
+	/**
3629
+	 * get_action_link_or_button
3630
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3631
+	 *
3632
+	 * @param string $action        use this to indicate which action the url is generated with.
3633
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3634
+	 *                              property.
3635
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3636
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3637
+	 * @param string $base_url      If this is not provided
3638
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3639
+	 *                              Otherwise this value will be used.
3640
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3641
+	 * @return string
3642
+	 * @throws InvalidArgumentException
3643
+	 * @throws InvalidInterfaceException
3644
+	 * @throws InvalidDataTypeException
3645
+	 * @throws EE_Error
3646
+	 */
3647
+	public function get_action_link_or_button(
3648
+		$action,
3649
+		$type = 'add',
3650
+		$extra_request = array(),
3651
+		$class = 'button-primary',
3652
+		$base_url = '',
3653
+		$exclude_nonce = false
3654
+	) {
3655
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3656
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3657
+			throw new EE_Error(
3658
+				sprintf(
3659
+					esc_html__(
3660
+						'There is no page route for given action for the button.  This action was given: %s',
3661
+						'event_espresso'
3662
+					),
3663
+					$action
3664
+				)
3665
+			);
3666
+		}
3667
+		if (! isset($this->_labels['buttons'][ $type ])) {
3668
+			throw new EE_Error(
3669
+				sprintf(
3670
+					__(
3671
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3672
+						'event_espresso'
3673
+					),
3674
+					$type
3675
+				)
3676
+			);
3677
+		}
3678
+		// finally check user access for this button.
3679
+		$has_access = $this->check_user_access($action, true);
3680
+		if (! $has_access) {
3681
+			return '';
3682
+		}
3683
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
3684
+		$query_args = array(
3685
+			'action' => $action,
3686
+		);
3687
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3688
+		if (! empty($extra_request)) {
3689
+			$query_args = array_merge($extra_request, $query_args);
3690
+		}
3691
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3692
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3693
+	}
3694
+
3695
+
3696
+	/**
3697
+	 * _per_page_screen_option
3698
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3699
+	 *
3700
+	 * @return void
3701
+	 * @throws InvalidArgumentException
3702
+	 * @throws InvalidInterfaceException
3703
+	 * @throws InvalidDataTypeException
3704
+	 */
3705
+	protected function _per_page_screen_option()
3706
+	{
3707
+		$option = 'per_page';
3708
+		$args = array(
3709
+			'label'   => apply_filters(
3710
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3711
+				$this->_admin_page_title,
3712
+				$this
3713
+			),
3714
+			'default' => (int) apply_filters(
3715
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3716
+				20
3717
+			),
3718
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3719
+		);
3720
+		// ONLY add the screen option if the user has access to it.
3721
+		if ($this->check_user_access($this->_current_view, true)) {
3722
+			add_screen_option($option, $args);
3723
+		}
3724
+	}
3725
+
3726
+
3727
+	/**
3728
+	 * set_per_page_screen_option
3729
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3730
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3731
+	 * admin_menu.
3732
+	 *
3733
+	 * @return void
3734
+	 */
3735
+	private function _set_per_page_screen_options()
3736
+	{
3737
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3738
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3739
+			if (! $user = wp_get_current_user()) {
3740
+				return;
3741
+			}
3742
+			$option = $_POST['wp_screen_options']['option'];
3743
+			$value = $_POST['wp_screen_options']['value'];
3744
+			if ($option != sanitize_key($option)) {
3745
+				return;
3746
+			}
3747
+			$map_option = $option;
3748
+			$option = str_replace('-', '_', $option);
3749
+			switch ($map_option) {
3750
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3751
+					$value = (int) $value;
3752
+					$max_value = apply_filters(
3753
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3754
+						999,
3755
+						$this->_current_page,
3756
+						$this->_current_view
3757
+					);
3758
+					if ($value < 1) {
3759
+						return;
3760
+					}
3761
+					$value = min($value, $max_value);
3762
+					break;
3763
+				default:
3764
+					$value = apply_filters(
3765
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3766
+						false,
3767
+						$option,
3768
+						$value
3769
+					);
3770
+					if (false === $value) {
3771
+						return;
3772
+					}
3773
+					break;
3774
+			}
3775
+			update_user_meta($user->ID, $option, $value);
3776
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3777
+			exit;
3778
+		}
3779
+	}
3780
+
3781
+
3782
+	/**
3783
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3784
+	 *
3785
+	 * @param array $data array that will be assigned to template args.
3786
+	 */
3787
+	public function set_template_args($data)
3788
+	{
3789
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3790
+	}
3791
+
3792
+
3793
+	/**
3794
+	 * This makes available the WP transient system for temporarily moving data between routes
3795
+	 *
3796
+	 * @param string $route             the route that should receive the transient
3797
+	 * @param array  $data              the data that gets sent
3798
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3799
+	 *                                  normal route transient.
3800
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3801
+	 *                                  when we are adding a transient before page_routes have been defined.
3802
+	 * @return void
3803
+	 * @throws EE_Error
3804
+	 */
3805
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3806
+	{
3807
+		$user_id = get_current_user_id();
3808
+		if (! $skip_route_verify) {
3809
+			$this->_verify_route($route);
3810
+		}
3811
+		// now let's set the string for what kind of transient we're setting
3812
+		$transient = $notices
3813
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3814
+			: 'rte_tx_' . $route . '_' . $user_id;
3815
+		$data = $notices ? array('notices' => $data) : $data;
3816
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3817
+		$existing = is_multisite() && is_network_admin()
3818
+			? get_site_transient($transient)
3819
+			: get_transient($transient);
3820
+		if ($existing) {
3821
+			$data = array_merge((array) $data, (array) $existing);
3822
+		}
3823
+		if (is_multisite() && is_network_admin()) {
3824
+			set_site_transient($transient, $data, 8);
3825
+		} else {
3826
+			set_transient($transient, $data, 8);
3827
+		}
3828
+	}
3829
+
3830
+
3831
+	/**
3832
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3833
+	 *
3834
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3835
+	 * @param string $route
3836
+	 * @return mixed data
3837
+	 */
3838
+	protected function _get_transient($notices = false, $route = '')
3839
+	{
3840
+		$user_id = get_current_user_id();
3841
+		$route = ! $route ? $this->_req_action : $route;
3842
+		$transient = $notices
3843
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3844
+			: 'rte_tx_' . $route . '_' . $user_id;
3845
+		$data = is_multisite() && is_network_admin()
3846
+			? get_site_transient($transient)
3847
+			: get_transient($transient);
3848
+		// delete transient after retrieval (just in case it hasn't expired);
3849
+		if (is_multisite() && is_network_admin()) {
3850
+			delete_site_transient($transient);
3851
+		} else {
3852
+			delete_transient($transient);
3853
+		}
3854
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3855
+	}
3856
+
3857
+
3858
+	/**
3859
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3860
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3861
+	 * default route callback on the EE_Admin page you want it run.)
3862
+	 *
3863
+	 * @return void
3864
+	 */
3865
+	protected function _transient_garbage_collection()
3866
+	{
3867
+		global $wpdb;
3868
+		// retrieve all existing transients
3869
+		$query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3870
+		if ($results = $wpdb->get_results($query)) {
3871
+			foreach ($results as $result) {
3872
+				$transient = str_replace('_transient_', '', $result->option_name);
3873
+				get_transient($transient);
3874
+				if (is_multisite() && is_network_admin()) {
3875
+					get_site_transient($transient);
3876
+				}
3877
+			}
3878
+		}
3879
+	}
3880
+
3881
+
3882
+	/**
3883
+	 * get_view
3884
+	 *
3885
+	 * @return string content of _view property
3886
+	 */
3887
+	public function get_view()
3888
+	{
3889
+		return $this->_view;
3890
+	}
3891
+
3892
+
3893
+	/**
3894
+	 * getter for the protected $_views property
3895
+	 *
3896
+	 * @return array
3897
+	 */
3898
+	public function get_views()
3899
+	{
3900
+		return $this->_views;
3901
+	}
3902
+
3903
+
3904
+	/**
3905
+	 * get_current_page
3906
+	 *
3907
+	 * @return string _current_page property value
3908
+	 */
3909
+	public function get_current_page()
3910
+	{
3911
+		return $this->_current_page;
3912
+	}
3913
+
3914
+
3915
+	/**
3916
+	 * get_current_view
3917
+	 *
3918
+	 * @return string _current_view property value
3919
+	 */
3920
+	public function get_current_view()
3921
+	{
3922
+		return $this->_current_view;
3923
+	}
3924
+
3925
+
3926
+	/**
3927
+	 * get_current_screen
3928
+	 *
3929
+	 * @return object The current WP_Screen object
3930
+	 */
3931
+	public function get_current_screen()
3932
+	{
3933
+		return $this->_current_screen;
3934
+	}
3935
+
3936
+
3937
+	/**
3938
+	 * get_current_page_view_url
3939
+	 *
3940
+	 * @return string This returns the url for the current_page_view.
3941
+	 */
3942
+	public function get_current_page_view_url()
3943
+	{
3944
+		return $this->_current_page_view_url;
3945
+	}
3946
+
3947
+
3948
+	/**
3949
+	 * just returns the _req_data property
3950
+	 *
3951
+	 * @return array
3952
+	 */
3953
+	public function get_request_data()
3954
+	{
3955
+		return $this->_req_data;
3956
+	}
3957
+
3958
+
3959
+	/**
3960
+	 * returns the _req_data protected property
3961
+	 *
3962
+	 * @return string
3963
+	 */
3964
+	public function get_req_action()
3965
+	{
3966
+		return $this->_req_action;
3967
+	}
3968
+
3969
+
3970
+	/**
3971
+	 * @return bool  value of $_is_caf property
3972
+	 */
3973
+	public function is_caf()
3974
+	{
3975
+		return $this->_is_caf;
3976
+	}
3977
+
3978
+
3979
+	/**
3980
+	 * @return mixed
3981
+	 */
3982
+	public function default_espresso_metaboxes()
3983
+	{
3984
+		return $this->_default_espresso_metaboxes;
3985
+	}
3986
+
3987
+
3988
+	/**
3989
+	 * @return mixed
3990
+	 */
3991
+	public function admin_base_url()
3992
+	{
3993
+		return $this->_admin_base_url;
3994
+	}
3995
+
3996
+
3997
+	/**
3998
+	 * @return mixed
3999
+	 */
4000
+	public function wp_page_slug()
4001
+	{
4002
+		return $this->_wp_page_slug;
4003
+	}
4004
+
4005
+
4006
+	/**
4007
+	 * updates  espresso configuration settings
4008
+	 *
4009
+	 * @param string                   $tab
4010
+	 * @param EE_Config_Base|EE_Config $config
4011
+	 * @param string                   $file file where error occurred
4012
+	 * @param string                   $func function  where error occurred
4013
+	 * @param string                   $line line no where error occurred
4014
+	 * @return boolean
4015
+	 */
4016
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4017
+	{
4018
+		// remove any options that are NOT going to be saved with the config settings.
4019
+		if (isset($config->core->ee_ueip_optin)) {
4020
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
4021
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4022
+			update_option('ee_ueip_has_notified', true);
4023
+		}
4024
+		// and save it (note we're also doing the network save here)
4025
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4026
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
4027
+		if ($config_saved && $net_saved) {
4028
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4029
+			return true;
4030
+		}
4031
+		EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4032
+		return false;
4033
+	}
4034
+
4035
+
4036
+	/**
4037
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4038
+	 *
4039
+	 * @return array
4040
+	 */
4041
+	public function get_yes_no_values()
4042
+	{
4043
+		return $this->_yes_no_values;
4044
+	}
4045
+
4046
+
4047
+	protected function _get_dir()
4048
+	{
4049
+		$reflector = new ReflectionClass(get_class($this));
4050
+		return dirname($reflector->getFileName());
4051
+	}
4052
+
4053
+
4054
+	/**
4055
+	 * A helper for getting a "next link".
4056
+	 *
4057
+	 * @param string $url   The url to link to
4058
+	 * @param string $class The class to use.
4059
+	 * @return string
4060
+	 */
4061
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4062
+	{
4063
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4064
+	}
4065
+
4066
+
4067
+	/**
4068
+	 * A helper for getting a "previous link".
4069
+	 *
4070
+	 * @param string $url   The url to link to
4071
+	 * @param string $class The class to use.
4072
+	 * @return string
4073
+	 */
4074
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4075
+	{
4076
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4077
+	}
4078
+
4079
+
4080
+
4081
+
4082
+
4083
+
4084
+
4085
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4086
+
4087
+
4088
+	/**
4089
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4090
+	 * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4091
+	 * _req_data array.
4092
+	 *
4093
+	 * @return bool success/fail
4094
+	 * @throws EE_Error
4095
+	 * @throws InvalidArgumentException
4096
+	 * @throws ReflectionException
4097
+	 * @throws InvalidDataTypeException
4098
+	 * @throws InvalidInterfaceException
4099
+	 */
4100
+	protected function _process_resend_registration()
4101
+	{
4102
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4103
+		do_action(
4104
+			'AHEE__EE_Admin_Page___process_resend_registration',
4105
+			$this->_template_args['success'],
4106
+			$this->_req_data
4107
+		);
4108
+		return $this->_template_args['success'];
4109
+	}
4110
+
4111
+
4112
+	/**
4113
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4114
+	 *
4115
+	 * @param \EE_Payment $payment
4116
+	 * @return bool success/fail
4117
+	 */
4118
+	protected function _process_payment_notification(EE_Payment $payment)
4119
+	{
4120
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4121
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4122
+		$this->_template_args['success'] = apply_filters(
4123
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4124
+			false,
4125
+			$payment
4126
+		);
4127
+		return $this->_template_args['success'];
4128
+	}
4129 4129
 }
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 . DS . 'notifications' . DS . '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 . DS . 'notifications' . DS . '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.