Completed
Branch BUG-10202-persistent-admin-not... (260a81)
by
unknown
12:43 queued 14s
created
4_5_0_stages/EE_DMS_4_5_0_invoice_settings.dmsstage.php 3 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
 		$invoice_settings = isset( EE_Config::instance()->gateway->payment_settings[ 'Invoice' ] ) ? EE_Config::instance()->gateway->payment_settings[ 'Invoice' ] : NULL;
65 65
 		if( ! $invoice_settings ){
66 66
 			$this->add_error( __( 'Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso' ) );
67
-		}else{
67
+		} else{
68 68
 			$invoice_settings[ 'template_payment_instructions' ] = $invoice_settings[ 'pdf_instructions' ];
69 69
 			$invoice_settings[ 'template_invoice_payee_name' ] = $invoice_settings[ 'payable_to' ];
70 70
 			$invoice_settings[ 'template_invoice_address' ] = $invoice_settings[ 'payment_address' ];
Please login to merge, or discard this patch.
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -51,15 +51,15 @@  discard block
 block discarded – undo
51 51
 
52 52
 
53 53
 
54
-    /**
55
-     *    _migration_step
56
-     *
57
-     * @access protected
58
-     * @param int $num_items
59
-     * @throws EE_Error
60
-     * @return int number of items ACTUALLY migrated
61
-     * @throws InvalidDataTypeException
62
-     */
54
+	/**
55
+	 *    _migration_step
56
+	 *
57
+	 * @access protected
58
+	 * @param int $num_items
59
+	 * @throws EE_Error
60
+	 * @return int number of items ACTUALLY migrated
61
+	 * @throws InvalidDataTypeException
62
+	 */
63 63
 	protected function _migration_step( $num_items = 1 ){
64 64
 		// if this isn't set then something is really wrong
65 65
 		if ( ! EE_Config::instance()->gateway instanceof EE_Gateway_Config ) {
@@ -86,29 +86,29 @@  discard block
 block discarded – undo
86 86
 			//update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code;
87 87
 			//also we don't want to build a dependency on the messages code because it is likely to change soon
88 88
 			if( ! in_array( $invoice_settings[ 'invoice_css' ], array( '', 'simple.css' ) ) ){
89
-                new PersistentAdminNotice(
90
-                    'invoice_css_not_updated',
91
-                    sprintf(
92
-                        esc_html__(
93
-                            'You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.',
94
-                            'event_espresso'
95
-                        ),
96
-                        $invoice_settings['invoice_css']
97
-                    )
98
-                );
89
+				new PersistentAdminNotice(
90
+					'invoice_css_not_updated',
91
+					sprintf(
92
+						esc_html__(
93
+							'You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.',
94
+							'event_espresso'
95
+						),
96
+						$invoice_settings['invoice_css']
97
+					)
98
+				);
99 99
 			}
100 100
 			$templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
101 101
 			$overridden_invoice_body = EEH_Template::locate_template( $templates_relative_path . 'invoice_body.template.php', NULL, FALSE, FALSE, TRUE );
102 102
 			$overridden_receipt_body= EEH_Template::locate_template( $templates_relative_path . 'receipt_body.template.php', NULL, FALSE, FALSE, TRUE );
103 103
 			if( $overridden_invoice_body || $overridden_receipt_body ) {
104
-                new PersistentAdminNotice(
105
-                    'invoice_overriding_templates',
106
-                    esc_html__(
107
-                        'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.',
108
-                        'event_espresso'
109
-                    ),
110
-                    true
111
-                );
104
+				new PersistentAdminNotice(
105
+					'invoice_overriding_templates',
106
+					esc_html__(
107
+						'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.',
108
+						'event_espresso'
109
+					),
110
+					true
111
+				);
112 112
 			}
113 113
 
114 114
 		}
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 * Just initializes the status of the migration
33 33
 	 */
34 34
 	public function __construct() {
35
-		$this->_pretty_name = __( 'Update Invoice Gateway Settings', 'event_espresso' );
35
+		$this->_pretty_name = __('Update Invoice Gateway Settings', 'event_espresso');
36 36
 		parent::__construct();
37 37
 	}
38 38
 
@@ -60,32 +60,32 @@  discard block
 block discarded – undo
60 60
      * @return int number of items ACTUALLY migrated
61 61
      * @throws InvalidDataTypeException
62 62
      */
63
-	protected function _migration_step( $num_items = 1 ){
63
+	protected function _migration_step($num_items = 1) {
64 64
 		// if this isn't set then something is really wrong
65
-		if ( ! EE_Config::instance()->gateway instanceof EE_Gateway_Config ) {
66
-			throw new EE_Error( __( 'It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso' ));
65
+		if ( ! EE_Config::instance()->gateway instanceof EE_Gateway_Config) {
66
+			throw new EE_Error(__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso'));
67 67
 		}
68
-		$invoice_settings = isset( EE_Config::instance()->gateway->payment_settings[ 'Invoice' ] ) ? EE_Config::instance()->gateway->payment_settings[ 'Invoice' ] : NULL;
69
-		if( ! $invoice_settings ){
70
-			$this->add_error( __( 'Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso' ) );
71
-		}else{
72
-			$invoice_settings[ 'template_payment_instructions' ] = $invoice_settings[ 'pdf_instructions' ];
73
-			$invoice_settings[ 'template_invoice_payee_name' ] = $invoice_settings[ 'payable_to' ];
74
-			$invoice_settings[ 'template_invoice_address' ] = $invoice_settings[ 'payment_address' ];
75
-			$invoice_settings[ 'template_invoice_email' ] = '';
76
-			$invoice_settings[ 'template_invoice_tax_number' ] = '';
77
-			unset( $invoice_settings[ 'pdf_instructions' ] );
78
-			unset( $invoice_settings[ 'payable_to' ] );
79
-			unset( $invoice_settings[ 'payment_address' ] );
80
-			EE_Config::instance()->gateway->payment_settings[ 'Invoice' ] = $invoice_settings;
81
-			EE_Config::instance()->update_espresso_config(false,false);
68
+		$invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : NULL;
69
+		if ( ! $invoice_settings) {
70
+			$this->add_error(__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso'));
71
+		} else {
72
+			$invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions'];
73
+			$invoice_settings['template_invoice_payee_name'] = $invoice_settings['payable_to'];
74
+			$invoice_settings['template_invoice_address'] = $invoice_settings['payment_address'];
75
+			$invoice_settings['template_invoice_email'] = '';
76
+			$invoice_settings['template_invoice_tax_number'] = '';
77
+			unset($invoice_settings['pdf_instructions']);
78
+			unset($invoice_settings['payable_to']);
79
+			unset($invoice_settings['payment_address']);
80
+			EE_Config::instance()->gateway->payment_settings['Invoice'] = $invoice_settings;
81
+			EE_Config::instance()->update_espresso_config(false, false);
82 82
 
83 83
 			//@todo: check 'invoice_css' too because we can't easily affect that so we might need to set a persistent notice
84 84
 			//(why is it tough to change? because we want to update the receipt and invoice message template, but
85 85
 			//message templates are only initialized AFTER migrations and those two are new in 4.5. So if we wanted to
86 86
 			//update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code;
87 87
 			//also we don't want to build a dependency on the messages code because it is likely to change soon
88
-			if( ! in_array( $invoice_settings[ 'invoice_css' ], array( '', 'simple.css' ) ) ){
88
+			if ( ! in_array($invoice_settings['invoice_css'], array('', 'simple.css'))) {
89 89
                 new PersistentAdminNotice(
90 90
                     'invoice_css_not_updated',
91 91
                     sprintf(
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
                 );
99 99
 			}
100 100
 			$templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
101
-			$overridden_invoice_body = EEH_Template::locate_template( $templates_relative_path . 'invoice_body.template.php', NULL, FALSE, FALSE, TRUE );
102
-			$overridden_receipt_body= EEH_Template::locate_template( $templates_relative_path . 'receipt_body.template.php', NULL, FALSE, FALSE, TRUE );
103
-			if( $overridden_invoice_body || $overridden_receipt_body ) {
101
+			$overridden_invoice_body = EEH_Template::locate_template($templates_relative_path.'invoice_body.template.php', NULL, FALSE, FALSE, TRUE);
102
+			$overridden_receipt_body = EEH_Template::locate_template($templates_relative_path.'receipt_body.template.php', NULL, FALSE, FALSE, TRUE);
103
+			if ($overridden_invoice_body || $overridden_receipt_body) {
104 104
                 new PersistentAdminNotice(
105 105
                     'invoice_overriding_templates',
106 106
                     esc_html__(
Please login to merge, or discard this patch.
core/domain/services/capabilities/RequiresCapCheckInterface.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -16,10 +16,10 @@
 block discarded – undo
16 16
 interface RequiresCapCheckInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @return CapCheckInterface
21
-     */
22
-    public function getCapCheck();
19
+	/**
20
+	 * @return CapCheckInterface
21
+	 */
22
+	public function getCapCheck();
23 23
 
24 24
 }
25 25
 // End of file RequiresCapCheckInterface.php
Please login to merge, or discard this patch.
espresso.php 2 patches
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php 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
-                ); ?>
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
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
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.3.9');
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
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.27.rc.003');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.27.rc.003');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -129,54 +129,54 @@  discard block
 block discarded – undo
129 129
         define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130 130
         define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131 131
         // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
132
+        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH.'admin_pages'.DS);
133
+        define('EE_CORE', EE_PLUGIN_DIR_PATH.'core'.DS);
134
+        define('EE_MODULES', EE_PLUGIN_DIR_PATH.'modules'.DS);
135
+        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH.'public'.DS);
136
+        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH.'shortcodes'.DS);
137
+        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH.'widgets'.DS);
138
+        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH.'payment_methods'.DS);
139
+        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH.'caffeinated'.DS);
140 140
         // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
141
+        define('EE_ADMIN', EE_CORE.'admin'.DS);
142
+        define('EE_CPTS', EE_CORE.'CPTs'.DS);
143
+        define('EE_CLASSES', EE_CORE.'db_classes'.DS);
144
+        define('EE_INTERFACES', EE_CORE.'interfaces'.DS);
145
+        define('EE_BUSINESS', EE_CORE.'business'.DS);
146
+        define('EE_MODELS', EE_CORE.'db_models'.DS);
147
+        define('EE_HELPERS', EE_CORE.'helpers'.DS);
148
+        define('EE_LIBRARIES', EE_CORE.'libraries'.DS);
149
+        define('EE_TEMPLATES', EE_CORE.'templates'.DS);
150
+        define('EE_THIRD_PARTY', EE_CORE.'third_party_libs'.DS);
151
+        define('EE_GLOBAL_ASSETS', EE_TEMPLATES.'global_assets'.DS);
152
+        define('EE_FORM_SECTIONS', EE_LIBRARIES.'form_sections'.DS);
153 153
         // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
154
+        define('EE_GATEWAYS', EE_MODULES.'gateways'.DS);
155
+        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules'.DS.'gateways'.DS);
156 156
         // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
157
+        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL.'core'.DS.'templates'.DS);
158
+        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL.'global_assets'.DS);
159
+        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL.'images'.DS);
160
+        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL.'core'.DS.'third_party_libs'.DS);
161
+        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL.'core/helpers/assets/');
162
+        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL.'core/libraries/');
163 163
         // define upload paths
164 164
         $uploads = wp_upload_dir();
165 165
         // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
166
+        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].DS.'espresso'.DS);
167
+        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].DS.'espresso'.DS);
168 168
         // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
169
+        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'].DS.'espresso'.DS.'templates'.DS);
170
+        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'].DS.'espresso'.DS.'templates'.DS);
171 171
         // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
172
+        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'].DS.'espresso'.DS.'gateways'.DS);
173
+        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'].DS.'espresso'.DS.'gateways'.DS);
174 174
         // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
175
+        define('EE_LANGUAGES_SAFE_LOC', '..'.DS.'uploads'.DS.'espresso'.DS.'languages'.DS);
176
+        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'languages'.DS);
177 177
         //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
178
+        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS)) {
179
+            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS);
180 180
         }
181 181
         //ajax constants
182 182
         define(
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
         //you're better to use this than its straight value (currently -1) in case you ever
192 192
         //want to change its default value! or find when -1 means infinity
193 193
         define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
194
+        define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX);
195 195
         define('EE_DEBUG', false);
196 196
         // for older WP versions
197 197
         if ( ! defined('MONTH_IN_SECONDS')) {
@@ -214,13 +214,13 @@  discard block
 block discarded – undo
214 214
         function espresso_load_error_handling()
215 215
         {
216 216
             // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
217
+            if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) {
218
+                require_once(EE_HELPERS.'EEH_Debug_Tools.helper.php');
219 219
                 EEH_Debug_Tools::instance();
220 220
             }
221 221
             // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
222
+            if (is_readable(EE_CORE.'EE_Error.core.php')) {
223
+                require_once(EE_CORE.'EE_Error.core.php');
224 224
             } else {
225 225
                 wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226 226
             }
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
             if (is_readable($full_path_to_file)) {
245 245
                 require_once($full_path_to_file);
246 246
             } else {
247
-                throw new EE_Error (
247
+                throw new EE_Error(
248 248
                         sprintf(
249 249
                                 esc_html__(
250 250
                                         'The %s class file could not be located or is not readable due to file permissions.',
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
             }
257 257
         }
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
259
+        espresso_load_required('EEH_Base', EE_CORE.'helpers'.DS.'EEH_Base.helper.php');
260
+        espresso_load_required('EEH_File', EE_CORE.'helpers'.DS.'EEH_File.helper.php');
261
+        espresso_load_required('EE_Bootstrap', EE_CORE.'EE_Bootstrap.core.php');
262 262
         new EE_Bootstrap();
263 263
     }
264 264
 }
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
     function espresso_deactivate_plugin($plugin_basename = '')
275 275
     {
276 276
         if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
277
+            require_once(ABSPATH.'wp-admin/includes/plugin.php');
278 278
         }
279 279
         unset($_GET['activate'], $_REQUEST['activate']);
280 280
         deactivate_plugins($plugin_basename);
Please login to merge, or discard this patch.
core/domain/services/capabilities/CapCheck.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
 
39 39
 
40 40
     /**
41
-     * @param string|array $capability   - the capability to be checked, like: 'ee_edit_registrations',
41
+     * @param string $capability   - the capability to be checked, like: 'ee_edit_registrations',
42 42
      *                                   or an array of capability strings
43 43
      * @param string       $context      - what the user is attempting to do, like: 'Edit Registration'
44 44
      * @param int          $ID           - (optional) ID for item where current_user_can is being called from
Please login to merge, or discard this patch.
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\exceptions\InvalidDataTypeException;
5 5
 
6 6
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -20,72 +20,72 @@  discard block
 block discarded – undo
20 20
 class CapCheck implements CapCheckInterface
21 21
 {
22 22
 
23
-    /**
24
-     * @var string|array $capability
25
-     */
26
-    private $capability;
27
-
28
-    /**
29
-     * @var string $context
30
-     */
31
-    private $context;
32
-
33
-    /**
34
-     * @var int|string $ID
35
-     */
36
-    private $ID;
37
-
38
-
39
-
40
-    /**
41
-     * @param string|array $capability   - the capability to be checked, like: 'ee_edit_registrations',
42
-     *                                   or an array of capability strings
43
-     * @param string       $context      - what the user is attempting to do, like: 'Edit Registration'
44
-     * @param int          $ID           - (optional) ID for item where current_user_can is being called from
45
-     * @throws InvalidDataTypeException
46
-     */
47
-    public function __construct($capability, $context, $ID = 0)
48
-    {
49
-        if ( ! (is_string($capability) || is_array($capability))) {
50
-            throw new InvalidDataTypeException('$capability', $capability, 'string or array');
51
-        }
52
-        if ( ! is_string($context)) {
53
-            throw new InvalidDataTypeException('$context', $context, 'string');
54
-        }
55
-        $this->capability = $capability;
56
-        $this->context = strtolower(str_replace(' ', '_', $context));
57
-        $this->ID = $ID;
58
-    }
59
-
60
-
61
-
62
-    /**
63
-     * @return string|array
64
-     */
65
-    public function capability()
66
-    {
67
-        return $this->capability;
68
-    }
69
-
70
-
71
-
72
-    /**
73
-     * @return string
74
-     */
75
-    public function context()
76
-    {
77
-        return $this->context;
78
-    }
79
-
80
-
81
-
82
-    /**
83
-     * @return int|string
84
-     */
85
-    public function ID()
86
-    {
87
-        return $this->ID;
88
-    }
23
+	/**
24
+	 * @var string|array $capability
25
+	 */
26
+	private $capability;
27
+
28
+	/**
29
+	 * @var string $context
30
+	 */
31
+	private $context;
32
+
33
+	/**
34
+	 * @var int|string $ID
35
+	 */
36
+	private $ID;
37
+
38
+
39
+
40
+	/**
41
+	 * @param string|array $capability   - the capability to be checked, like: 'ee_edit_registrations',
42
+	 *                                   or an array of capability strings
43
+	 * @param string       $context      - what the user is attempting to do, like: 'Edit Registration'
44
+	 * @param int          $ID           - (optional) ID for item where current_user_can is being called from
45
+	 * @throws InvalidDataTypeException
46
+	 */
47
+	public function __construct($capability, $context, $ID = 0)
48
+	{
49
+		if ( ! (is_string($capability) || is_array($capability))) {
50
+			throw new InvalidDataTypeException('$capability', $capability, 'string or array');
51
+		}
52
+		if ( ! is_string($context)) {
53
+			throw new InvalidDataTypeException('$context', $context, 'string');
54
+		}
55
+		$this->capability = $capability;
56
+		$this->context = strtolower(str_replace(' ', '_', $context));
57
+		$this->ID = $ID;
58
+	}
59
+
60
+
61
+
62
+	/**
63
+	 * @return string|array
64
+	 */
65
+	public function capability()
66
+	{
67
+		return $this->capability;
68
+	}
69
+
70
+
71
+
72
+	/**
73
+	 * @return string
74
+	 */
75
+	public function context()
76
+	{
77
+		return $this->context;
78
+	}
79
+
80
+
81
+
82
+	/**
83
+	 * @return int|string
84
+	 */
85
+	public function ID()
86
+	{
87
+		return $this->ID;
88
+	}
89 89
 
90 90
 
91 91
 }
Please login to merge, or discard this patch.
core/EE_Error.core.php 4 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	/**
97 97
 	 *    error_handler
98 98
 	 * @access public
99
-	 * @param $code
99
+	 * @param integer $code
100 100
 	 * @param $message
101 101
 	 * @param $file
102 102
 	 * @param $line
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	/**
198 198
 	 *    _format_error
199 199
 	 * @access private
200
-	 * @param $code
200
+	 * @param string $code
201 201
 	 * @param $message
202 202
 	 * @param $file
203 203
 	 * @param $line
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 	/**
232 232
 	*	_add_actions
233 233
 	*	@access public
234
-	*	@return void
234
+	*	@return string|null
235 235
 	*/
236 236
     public function get_error() {
237 237
 
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
 	 *
908 908
 	 * @access 	public
909 909
 	 * @param 	bool $force_print
910
-	 * @return 	void
910
+	 * @return 	null|string
911 911
 	 */
912 912
 	private static function _print_scripts( $force_print = FALSE ) {
913 913
 		if (( did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' )) && ! $force_print ) {
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
 
1057 1057
 	/**
1058 1058
 	 * Like get_notices, but returns an array of all the notices of the given type.
1059
-	 * @return array {
1059
+	 * @return boolean {
1060 1060
 	 *	@type array $success all the success messages
1061 1061
 	 *	@type array $errors all the error messages
1062 1062
 	 *	@type array $attention all the attention messages
Please login to merge, or discard this patch.
Indentation   +263 added lines, -263 removed lines patch added patch discarded remove patch
@@ -26,52 +26,52 @@  discard block
 block discarded – undo
26 26
 
27 27
 
28 28
 	/**
29
-	* 	name of the file to log exceptions to
30
-	* 	@access	private
31
-    *	@var string
32
-	*/
29
+	 * 	name of the file to log exceptions to
30
+	 * 	@access	private
31
+	 *	@var string
32
+	 */
33 33
 	private static $_exception_log_file = 'espresso_error_log.txt';
34 34
 
35 35
 	/**
36
-	* 	the exception
37
-	* 	@access	private
38
-    *	@var object
39
-	*/
36
+	 * 	the exception
37
+	 * 	@access	private
38
+	 *	@var object
39
+	 */
40 40
 	private $_exception;
41 41
 
42 42
 	/**
43
-	* 	stores details for all exception
44
-	* 	@access	private
45
-    *	@var array
46
-	*/
43
+	 * 	stores details for all exception
44
+	 * 	@access	private
45
+	 *	@var array
46
+	 */
47 47
 	private static $_all_exceptions = array();
48 48
 
49 49
 	/**
50
-	* 	tracks number of errors
51
-	* 	@access	private
52
-    *	@var int
53
-	*/
50
+	 * 	tracks number of errors
51
+	 * 	@access	private
52
+	 *	@var int
53
+	 */
54 54
 	private static $_error_count = 0;
55 55
 
56 56
 	/**
57
-	* 	has JS been loaded ?
58
-	* 	@access	private
59
-    *	@var boolean
60
-	*/
57
+	 * 	has JS been loaded ?
58
+	 * 	@access	private
59
+	 *	@var boolean
60
+	 */
61 61
 	private static $_js_loaded = FALSE;
62 62
 
63 63
 	/**
64
-	* 	has shutdown action been added ?
65
-	* 	@access	private
66
-    *	@var boolean
67
-	*/
64
+	 * 	has shutdown action been added ?
65
+	 * 	@access	private
66
+	 *	@var boolean
67
+	 */
68 68
 	private static $_action_added = FALSE;
69 69
 
70 70
 	/**
71
-	* 	has shutdown action been added ?
72
-	* 	@access	private
73
-    *	@var boolean
74
-	*/
71
+	 * 	has shutdown action been added ?
72
+	 * 	@access	private
73
+	 *	@var boolean
74
+	 */
75 75
 	private static $_espresso_notices = array( 'success' => FALSE, 'errors' => FALSE, 'attention' => FALSE );
76 76
 
77 77
 
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
 
80 80
 
81 81
 	/**
82
-	*	@override default exception handling
83
-	*	@access public
84
-	*	@echo string
85
-	*/
82
+	 *	@override default exception handling
83
+	 *	@access public
84
+	 *	@echo string
85
+	 */
86 86
 	function __construct( $message, $code = 0, Exception $previous = NULL ) {
87 87
 		if ( version_compare( phpversion(), '5.3.0', '<' )) {
88 88
 			parent::__construct( $message, $code );
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
 
182 182
 
183 183
 	/**
184
-	*	fatal_error_handler
185
-	*	@access public
186
-	*	@return void
187
-	*/
184
+	 *	fatal_error_handler
185
+	 *	@access public
186
+	 *	@return void
187
+	 */
188 188
 	public static function fatal_error_handler() {
189 189
 		$last_error = error_get_last();
190 190
 		if ( $last_error['type'] === E_ERROR ) {
@@ -229,11 +229,11 @@  discard block
 block discarded – undo
229 229
 
230 230
 
231 231
 	/**
232
-	*	_add_actions
233
-	*	@access public
234
-	*	@return void
235
-	*/
236
-    public function get_error() {
232
+	 *	_add_actions
233
+	 *	@access public
234
+	 *	@return void
235
+	 */
236
+	public function get_error() {
237 237
 
238 238
 		if( apply_filters( 'FHEE__EE_Error__get_error__show_normal_exceptions', FALSE ) ){
239 239
 			throw $this;
@@ -262,37 +262,37 @@  discard block
 block discarded – undo
262 262
 
263 263
 
264 264
 
265
-    /**
266
-     *    has_error
267
-     *
268
-     * @access public
269
-     * @param bool   $check_stored
270
-     * @param string $type_to_check
271
-     * @return bool
272
-     */
273
-    public static function has_error( $check_stored = false, $type_to_check = 'errors' ){
274
-	    $has_error = isset(self::$_espresso_notices[$type_to_check]) && ! empty(self::$_espresso_notices[$type_to_check])
275
-            ? true
276
-            : false;
277
-	    if ( $check_stored && ! $has_error ) {
278
-		    $notices = (array) get_option( 'ee_notices', array() );
279
-		    foreach ( $notices as $type => $notice ) {
280
-			    if ( $type === $type_to_check && $notice ) {
281
-				    return true;
282
-			    }
283
-		    }
284
-	    }
285
-	    return $has_error;
286
-    }
265
+	/**
266
+	 *    has_error
267
+	 *
268
+	 * @access public
269
+	 * @param bool   $check_stored
270
+	 * @param string $type_to_check
271
+	 * @return bool
272
+	 */
273
+	public static function has_error( $check_stored = false, $type_to_check = 'errors' ){
274
+		$has_error = isset(self::$_espresso_notices[$type_to_check]) && ! empty(self::$_espresso_notices[$type_to_check])
275
+			? true
276
+			: false;
277
+		if ( $check_stored && ! $has_error ) {
278
+			$notices = (array) get_option( 'ee_notices', array() );
279
+			foreach ( $notices as $type => $notice ) {
280
+				if ( $type === $type_to_check && $notice ) {
281
+					return true;
282
+				}
283
+			}
284
+		}
285
+		return $has_error;
286
+	}
287 287
 
288 288
 
289 289
 
290 290
 	/**
291
-	*	display_errors
292
-	*	@access public
293
-	*	@echo string
294
-	*/
295
-    public function display_errors(){
291
+	 *	display_errors
292
+	 *	@access public
293
+	 *	@echo string
294
+	 */
295
+	public function display_errors(){
296 296
 
297 297
 		$trace_details = '';
298 298
 
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
 			// process trace info
365 365
 			if ( empty( $ex['trace'] )) {
366 366
 
367
-	            $trace_details .= __( 'Sorry, but no trace information was available for this exception.', 'event_espresso' );
367
+				$trace_details .= __( 'Sorry, but no trace information was available for this exception.', 'event_espresso' );
368 368
 
369 369
 			} else {
370 370
 
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 					$function_dsply = ! empty( $function ) ? $function : '&nbsp;';
417 417
 					$args_dsply = ! empty( $args ) ? '( ' . $args . ' )' : '';
418 418
 
419
-		              $trace_details .= '
419
+					  $trace_details .= '
420 420
 					<tr>
421 421
 						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
422 422
 						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 
429 429
 				}
430 430
 
431
-	            $trace_details .= '
431
+				$trace_details .= '
432 432
 			 </table>
433 433
 			</div>';
434 434
 
@@ -508,12 +508,12 @@  discard block
 block discarded – undo
508 508
 
509 509
 
510 510
 	/**
511
-	*	generate string from exception trace args
512
-	*
513
-	*	@access private
514
-	*	@ param array $arguments
515
-	*	@ return string
516
-	*/
511
+	 *	generate string from exception trace args
512
+	 *
513
+	 *	@access private
514
+	 *	@ param array $arguments
515
+	 *	@ return string
516
+	 */
517 517
 	private function _convert_args_to_string ( $arguments = array(), $array = FALSE ) {
518 518
 
519 519
 		$arg_string = '';
@@ -557,15 +557,15 @@  discard block
 block discarded – undo
557 557
 
558 558
 
559 559
 	/**
560
-	* 	add error message
561
-	*
562
-	*	@access public
563
-	* 	@param		string		$msg	the message to display to users or developers - adding a double pipe || (OR) creates separate messages for user || dev
564
-	* 	@param		string		$file		the file that the error occurred in - just use __FILE__
565
-	* 	@param		string		$func	the function/method that the error occurred in - just use __FUNCTION__
566
-	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
567
-	* 	@return 		void
568
-	*/
560
+	 * 	add error message
561
+	 *
562
+	 *	@access public
563
+	 * 	@param		string		$msg	the message to display to users or developers - adding a double pipe || (OR) creates separate messages for user || dev
564
+	 * 	@param		string		$file		the file that the error occurred in - just use __FILE__
565
+	 * 	@param		string		$func	the function/method that the error occurred in - just use __FUNCTION__
566
+	 * 	@param		string		$line	the line number where the error occurred - just use __LINE__
567
+	 * 	@return 		void
568
+	 */
569 569
 	public static function add_error( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
570 570
 		self::_add_notice ( 'errors', $msg, $file, $func, $line );
571 571
 		self::$_error_count++;
@@ -593,15 +593,15 @@  discard block
 block discarded – undo
593 593
 
594 594
 
595 595
 	/**
596
-	* 	add success message
597
-	*
598
-	*	@access public
599
-	* 	@param		string		$msg	the message to display to users or developers - adding a double pipe || (OR) creates separate messages for user || dev
600
-	* 	@param		string		$file		the file that the error occurred in - just use __FILE__
601
-	* 	@param		string		$func	the function/method that the error occurred in - just use __FUNCTION__
602
-	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
603
-	* 	@return 		void
604
-	*/
596
+	 * 	add success message
597
+	 *
598
+	 *	@access public
599
+	 * 	@param		string		$msg	the message to display to users or developers - adding a double pipe || (OR) creates separate messages for user || dev
600
+	 * 	@param		string		$file		the file that the error occurred in - just use __FILE__
601
+	 * 	@param		string		$func	the function/method that the error occurred in - just use __FUNCTION__
602
+	 * 	@param		string		$line	the line number where the error occurred - just use __LINE__
603
+	 * 	@return 		void
604
+	 */
605 605
 	public static function add_success( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
606 606
 		self::_add_notice ( 'success', $msg, $file, $func, $line );
607 607
 	}
@@ -611,15 +611,15 @@  discard block
 block discarded – undo
611 611
 
612 612
 
613 613
 	/**
614
-	* 	add attention message
615
-	*
616
-	*	@access public
617
-	* 	@param		string		$msg	the message to display to users or developers - adding a double pipe || (OR) creates separate messages for user || dev
618
-	* 	@param		string		$file		the file that the error occurred in - just use __FILE__
619
-	* 	@param		string		$func	the function/method that the error occurred in - just use __FUNCTION__
620
-	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
621
-	* 	@return 		void
622
-	*/
614
+	 * 	add attention message
615
+	 *
616
+	 *	@access public
617
+	 * 	@param		string		$msg	the message to display to users or developers - adding a double pipe || (OR) creates separate messages for user || dev
618
+	 * 	@param		string		$file		the file that the error occurred in - just use __FILE__
619
+	 * 	@param		string		$func	the function/method that the error occurred in - just use __FUNCTION__
620
+	 * 	@param		string		$line	the line number where the error occurred - just use __LINE__
621
+	 * 	@return 		void
622
+	 */
623 623
 	public static function add_attention( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
624 624
 		self::_add_notice ( 'attention', $msg, $file, $func, $line );
625 625
 	}
@@ -629,16 +629,16 @@  discard block
 block discarded – undo
629 629
 
630 630
 
631 631
 	/**
632
-	* 	add success message
633
-	*
634
-	*	@access public
635
-	* 	@param		string		$type	whether the message is for a success or error notification
636
-	* 	@param		string		$msg	the message to display to users or developers - adding a double pipe || (OR) creates separate messages for user || dev
637
-	* 	@param		string		$file		the file that the error occurred in - just use __FILE__
638
-	* 	@param		string		$func	the function/method that the error occurred in - just use __FUNCTION__
639
-	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
640
-	* 	@return 		void
641
-	*/
632
+	 * 	add success message
633
+	 *
634
+	 *	@access public
635
+	 * 	@param		string		$type	whether the message is for a success or error notification
636
+	 * 	@param		string		$msg	the message to display to users or developers - adding a double pipe || (OR) creates separate messages for user || dev
637
+	 * 	@param		string		$file		the file that the error occurred in - just use __FILE__
638
+	 * 	@param		string		$func	the function/method that the error occurred in - just use __FUNCTION__
639
+	 * 	@param		string		$line	the line number where the error occurred - just use __LINE__
640
+	 * 	@return 		void
641
+	 */
642 642
 	private static function _add_notice( $type = 'success', $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
643 643
 		if ( empty( $msg )) {
644 644
 			EE_Error::doing_it_wrong(
@@ -697,11 +697,11 @@  discard block
 block discarded – undo
697 697
 
698 698
 
699 699
 	/**
700
-	* 	in some case it may be necessary to overwrite the existing success messages
701
-	*
702
-	*	@access public
703
-	* 	@return 		void
704
-	*/
700
+	 * 	in some case it may be necessary to overwrite the existing success messages
701
+	 *
702
+	 *	@access public
703
+	 * 	@return 		void
704
+	 */
705 705
 	public static function overwrite_success() {
706 706
 		self::$_espresso_notices['success'] = FALSE;
707 707
 	}
@@ -711,11 +711,11 @@  discard block
 block discarded – undo
711 711
 
712 712
 
713 713
 	/**
714
-	* 	in some case it may be necessary to overwrite the existing attention messages
715
-	*
716
-	*	@access public
717
-	* 	@return 		void
718
-	*/
714
+	 * 	in some case it may be necessary to overwrite the existing attention messages
715
+	 *
716
+	 *	@access public
717
+	 * 	@return 		void
718
+	 */
719 719
 	public static function overwrite_attention() {
720 720
 		self::$_espresso_notices['attention'] = FALSE;
721 721
 	}
@@ -725,11 +725,11 @@  discard block
 block discarded – undo
725 725
 
726 726
 
727 727
 	/**
728
-	* 	in some case it may be necessary to overwrite the existing error messages
729
-	*
730
-	*	@access public
731
-	* 	@return 		void
732
-	*/
728
+	 * 	in some case it may be necessary to overwrite the existing error messages
729
+	 *
730
+	 *	@access public
731
+	 * 	@return 		void
732
+	 */
733 733
 	public static function overwrite_errors() {
734 734
 		self::$_espresso_notices['errors'] = FALSE;
735 735
 	}
@@ -737,24 +737,24 @@  discard block
 block discarded – undo
737 737
 
738 738
 
739 739
 	/**
740
-	*	reset_notices
741
-	*	@access private
742
-	*	@return void
743
-	*/
740
+	 *	reset_notices
741
+	 *	@access private
742
+	 *	@return void
743
+	 */
744 744
 	public static function reset_notices(){
745
-    	self::$_espresso_notices['success'] = FALSE;
746
-    	self::$_espresso_notices['attention'] = FALSE;
747
-    	self::$_espresso_notices['errors'] = FALSE;
748
-    }
745
+		self::$_espresso_notices['success'] = FALSE;
746
+		self::$_espresso_notices['attention'] = FALSE;
747
+		self::$_espresso_notices['errors'] = FALSE;
748
+	}
749 749
 
750 750
 
751 751
 
752 752
 	/**
753
-	*	has_errors
754
-	*	@access public
755
-	*	@return int
756
-	*/
757
-    public static function has_notices(){
753
+	 *	has_errors
754
+	 *	@access public
755
+	 *	@return int
756
+	 */
757
+	public static function has_notices(){
758 758
 		$has_notices = 0;
759 759
 		// check for success messages
760 760
 		$has_notices = self::$_espresso_notices['success'] && ! empty(  self::$_espresso_notices['success'] ) ? 3 : $has_notices;
@@ -785,15 +785,15 @@  discard block
 block discarded – undo
785 785
 
786 786
 
787 787
 	/**
788
-	* 	compile all error or success messages into one string
789
-	*	@see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
790
-	*
791
-	*	@access public
792
-	* 	@param		boolean		$format_output		whether or not to format the messages for display in the WP admin
793
-	* 	@param		boolean		$save_to_transient	whether or not to save notices to the db for retrieval on next request - ONLY do this just before redirecting
794
-	* 	@param		boolean		$remove_empty		whether or not to unset empty messages
795
-	* 	@return 		array
796
-	*/
788
+	 * 	compile all error or success messages into one string
789
+	 *	@see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
790
+	 *
791
+	 *	@access public
792
+	 * 	@param		boolean		$format_output		whether or not to format the messages for display in the WP admin
793
+	 * 	@param		boolean		$save_to_transient	whether or not to save notices to the db for retrieval on next request - ONLY do this just before redirecting
794
+	 * 	@param		boolean		$remove_empty		whether or not to unset empty messages
795
+	 * 	@return 		array
796
+	 */
797 797
 	public static function get_notices( $format_output = TRUE, $save_to_transient = FALSE, $remove_empty = TRUE ) {
798 798
 		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
799 799
 
@@ -941,11 +941,11 @@  discard block
 block discarded – undo
941 941
 
942 942
 
943 943
 	/**
944
-	* 	enqueue_error_scripts
945
-	*
946
-	*	@access public
947
-	* 	@return 		void
948
-	*/
944
+	 * 	enqueue_error_scripts
945
+	 *
946
+	 *	@access public
947
+	 * 	@return 		void
948
+	 */
949 949
 	public static function enqueue_error_scripts() {
950 950
 		self::_print_scripts();
951 951
 	}
@@ -953,15 +953,15 @@  discard block
 block discarded – undo
953 953
 
954 954
 
955 955
 	/**
956
-	*	create error code from filepath, function name,
957
-	*	and line number where exception or error was thrown
958
-	*
959
-	*	@access public
960
-	*	@param string $file
961
-	*	@param string $func
962
-	*	@param string $line
963
-	*	@return string
964
-	*/
956
+	 *	create error code from filepath, function name,
957
+	 *	and line number where exception or error was thrown
958
+	 *
959
+	 *	@access public
960
+	 *	@param string $file
961
+	 *	@param string $func
962
+	 *	@param string $line
963
+	 *	@return string
964
+	 */
965 965
 	public static function generate_error_code ( $file = '', $func = '', $line = '' ) {
966 966
 		$file = explode( '.', basename( $file ));
967 967
 		$error_code = ! empty( $file[0] ) ? $file[0] : '';
@@ -975,13 +975,13 @@  discard block
 block discarded – undo
975 975
 
976 976
 
977 977
 	/**
978
-	*	write exception details to log file
979
-	*
980
-	*	@access public
981
-	*	@ param timestamp $time
982
-	*	@ param object $ex
983
-	*	@ return void
984
-	*/
978
+	 *	write exception details to log file
979
+	 *
980
+	 *	@access public
981
+	 *	@ param timestamp $time
982
+	 *	@ param object $ex
983
+	 *	@ return void
984
+	 */
985 985
 	public function write_to_error_log ( $time = FALSE, $ex = FALSE, $clear = FALSE ) {
986 986
 
987 987
 		if ( ! $ex ) {
@@ -1068,97 +1068,97 @@  discard block
 block discarded – undo
1068 1068
 
1069 1069
 
1070 1070
 
1071
-    /**
1072
-     * @deprecated 4.9.27
1073
-     * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1074
-     * @param string $pan_message  the message to be stored persistently until dismissed
1075
-     * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1076
-     * @return void
1077
-     * @throws InvalidDataTypeException
1078
-     */
1079
-    public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1080
-    {
1081
-        new PersistentAdminNotice(
1082
-            $pan_name,
1083
-            $pan_message,
1084
-            $force_update
1085
-        );
1086
-        EE_Error::doing_it_wrong(
1087
-            __METHOD__,
1088
-            sprintf(
1089
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1090
-                '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1091
-            ),
1092
-            '4.9.27'
1093
-        );
1094
-    }
1095
-
1096
-
1097
-
1098
-    /**
1099
-     * @deprecated 4.9.27
1100
-     * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1101
-     * @param bool   $purge
1102
-     * @param bool   $return
1103
-     * @throws DomainException
1104
-     * @throws InvalidInterfaceException
1105
-     * @throws InvalidDataTypeException
1106
-     * @throws ServiceNotFoundException
1107
-     */
1108
-    public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1109
-    {
1110
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1111
-        $persistent_admin_notice_manager = CoffeeMill::getService(
1112
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1113
-        );
1114
-        $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1115
-        EE_Error::doing_it_wrong(
1116
-            __METHOD__,
1117
-            sprintf(
1118
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1119
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1120
-            ),
1121
-            '4.9.27'
1122
-        );
1123
-    }
1124
-
1125
-
1126
-
1127
-    /**
1128
-     * @deprecated 4.9.27
1129
-     * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1130
-     * @param  string $pan_message the message to be stored persistently until dismissed
1131
-     * @param  string $return_url  URL to go back to after nag notice is dismissed
1132
-     */
1133
-    public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1134
-    {
1135
-        EE_Error::doing_it_wrong(
1136
-            __METHOD__,
1137
-            sprintf(
1138
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1139
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1140
-            ),
1141
-            '4.9.27'
1142
-        );
1143
-    }
1144
-
1145
-
1146
-
1147
-    /**
1148
-     * @deprecated 4.9.27
1149
-     * @param string $return_url
1150
-     */
1151
-    public static function get_persistent_admin_notices($return_url = '')
1152
-    {
1153
-        EE_Error::doing_it_wrong(
1154
-            __METHOD__,
1155
-            sprintf(
1156
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1157
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1158
-            ),
1159
-            '4.9.27'
1160
-        );
1161
-    }
1071
+	/**
1072
+	 * @deprecated 4.9.27
1073
+	 * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1074
+	 * @param string $pan_message  the message to be stored persistently until dismissed
1075
+	 * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1076
+	 * @return void
1077
+	 * @throws InvalidDataTypeException
1078
+	 */
1079
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1080
+	{
1081
+		new PersistentAdminNotice(
1082
+			$pan_name,
1083
+			$pan_message,
1084
+			$force_update
1085
+		);
1086
+		EE_Error::doing_it_wrong(
1087
+			__METHOD__,
1088
+			sprintf(
1089
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1090
+				'\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1091
+			),
1092
+			'4.9.27'
1093
+		);
1094
+	}
1095
+
1096
+
1097
+
1098
+	/**
1099
+	 * @deprecated 4.9.27
1100
+	 * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1101
+	 * @param bool   $purge
1102
+	 * @param bool   $return
1103
+	 * @throws DomainException
1104
+	 * @throws InvalidInterfaceException
1105
+	 * @throws InvalidDataTypeException
1106
+	 * @throws ServiceNotFoundException
1107
+	 */
1108
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1109
+	{
1110
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1111
+		$persistent_admin_notice_manager = CoffeeMill::getService(
1112
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1113
+		);
1114
+		$persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1115
+		EE_Error::doing_it_wrong(
1116
+			__METHOD__,
1117
+			sprintf(
1118
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1119
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1120
+			),
1121
+			'4.9.27'
1122
+		);
1123
+	}
1124
+
1125
+
1126
+
1127
+	/**
1128
+	 * @deprecated 4.9.27
1129
+	 * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1130
+	 * @param  string $pan_message the message to be stored persistently until dismissed
1131
+	 * @param  string $return_url  URL to go back to after nag notice is dismissed
1132
+	 */
1133
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1134
+	{
1135
+		EE_Error::doing_it_wrong(
1136
+			__METHOD__,
1137
+			sprintf(
1138
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1139
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1140
+			),
1141
+			'4.9.27'
1142
+		);
1143
+	}
1144
+
1145
+
1146
+
1147
+	/**
1148
+	 * @deprecated 4.9.27
1149
+	 * @param string $return_url
1150
+	 */
1151
+	public static function get_persistent_admin_notices($return_url = '')
1152
+	{
1153
+		EE_Error::doing_it_wrong(
1154
+			__METHOD__,
1155
+			sprintf(
1156
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1157
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1158
+			),
1159
+			'4.9.27'
1160
+		);
1161
+	}
1162 1162
 
1163 1163
 
1164 1164
 
Please login to merge, or discard this patch.
Spacing   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -8,9 +8,9 @@  discard block
 block discarded – undo
8 8
 
9 9
 if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
10 10
 // if you're a dev and want to receive all errors via email add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
11
-if ( defined( 'WP_DEBUG' ) && WP_DEBUG === TRUE && defined( 'EE_ERROR_EMAILS' ) && EE_ERROR_EMAILS === TRUE ) {
12
-	set_error_handler( array( 'EE_Error', 'error_handler' ));
13
-	register_shutdown_function( array( 'EE_Error', 'fatal_error_handler' ));
11
+if (defined('WP_DEBUG') && WP_DEBUG === TRUE && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === TRUE) {
12
+	set_error_handler(array('EE_Error', 'error_handler'));
13
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
14 14
 }
15 15
 /**
16 16
  *
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	* 	@access	private
73 73
     *	@var boolean
74 74
 	*/
75
-	private static $_espresso_notices = array( 'success' => FALSE, 'errors' => FALSE, 'attention' => FALSE );
75
+	private static $_espresso_notices = array('success' => FALSE, 'errors' => FALSE, 'attention' => FALSE);
76 76
 
77 77
 
78 78
 
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 	*	@access public
84 84
 	*	@echo string
85 85
 	*/
86
-	function __construct( $message, $code = 0, Exception $previous = NULL ) {
87
-		if ( version_compare( phpversion(), '5.3.0', '<' )) {
88
-			parent::__construct( $message, $code );
86
+	function __construct($message, $code = 0, Exception $previous = NULL) {
87
+		if (version_compare(phpversion(), '5.3.0', '<')) {
88
+			parent::__construct($message, $code);
89 89
 		} else {
90
-			parent::__construct( $message, $code, $previous );
90
+			parent::__construct($message, $code, $previous);
91 91
 		}
92 92
 	}
93 93
 
@@ -102,10 +102,10 @@  discard block
 block discarded – undo
102 102
 	 * @param $line
103 103
 	 * @return void
104 104
 	 */
105
-	public static function error_handler( $code, $message, $file, $line ) {
106
-		$type = EE_Error::error_type( $code );
105
+	public static function error_handler($code, $message, $file, $line) {
106
+		$type = EE_Error::error_type($code);
107 107
 		$site = site_url();
108
-		switch ( $site ) {
108
+		switch ($site) {
109 109
 			case 'http://ee4.eventespresso.com/' :
110 110
 			case 'http://ee4decaf.eventespresso.com/' :
111 111
 			case 'http://ee4hf.eventespresso.com/' :
@@ -118,16 +118,16 @@  discard block
 block discarded – undo
118 118
 				$to = '[email protected]';
119 119
 				break;
120 120
 			default :
121
-				$to = get_option( 'admin_email' );
121
+				$to = get_option('admin_email');
122 122
 		}
123
-		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
124
-		$msg = EE_Error::_format_error( $type, $message, $file, $line );
125
-		if ( function_exists( 'wp_mail' )) {
126
-			add_filter( 'wp_mail_content_type', array( 'EE_Error', 'set_content_type' ));
127
-			wp_mail( $to, $subject, $msg );
123
+		$subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url();
124
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
125
+		if (function_exists('wp_mail')) {
126
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
127
+			wp_mail($to, $subject, $msg);
128 128
 		}
129 129
 		echo '<div id="message" class="espresso-notices error"><p>';
130
-		echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
130
+		echo $type.': '.$message.'<br />'.$file.' line '.$line;
131 131
 		echo '<br /></p></div>';
132 132
 	}
133 133
 
@@ -140,8 +140,8 @@  discard block
 block discarded – undo
140 140
 	 * @param $code
141 141
 	 * @return string
142 142
 	 */
143
-	public static function error_type( $code ) {
144
-		switch( $code ) {
143
+	public static function error_type($code) {
144
+		switch ($code) {
145 145
 			case E_ERROR: // 1 //
146 146
 			return 'E_ERROR';
147 147
 			case E_WARNING: // 2 //
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
 	*/
188 188
 	public static function fatal_error_handler() {
189 189
 		$last_error = error_get_last();
190
-		if ( $last_error['type'] === E_ERROR ) {
191
-			EE_Error::error_handler( E_ERROR, $last_error['message'], $last_error['file'], $last_error['line'] );
190
+		if ($last_error['type'] === E_ERROR) {
191
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
192 192
 		}
193 193
 	}
194 194
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	 * @param $line
204 204
 	 * @return string
205 205
 	 */
206
-	private static function _format_error( $code, $message, $file, $line ) {
206
+	private static function _format_error($code, $message, $file, $line) {
207 207
 		$html  = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
208 208
 		$html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
209 209
 		$html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 	 * @param $content_type
222 222
 	 * @return string
223 223
 	 */
224
-	public static function set_content_type( $content_type ) {
224
+	public static function set_content_type($content_type) {
225 225
 		return 'text/html';
226 226
 	}
227 227
 
@@ -235,24 +235,24 @@  discard block
 block discarded – undo
235 235
 	*/
236 236
     public function get_error() {
237 237
 
238
-		if( apply_filters( 'FHEE__EE_Error__get_error__show_normal_exceptions', FALSE ) ){
238
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', FALSE)) {
239 239
 			throw $this;
240 240
 		}
241 241
 		// get separate user and developer messages if they exist
242
-		$msg = explode( '||', $this->getMessage() );
242
+		$msg = explode('||', $this->getMessage());
243 243
 		$user_msg = $msg[0];
244
-		$dev_msg = isset( $msg[1] ) ? $msg[1] : $msg[0];
244
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
245 245
 		$msg = WP_DEBUG ? $dev_msg : $user_msg;
246 246
 
247 247
 		// add details to _all_exceptions array
248 248
 		$x_time = time();
249
-		self::$_all_exceptions[ $x_time ]['name'] 	= get_class( $this );
250
-		self::$_all_exceptions[ $x_time ]['file'] 		= $this->getFile();
251
-		self::$_all_exceptions[ $x_time ]['line'] 		= $this->getLine();
252
-		self::$_all_exceptions[ $x_time ]['msg'] 	= $msg;
253
-		self::$_all_exceptions[ $x_time ]['code'] 	= $this->getCode();
254
-		self::$_all_exceptions[ $x_time ]['trace'] 	= $this->getTrace();
255
-		self::$_all_exceptions[ $x_time ]['string'] 	= $this->getTraceAsString();
249
+		self::$_all_exceptions[$x_time]['name'] = get_class($this);
250
+		self::$_all_exceptions[$x_time]['file'] 		= $this->getFile();
251
+		self::$_all_exceptions[$x_time]['line'] 		= $this->getLine();
252
+		self::$_all_exceptions[$x_time]['msg'] = $msg;
253
+		self::$_all_exceptions[$x_time]['code'] = $this->getCode();
254
+		self::$_all_exceptions[$x_time]['trace'] 	= $this->getTrace();
255
+		self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
256 256
 		self::$_error_count++;
257 257
 
258 258
 		//add_action( 'shutdown', array( $this, 'display_errors' ));
@@ -270,14 +270,14 @@  discard block
 block discarded – undo
270 270
      * @param string $type_to_check
271 271
      * @return bool
272 272
      */
273
-    public static function has_error( $check_stored = false, $type_to_check = 'errors' ){
273
+    public static function has_error($check_stored = false, $type_to_check = 'errors') {
274 274
 	    $has_error = isset(self::$_espresso_notices[$type_to_check]) && ! empty(self::$_espresso_notices[$type_to_check])
275 275
             ? true
276 276
             : false;
277
-	    if ( $check_stored && ! $has_error ) {
278
-		    $notices = (array) get_option( 'ee_notices', array() );
279
-		    foreach ( $notices as $type => $notice ) {
280
-			    if ( $type === $type_to_check && $notice ) {
277
+	    if ($check_stored && ! $has_error) {
278
+		    $notices = (array) get_option('ee_notices', array());
279
+		    foreach ($notices as $type => $notice) {
280
+			    if ($type === $type_to_check && $notice) {
281 281
 				    return true;
282 282
 			    }
283 283
 		    }
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	*	@access public
293 293
 	*	@echo string
294 294
 	*/
295
-    public function display_errors(){
295
+    public function display_errors() {
296 296
 
297 297
 		$trace_details = '';
298 298
 
@@ -353,18 +353,18 @@  discard block
 block discarded – undo
353 353
 </style>
354 354
 <div id="ee-error-message" class="error">';
355 355
 
356
-		if ( ! WP_DEBUG ) {
356
+		if ( ! WP_DEBUG) {
357 357
 			$output .= '
358 358
 	<p>';
359 359
 		}
360 360
 
361 361
 		// cycle thru errors
362
-		foreach ( self::$_all_exceptions as $time => $ex ) {
362
+		foreach (self::$_all_exceptions as $time => $ex) {
363 363
 
364 364
 			// process trace info
365
-			if ( empty( $ex['trace'] )) {
365
+			if (empty($ex['trace'])) {
366 366
 
367
-	            $trace_details .= __( 'Sorry, but no trace information was available for this exception.', 'event_espresso' );
367
+	            $trace_details .= __('Sorry, but no trace information was available for this exception.', 'event_espresso');
368 368
 
369 369
 			} else {
370 370
 
@@ -379,50 +379,50 @@  discard block
 block discarded – undo
379 379
 					<th scope="col" align="left">Method( arguments )</th>
380 380
 				</tr>';
381 381
 
382
-				$last_on_stack = count( $ex['trace'] ) - 1;
382
+				$last_on_stack = count($ex['trace']) - 1;
383 383
 				// reverse array so that stack is in proper chronological order
384
-				$sorted_trace = array_reverse( $ex['trace'] );
384
+				$sorted_trace = array_reverse($ex['trace']);
385 385
 
386
-				foreach ( $sorted_trace as $nmbr => $trace ) {
386
+				foreach ($sorted_trace as $nmbr => $trace) {
387 387
 
388
-					$file = isset( $trace['file'] ) ? $trace['file'] : '' ;
389
-					$class = isset( $trace['class'] ) ? $trace['class'] : '';
390
-					$type = isset( $trace['type'] ) ? $trace['type'] : '';
391
-					$function = isset( $trace['function'] ) ? $trace['function'] : '';
392
-					$args = isset( $trace['args'] ) ? $this->_convert_args_to_string( $trace['args'] ) : '';
393
-					$line = isset( $trace['line'] ) ? $trace['line'] : '';
388
+					$file = isset($trace['file']) ? $trace['file'] : '';
389
+					$class = isset($trace['class']) ? $trace['class'] : '';
390
+					$type = isset($trace['type']) ? $trace['type'] : '';
391
+					$function = isset($trace['function']) ? $trace['function'] : '';
392
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
393
+					$line = isset($trace['line']) ? $trace['line'] : '';
394 394
 					$zebra = $nmbr % 2 ? ' odd' : '';
395 395
 
396
-					if ( empty( $file ) && ! empty( $class )) {
397
-						$a = new ReflectionClass( $class );
396
+					if (empty($file) && ! empty($class)) {
397
+						$a = new ReflectionClass($class);
398 398
 						$file = $a->getFileName();
399
-						if ( empty( $line ) && ! empty( $function )) {
400
-							$b = new ReflectionMethod( $class, $function );
399
+						if (empty($line) && ! empty($function)) {
400
+							$b = new ReflectionMethod($class, $function);
401 401
 							$line = $b->getStartLine();
402 402
 						}
403 403
 					}
404 404
 
405
-					if ( $nmbr == $last_on_stack ) {
405
+					if ($nmbr == $last_on_stack) {
406 406
 						$file = $ex['file'] != '' ? $ex['file'] : $file;
407 407
 						$line = $ex['line'] != '' ? $ex['line'] : $line;
408
-						$error_code = self::generate_error_code ( $file, $trace['function'], $line );
408
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
409 409
 					}
410 410
 
411
-					$nmbr_dsply = ! empty( $nmbr ) ? $nmbr : '&nbsp;';
412
-					$line_dsply = ! empty( $line ) ? $line : '&nbsp;';
413
-					$file_dsply = ! empty( $file ) ? $file : '&nbsp;';
414
-					$class_dsply = ! empty( $class ) ? $class : '&nbsp;';
415
-					$type_dsply = ! empty( $type ) ? $type : '&nbsp;';
416
-					$function_dsply = ! empty( $function ) ? $function : '&nbsp;';
417
-					$args_dsply = ! empty( $args ) ? '( ' . $args . ' )' : '';
411
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
412
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
413
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
414
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
415
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
416
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
417
+					$args_dsply = ! empty($args) ? '( '.$args.' )' : '';
418 418
 
419 419
 		              $trace_details .= '
420 420
 					<tr>
421
-						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
422
-						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
423
-						<td align="left" class="' . $zebra . '">' . $file_dsply . '</td>
424
-						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
425
-						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
421
+						<td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td>
422
+						<td align="right" class="' . $zebra.'">'.$line_dsply.'</td>
423
+						<td align="left" class="' . $zebra.'">'.$file_dsply.'</td>
424
+						<td align="left" class="' . $zebra.'">'.$class_dsply.'</td>
425
+						<td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td>
426 426
 					</tr>';
427 427
 
428 428
 
@@ -437,9 +437,9 @@  discard block
 block discarded – undo
437 437
 			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
438 438
 
439 439
 			// add generic non-identifying messages for non-privileged uesrs
440
-			if ( ! WP_DEBUG ) {
440
+			if ( ! WP_DEBUG) {
441 441
 
442
-				$output .= '<span class="ee-error-user-msg-spn">' . trim( $ex['msg'] )  . '</span> &nbsp; <sup>' . $ex['code'] . '</sup><br />';
442
+				$output .= '<span class="ee-error-user-msg-spn">'.trim($ex['msg']).'</span> &nbsp; <sup>'.$ex['code'].'</sup><br />';
443 443
 
444 444
 			} else {
445 445
 
@@ -447,24 +447,24 @@  discard block
 block discarded – undo
447 447
 				$output .= '
448 448
 		<div class="ee-error-dev-msg-dv">
449 449
 			<p class="ee-error-dev-msg-pg">
450
-				<strong class="ee-error-dev-msg-str">An ' . $ex['name'] . ' exception was thrown!</strong>  &nbsp; <span>code: ' . $ex['code'] . '</span><br />
451
-				<span class="big-text">"' . trim( $ex['msg'] ) . '"</span><br/>
452
-				<a id="display-ee-error-trace-' . self::$_error_count . $time . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' . self::$_error_count . $time . '">
453
-					' . __( 'click to view backtrace and class/method details', 'event_espresso' ) . '
450
+				<strong class="ee-error-dev-msg-str">An ' . $ex['name'].' exception was thrown!</strong>  &nbsp; <span>code: '.$ex['code'].'</span><br />
451
+				<span class="big-text">"' . trim($ex['msg']).'"</span><br/>
452
+				<a id="display-ee-error-trace-' . self::$_error_count.$time.'" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'.self::$_error_count.$time.'">
453
+					' . __('click to view backtrace and class/method details', 'event_espresso').'
454 454
 				</a><br />
455 455
 				<span class="small-text lt-grey-text">'.$ex['file'].' &nbsp; ( line no: '.$ex['line'].' )</span>
456 456
 			</p>
457
-			<div id="ee-error-trace-' . self::$_error_count . $time . '-dv" class="ee-error-trace-dv" style="display: none;">
457
+			<div id="ee-error-trace-' . self::$_error_count.$time.'-dv" class="ee-error-trace-dv" style="display: none;">
458 458
 				' . $trace_details;
459 459
 
460
-				if ( ! empty( $class )) {
460
+				if ( ! empty($class)) {
461 461
 					$output .= '
462 462
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
463 463
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
464 464
 						<h3>Class Details</h3>';
465
-						$a = new ReflectionClass( $class );
465
+						$a = new ReflectionClass($class);
466 466
 						$output .= '
467
-						<pre>' . $a . '</pre>
467
+						<pre>' . $a.'</pre>
468 468
 					</div>
469 469
 				</div>';
470 470
 				}
@@ -476,14 +476,14 @@  discard block
 block discarded – undo
476 476
 
477 477
 			}
478 478
 
479
-			$this->write_to_error_log( $time, $ex );
479
+			$this->write_to_error_log($time, $ex);
480 480
 
481 481
 		}
482 482
 
483 483
 		// remove last linebreak
484
-		$output = substr( $output, 0, ( count( $output ) - 7 ));
484
+		$output = substr($output, 0, (count($output) - 7));
485 485
 
486
-		if ( ! WP_DEBUG ) {
486
+		if ( ! WP_DEBUG) {
487 487
 			$output .= '
488 488
 	</p>';
489 489
 		}
@@ -491,10 +491,10 @@  discard block
 block discarded – undo
491 491
 		$output .= '
492 492
 </div>';
493 493
 
494
-		$output .= self::_print_scripts( TRUE );
494
+		$output .= self::_print_scripts(TRUE);
495 495
 
496
-		if ( defined( 'DOING_AJAX' )) {
497
-			echo wp_json_encode( array( 'error' => $output ));
496
+		if (defined('DOING_AJAX')) {
497
+			echo wp_json_encode(array('error' => $output));
498 498
 			exit();
499 499
 		}
500 500
 
@@ -514,29 +514,29 @@  discard block
 block discarded – undo
514 514
 	*	@ param array $arguments
515 515
 	*	@ return string
516 516
 	*/
517
-	private function _convert_args_to_string ( $arguments = array(), $array = FALSE ) {
517
+	private function _convert_args_to_string($arguments = array(), $array = FALSE) {
518 518
 
519 519
 		$arg_string = '';
520
-		if ( ! empty( $arguments )) {
520
+		if ( ! empty($arguments)) {
521 521
 
522 522
 			$args = array();
523 523
 
524
-			foreach ( $arguments as $arg ) {
524
+			foreach ($arguments as $arg) {
525 525
 
526
-				if ( ! empty( $arg )) {
526
+				if ( ! empty($arg)) {
527 527
 
528
-					if ( is_string( $arg )) {
529
-						$args[] = " '" . $arg . "'";
530
-					} elseif ( is_array( $arg )) {
531
-						$args[] = 'ARRAY(' . $this->_convert_args_to_string( $arg, TRUE );
532
-					} elseif ( is_null( $arg )) {
528
+					if (is_string($arg)) {
529
+						$args[] = " '".$arg."'";
530
+					} elseif (is_array($arg)) {
531
+						$args[] = 'ARRAY('.$this->_convert_args_to_string($arg, TRUE);
532
+					} elseif (is_null($arg)) {
533 533
 						$args[] = ' NULL';
534
-					} elseif ( is_bool( $arg )) {
535
-						$args[] = ( $arg ) ? ' TRUE' : ' FALSE';
536
-					} elseif ( is_object( $arg )) {
537
-						$args[] = ' OBJECT ' . get_class( $arg );
538
-					} elseif ( is_resource( $arg )) {
539
-						$args[] = get_resource_type( $arg );
534
+					} elseif (is_bool($arg)) {
535
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
536
+					} elseif (is_object($arg)) {
537
+						$args[] = ' OBJECT '.get_class($arg);
538
+					} elseif (is_resource($arg)) {
539
+						$args[] = get_resource_type($arg);
540 540
 					} else {
541 541
 						$args[] = $arg;
542 542
 					}
@@ -544,9 +544,9 @@  discard block
 block discarded – undo
544 544
 				}
545 545
 
546 546
 			}
547
-			$arg_string = implode( ', ', $args );
547
+			$arg_string = implode(', ', $args);
548 548
 		}
549
-		if ( $array ) {
549
+		if ($array) {
550 550
 			$arg_string .= ' )';
551 551
 		}
552 552
 		return $arg_string;
@@ -566,8 +566,8 @@  discard block
 block discarded – undo
566 566
 	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
567 567
 	* 	@return 		void
568 568
 	*/
569
-	public static function add_error( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
570
-		self::_add_notice ( 'errors', $msg, $file, $func, $line );
569
+	public static function add_error($msg = NULL, $file = NULL, $func = NULL, $line = NULL) {
570
+		self::_add_notice('errors', $msg, $file, $func, $line);
571 571
 		self::$_error_count++;
572 572
 	}
573 573
 
@@ -580,11 +580,11 @@  discard block
 block discarded – undo
580 580
 	 * @param string $line
581 581
 	 * @throws EE_Error
582 582
 	 */
583
-	public static function throw_exception_if_debugging( $msg = null, $file = null, $func = null, $line = null ) {
584
-		if( WP_DEBUG ) {
585
-			throw new EE_Error( $msg );
586
-		} else  {
587
-			EE_Error::add_error( $msg, $file, $func, $line );
583
+	public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) {
584
+		if (WP_DEBUG) {
585
+			throw new EE_Error($msg);
586
+		} else {
587
+			EE_Error::add_error($msg, $file, $func, $line);
588 588
 		}
589 589
 	}
590 590
 
@@ -602,8 +602,8 @@  discard block
 block discarded – undo
602 602
 	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
603 603
 	* 	@return 		void
604 604
 	*/
605
-	public static function add_success( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
606
-		self::_add_notice ( 'success', $msg, $file, $func, $line );
605
+	public static function add_success($msg = NULL, $file = NULL, $func = NULL, $line = NULL) {
606
+		self::_add_notice('success', $msg, $file, $func, $line);
607 607
 	}
608 608
 
609 609
 
@@ -620,8 +620,8 @@  discard block
 block discarded – undo
620 620
 	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
621 621
 	* 	@return 		void
622 622
 	*/
623
-	public static function add_attention( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
624
-		self::_add_notice ( 'attention', $msg, $file, $func, $line );
623
+	public static function add_attention($msg = NULL, $file = NULL, $func = NULL, $line = NULL) {
624
+		self::_add_notice('attention', $msg, $file, $func, $line);
625 625
 	}
626 626
 
627 627
 
@@ -639,12 +639,12 @@  discard block
 block discarded – undo
639 639
 	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
640 640
 	* 	@return 		void
641 641
 	*/
642
-	private static function _add_notice( $type = 'success', $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
643
-		if ( empty( $msg )) {
642
+	private static function _add_notice($type = 'success', $msg = NULL, $file = NULL, $func = NULL, $line = NULL) {
643
+		if (empty($msg)) {
644 644
 			EE_Error::doing_it_wrong(
645
-				'EE_Error::add_' . $type . '()',
645
+				'EE_Error::add_'.$type.'()',
646 646
 				sprintf(
647
-					__( 'Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', 'event_espresso' ),
647
+					__('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', 'event_espresso'),
648 648
 					$type,
649 649
 					$file,
650 650
 					$line
@@ -652,17 +652,17 @@  discard block
 block discarded – undo
652 652
 				EVENT_ESPRESSO_VERSION
653 653
 			);
654 654
 		}
655
-		if ( $type == 'errors' && ( empty( $file ) || empty( $func ) || empty( $line ))) {
655
+		if ($type == 'errors' && (empty($file) || empty($func) || empty($line))) {
656 656
 			EE_Error::doing_it_wrong(
657 657
 				'EE_Error::add_error()',
658
-				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', 'event_espresso' ),
658
+				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', 'event_espresso'),
659 659
 				EVENT_ESPRESSO_VERSION
660 660
 			);
661 661
 		}
662 662
 		// get separate user and developer messages if they exist
663
-		$msg = explode( '||', $msg );
663
+		$msg = explode('||', $msg);
664 664
 		$user_msg = $msg[0];
665
-		$dev_msg = isset( $msg[1] ) ? $msg[1] : $msg[0];
665
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
666 666
 		/**
667 667
 		 * Do an action so other code can be triggered when a notice is created
668 668
 		 * @param string $type can be 'errors', 'attention', or 'success'
@@ -672,22 +672,22 @@  discard block
 block discarded – undo
672 672
 		 * @param string $func function where error was generated
673 673
 		 * @param string $line line where error was generated
674 674
 		 */
675
-		do_action( 'AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line );
675
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
676 676
 		$msg = WP_DEBUG ? $dev_msg : $user_msg;
677 677
 		// add notice if message exists
678
-		if ( ! empty( $msg )) {
678
+		if ( ! empty($msg)) {
679 679
 			// get error code
680
-			$notice_code = EE_Error::generate_error_code( $file, $func, $line );
681
-			if ( WP_DEBUG && $type == 'errors' ) {
682
-				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
680
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
681
+			if (WP_DEBUG && $type == 'errors') {
682
+				$msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>';
683 683
 			}
684 684
 			// add notice. Index by code if it's not blank
685
-			if( $notice_code ) {
686
-				self::$_espresso_notices[ $type ][ $notice_code ] = $msg;
685
+			if ($notice_code) {
686
+				self::$_espresso_notices[$type][$notice_code] = $msg;
687 687
 			} else {
688
-				self::$_espresso_notices[ $type ][] = $msg;
688
+				self::$_espresso_notices[$type][] = $msg;
689 689
 			}
690
-			add_action( 'wp_footer', array( 'EE_Error', 'enqueue_error_scripts' ), 1 );
690
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
691 691
 		}
692 692
 
693 693
 	}
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
 	*	@access private
742 742
 	*	@return void
743 743
 	*/
744
-	public static function reset_notices(){
744
+	public static function reset_notices() {
745 745
     	self::$_espresso_notices['success'] = FALSE;
746 746
     	self::$_espresso_notices['attention'] = FALSE;
747 747
     	self::$_espresso_notices['errors'] = FALSE;
@@ -754,14 +754,14 @@  discard block
 block discarded – undo
754 754
 	*	@access public
755 755
 	*	@return int
756 756
 	*/
757
-    public static function has_notices(){
757
+    public static function has_notices() {
758 758
 		$has_notices = 0;
759 759
 		// check for success messages
760
-		$has_notices = self::$_espresso_notices['success'] && ! empty(  self::$_espresso_notices['success'] ) ? 3 : $has_notices;
760
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3 : $has_notices;
761 761
 		// check for attention messages
762
-		$has_notices = self::$_espresso_notices['attention'] && ! empty(  self::$_espresso_notices['attention'] ) ? 2 : $has_notices;
762
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2 : $has_notices;
763 763
 		// check for error messages
764
-		$has_notices = self::$_espresso_notices['errors'] && ! empty(  self::$_espresso_notices['errors'] ) ? 1 : $has_notices;
764
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1 : $has_notices;
765 765
 		return $has_notices;
766 766
 	}
767 767
 
@@ -776,9 +776,9 @@  discard block
 block discarded – undo
776 776
 	 */
777 777
 	public static function get_vanilla_notices() {
778 778
 		return array(
779
-			'success' => isset( self::$_espresso_notices['success'] ) ? self::$_espresso_notices['success'] : array(),
780
-			'attention' => isset( self::$_espresso_notices['attention'] )  ? self::$_espresso_notices['attention'] : array(),
781
-			'errors' => isset( self::$_espresso_notices['errors'] ) ? self::$_espresso_notices['errors'] : array(),
779
+			'success' => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(),
780
+			'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention'] : array(),
781
+			'errors' => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(),
782 782
 		);
783 783
 	}
784 784
 
@@ -794,8 +794,8 @@  discard block
 block discarded – undo
794 794
 	* 	@param		boolean		$remove_empty		whether or not to unset empty messages
795 795
 	* 	@return 		array
796 796
 	*/
797
-	public static function get_notices( $format_output = TRUE, $save_to_transient = FALSE, $remove_empty = TRUE ) {
798
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
797
+	public static function get_notices($format_output = TRUE, $save_to_transient = FALSE, $remove_empty = TRUE) {
798
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
799 799
 
800 800
 		$success_messages = '';
801 801
 		$attention_messages = '';
@@ -805,44 +805,44 @@  discard block
 block discarded – undo
805 805
 		// EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
806 806
 
807 807
 		// either save notices to the db
808
-		if ( $save_to_transient ) {
809
-			update_option( 'ee_notices', self::$_espresso_notices );
808
+		if ($save_to_transient) {
809
+			update_option('ee_notices', self::$_espresso_notices);
810 810
 			return;
811 811
 		}
812 812
 		// grab any notices that have been previously saved
813
-		if ( $notices = get_option( 'ee_notices', FALSE )) {
814
-			foreach ( $notices as $type => $notice ) {
815
-				if ( is_array( $notice ) && ! empty( $notice )) {
813
+		if ($notices = get_option('ee_notices', FALSE)) {
814
+			foreach ($notices as $type => $notice) {
815
+				if (is_array($notice) && ! empty($notice)) {
816 816
 					// make sure that existing notice type is an array
817
-					self::$_espresso_notices[ $type ] =  is_array( self::$_espresso_notices[ $type ] ) && ! empty( self::$_espresso_notices[ $type ] ) ? self::$_espresso_notices[ $type ] : array();
817
+					self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) && ! empty(self::$_espresso_notices[$type]) ? self::$_espresso_notices[$type] : array();
818 818
 					// merge stored notices with any newly created ones
819
-					self::$_espresso_notices[ $type ] = array_merge( self::$_espresso_notices[ $type ], $notice );
819
+					self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
820 820
 					$print_scripts = TRUE;
821 821
 				}
822 822
 			}
823 823
 			// now clear any stored notices
824
-			update_option( 'ee_notices', FALSE );
824
+			update_option('ee_notices', FALSE);
825 825
 		}
826 826
 
827 827
 		// check for success messages
828
-		if ( self::$_espresso_notices['success'] && ! empty(  self::$_espresso_notices['success'] )) {
828
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
829 829
 			// combine messages
830
-			$success_messages .= implode( self::$_espresso_notices['success'], '<br />' );
830
+			$success_messages .= implode(self::$_espresso_notices['success'], '<br />');
831 831
 			$print_scripts = TRUE;
832 832
 		}
833 833
 
834 834
 		// check for attention messages
835
-		if ( self::$_espresso_notices['attention'] && ! empty(  self::$_espresso_notices['attention'] ) ) {
835
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
836 836
 			// combine messages
837
-			$attention_messages .= implode( self::$_espresso_notices['attention'], '<br />' );
837
+			$attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
838 838
 			$print_scripts = TRUE;
839 839
 		}
840 840
 
841 841
 		// check for error messages
842
-		if ( self::$_espresso_notices['errors'] && ! empty(  self::$_espresso_notices['errors'] ) ) {
843
-			$error_messages .= count( self::$_espresso_notices['errors'] ) > 1 ? __( 'The following errors have occurred:<br />', 'event_espresso' ) : __( 'An error has occurred:<br />', 'event_espresso' );
842
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
843
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1 ? __('The following errors have occurred:<br />', 'event_espresso') : __('An error has occurred:<br />', 'event_espresso');
844 844
 			// combine messages
845
-			$error_messages .= implode( self::$_espresso_notices['errors'], '<br />' );
845
+			$error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
846 846
 			$print_scripts = TRUE;
847 847
 		}
848 848
 
@@ -856,21 +856,21 @@  discard block
 block discarded – undo
856 856
 				$css_id = is_admin() ? 'message' : 'espresso-notices-success';
857 857
 				$css_class = is_admin() ? 'updated fade' : 'success fade-away';
858 858
 				//showMessage( $success_messages );
859
-				$notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $success_messages . '</p>' . $close . '</div>';
859
+				$notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$success_messages.'</p>'.$close.'</div>';
860 860
 			}
861 861
 
862 862
 			if ($attention_messages !== '') {
863 863
 				$css_id = is_admin() ? 'message' : 'espresso-notices-attention';
864 864
 				$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
865 865
 				//showMessage( $error_messages, TRUE );
866
-				$notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $attention_messages . '</p>' . $close . '</div>';
866
+				$notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$attention_messages.'</p>'.$close.'</div>';
867 867
 			}
868 868
 
869 869
 			if ($error_messages !== '') {
870 870
 				$css_id = is_admin() ? 'message' : 'espresso-notices-error';
871 871
 				$css_class = is_admin() ? 'error' : 'error fade-away';
872 872
 				//showMessage( $error_messages, TRUE );
873
-				$notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $error_messages . '</p>' . $close . '</div>';
873
+				$notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$error_messages.'</p>'.$close.'</div>';
874 874
 			}
875 875
 
876 876
 			$notices .= '</div>';
@@ -883,7 +883,7 @@  discard block
 block discarded – undo
883 883
 					'errors' => $error_messages
884 884
 			);
885 885
 
886
-			if ( $remove_empty ) {
886
+			if ($remove_empty) {
887 887
 				// remove empty notices
888 888
 				foreach ($notices as $type => $notice) {
889 889
 					if (empty($notice)) {
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 			}
894 894
 		}
895 895
 
896
-		if ( $print_scripts ) {
896
+		if ($print_scripts) {
897 897
 			self::_print_scripts();
898 898
 		}
899 899
 
@@ -909,26 +909,26 @@  discard block
 block discarded – undo
909 909
 	 * @param 	bool $force_print
910 910
 	 * @return 	void
911 911
 	 */
912
-	private static function _print_scripts( $force_print = FALSE ) {
913
-		if (( did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' )) && ! $force_print ) {
914
-			if ( wp_script_is( 'ee_error_js', 'enqueued' )) {
912
+	private static function _print_scripts($force_print = FALSE) {
913
+		if ((did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts')) && ! $force_print) {
914
+			if (wp_script_is('ee_error_js', 'enqueued')) {
915 915
 				return;
916
-			} else if ( wp_script_is( 'ee_error_js', 'registered' )) {
917
-				add_filter( 'FHEE_load_css', '__return_true' );
918
-				add_filter( 'FHEE_load_js', '__return_true' );
919
-				wp_enqueue_script( 'ee_error_js' );
920
-				wp_localize_script( 'ee_error_js','ee_settings', array( 'wp_debug'=>WP_DEBUG ));
916
+			} else if (wp_script_is('ee_error_js', 'registered')) {
917
+				add_filter('FHEE_load_css', '__return_true');
918
+				add_filter('FHEE_load_js', '__return_true');
919
+				wp_enqueue_script('ee_error_js');
920
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug'=>WP_DEBUG));
921 921
 			}
922 922
 		} else {
923 923
 			return '
924 924
 <script>
925 925
 /* <![CDATA[ */
926
-var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
926
+var ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
927 927
 /* ]]> */
928 928
 </script>
929
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
930
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
931
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
929
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
930
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
931
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
932 932
 ';
933 933
 
934 934
 		}
@@ -962,11 +962,11 @@  discard block
 block discarded – undo
962 962
 	*	@param string $line
963 963
 	*	@return string
964 964
 	*/
965
-	public static function generate_error_code ( $file = '', $func = '', $line = '' ) {
966
-		$file = explode( '.', basename( $file ));
967
-		$error_code = ! empty( $file[0] ) ? $file[0] : '';
968
-		$error_code .= ! empty( $func ) ? ' - ' . $func : '';
969
-		$error_code .= ! empty( $line ) ? ' - ' . $line : '';
965
+	public static function generate_error_code($file = '', $func = '', $line = '') {
966
+		$file = explode('.', basename($file));
967
+		$error_code = ! empty($file[0]) ? $file[0] : '';
968
+		$error_code .= ! empty($func) ? ' - '.$func : '';
969
+		$error_code .= ! empty($line) ? ' - '.$line : '';
970 970
 		return $error_code;
971 971
 	}
972 972
 
@@ -982,36 +982,36 @@  discard block
 block discarded – undo
982 982
 	*	@ param object $ex
983 983
 	*	@ return void
984 984
 	*/
985
-	public function write_to_error_log ( $time = FALSE, $ex = FALSE, $clear = FALSE ) {
985
+	public function write_to_error_log($time = FALSE, $ex = FALSE, $clear = FALSE) {
986 986
 
987
-		if ( ! $ex ) {
987
+		if ( ! $ex) {
988 988
 			return;
989 989
 		}
990 990
 
991
-		if ( ! $time ) {
991
+		if ( ! $time) {
992 992
 			$time = time();
993 993
 		}
994 994
 
995
-		$exception_log = '----------------------------------------------------------------------------------------' . PHP_EOL;
996
-		$exception_log .= '[' . date( 'Y-m-d H:i:s', $time ) . ']  Exception Details' . PHP_EOL;
997
-		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
998
-		$exception_log .= 'Code: '. $ex['code'] . PHP_EOL;
999
-		$exception_log .= 'File: '. $ex['file'] . PHP_EOL;
1000
-		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1001
-		$exception_log .= 'Stack trace: ' . PHP_EOL;
1002
-		$exception_log .= $ex['string'] . PHP_EOL;
1003
-		$exception_log .= '----------------------------------------------------------------------------------------' . PHP_EOL;
995
+		$exception_log = '----------------------------------------------------------------------------------------'.PHP_EOL;
996
+		$exception_log .= '['.date('Y-m-d H:i:s', $time).']  Exception Details'.PHP_EOL;
997
+		$exception_log .= 'Message: '.$ex['msg'].PHP_EOL;
998
+		$exception_log .= 'Code: '.$ex['code'].PHP_EOL;
999
+		$exception_log .= 'File: '.$ex['file'].PHP_EOL;
1000
+		$exception_log .= 'Line No: '.$ex['line'].PHP_EOL;
1001
+		$exception_log .= 'Stack trace: '.PHP_EOL;
1002
+		$exception_log .= $ex['string'].PHP_EOL;
1003
+		$exception_log .= '----------------------------------------------------------------------------------------'.PHP_EOL;
1004 1004
 
1005 1005
 		try {
1006
-			EEH_File::ensure_file_exists_and_is_writable( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file );
1007
-			EEH_File::add_htaccess_deny_from_all( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' );
1008
-			if ( ! $clear ) {
1006
+			EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file);
1007
+			EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs');
1008
+			if ( ! $clear) {
1009 1009
 				//get existing log file and append new log info
1010
-				$exception_log = EEH_File::get_file_contents( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file ) . $exception_log;
1010
+				$exception_log = EEH_File::get_file_contents(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file).$exception_log;
1011 1011
 			}
1012
-			EEH_File::write_to_file( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file, $exception_log );
1013
-		} catch( EE_Error $e ){
1014
-			EE_Error::add_error( sprintf( __(  'Event Espresso error logging could not be setup because: %s', 'event_espresso' ), $e->getMessage() ));
1012
+			EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file, $exception_log);
1013
+		} catch (EE_Error $e) {
1014
+			EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', 'event_espresso'), $e->getMessage()));
1015 1015
 			return;
1016 1016
 		}
1017 1017
 
@@ -1047,8 +1047,8 @@  discard block
 block discarded – undo
1047 1047
 		$applies_when = '',
1048 1048
 		$error_type = null
1049 1049
 	) {
1050
-		if ( defined('WP_DEBUG') && WP_DEBUG ) {
1051
-			EEH_Debug_Tools::instance()->doing_it_wrong( $function, $message, $version, $applies_when, $error_type );
1050
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1051
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1052 1052
 		}
1053 1053
 	}
1054 1054
 
@@ -1175,13 +1175,13 @@  discard block
 block discarded – undo
1175 1175
  */
1176 1176
 function espresso_error_enqueue_scripts() {
1177 1177
 	// js for error handling
1178
-	wp_register_script( 'espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, FALSE );
1179
-	wp_register_script( 'ee_error_js', EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, FALSE );
1178
+	wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, FALSE);
1179
+	wp_register_script('ee_error_js', EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, FALSE);
1180 1180
 }
1181
-if ( is_admin() ) {
1182
-	add_action( 'admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2 );
1181
+if (is_admin()) {
1182
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1183 1183
 } else {
1184
-	add_action( 'wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2 );
1184
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1185 1185
 }
1186 1186
 
1187 1187
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,9 @@
 block discarded – undo
6 6
 use EventEspresso\core\services\container\exceptions\ServiceNotFoundException;
7 7
 use EventEspresso\core\services\notifications\PersistentAdminNoticeManager;
8 8
 
9
-if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
9
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
10
+	exit('No direct script access allowed');
11
+}
10 12
 // if you're a dev and want to receive all errors via email add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
11 13
 if ( defined( 'WP_DEBUG' ) && WP_DEBUG === TRUE && defined( 'EE_ERROR_EMAILS' ) && EE_ERROR_EMAILS === TRUE ) {
12 14
 	set_error_handler( array( 'EE_Error', 'error_handler' ));
Please login to merge, or discard this patch.
core/services/collections/Collection.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	  *
116 116
 	  * @access public
117 117
 	  * @param mixed $identifier
118
-	  * @return mixed
118
+	  * @return boolean
119 119
 	  */
120 120
 	 public function get( $identifier ) {
121 121
 		 $this->rewind();
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 	  * advances pointer to the provided object
238 238
 	  *
239 239
 	  * @access public
240
-	  * @param $object
240
+	  * @param \EventEspresso\core\libraries\form_sections\form_handlers\SequentialStepFormInterface $object
241 241
 	  * @return boolean
242 242
 	  */
243 243
 	 public function setCurrentUsingObject( $object ) {
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	  *
276 276
 	  * @see http://stackoverflow.com/a/8736013
277 277
 	  * @param $object
278
-	  * @return boolean|int|string
278
+	  * @return integer
279 279
 	  */
280 280
 	 public function indexOf( $object ) {
281 281
 		 if ( ! $this->contains( $object ) ) {
Please login to merge, or discard this patch.
Indentation   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -83,7 +83,6 @@  discard block
 block discarded – undo
83 83
 
84 84
 	 /**
85 85
 	  * setIdentifier
86
-
87 86
 	  * Sets the data associated with an object in the Collection
88 87
 	  * if no $identifier is supplied, then the spl_object_hash() is used
89 88
 	  *
@@ -172,9 +171,9 @@  discard block
 block discarded – undo
172 171
 
173 172
 	 /**
174 173
 	  * hasObjects
175
-      * returns true if there are objects within the Collection, and false if it is empty
176
-      *
177
-      * @access public
174
+	  * returns true if there are objects within the Collection, and false if it is empty
175
+	  *
176
+	  * @access public
178 177
 	  * @return bool
179 178
 	  */
180 179
 	 public function hasObjects() {
Please login to merge, or discard this patch.
modules/add_new_state/EED_Add_New_State.module.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
      * @param string $CNT_ISO
469 469
      * @param string $STA_ID
470 470
      * @param array  $cols_n_values
471
-     * @return        boolean
471
+     * @return        boolean|null
472 472
      * @throws InvalidInterfaceException
473 473
      * @throws InvalidDataTypeException
474 474
      * @throws DomainException
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 	 *
566 566
 	 * @access        public
567 567
 	 * @param EE_State[]  $state_options
568
-	 * @return        boolean
568
+	 * @return        EE_State[]
569 569
 	 */
570 570
 	public static function state_options( $state_options = array() ) {
571 571
 		$new_states = EED_Add_New_State::_get_new_states();
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -414,14 +414,14 @@  discard block
 block discarded – undo
414 414
 
415 415
 
416 416
 
417
-    /**
418
-     * generate_state_abbreviation
419
-     *
420
-     * @param array $props_n_values
421
-     * @return boolean
422
-     * @throws \EE_Error
423
-     * @throws InvalidDataTypeException
424
-     */
417
+	/**
418
+	 * generate_state_abbreviation
419
+	 *
420
+	 * @param array $props_n_values
421
+	 * @return boolean
422
+	 * @throws \EE_Error
423
+	 * @throws InvalidDataTypeException
424
+	 */
425 425
 	public static function save_new_state_to_db ( $props_n_values = array() ) {
426 426
 		$existing_state = EEM_State::instance()->get_all( array( $props_n_values, 'limit' => 1 ));
427 427
 		if ( ! empty( $existing_state )) {
@@ -429,29 +429,29 @@  discard block
 block discarded – undo
429 429
 		}
430 430
 		$new_state = EE_State::new_instance( $props_n_values );
431 431
 		if ( $new_state instanceof EE_State ) {
432
-		    $country_settings_url = add_query_arg(
433
-                array(
434
-                    'page'    => 'espresso_general_settings',
435
-                    'action'  => 'country_settings',
436
-                    'country' => $new_state->country_iso()
437
-                ),
438
-                admin_url('admin.php')
439
-            );
432
+			$country_settings_url = add_query_arg(
433
+				array(
434
+					'page'    => 'espresso_general_settings',
435
+					'action'  => 'country_settings',
436
+					'country' => $new_state->country_iso()
437
+				),
438
+				admin_url('admin.php')
439
+			);
440 440
 			// if not non-ajax admin
441
-            new PersistentAdminNotice(
442
-                'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
443
-                sprintf(
444
-                    __(
445
-                        'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
446
-                        'event_espresso'
447
-                    ),
448
-                    '<b>' . $new_state->name() . '</b>',
449
-                    '<b>' . $new_state->abbrev() . '</b>',
450
-                    '<b>' . $new_state->country()->name() . '</b>',
451
-                    '<a href="' . $country_settings_url . '">' . __('Event Espresso - General Settings > Countries Tab', 'event_espresso') . '</a>',
452
-                    '<br />'
453
-                )
454
-            );
441
+			new PersistentAdminNotice(
442
+				'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
443
+				sprintf(
444
+					__(
445
+						'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
446
+						'event_espresso'
447
+					),
448
+					'<b>' . $new_state->name() . '</b>',
449
+					'<b>' . $new_state->abbrev() . '</b>',
450
+					'<b>' . $new_state->country()->name() . '</b>',
451
+					'<a href="' . $country_settings_url . '">' . __('Event Espresso - General Settings > Countries Tab', 'event_espresso') . '</a>',
452
+					'<br />'
453
+				)
454
+			);
455 455
 			$new_state->save();
456 456
 			EEM_State::instance()->reset_cached_states();
457 457
 			return $new_state;
@@ -461,19 +461,19 @@  discard block
 block discarded – undo
461 461
 
462 462
 
463 463
 
464
-    /**
465
-     *        update_country_settings
466
-     *
467
-     * @access        public
468
-     * @param string $CNT_ISO
469
-     * @param string $STA_ID
470
-     * @param array  $cols_n_values
471
-     * @return        boolean
472
-     * @throws InvalidInterfaceException
473
-     * @throws InvalidDataTypeException
474
-     * @throws DomainException
475
-     * @throws ServiceNotFoundException
476
-     */
464
+	/**
465
+	 *        update_country_settings
466
+	 *
467
+	 * @access        public
468
+	 * @param string $CNT_ISO
469
+	 * @param string $STA_ID
470
+	 * @param array  $cols_n_values
471
+	 * @return        boolean
472
+	 * @throws InvalidInterfaceException
473
+	 * @throws InvalidDataTypeException
474
+	 * @throws DomainException
475
+	 * @throws ServiceNotFoundException
476
+	 */
477 477
 	public static function update_country_settings( $CNT_ISO = '', $STA_ID = '', $cols_n_values = array() ) {
478 478
 		$CNT_ISO = ! empty( $CNT_ISO ) ? $CNT_ISO : FALSE;
479 479
 		if ( ! $CNT_ISO ) {
@@ -489,11 +489,11 @@  discard block
 block discarded – undo
489 489
 		if ( ! $STA_abbrev ) {
490 490
 			EE_Error::add_error( __( 'An invalid or missing State Abbreviation was received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
491 491
 		}
492
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
493
-        $persistent_admin_notice_manager = CoffeeMill::getService(
494
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
495
-        );
496
-        $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
492
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
493
+		$persistent_admin_notice_manager = CoffeeMill::getService(
494
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
495
+		);
496
+		$persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
497 497
 	}
498 498
 
499 499
 
Please login to merge, or discard this patch.
Spacing   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * @return EED_Add_New_State
25 25
 	 */
26 26
 	public static function instance() {
27
-		return parent::get_instance( __CLASS__ );
27
+		return parent::get_instance(__CLASS__);
28 28
 	}
29 29
 
30 30
 
@@ -35,16 +35,16 @@  discard block
 block discarded – undo
35 35
 	 *  	@return 		void
36 36
 	 */
37 37
 	public static function set_hooks() {
38
-		add_action( 'wp_loaded', array( 'EED_Add_New_State', 'set_definitions' ), 2 );
39
-		add_action( 'wp_enqueue_scripts', array( 'EED_Add_New_State', 'translate_js_strings' ), 0 );
40
-		add_action( 'wp_enqueue_scripts', array( 'EED_Add_New_State', 'wp_enqueue_scripts' ), 10 );
41
-		add_filter( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', array( 'EED_Add_New_State', 'display_add_new_state_micro_form' ), 1, 1 );
42
-		add_filter( 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', array( 'EED_Add_New_State', 'display_add_new_state_micro_form' ), 1, 1 );
43
-		add_filter( 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', array( 'EED_Add_New_State', 'unset_new_state_request_params' ), 10, 1 );
44
-		add_filter( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', array( 'EED_Add_New_State', 'inject_new_reg_state_into_options' ), 10, 5 );
45
-		add_filter( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', array( 'EED_Add_New_State', 'inject_new_reg_country_into_options' ), 10, 5 );
46
-		add_filter( 'FHEE__EE_State_Select_Input____construct__state_options', array( 'EED_Add_New_State', 'state_options' ), 10, 1 );
47
-		add_filter( 'FHEE__EE_Country_Select_Input____construct__country_options', array( 'EED_Add_New_State', 'country_options' ), 10, 1 );
38
+		add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
39
+		add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0);
40
+		add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10);
41
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
42
+		add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
43
+		add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1);
44
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5);
45
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5);
46
+		add_filter('FHEE__EE_State_Select_Input____construct__state_options', array('EED_Add_New_State', 'state_options'), 10, 1);
47
+		add_filter('FHEE__EE_Country_Select_Input____construct__country_options', array('EED_Add_New_State', 'country_options'), 10, 1);
48 48
 	}
49 49
 
50 50
 	/**
@@ -54,20 +54,20 @@  discard block
 block discarded – undo
54 54
 	 *  	@return 		void
55 55
 	 */
56 56
 	public static function set_hooks_admin() {
57
-		add_action( 'wp_loaded', array( 'EED_Add_New_State', 'set_definitions' ), 2 );
58
-		add_filter( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', array( 'EED_Add_New_State', 'display_add_new_state_micro_form' ), 1, 1 );
59
-		add_filter( 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', array( 'EED_Add_New_State', 'display_add_new_state_micro_form' ), 1, 1 );
60
-		add_action( 'wp_ajax_espresso_add_new_state', array( 'EED_Add_New_State', 'add_new_state' ));
61
-		add_action( 'wp_ajax_nopriv_espresso_add_new_state', array( 'EED_Add_New_State', 'add_new_state' ));
62
-		add_filter( 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', array( 'EED_Add_New_State', 'unset_new_state_request_params' ), 10, 1 );
63
-		add_action( 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', array( 'EED_Add_New_State', 'update_country_settings' ), 10, 3 );
64
-		add_action( 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', array( 'EED_Add_New_State', 'update_country_settings' ), 10, 3 );
65
-		add_filter( 'FHEE__EE_State_Select_Input____construct__state_options', array( 'EED_Add_New_State', 'state_options' ), 10, 1 );
66
-		add_filter( 'FHEE__EE_Country_Select_Input____construct__country_options', array( 'EED_Add_New_State', 'country_options' ), 10, 1 );
57
+		add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
58
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
59
+		add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
60
+		add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
61
+		add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
62
+		add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1);
63
+		add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', array('EED_Add_New_State', 'update_country_settings'), 10, 3);
64
+		add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', array('EED_Add_New_State', 'update_country_settings'), 10, 3);
65
+		add_filter('FHEE__EE_State_Select_Input____construct__state_options', array('EED_Add_New_State', 'state_options'), 10, 1);
66
+		add_filter('FHEE__EE_Country_Select_Input____construct__country_options', array('EED_Add_New_State', 'country_options'), 10, 1);
67 67
 		//add_filter( 'FHEE__Single_Page_Checkout___check_form_submission__request_params', array( 'EED_Add_New_State', 'filter_checkout_request_params' ), 10, 1 );
68
-		add_filter( 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', array( 'EED_Add_New_State', 'filter_checkout_request_params' ), 10, 1 );
69
-		add_filter( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', array( 'EED_Add_New_State', 'inject_new_reg_state_into_options' ), 10, 5 );
70
-		add_filter( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', array( 'EED_Add_New_State', 'inject_new_reg_country_into_options' ), 10, 5 );
68
+		add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1);
69
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5);
70
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5);
71 71
 	}
72 72
 
73 73
 
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
 	 *  	@return 		void
80 80
 	 */
81 81
 	public static function set_definitions() {
82
-		define( 'ANS_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
83
-		define( 'ANS_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS );
82
+		define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
83
+		define('ANS_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS);
84 84
 	}
85 85
 
86 86
 
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 * @param \WP $WP
93 93
 	 * @return        void
94 94
 	 */
95
-	public function run( $WP ) {
95
+	public function run($WP) {
96 96
 	}
97 97
 
98 98
 
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 	 * 	@return 		void
121 121
 	 */
122 122
 	public static function wp_enqueue_scripts() {
123
-		if ( apply_filters( 'EED_Single_Page_Checkout__SPCO_active', false ) ) {
124
-			wp_register_script( 'add_new_state', ANS_ASSETS_URL . 'add_new_state.js', array( 'espresso_core', 'single_page_checkout' ), EVENT_ESPRESSO_VERSION, true );
125
-			wp_enqueue_script( 'add_new_state' );
123
+		if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
124
+			wp_register_script('add_new_state', ANS_ASSETS_URL.'add_new_state.js', array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true);
125
+			wp_enqueue_script('add_new_state');
126 126
 		}
127 127
 	}
128 128
 
@@ -136,34 +136,34 @@  discard block
 block discarded – undo
136 136
 	 * @return 	string
137 137
 	 */
138 138
 //	public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){
139
-	public static function display_add_new_state_micro_form( EE_Form_Section_Proper $question_group_reg_form ){
139
+	public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) {
140 140
 		// only add the 'new_state_micro_form' when displaying reg forms,
141 141
 		// not during processing since we process the 'new_state_micro_form' in it's own AJAX request
142
-		$action = EE_Registry::instance()->REQ->get( 'action', '' );
142
+		$action = EE_Registry::instance()->REQ->get('action', '');
143 143
 		// is the "state" question in this form section?
144
-		$input = $question_group_reg_form->get_subsection( 'state' );
145
-		if ( $action === 'process_reg_step' || $action === 'update_reg_step' ) {
144
+		$input = $question_group_reg_form->get_subsection('state');
145
+		if ($action === 'process_reg_step' || $action === 'update_reg_step') {
146 146
 			//ok then all we need to do is make sure the input's HTML name is consistent
147 147
 			//by forcing it to set it now, like it did while getting the form for display
148
-			if( $input instanceof EE_State_Select_Input ) {
148
+			if ($input instanceof EE_State_Select_Input) {
149 149
 				$input->html_name();
150 150
 			}
151 151
 			return $question_group_reg_form;
152 152
 		}
153 153
 
154 154
 		// we're only doing this for state select inputs
155
-		if ( $input instanceof EE_State_Select_Input ) {
155
+		if ($input instanceof EE_State_Select_Input) {
156 156
 			// grab any set values from the request
157
-			$country_name = str_replace( 'state', 'nsmf_new_state_country', $input->html_name() );
158
-			$state_name = str_replace( 'state', 'nsmf_new_state_name', $input->html_name() );
159
-			$abbrv_name = str_replace( 'state', 'nsmf_new_state_abbrv', $input->html_name() );
160
-			$new_state_submit_id = str_replace( 'state', 'new_state', $input->html_id() );
157
+			$country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name());
158
+			$state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name());
159
+			$abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
160
+			$new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
161 161
 			$country_options = array();
162 162
 			$countries = EEM_Country::instance()->get_all_countries();
163
-			if ( ! empty( $countries )) {
164
-				foreach( $countries as $country ){
165
-					if ( $country instanceof EE_Country ) {
166
-						$country_options[ $country->ID() ] = $country->name();
163
+			if ( ! empty($countries)) {
164
+				foreach ($countries as $country) {
165
+					if ($country instanceof EE_Country) {
166
+						$country_options[$country->ID()] = $country->name();
167 167
 					}
168 168
 				}
169 169
 			}
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
 						// add hidden input to indicate that a new state is being added
177 177
 						'add_new_state' 	=> new EE_Hidden_Input(
178 178
 							array(
179
-								'html_name' 	=> str_replace( 'state', 'nsmf_add_new_state', $input->html_name() ),
180
-								'html_id' 			=> str_replace( 'state', 'nsmf_add_new_state', $input->html_id() ),
179
+								'html_name' 	=> str_replace('state', 'nsmf_add_new_state', $input->html_name()),
180
+								'html_id' 			=> str_replace('state', 'nsmf_add_new_state', $input->html_id()),
181 181
 								'default'			=> 0
182 182
 							)
183 183
 						),
@@ -189,10 +189,10 @@  discard block
 block discarded – undo
189 189
 									'',
190 190
 									__('click here to add a new state/province', 'event_espresso'),
191 191
 									'',
192
-									'display-' . $input->html_id(),
192
+									'display-'.$input->html_id(),
193 193
 									'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
194 194
 									'',
195
-									'data-target="' . $input->html_id() . '"'
195
+									'data-target="'.$input->html_id().'"'
196 196
 								)
197 197
 							)
198 198
 						),
@@ -200,13 +200,13 @@  discard block
 block discarded – undo
200 200
 						'add_new_state_micro_form' =>new EE_Form_Section_HTML(
201 201
 							apply_filters(
202 202
 								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
203
-								EEH_HTML::div( '', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', 'display: none;' ) .
204
-								EEH_HTML::h6( __('If your State/Province does not appear in the list above, you can easily add it by doing the following:', 'event_espresso')) .
205
-								EEH_HTML::ul() .
206
-								EEH_HTML::li( __('first select the Country that your State/Province belongs to', 'event_espresso') ) .
207
-								EEH_HTML::li( __('enter the name of your State/Province', 'event_espresso') ) .
208
-								EEH_HTML::li( __('enter a two to six letter abbreviation for the name of your State/Province', 'event_espresso') ) .
209
-								EEH_HTML::li( __('click the ADD button', 'event_espresso') ) .
203
+								EEH_HTML::div('', $input->html_id().'-dv', 'ee-form-add-new-state-dv', 'display: none;').
204
+								EEH_HTML::h6(__('If your State/Province does not appear in the list above, you can easily add it by doing the following:', 'event_espresso')).
205
+								EEH_HTML::ul().
206
+								EEH_HTML::li(__('first select the Country that your State/Province belongs to', 'event_espresso')).
207
+								EEH_HTML::li(__('enter the name of your State/Province', 'event_espresso')).
208
+								EEH_HTML::li(__('enter a two to six letter abbreviation for the name of your State/Province', 'event_espresso')).
209
+								EEH_HTML::li(__('click the ADD button', 'event_espresso')).
210 210
 								EEH_HTML::ulx()
211 211
 							)
212 212
 						),
@@ -215,10 +215,10 @@  discard block
 block discarded – undo
215 215
 							$country_options,
216 216
 							array(
217 217
 								'html_name' 			=> $country_name,
218
-								'html_id' 					=> str_replace( 'state', 'nsmf_new_state_country', $input->html_id() ),
219
-								'html_class' 			=> $input->html_class() . ' new-state-country',
218
+								'html_id' 					=> str_replace('state', 'nsmf_new_state_country', $input->html_id()),
219
+								'html_class' 			=> $input->html_class().' new-state-country',
220 220
 								'html_label_text'		=> __('New State/Province Country', 'event_espresso'),
221
-								'default'					=> EE_Registry::instance()->REQ->get( $country_name, '' ),
221
+								'default'					=> EE_Registry::instance()->REQ->get($country_name, ''),
222 222
 								'required' 				=> false
223 223
 							)
224 224
 						),
@@ -226,23 +226,23 @@  discard block
 block discarded – undo
226 226
 						'new_state_name' => new EE_Text_Input(
227 227
 							array(
228 228
 								'html_name' 			=> $state_name,
229
-								'html_id' 					=> str_replace( 'state', 'nsmf_new_state_name', $input->html_id() ),
230
-								'html_class' 			=> $input->html_class() . ' new-state-state',
229
+								'html_id' 					=> str_replace('state', 'nsmf_new_state_name', $input->html_id()),
230
+								'html_class' 			=> $input->html_class().' new-state-state',
231 231
 								'html_label_text'		=> __('New State/Province Name', 'event_espresso'),
232
-								'default'					=> EE_Registry::instance()->REQ->get( $state_name, '' ),
232
+								'default'					=> EE_Registry::instance()->REQ->get($state_name, ''),
233 233
 								'required' 				=> false
234 234
 							)
235 235
 						),
236
-						'spacer' => new EE_Form_Section_HTML( EEH_HTML::br() ),
236
+						'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()),
237 237
 						// NEW STATE NAME
238 238
 						'new_state_abbrv' => new EE_Text_Input(
239 239
 							array(
240 240
 								'html_name' 					=> $abbrv_name,
241
-								'html_id' 							=> str_replace( 'state', 'nsmf_new_state_abbrv', $input->html_id() ),
242
-								'html_class' 					=> $input->html_class() . ' new-state-abbrv',
241
+								'html_id' 							=> str_replace('state', 'nsmf_new_state_abbrv', $input->html_id()),
242
+								'html_class' 					=> $input->html_class().' new-state-abbrv',
243 243
 								'html_label_text'				=> __('New State/Province Abbreviation', 'event_espresso'),
244 244
 								'html_other_attributes'	=> 'size="24"',
245
-								'default'							=> EE_Registry::instance()->REQ->get( $abbrv_name, '' ),
245
+								'default'							=> EE_Registry::instance()->REQ->get($abbrv_name, ''),
246 246
 								'required' 						=> false
247 247
 							)
248 248
 						),
@@ -250,15 +250,15 @@  discard block
 block discarded – undo
250 250
 						'add_new_state_submit_button' => new EE_Form_Section_HTML(
251 251
 							apply_filters(
252 252
 								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
253
-								EEH_HTML::nbsp(3) .
253
+								EEH_HTML::nbsp(3).
254 254
 								EEH_HTML::link(
255 255
 									'',
256 256
 									__('ADD', 'event_espresso'),
257 257
 									'',
258
-									'submit-' . $new_state_submit_id,
258
+									'submit-'.$new_state_submit_id,
259 259
 									'ee-form-add-new-state-submit button button-secondary',
260 260
 									'',
261
-									'data-target="' . $new_state_submit_id . '"'
261
+									'data-target="'.$new_state_submit_id.'"'
262 262
 								)
263 263
 							)
264 264
 						),
@@ -266,18 +266,18 @@  discard block
 block discarded – undo
266 266
 						'add_new_state_extra' => new EE_Form_Section_HTML(
267 267
 							apply_filters(
268 268
 								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
269
-								EEH_HTML::br(2) .
270
-								EEH_HTML::div( '', '', 'small-text' ) .
271
-								EEH_HTML::strong( __('Don\'t know your State/Province Abbreviation?', 'event_espresso') ) .
272
-								EEH_HTML::br() .
269
+								EEH_HTML::br(2).
270
+								EEH_HTML::div('', '', 'small-text').
271
+								EEH_HTML::strong(__('Don\'t know your State/Province Abbreviation?', 'event_espresso')).
272
+								EEH_HTML::br().
273 273
 								sprintf(
274 274
 									__('You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', 'event_espresso'),
275
-									EEH_HTML::link( 'http://en.wikipedia.org/wiki/ISO_3166-2', 'http://en.wikipedia.org/wiki/ISO_3166-2', '', '', 'ee-form-add-new-state-wiki-lnk' )
276
-								) .
277
-								EEH_HTML::divx() .
278
-								EEH_HTML::br() .
279
-								EEH_HTML::link( '', __('cancel new state/province', 'event_espresso'), '', 'hide-' . $input->html_id(), 'ee-form-cancel-new-state-lnk smaller-text', '', 'data-target="' . $input->html_id() . '"' ) .
280
-								EEH_HTML::divx() .
275
+									EEH_HTML::link('http://en.wikipedia.org/wiki/ISO_3166-2', 'http://en.wikipedia.org/wiki/ISO_3166-2', '', '', 'ee-form-add-new-state-wiki-lnk')
276
+								).
277
+								EEH_HTML::divx().
278
+								EEH_HTML::br().
279
+								EEH_HTML::link('', __('cancel new state/province', 'event_espresso'), '', 'hide-'.$input->html_id(), 'ee-form-cancel-new-state-lnk smaller-text', '', 'data-target="'.$input->html_id().'"').
280
+								EEH_HTML::divx().
281 281
 								EEH_HTML::br()
282 282
 							)
283 283
 						)
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 					)
286 286
 				)
287 287
 			);
288
-			$question_group_reg_form->add_subsections( array( 'new_state_micro_form' => $new_state_micro_form ), 'state', false );
288
+			$question_group_reg_form->add_subsections(array('new_state_micro_form' => $new_state_micro_form), 'state', false);
289 289
 		}
290 290
 		return $question_group_reg_form;
291 291
 	}
@@ -303,50 +303,50 @@  discard block
 block discarded – undo
303 303
 	public static function add_new_state() {
304 304
 		$REQ = EE_Registry::instance()->load_core('Request_Handler');
305 305
 		if (
306
-			$REQ->is_set( 'nsmf_add_new_state' )
307
-			&& $REQ->get( 'nsmf_add_new_state' ) == 1
306
+			$REQ->is_set('nsmf_add_new_state')
307
+			&& $REQ->get('nsmf_add_new_state') == 1
308 308
 		) {
309 309
 			EE_Registry::instance()->load_model('State');
310 310
 			// grab country ISO code, new state name, and new state abbreviation
311
-			$state_country = $REQ->is_set( 'nsmf_new_state_country' )
312
-				? sanitize_text_field( $REQ->get( 'nsmf_new_state_country' ) )
311
+			$state_country = $REQ->is_set('nsmf_new_state_country')
312
+				? sanitize_text_field($REQ->get('nsmf_new_state_country'))
313 313
 				: false;
314
-			$state_name = $REQ->is_set( 'nsmf_new_state_name' )
315
-				? sanitize_text_field( $REQ->get( 'nsmf_new_state_name' ) )
314
+			$state_name = $REQ->is_set('nsmf_new_state_name')
315
+				? sanitize_text_field($REQ->get('nsmf_new_state_name'))
316 316
 				: false;
317
-			$state_abbr = $REQ->is_set( 'nsmf_new_state_abbrv' )
318
-				? sanitize_text_field( $REQ->get( 'nsmf_new_state_abbrv' ) )
317
+			$state_abbr = $REQ->is_set('nsmf_new_state_abbrv')
318
+				? sanitize_text_field($REQ->get('nsmf_new_state_abbrv'))
319 319
 				: false;
320 320
 //echo '<h4>$state_country : ' . $state_country . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
321 321
 //echo '<h4>$state_name : ' . $state_name . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
322 322
 //echo '<h4>$state_abbr : ' . $state_abbr . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
323 323
 
324
-			if ( $state_country && $state_name && $state_abbr ) {
325
-				$new_state = EED_Add_New_State::save_new_state_to_db( array(
326
-					'CNT_ISO'=> strtoupper( $state_country ),
327
-					'STA_abbrev' => strtoupper( $state_abbr ),
328
-					'STA_name' => ucwords( $state_name ),
324
+			if ($state_country && $state_name && $state_abbr) {
325
+				$new_state = EED_Add_New_State::save_new_state_to_db(array(
326
+					'CNT_ISO'=> strtoupper($state_country),
327
+					'STA_abbrev' => strtoupper($state_abbr),
328
+					'STA_name' => ucwords($state_name),
329 329
 					'STA_active' => FALSE
330 330
 				));
331 331
 
332
-				if ( $new_state instanceof EE_State ) {
332
+				if ($new_state instanceof EE_State) {
333 333
 					// clean house
334
-					EE_Registry::instance()->REQ->un_set( 'nsmf_add_new_state' );
335
-					EE_Registry::instance()->REQ->un_set( 'nsmf_new_state_country' );
336
-					EE_Registry::instance()->REQ->un_set( 'nsmf_new_state_name' );
337
-					EE_Registry::instance()->REQ->un_set( 'nsmf_new_state_abbrv' );
334
+					EE_Registry::instance()->REQ->un_set('nsmf_add_new_state');
335
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_country');
336
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_name');
337
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv');
338 338
 
339 339
 					// get any existing new states
340 340
 					$new_states = EE_Registry::instance()->SSN->get_session_data(
341 341
 						'nsmf_new_states'
342 342
 					);
343
-					$new_states[ $new_state->ID() ] = $new_state;
343
+					$new_states[$new_state->ID()] = $new_state;
344 344
 					EE_Registry::instance()->SSN->set_session_data(
345
-						array( 'nsmf_new_states' => $new_states )
345
+						array('nsmf_new_states' => $new_states)
346 346
 					);
347 347
 
348
-					if ( EE_Registry::instance()->REQ->ajax ) {
349
-						echo wp_json_encode( array(
348
+					if (EE_Registry::instance()->REQ->ajax) {
349
+						echo wp_json_encode(array(
350 350
 							'success' => TRUE,
351 351
 							'id' => $new_state->ID(),
352 352
 							'name' => $new_state->name(),
@@ -361,12 +361,12 @@  discard block
 block discarded – undo
361 361
 				}
362 362
 
363 363
 			} else {
364
-				$error = __( 'A new State/Province could not be added because invalid or missing data was received.', 'event_espresso' );
365
-				if ( EE_Registry::instance()->REQ->ajax ) {
366
-					echo wp_json_encode( array( 'error' => $error ));
364
+				$error = __('A new State/Province could not be added because invalid or missing data was received.', 'event_espresso');
365
+				if (EE_Registry::instance()->REQ->ajax) {
366
+					echo wp_json_encode(array('error' => $error));
367 367
 					exit();
368 368
 				} else {
369
-					EE_Error::add_error( $error, __FILE__, __FUNCTION__, __LINE__ );
369
+					EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
370 370
 				}
371 371
 			}
372 372
 		}
@@ -384,11 +384,11 @@  discard block
 block discarded – undo
384 384
 	 * @param array $request_params
385 385
 	 * @return array
386 386
 	 */
387
-	public static function filter_checkout_request_params ( $request_params ) {
388
-		foreach ( $request_params as $form_section ) {
389
-			if ( is_array( $form_section )) {
390
-				EED_Add_New_State::unset_new_state_request_params( $form_section );
391
-				EED_Add_New_State::filter_checkout_request_params( $form_section );
387
+	public static function filter_checkout_request_params($request_params) {
388
+		foreach ($request_params as $form_section) {
389
+			if (is_array($form_section)) {
390
+				EED_Add_New_State::unset_new_state_request_params($form_section);
391
+				EED_Add_New_State::filter_checkout_request_params($form_section);
392 392
 			}
393 393
 		}
394 394
 		return $request_params;
@@ -403,12 +403,12 @@  discard block
 block discarded – undo
403 403
 	 * @param array $request_params
404 404
 	 * @return        boolean
405 405
 	 */
406
-	public static function unset_new_state_request_params ( $request_params ) {
407
-		unset( $request_params[ 'new_state_micro_form' ] );
408
-		unset( $request_params[ 'new_state_micro_add_new_state' ] );
409
-		unset( $request_params[ 'new_state_micro_new_state_country' ] );
410
-		unset( $request_params[ 'new_state_micro_new_state_name' ] );
411
-		unset( $request_params[ 'new_state_micro_new_state_abbrv' ] );
406
+	public static function unset_new_state_request_params($request_params) {
407
+		unset($request_params['new_state_micro_form']);
408
+		unset($request_params['new_state_micro_add_new_state']);
409
+		unset($request_params['new_state_micro_new_state_country']);
410
+		unset($request_params['new_state_micro_new_state_name']);
411
+		unset($request_params['new_state_micro_new_state_abbrv']);
412 412
 		return $request_params;
413 413
 	}
414 414
 
@@ -422,13 +422,13 @@  discard block
 block discarded – undo
422 422
      * @throws \EE_Error
423 423
      * @throws InvalidDataTypeException
424 424
      */
425
-	public static function save_new_state_to_db ( $props_n_values = array() ) {
426
-		$existing_state = EEM_State::instance()->get_all( array( $props_n_values, 'limit' => 1 ));
427
-		if ( ! empty( $existing_state )) {
428
-			return array_pop( $existing_state );
425
+	public static function save_new_state_to_db($props_n_values = array()) {
426
+		$existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
427
+		if ( ! empty($existing_state)) {
428
+			return array_pop($existing_state);
429 429
 		}
430
-		$new_state = EE_State::new_instance( $props_n_values );
431
-		if ( $new_state instanceof EE_State ) {
430
+		$new_state = EE_State::new_instance($props_n_values);
431
+		if ($new_state instanceof EE_State) {
432 432
 		    $country_settings_url = add_query_arg(
433 433
                 array(
434 434
                     'page'    => 'espresso_general_settings',
@@ -439,16 +439,16 @@  discard block
 block discarded – undo
439 439
             );
440 440
 			// if not non-ajax admin
441 441
             new PersistentAdminNotice(
442
-                'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
442
+                'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(),
443 443
                 sprintf(
444 444
                     __(
445 445
                         'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
446 446
                         'event_espresso'
447 447
                     ),
448
-                    '<b>' . $new_state->name() . '</b>',
449
-                    '<b>' . $new_state->abbrev() . '</b>',
450
-                    '<b>' . $new_state->country()->name() . '</b>',
451
-                    '<a href="' . $country_settings_url . '">' . __('Event Espresso - General Settings > Countries Tab', 'event_espresso') . '</a>',
448
+                    '<b>'.$new_state->name().'</b>',
449
+                    '<b>'.$new_state->abbrev().'</b>',
450
+                    '<b>'.$new_state->country()->name().'</b>',
451
+                    '<a href="'.$country_settings_url.'">'.__('Event Espresso - General Settings > Countries Tab', 'event_espresso').'</a>',
452 452
                     '<br />'
453 453
                 )
454 454
             );
@@ -474,26 +474,26 @@  discard block
 block discarded – undo
474 474
      * @throws DomainException
475 475
      * @throws ServiceNotFoundException
476 476
      */
477
-	public static function update_country_settings( $CNT_ISO = '', $STA_ID = '', $cols_n_values = array() ) {
478
-		$CNT_ISO = ! empty( $CNT_ISO ) ? $CNT_ISO : FALSE;
479
-		if ( ! $CNT_ISO ) {
480
-			EE_Error::add_error( __( 'An invalid or missing Country ISO Code was received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
477
+	public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) {
478
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : FALSE;
479
+		if ( ! $CNT_ISO) {
480
+			EE_Error::add_error(__('An invalid or missing Country ISO Code was received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
481 481
 		}
482
-		$STA_abbrev = is_array( $cols_n_values ) && isset( $cols_n_values['STA_abbrev'] ) ? $cols_n_values['STA_abbrev'] : FALSE;
483
-		if (  ! $STA_abbrev && ! empty( $STA_ID )) {
484
-			$state = EEM_State::instance()->get_one_by_ID( $STA_ID );
485
-			if ( $state instanceof EE_State ) {
482
+		$STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] : FALSE;
483
+		if ( ! $STA_abbrev && ! empty($STA_ID)) {
484
+			$state = EEM_State::instance()->get_one_by_ID($STA_ID);
485
+			if ($state instanceof EE_State) {
486 486
 				$STA_abbrev = $state->abbrev();
487 487
 			}
488 488
 		}
489
-		if ( ! $STA_abbrev ) {
490
-			EE_Error::add_error( __( 'An invalid or missing State Abbreviation was received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
489
+		if ( ! $STA_abbrev) {
490
+			EE_Error::add_error(__('An invalid or missing State Abbreviation was received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
491 491
 		}
492 492
         /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
493 493
         $persistent_admin_notice_manager = CoffeeMill::getService(
494 494
             'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
495 495
         );
496
-        $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
496
+        $persistent_admin_notice_manager->dismissNotice($CNT_ISO.'-'.$STA_abbrev, true, true);
497 497
 	}
498 498
 
499 499
 
@@ -509,19 +509,19 @@  discard block
 block discarded – undo
509 509
 	 * @param $answer
510 510
 	 * @return bool
511 511
 	 */
512
-	public static function inject_new_reg_state_into_options( $state_options = array(), EE_SPCO_Reg_Step_Attendee_Information $reg_step, EE_Registration $registration, EE_Question $question, $answer ) {
513
-		if ( $answer instanceof EE_Answer  && $question instanceof EE_Question && $question->type() === EEM_Question::QST_type_state ) {
512
+	public static function inject_new_reg_state_into_options($state_options = array(), EE_SPCO_Reg_Step_Attendee_Information $reg_step, EE_Registration $registration, EE_Question $question, $answer) {
513
+		if ($answer instanceof EE_Answer && $question instanceof EE_Question && $question->type() === EEM_Question::QST_type_state) {
514 514
 			$STA_ID = $answer->value();
515
-			if ( ! empty( $STA_ID ) ) {
516
-				$state = EEM_State::instance()->get_one_by_ID( $STA_ID );
517
-				if ( $state instanceof EE_State ) {
515
+			if ( ! empty($STA_ID)) {
516
+				$state = EEM_State::instance()->get_one_by_ID($STA_ID);
517
+				if ($state instanceof EE_State) {
518 518
 					$country = $state->country();
519
-					if ( $country instanceof EE_Country ) {
520
-						if ( ! isset( $state_options[ $country->name() ] )) {
521
-							$state_options[ $country->name() ] = array();
519
+					if ($country instanceof EE_Country) {
520
+						if ( ! isset($state_options[$country->name()])) {
521
+							$state_options[$country->name()] = array();
522 522
 						}
523
-						if ( ! isset( $state_options[ $country->name() ][ $STA_ID ] )) {
524
-							$state_options[ $country->name() ][ $STA_ID ] = $state->name();
523
+						if ( ! isset($state_options[$country->name()][$STA_ID])) {
524
+							$state_options[$country->name()][$STA_ID] = $state->name();
525 525
 						}
526 526
 					}
527 527
 				}
@@ -543,14 +543,14 @@  discard block
 block discarded – undo
543 543
 	 * @param $answer
544 544
 	 * @return bool
545 545
 	 */
546
-	public static function inject_new_reg_country_into_options( $country_options = array(), EE_SPCO_Reg_Step_Attendee_Information $reg_step, EE_Registration $registration, EE_Question $question, $answer ) {
547
-		if ( $answer instanceof EE_Answer && $question instanceof EE_Question && $question->type() === EEM_Question::QST_type_country ) {
546
+	public static function inject_new_reg_country_into_options($country_options = array(), EE_SPCO_Reg_Step_Attendee_Information $reg_step, EE_Registration $registration, EE_Question $question, $answer) {
547
+		if ($answer instanceof EE_Answer && $question instanceof EE_Question && $question->type() === EEM_Question::QST_type_country) {
548 548
 			$CNT_ISO = $answer->value();
549
-			if ( ! empty( $CNT_ISO ) ) {
550
-				$country = EEM_Country::instance()->get_one_by_ID( $CNT_ISO );
551
-				if ( $country instanceof EE_Country ) {
552
-					if ( ! isset( $country_options[ $CNT_ISO ] ) ) {
553
-						$country_options[ $CNT_ISO ] = $country->name();
549
+			if ( ! empty($CNT_ISO)) {
550
+				$country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
551
+				if ($country instanceof EE_Country) {
552
+					if ( ! isset($country_options[$CNT_ISO])) {
553
+						$country_options[$CNT_ISO] = $country->name();
554 554
 					}
555 555
 				}
556 556
 			}
@@ -567,14 +567,14 @@  discard block
 block discarded – undo
567 567
 	 * @param EE_State[]  $state_options
568 568
 	 * @return        boolean
569 569
 	 */
570
-	public static function state_options( $state_options = array() ) {
570
+	public static function state_options($state_options = array()) {
571 571
 		$new_states = EED_Add_New_State::_get_new_states();
572
-		foreach ( $new_states as $new_state ) {
572
+		foreach ($new_states as $new_state) {
573 573
 			if (
574 574
 				$new_state instanceof EE_State
575 575
 				&& $new_state->country() instanceof EE_Country
576 576
 			) {
577
-				$state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
577
+				$state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name();
578 578
 			}
579 579
 		}
580 580
 		return $state_options;
@@ -590,12 +590,12 @@  discard block
 block discarded – undo
590 590
 	 */
591 591
 	protected static function _get_new_states() {
592 592
 		$new_states = array();
593
-		if ( EE_Registry::instance()->SSN instanceof EE_Session ) {
593
+		if (EE_Registry::instance()->SSN instanceof EE_Session) {
594 594
 			$new_states = EE_Registry::instance()->SSN->get_session_data(
595 595
 				'nsmf_new_states'
596 596
 			);
597 597
 		}
598
-		return is_array( $new_states ) ? $new_states : array();
598
+		return is_array($new_states) ? $new_states : array();
599 599
 	}
600 600
 
601 601
 
@@ -607,14 +607,14 @@  discard block
 block discarded – undo
607 607
 	 * @param EE_Country[]  $country_options
608 608
 	 * @return        boolean
609 609
 	 */
610
-	public static function country_options( $country_options = array() ) {
610
+	public static function country_options($country_options = array()) {
611 611
 		$new_states = EED_Add_New_State::_get_new_states();
612
-		foreach ( $new_states as $new_state ) {
612
+		foreach ($new_states as $new_state) {
613 613
 			if (
614 614
 				$new_state instanceof EE_State
615 615
 				&& $new_state->country() instanceof EE_Country
616 616
 			) {
617
-				$country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
617
+				$country_options[$new_state->country()->ID()] = $new_state->country()->name();
618 618
 			}
619 619
 		}
620 620
 		return $country_options;
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,9 @@
 block discarded – undo
6 6
 use EventEspresso\core\services\container\exceptions\ServiceNotFoundException;
7 7
 use EventEspresso\core\services\notifications\PersistentAdminNoticeManager;
8 8
 
9
-if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
9
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
10
+	exit('No direct script access allowed');
11
+}
10 12
 /**
11 13
  *
12 14
  * EED_Add_New_State class
Please login to merge, or discard this patch.
modules/core_rest_api/EED_Core_Rest_Api.module.php 2 patches
Indentation   +843 added lines, -843 removed lines patch added patch discarded remove patch
@@ -20,850 +20,850 @@
 block discarded – undo
20 20
 class EED_Core_Rest_Api extends \EED_Module
21 21
 {
22 22
 
23
-    const ee_api_namespace           = 'ee/v';
23
+	const ee_api_namespace           = 'ee/v';
24 24
 
25
-    const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
26
-
27
-    const saved_routes_option_names  = 'ee_core_routes';
28
-
29
-    /**
30
-     * string used in _links response bodies to make them globally unique.
31
-     *
32
-     * @see http://v2.wp-api.org/extending/linking/
33
-     */
34
-    const ee_api_link_namespace = 'https://api.eventespresso.com/';
35
-
36
-    /**
37
-     * @var Calculated_Model_Fields
38
-     */
39
-    protected static $_field_calculator = null;
40
-
41
-
42
-
43
-    /**
44
-     * @return EED_Core_Rest_Api
45
-     */
46
-    public static function instance()
47
-    {
48
-        self::$_field_calculator = new Calculated_Model_Fields();
49
-        return parent::get_instance(__CLASS__);
50
-    }
51
-
52
-
53
-
54
-    /**
55
-     *    set_hooks - for hooking into EE Core, other modules, etc
56
-     *
57
-     * @access    public
58
-     * @return    void
59
-     */
60
-    public static function set_hooks()
61
-    {
62
-        self::set_hooks_both();
63
-    }
64
-
65
-
66
-
67
-    /**
68
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
69
-     *
70
-     * @access    public
71
-     * @return    void
72
-     */
73
-    public static function set_hooks_admin()
74
-    {
75
-        self::set_hooks_both();
76
-    }
77
-
78
-
79
-
80
-    public static function set_hooks_both()
81
-    {
82
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
83
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
84
-        add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
85
-        add_filter('rest_index',
86
-            array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index'));
87
-        EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
88
-    }
89
-
90
-
91
-
92
-    /**
93
-     * sets up hooks which only need to be included as part of REST API requests;
94
-     * other requests like to the frontend or admin etc don't need them
95
-     */
96
-    public static function set_hooks_rest_api()
97
-    {
98
-        //set hooks which account for changes made to the API
99
-        EED_Core_Rest_Api::_set_hooks_for_changes();
100
-        EED_Core_Rest_Api::maybe_notify_of_basic_auth_removal();
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * public wrapper of _set_hooks_for_changes.
107
-     * Loads all the hooks which make requests to old versions of the API
108
-     * appear the same as they always did
109
-     */
110
-    public static function set_hooks_for_changes()
111
-    {
112
-        self::_set_hooks_for_changes();
113
-    }
114
-
115
-
116
-
117
-    /**
118
-     * If the user appears to be using WP API basic auth, tell them (via a persistent
119
-     * admin notice and an email) that we're going to remove it soon, so they should
120
-     * replace it with application passwords.
121
-     *
122
-     * @throws InvalidDataTypeException
123
-     */
124
-    public static function maybe_notify_of_basic_auth_removal()
125
-    {
126
-        if (
127
-        apply_filters(
128
-            'FHEE__EED_Core_Rest_Api__maybe_notify_of_basic_auth_removal__override',
129
-            ! isset($_SERVER['PHP_AUTH_USER'])
130
-            && ! isset($_SERVER['HTTP_AUTHORIZATION'])
131
-        )
132
-        ) {
133
-            //sure it's a WP API request, but they aren't using basic auth, so don't bother them
134
-            return;
135
-        }
136
-        //ok they're using the WP API with Basic Auth
137
-        new PersistentAdminNotice(
138
-            'using_basic_auth',
139
-            sprintf(
140
-                __(
141
-                    'We noticed you\'re using the WP API, which is used by the Event Espresso 4 mobile apps. Because of security and compatibility concerns, we will soon be removing our default authentication mechanism, WP API Basic Auth, from Event Espresso. It is recommended you instead install the %1$sWP Application Passwords plugin%2$s and use it with the EE4 Mobile apps. See %3$sour mobile app documentation%2$s for more information. %4$sIf you have installed the WP API Basic Auth plugin separately, or are not using the Event Espresso 4 mobile apps, you can disregard this message.%4$sThe Event Espresso Team',
142
-                    'event_espresso'
143
-                ),
144
-                '<a href="https://wordpress.org/plugins/application-passwords/">',
145
-                '</a>',
146
-                '<a href="https://eventespresso.com/wiki/ee4-event-apps/#authentication">',
147
-                '<br/>'
148
-            )
149
-        );
150
-        if ( ! get_option('ee_notified_admin_on_basic_auth_removal', false)) {
151
-            add_option('ee_notified_admin_on_basic_auth_removal', true);
152
-            //piggy back off EE_Error::set_content_type, which sets the content type to HTML
153
-            add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
154
-            //and send the message to the site admin too
155
-            wp_mail(get_option('admin_email'),
156
-                __('Notice of Removal of WP API Basic Auth From Event Espresso 4', 'event_espresso'), $message);
157
-            remove_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
158
-        }
159
-    }
160
-
161
-
162
-
163
-    /**
164
-     * Loads all the hooks which make requests to old versions of the API
165
-     * appear the same as they always did
166
-     */
167
-    protected static function _set_hooks_for_changes()
168
-    {
169
-        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
170
-        foreach ($folder_contents as $classname_in_namespace => $filepath) {
171
-            //ignore the base parent class
172
-            if ($classname_in_namespace === 'Changes_In_Base') {
173
-                continue;
174
-            }
175
-            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
176
-            if (class_exists($full_classname)) {
177
-                $instance_of_class = new $full_classname;
178
-                if ($instance_of_class instanceof Changes_In_Base) {
179
-                    $instance_of_class->set_hooks();
180
-                }
181
-            }
182
-        }
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * Filters the WP routes to add our EE-related ones. This takes a bit of time
189
-     * so we actually prefer to only do it when an EE plugin is activated or upgraded
190
-     */
191
-    public static function register_routes()
192
-    {
193
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
194
-            foreach ($relative_urls as $endpoint => $routes) {
195
-                foreach ($routes as $route) {
196
-                    $route_args = array(
197
-                        array(
198
-                            'callback' => $route['callback'],
199
-                            'methods'  => $route['methods'],
200
-                            'args'     => isset($route['args']) ? $route['args'] : array(),
201
-                        )
202
-                    );
203
-                    if (isset($route['schema_callback'])) {
204
-                        $model_name = isset($route['schema_callback'][0])
205
-                            ? $route['schema_callback'][0]
206
-                            : '';
207
-                        $version = isset( $route['schema_callback'][1])
208
-                            ? $route['schema_callback'][1]
209
-                            : '';
210
-                        if (! empty($model_name) && ! empty($version)) {
211
-                            $route_args['schema'] = function () use ($model_name, $version) {
212
-                                return ModelRead::handle_schema_request(
213
-                                    $model_name,
214
-                                    $version
215
-                                );
216
-                            };
217
-                        }
218
-                    }
219
-                    register_rest_route(
220
-                        $namespace,
221
-                        $endpoint,
222
-                        $route_args
223
-                    );
224
-                }
225
-            }
226
-        }
227
-    }
228
-
229
-
230
-
231
-    /**
232
-     * Checks if there was a version change or something that merits invalidating the cached
233
-     * route data. If so, invalidates the cached route data so that it gets refreshed
234
-     * next time the WP API is used
235
-     */
236
-    public static function invalidate_cached_route_data_on_version_change()
237
-    {
238
-        if (EE_System::instance()->detect_req_type() != EE_System::req_type_normal) {
239
-            EED_Core_Rest_Api::invalidate_cached_route_data();
240
-        }
241
-        foreach (EE_Registry::instance()->addons as $addon) {
242
-            if ($addon instanceof EE_Addon && $addon->detect_req_type() != EE_System::req_type_normal) {
243
-                EED_Core_Rest_Api::invalidate_cached_route_data();
244
-            }
245
-        }
246
-    }
247
-
248
-
249
-
250
-    /**
251
-     * Removes the cached route data so it will get refreshed next time the WP API is used
252
-     */
253
-    public static function invalidate_cached_route_data()
254
-    {
255
-        //delete the saved EE REST API routes
256
-        foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
257
-            delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
258
-        }
259
-    }
260
-
261
-
262
-
263
-    /**
264
-     * Gets the EE route data
265
-     *
266
-     * @return array top-level key is the namespace, next-level key is the route and its value is array{
267
-     * @type string|array $callback
268
-     * @type string       $methods
269
-     * @type boolean      $hidden_endpoint
270
-     * }
271
-     */
272
-    public static function get_ee_route_data()
273
-    {
274
-        $ee_routes = array();
275
-        foreach (self::versions_served() as $version => $hidden_endpoints) {
276
-            $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version($version,
277
-                $hidden_endpoints);
278
-        }
279
-        return $ee_routes;
280
-    }
281
-
282
-
283
-
284
-    /**
285
-     * Gets the EE route data from the wp options if it exists already,
286
-     * otherwise re-generates it and saves it to the option
287
-     *
288
-     * @param string  $version
289
-     * @param boolean $hidden_endpoints
290
-     * @return array
291
-     */
292
-    protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
293
-    {
294
-        $ee_routes = get_option(self::saved_routes_option_names . $version, null);
295
-        if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
296
-            $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
297
-        }
298
-        return $ee_routes;
299
-    }
300
-
301
-
302
-
303
-    /**
304
-     * Saves the EE REST API route data to a wp option and returns it
305
-     *
306
-     * @param string  $version
307
-     * @param boolean $hidden_endpoints
308
-     * @return mixed|null|void
309
-     */
310
-    protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
311
-    {
312
-        $instance = self::instance();
313
-        $routes = apply_filters(
314
-            'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
315
-            array_replace_recursive(
316
-                $instance->_get_config_route_data_for_version($version, $hidden_endpoints),
317
-                $instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
318
-                $instance->_get_model_route_data_for_version($version, $hidden_endpoints),
319
-                $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
320
-            )
321
-        );
322
-        $option_name = self::saved_routes_option_names . $version;
323
-        if (get_option($option_name)) {
324
-            update_option($option_name, $routes, true);
325
-        } else {
326
-            add_option($option_name, $routes, null, 'no');
327
-        }
328
-        return $routes;
329
-    }
330
-
331
-
332
-
333
-    /**
334
-     * Calculates all the EE routes and saves it to a wordpress option so we don't
335
-     * need to calculate it on every request
336
-     *
337
-     * @deprecated since version 4.9.1
338
-     * @return void
339
-     */
340
-    public static function save_ee_routes()
341
-    {
342
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
343
-            $instance = self::instance();
344
-            $routes = apply_filters(
345
-                'EED_Core_Rest_Api__save_ee_routes__routes',
346
-                array_replace_recursive(
347
-                    $instance->_register_config_routes(),
348
-                    $instance->_register_meta_routes(),
349
-                    $instance->_register_model_routes(),
350
-                    $instance->_register_rpc_routes()
351
-                )
352
-            );
353
-            update_option(self::saved_routes_option_names, $routes, true);
354
-        }
355
-    }
356
-
357
-
358
-
359
-    /**
360
-     * Gets all the route information relating to EE models
361
-     *
362
-     * @return array @see get_ee_route_data
363
-     * @deprecated since version 4.9.1
364
-     */
365
-    protected function _register_model_routes()
366
-    {
367
-        $model_routes = array();
368
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
369
-            $model_routes[EED_Core_Rest_Api::ee_api_namespace
370
-                          . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
371
-        }
372
-        return $model_routes;
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * Gets the route data for EE models in the specified version
379
-     *
380
-     * @param string  $version
381
-     * @param boolean $hidden_endpoint
382
-     * @return array
383
-     */
384
-    protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
385
-    {
386
-        $model_version_info = new Model_Version_Info($version);
387
-        $models_to_register = apply_filters(
388
-            'FHEE__EED_Core_REST_API___register_model_routes',
389
-            $model_version_info->models_for_requested_version()
390
-        );
391
-        //let's not bother having endpoints for extra metas
392
-        unset($models_to_register['Extra_Meta']);
393
-        unset($models_to_register['Extra_Join']);
394
-        $model_routes = array();
395
-        foreach ($models_to_register as $model_name => $model_classname) {
396
-            $model = \EE_Registry::instance()->load_model($model_name);
397
-
398
-            //if this isn't a valid model then let's skip iterate to the next item in the loop.
399
-            if (! $model instanceof EEM_Base) {
400
-                continue;
401
-            }
402
-
403
-            //yes we could just register one route for ALL models, but then they wouldn't show up in the index
404
-            $plural_model_route = EEH_Inflector::pluralize_and_lower($model_name);
405
-            $singular_model_route = $plural_model_route . '/(?P<id>\d+)';
406
-            $model_routes[$plural_model_route] = array(
407
-                array(
408
-                    'callback'        => array(
409
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
410
-                        'handle_request_get_all',
411
-                    ),
412
-                    'methods'         => WP_REST_Server::READABLE,
413
-                    'hidden_endpoint' => $hidden_endpoint,
414
-                    'args'            => $this->_get_read_query_params($model, $version),
415
-                    '_links'          => array(
416
-                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
417
-                    ),
418
-                    'schema_callback' => array($model_name, $version)
419
-                ),
420
-                //						array(
421
-                //							'callback' => array(
422
-                //								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
423
-                //								'handle_request_create_one' ),
424
-                //							'methods' => WP_REST_Server::CREATABLE,
425
-                //							'hidden_endpoint' => $hidden_endpoint
426
-                //						)
427
-            );
428
-            $model_routes[$singular_model_route] = array(
429
-                array(
430
-                    'callback'        => array(
431
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
432
-                        'handle_request_get_one',
433
-                    ),
434
-                    'methods'         => WP_REST_Server::READABLE,
435
-                    'hidden_endpoint' => $hidden_endpoint,
436
-                    'args'            => $this->_get_response_selection_query_params($model, $version),
437
-                ),
438
-                //						array(
439
-                //							'callback' => array(
440
-                //								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
441
-                //								'handle_request_edit_one' ),
442
-                //							'methods' => WP_REST_Server::EDITABLE,
443
-                //							'hidden_endpoint' => $hidden_endpoint
444
-                //							),
445
-            );
446
-            //@todo: also handle  DELETE for a single item
447
-            foreach ($model_version_info->relation_settings($model) as $relation_name => $relation_obj) {
448
-                $related_model_name_endpoint_part = ModelRead::get_related_entity_name(
449
-                    $relation_name,
450
-                    $relation_obj
451
-                );
452
-                $model_routes[$singular_model_route . '/' . $related_model_name_endpoint_part] = array(
453
-                    array(
454
-                        'callback'        => array(
455
-                            'EventEspresso\core\libraries\rest_api\controllers\model\Read',
456
-                            'handle_request_get_related',
457
-                        ),
458
-                        'methods'         => WP_REST_Server::READABLE,
459
-                        'hidden_endpoint' => $hidden_endpoint,
460
-                        'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
461
-                    ),
462
-                    //							array(
463
-                    //								'callback' => array(
464
-                    //									'EventEspresso\core\libraries\rest_api\controllers\model\Write',
465
-                    //									'handle_request_create_or_update_related' ),
466
-                    //								'methods' => WP_REST_Server::EDITABLE,
467
-                    //								'hidden_endpoint' => $hidden_endpoint
468
-                    //							)
469
-                );
470
-                //@todo: handle delete related and possibly remove relation (not sure hwo to distinguish)
471
-            }
472
-        }
473
-        return $model_routes;
474
-    }
475
-
476
-
477
-
478
-    /**
479
-     * Adds all the RPC-style routes (remote procedure call-like routes, ie
480
-     * routes that don't conform to the traditional REST CRUD-style).
481
-     *
482
-     * @deprecated since 4.9.1
483
-     */
484
-    protected function _register_rpc_routes()
485
-    {
486
-        $routes = array();
487
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
488
-            $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version($version,
489
-                $hidden_endpoint);
490
-        }
491
-        return $routes;
492
-    }
493
-
494
-
495
-
496
-    /**
497
-     * @param string  $version
498
-     * @param boolean $hidden_endpoint
499
-     * @return array
500
-     */
501
-    protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
502
-    {
503
-        $this_versions_routes = array();
504
-        //checkin endpoint
505
-        $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
506
-            array(
507
-                'callback'        => array(
508
-                    'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
509
-                    'handle_request_toggle_checkin',
510
-                ),
511
-                'methods'         => WP_REST_Server::CREATABLE,
512
-                'hidden_endpoint' => $hidden_endpoint,
513
-                'args'            => array(
514
-                    'force' => array(
515
-                        'required'    => false,
516
-                        'default'     => false,
517
-                        'description' => __('Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
518
-                            'event_espresso'),
519
-                    ),
520
-                ),
521
-            ),
522
-        );
523
-        return apply_filters(
524
-            'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
525
-            $this_versions_routes,
526
-            $version,
527
-            $hidden_endpoint
528
-        );
529
-    }
530
-
531
-
532
-
533
-    /**
534
-     * Gets the query params that can be used when request one or many
535
-     *
536
-     * @param EEM_Base $model
537
-     * @param string   $version
538
-     * @return array
539
-     */
540
-    protected function _get_response_selection_query_params(\EEM_Base $model, $version)
541
-    {
542
-        return apply_filters(
543
-            'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
544
-            array(
545
-                'include'   => array(
546
-                    'required' => false,
547
-                    'default'  => '*',
548
-                ),
549
-                'calculate' => array(
550
-                    'required' => false,
551
-                    'default'  => '',
552
-                    'enum'     => self::$_field_calculator->retrieve_calculated_fields_for_model($model),
553
-                ),
554
-            ),
555
-            $model,
556
-            $version
557
-        );
558
-    }
559
-
560
-
561
-
562
-    /**
563
-     * Gets info about reading query params that are acceptable
564
-     *
565
-     * @param \EEM_Base $model eg 'Event' or 'Venue'
566
-     * @param  string   $version
567
-     * @return array    describing the args acceptable when querying this model
568
-     * @throws \EE_Error
569
-     */
570
-    protected function _get_read_query_params(\EEM_Base $model, $version)
571
-    {
572
-        $default_orderby = array();
573
-        foreach ($model->get_combined_primary_key_fields() as $key_field) {
574
-            $default_orderby[$key_field->get_name()] = 'ASC';
575
-        }
576
-        return array_merge(
577
-            $this->_get_response_selection_query_params($model, $version),
578
-            array(
579
-                'where'    => array(
580
-                    'required' => false,
581
-                    'default'  => array(),
582
-                ),
583
-                'limit'    => array(
584
-                    'required' => false,
585
-                    'default'  => EED_Core_Rest_Api::get_default_query_limit(),
586
-                ),
587
-                'order_by' => array(
588
-                    'required' => false,
589
-                    'default'  => $default_orderby,
590
-                ),
591
-                'group_by' => array(
592
-                    'required' => false,
593
-                    'default'  => null,
594
-                ),
595
-                'having'   => array(
596
-                    'required' => false,
597
-                    'default'  => null,
598
-                ),
599
-                'caps'     => array(
600
-                    'required' => false,
601
-                    'default'  => EEM_Base::caps_read,
602
-                ),
603
-            )
604
-        );
605
-    }
606
-
607
-
608
-
609
-    /**
610
-     * Gets routes for the config
611
-     *
612
-     * @return array @see _register_model_routes
613
-     * @deprecated since version 4.9.1
614
-     */
615
-    protected function _register_config_routes()
616
-    {
617
-        $config_routes = array();
618
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
619
-            $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version($version,
620
-                $hidden_endpoint);
621
-        }
622
-        return $config_routes;
623
-    }
624
-
625
-
626
-
627
-    /**
628
-     * Gets routes for the config for the specified version
629
-     *
630
-     * @param string  $version
631
-     * @param boolean $hidden_endpoint
632
-     * @return array
633
-     */
634
-    protected function _get_config_route_data_for_version($version, $hidden_endpoint)
635
-    {
636
-        return array(
637
-            'config'    => array(
638
-                array(
639
-                    'callback'        => array(
640
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
641
-                        'handle_request',
642
-                    ),
643
-                    'methods'         => WP_REST_Server::READABLE,
644
-                    'hidden_endpoint' => $hidden_endpoint,
645
-                ),
646
-            ),
647
-            'site_info' => array(
648
-                array(
649
-                    'callback'        => array(
650
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
651
-                        'handle_request_site_info',
652
-                    ),
653
-                    'methods'         => WP_REST_Server::READABLE,
654
-                    'hidden_endpoint' => $hidden_endpoint,
655
-                ),
656
-            ),
657
-        );
658
-    }
659
-
660
-
661
-
662
-    /**
663
-     * Gets the meta info routes
664
-     *
665
-     * @return array @see _register_model_routes
666
-     * @deprecated since version 4.9.1
667
-     */
668
-    protected function _register_meta_routes()
669
-    {
670
-        $meta_routes = array();
671
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
672
-            $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version($version,
673
-                $hidden_endpoint);
674
-        }
675
-        return $meta_routes;
676
-    }
677
-
678
-
679
-
680
-    /**
681
-     * @param string  $version
682
-     * @param boolean $hidden_endpoint
683
-     * @return array
684
-     */
685
-    protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
686
-    {
687
-        return array(
688
-            'resources' => array(
689
-                array(
690
-                    'callback'        => array(
691
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
692
-                        'handle_request_models_meta',
693
-                    ),
694
-                    'methods'         => WP_REST_Server::READABLE,
695
-                    'hidden_endpoint' => $hidden_endpoint,
696
-                ),
697
-            ),
698
-        );
699
-    }
700
-
701
-
702
-
703
-    /**
704
-     * Tries to hide old 4.6 endpoints from the
705
-     *
706
-     * @param array $route_data
707
-     * @return array
708
-     */
709
-    public static function hide_old_endpoints($route_data)
710
-    {
711
-        //allow API clients to override which endpoints get hidden, in case
712
-        //they want to discover particular endpoints
713
-        //also, we don't have access to the request so we have to just grab it from the superglobal
714
-        $force_show_ee_namespace = ltrim(
715
-            EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''),
716
-            '/'
717
-        );
718
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
719
-            foreach ($relative_urls as $endpoint => $routes) {
720
-                foreach ($routes as $route) {
721
-                    //by default, hide "hidden_endpoint"s, unless the request indicates
722
-                    //to $force_show_ee_namespace, in which case only show that one
723
-                    //namespace's endpoints (and hide all others)
724
-                    if (($route['hidden_endpoint'] && $force_show_ee_namespace === '')
725
-                        || ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
726
-                    ) {
727
-                        $full_route = '/' . ltrim($namespace, '/') . '/' . ltrim($endpoint, '/');
728
-                        unset($route_data[$full_route]);
729
-                    }
730
-                }
731
-            }
732
-        }
733
-        return $route_data;
734
-    }
735
-
736
-
737
-
738
-    /**
739
-     * Returns an array describing which versions of core support serving requests for.
740
-     * Keys are core versions' major and minor version, and values are the
741
-     * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
742
-     * data by just removing a few models and fields from the responses. However, 4.15 might remove
743
-     * the answers table entirely, in which case it would be very difficult for
744
-     * it to serve 4.6-style responses.
745
-     * Versions of core that are missing from this array are unknowns.
746
-     * previous ver
747
-     *
748
-     * @return array
749
-     */
750
-    public static function version_compatibilities()
751
-    {
752
-        return apply_filters(
753
-            'FHEE__EED_Core_REST_API__version_compatibilities',
754
-            array(
755
-                '4.8.29' => '4.8.29',
756
-                '4.8.33' => '4.8.29',
757
-                '4.8.34' => '4.8.29',
758
-                '4.8.36' => '4.8.29',
759
-            )
760
-        );
761
-    }
762
-
763
-
764
-
765
-    /**
766
-     * Gets the latest API version served. Eg if there
767
-     * are two versions served of the API, 4.8.29 and 4.8.32, and
768
-     * we are on core version 4.8.34, it will return the string "4.8.32"
769
-     *
770
-     * @return string
771
-     */
772
-    public static function latest_rest_api_version()
773
-    {
774
-        $versions_served = \EED_Core_Rest_Api::versions_served();
775
-        $versions_served_keys = array_keys($versions_served);
776
-        return end($versions_served_keys);
777
-    }
778
-
779
-
780
-
781
-    /**
782
-     * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
783
-     * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
784
-     * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
785
-     * We also indicate whether or not this version should be put in the index or not
786
-     *
787
-     * @return array keys are API version numbers (just major and minor numbers), and values
788
-     * are whether or not they should be hidden
789
-     */
790
-    public static function versions_served()
791
-    {
792
-        $versions_served = array();
793
-        $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
794
-        $lowest_compatible_version = end($possibly_served_versions);
795
-        reset($possibly_served_versions);
796
-        $versions_served_historically = array_keys($possibly_served_versions);
797
-        $latest_version = end($versions_served_historically);
798
-        reset($versions_served_historically);
799
-        //for each version of core we have ever served:
800
-        foreach ($versions_served_historically as $key_versioned_endpoint) {
801
-            //if it's not above the current core version, and it's compatible with the current version of core
802
-            if ($key_versioned_endpoint == $latest_version) {
803
-                //don't hide the latest version in the index
804
-                $versions_served[$key_versioned_endpoint] = false;
805
-            } else if (
806
-                $key_versioned_endpoint < EED_Core_Rest_Api::core_version()
807
-                && $key_versioned_endpoint >= $lowest_compatible_version
808
-            ) {
809
-                //include, but hide, previous versions which are still supported
810
-                $versions_served[$key_versioned_endpoint] = true;
811
-            } elseif (
812
-            apply_filters(
813
-                'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
814
-                false,
815
-                $possibly_served_versions
816
-            )
817
-            ) {
818
-                //if a version is no longer supported, don't include it in index or list of versions served
819
-                $versions_served[$key_versioned_endpoint] = true;
820
-            }
821
-        }
822
-        return $versions_served;
823
-    }
824
-
825
-
826
-
827
-    /**
828
-     * Gets the major and minor version of EE core's version string
829
-     *
830
-     * @return string
831
-     */
832
-    public static function core_version()
833
-    {
834
-        return apply_filters('FHEE__EED_Core_REST_API__core_version',
835
-            implode('.', array_slice(explode('.', espresso_version()), 0, 3)));
836
-    }
837
-
838
-
839
-
840
-    /**
841
-     * Gets the default limit that should be used when querying for resources
842
-     *
843
-     * @return int
844
-     */
845
-    public static function get_default_query_limit()
846
-    {
847
-        //we actually don't use a const because we want folks to always use
848
-        //this method, not the const directly
849
-        return apply_filters(
850
-            'FHEE__EED_Core_Rest_Api__get_default_query_limit',
851
-            50
852
-        );
853
-    }
854
-
855
-
856
-
857
-    /**
858
-     *    run - initial module setup
859
-     *
860
-     * @access    public
861
-     * @param  WP $WP
862
-     * @return    void
863
-     */
864
-    public function run($WP)
865
-    {
866
-    }
25
+	const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
26
+
27
+	const saved_routes_option_names  = 'ee_core_routes';
28
+
29
+	/**
30
+	 * string used in _links response bodies to make them globally unique.
31
+	 *
32
+	 * @see http://v2.wp-api.org/extending/linking/
33
+	 */
34
+	const ee_api_link_namespace = 'https://api.eventespresso.com/';
35
+
36
+	/**
37
+	 * @var Calculated_Model_Fields
38
+	 */
39
+	protected static $_field_calculator = null;
40
+
41
+
42
+
43
+	/**
44
+	 * @return EED_Core_Rest_Api
45
+	 */
46
+	public static function instance()
47
+	{
48
+		self::$_field_calculator = new Calculated_Model_Fields();
49
+		return parent::get_instance(__CLASS__);
50
+	}
51
+
52
+
53
+
54
+	/**
55
+	 *    set_hooks - for hooking into EE Core, other modules, etc
56
+	 *
57
+	 * @access    public
58
+	 * @return    void
59
+	 */
60
+	public static function set_hooks()
61
+	{
62
+		self::set_hooks_both();
63
+	}
64
+
65
+
66
+
67
+	/**
68
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
69
+	 *
70
+	 * @access    public
71
+	 * @return    void
72
+	 */
73
+	public static function set_hooks_admin()
74
+	{
75
+		self::set_hooks_both();
76
+	}
77
+
78
+
79
+
80
+	public static function set_hooks_both()
81
+	{
82
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
83
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
84
+		add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
85
+		add_filter('rest_index',
86
+			array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index'));
87
+		EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
88
+	}
89
+
90
+
91
+
92
+	/**
93
+	 * sets up hooks which only need to be included as part of REST API requests;
94
+	 * other requests like to the frontend or admin etc don't need them
95
+	 */
96
+	public static function set_hooks_rest_api()
97
+	{
98
+		//set hooks which account for changes made to the API
99
+		EED_Core_Rest_Api::_set_hooks_for_changes();
100
+		EED_Core_Rest_Api::maybe_notify_of_basic_auth_removal();
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * public wrapper of _set_hooks_for_changes.
107
+	 * Loads all the hooks which make requests to old versions of the API
108
+	 * appear the same as they always did
109
+	 */
110
+	public static function set_hooks_for_changes()
111
+	{
112
+		self::_set_hooks_for_changes();
113
+	}
114
+
115
+
116
+
117
+	/**
118
+	 * If the user appears to be using WP API basic auth, tell them (via a persistent
119
+	 * admin notice and an email) that we're going to remove it soon, so they should
120
+	 * replace it with application passwords.
121
+	 *
122
+	 * @throws InvalidDataTypeException
123
+	 */
124
+	public static function maybe_notify_of_basic_auth_removal()
125
+	{
126
+		if (
127
+		apply_filters(
128
+			'FHEE__EED_Core_Rest_Api__maybe_notify_of_basic_auth_removal__override',
129
+			! isset($_SERVER['PHP_AUTH_USER'])
130
+			&& ! isset($_SERVER['HTTP_AUTHORIZATION'])
131
+		)
132
+		) {
133
+			//sure it's a WP API request, but they aren't using basic auth, so don't bother them
134
+			return;
135
+		}
136
+		//ok they're using the WP API with Basic Auth
137
+		new PersistentAdminNotice(
138
+			'using_basic_auth',
139
+			sprintf(
140
+				__(
141
+					'We noticed you\'re using the WP API, which is used by the Event Espresso 4 mobile apps. Because of security and compatibility concerns, we will soon be removing our default authentication mechanism, WP API Basic Auth, from Event Espresso. It is recommended you instead install the %1$sWP Application Passwords plugin%2$s and use it with the EE4 Mobile apps. See %3$sour mobile app documentation%2$s for more information. %4$sIf you have installed the WP API Basic Auth plugin separately, or are not using the Event Espresso 4 mobile apps, you can disregard this message.%4$sThe Event Espresso Team',
142
+					'event_espresso'
143
+				),
144
+				'<a href="https://wordpress.org/plugins/application-passwords/">',
145
+				'</a>',
146
+				'<a href="https://eventespresso.com/wiki/ee4-event-apps/#authentication">',
147
+				'<br/>'
148
+			)
149
+		);
150
+		if ( ! get_option('ee_notified_admin_on_basic_auth_removal', false)) {
151
+			add_option('ee_notified_admin_on_basic_auth_removal', true);
152
+			//piggy back off EE_Error::set_content_type, which sets the content type to HTML
153
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
154
+			//and send the message to the site admin too
155
+			wp_mail(get_option('admin_email'),
156
+				__('Notice of Removal of WP API Basic Auth From Event Espresso 4', 'event_espresso'), $message);
157
+			remove_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
158
+		}
159
+	}
160
+
161
+
162
+
163
+	/**
164
+	 * Loads all the hooks which make requests to old versions of the API
165
+	 * appear the same as they always did
166
+	 */
167
+	protected static function _set_hooks_for_changes()
168
+	{
169
+		$folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
170
+		foreach ($folder_contents as $classname_in_namespace => $filepath) {
171
+			//ignore the base parent class
172
+			if ($classname_in_namespace === 'Changes_In_Base') {
173
+				continue;
174
+			}
175
+			$full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
176
+			if (class_exists($full_classname)) {
177
+				$instance_of_class = new $full_classname;
178
+				if ($instance_of_class instanceof Changes_In_Base) {
179
+					$instance_of_class->set_hooks();
180
+				}
181
+			}
182
+		}
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * Filters the WP routes to add our EE-related ones. This takes a bit of time
189
+	 * so we actually prefer to only do it when an EE plugin is activated or upgraded
190
+	 */
191
+	public static function register_routes()
192
+	{
193
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
194
+			foreach ($relative_urls as $endpoint => $routes) {
195
+				foreach ($routes as $route) {
196
+					$route_args = array(
197
+						array(
198
+							'callback' => $route['callback'],
199
+							'methods'  => $route['methods'],
200
+							'args'     => isset($route['args']) ? $route['args'] : array(),
201
+						)
202
+					);
203
+					if (isset($route['schema_callback'])) {
204
+						$model_name = isset($route['schema_callback'][0])
205
+							? $route['schema_callback'][0]
206
+							: '';
207
+						$version = isset( $route['schema_callback'][1])
208
+							? $route['schema_callback'][1]
209
+							: '';
210
+						if (! empty($model_name) && ! empty($version)) {
211
+							$route_args['schema'] = function () use ($model_name, $version) {
212
+								return ModelRead::handle_schema_request(
213
+									$model_name,
214
+									$version
215
+								);
216
+							};
217
+						}
218
+					}
219
+					register_rest_route(
220
+						$namespace,
221
+						$endpoint,
222
+						$route_args
223
+					);
224
+				}
225
+			}
226
+		}
227
+	}
228
+
229
+
230
+
231
+	/**
232
+	 * Checks if there was a version change or something that merits invalidating the cached
233
+	 * route data. If so, invalidates the cached route data so that it gets refreshed
234
+	 * next time the WP API is used
235
+	 */
236
+	public static function invalidate_cached_route_data_on_version_change()
237
+	{
238
+		if (EE_System::instance()->detect_req_type() != EE_System::req_type_normal) {
239
+			EED_Core_Rest_Api::invalidate_cached_route_data();
240
+		}
241
+		foreach (EE_Registry::instance()->addons as $addon) {
242
+			if ($addon instanceof EE_Addon && $addon->detect_req_type() != EE_System::req_type_normal) {
243
+				EED_Core_Rest_Api::invalidate_cached_route_data();
244
+			}
245
+		}
246
+	}
247
+
248
+
249
+
250
+	/**
251
+	 * Removes the cached route data so it will get refreshed next time the WP API is used
252
+	 */
253
+	public static function invalidate_cached_route_data()
254
+	{
255
+		//delete the saved EE REST API routes
256
+		foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
257
+			delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
258
+		}
259
+	}
260
+
261
+
262
+
263
+	/**
264
+	 * Gets the EE route data
265
+	 *
266
+	 * @return array top-level key is the namespace, next-level key is the route and its value is array{
267
+	 * @type string|array $callback
268
+	 * @type string       $methods
269
+	 * @type boolean      $hidden_endpoint
270
+	 * }
271
+	 */
272
+	public static function get_ee_route_data()
273
+	{
274
+		$ee_routes = array();
275
+		foreach (self::versions_served() as $version => $hidden_endpoints) {
276
+			$ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version($version,
277
+				$hidden_endpoints);
278
+		}
279
+		return $ee_routes;
280
+	}
281
+
282
+
283
+
284
+	/**
285
+	 * Gets the EE route data from the wp options if it exists already,
286
+	 * otherwise re-generates it and saves it to the option
287
+	 *
288
+	 * @param string  $version
289
+	 * @param boolean $hidden_endpoints
290
+	 * @return array
291
+	 */
292
+	protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
293
+	{
294
+		$ee_routes = get_option(self::saved_routes_option_names . $version, null);
295
+		if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
296
+			$ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
297
+		}
298
+		return $ee_routes;
299
+	}
300
+
301
+
302
+
303
+	/**
304
+	 * Saves the EE REST API route data to a wp option and returns it
305
+	 *
306
+	 * @param string  $version
307
+	 * @param boolean $hidden_endpoints
308
+	 * @return mixed|null|void
309
+	 */
310
+	protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
311
+	{
312
+		$instance = self::instance();
313
+		$routes = apply_filters(
314
+			'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
315
+			array_replace_recursive(
316
+				$instance->_get_config_route_data_for_version($version, $hidden_endpoints),
317
+				$instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
318
+				$instance->_get_model_route_data_for_version($version, $hidden_endpoints),
319
+				$instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
320
+			)
321
+		);
322
+		$option_name = self::saved_routes_option_names . $version;
323
+		if (get_option($option_name)) {
324
+			update_option($option_name, $routes, true);
325
+		} else {
326
+			add_option($option_name, $routes, null, 'no');
327
+		}
328
+		return $routes;
329
+	}
330
+
331
+
332
+
333
+	/**
334
+	 * Calculates all the EE routes and saves it to a wordpress option so we don't
335
+	 * need to calculate it on every request
336
+	 *
337
+	 * @deprecated since version 4.9.1
338
+	 * @return void
339
+	 */
340
+	public static function save_ee_routes()
341
+	{
342
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
343
+			$instance = self::instance();
344
+			$routes = apply_filters(
345
+				'EED_Core_Rest_Api__save_ee_routes__routes',
346
+				array_replace_recursive(
347
+					$instance->_register_config_routes(),
348
+					$instance->_register_meta_routes(),
349
+					$instance->_register_model_routes(),
350
+					$instance->_register_rpc_routes()
351
+				)
352
+			);
353
+			update_option(self::saved_routes_option_names, $routes, true);
354
+		}
355
+	}
356
+
357
+
358
+
359
+	/**
360
+	 * Gets all the route information relating to EE models
361
+	 *
362
+	 * @return array @see get_ee_route_data
363
+	 * @deprecated since version 4.9.1
364
+	 */
365
+	protected function _register_model_routes()
366
+	{
367
+		$model_routes = array();
368
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
369
+			$model_routes[EED_Core_Rest_Api::ee_api_namespace
370
+						  . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
371
+		}
372
+		return $model_routes;
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * Gets the route data for EE models in the specified version
379
+	 *
380
+	 * @param string  $version
381
+	 * @param boolean $hidden_endpoint
382
+	 * @return array
383
+	 */
384
+	protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
385
+	{
386
+		$model_version_info = new Model_Version_Info($version);
387
+		$models_to_register = apply_filters(
388
+			'FHEE__EED_Core_REST_API___register_model_routes',
389
+			$model_version_info->models_for_requested_version()
390
+		);
391
+		//let's not bother having endpoints for extra metas
392
+		unset($models_to_register['Extra_Meta']);
393
+		unset($models_to_register['Extra_Join']);
394
+		$model_routes = array();
395
+		foreach ($models_to_register as $model_name => $model_classname) {
396
+			$model = \EE_Registry::instance()->load_model($model_name);
397
+
398
+			//if this isn't a valid model then let's skip iterate to the next item in the loop.
399
+			if (! $model instanceof EEM_Base) {
400
+				continue;
401
+			}
402
+
403
+			//yes we could just register one route for ALL models, but then they wouldn't show up in the index
404
+			$plural_model_route = EEH_Inflector::pluralize_and_lower($model_name);
405
+			$singular_model_route = $plural_model_route . '/(?P<id>\d+)';
406
+			$model_routes[$plural_model_route] = array(
407
+				array(
408
+					'callback'        => array(
409
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
410
+						'handle_request_get_all',
411
+					),
412
+					'methods'         => WP_REST_Server::READABLE,
413
+					'hidden_endpoint' => $hidden_endpoint,
414
+					'args'            => $this->_get_read_query_params($model, $version),
415
+					'_links'          => array(
416
+						'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
417
+					),
418
+					'schema_callback' => array($model_name, $version)
419
+				),
420
+				//						array(
421
+				//							'callback' => array(
422
+				//								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
423
+				//								'handle_request_create_one' ),
424
+				//							'methods' => WP_REST_Server::CREATABLE,
425
+				//							'hidden_endpoint' => $hidden_endpoint
426
+				//						)
427
+			);
428
+			$model_routes[$singular_model_route] = array(
429
+				array(
430
+					'callback'        => array(
431
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
432
+						'handle_request_get_one',
433
+					),
434
+					'methods'         => WP_REST_Server::READABLE,
435
+					'hidden_endpoint' => $hidden_endpoint,
436
+					'args'            => $this->_get_response_selection_query_params($model, $version),
437
+				),
438
+				//						array(
439
+				//							'callback' => array(
440
+				//								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
441
+				//								'handle_request_edit_one' ),
442
+				//							'methods' => WP_REST_Server::EDITABLE,
443
+				//							'hidden_endpoint' => $hidden_endpoint
444
+				//							),
445
+			);
446
+			//@todo: also handle  DELETE for a single item
447
+			foreach ($model_version_info->relation_settings($model) as $relation_name => $relation_obj) {
448
+				$related_model_name_endpoint_part = ModelRead::get_related_entity_name(
449
+					$relation_name,
450
+					$relation_obj
451
+				);
452
+				$model_routes[$singular_model_route . '/' . $related_model_name_endpoint_part] = array(
453
+					array(
454
+						'callback'        => array(
455
+							'EventEspresso\core\libraries\rest_api\controllers\model\Read',
456
+							'handle_request_get_related',
457
+						),
458
+						'methods'         => WP_REST_Server::READABLE,
459
+						'hidden_endpoint' => $hidden_endpoint,
460
+						'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
461
+					),
462
+					//							array(
463
+					//								'callback' => array(
464
+					//									'EventEspresso\core\libraries\rest_api\controllers\model\Write',
465
+					//									'handle_request_create_or_update_related' ),
466
+					//								'methods' => WP_REST_Server::EDITABLE,
467
+					//								'hidden_endpoint' => $hidden_endpoint
468
+					//							)
469
+				);
470
+				//@todo: handle delete related and possibly remove relation (not sure hwo to distinguish)
471
+			}
472
+		}
473
+		return $model_routes;
474
+	}
475
+
476
+
477
+
478
+	/**
479
+	 * Adds all the RPC-style routes (remote procedure call-like routes, ie
480
+	 * routes that don't conform to the traditional REST CRUD-style).
481
+	 *
482
+	 * @deprecated since 4.9.1
483
+	 */
484
+	protected function _register_rpc_routes()
485
+	{
486
+		$routes = array();
487
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
488
+			$routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version($version,
489
+				$hidden_endpoint);
490
+		}
491
+		return $routes;
492
+	}
493
+
494
+
495
+
496
+	/**
497
+	 * @param string  $version
498
+	 * @param boolean $hidden_endpoint
499
+	 * @return array
500
+	 */
501
+	protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
502
+	{
503
+		$this_versions_routes = array();
504
+		//checkin endpoint
505
+		$this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
506
+			array(
507
+				'callback'        => array(
508
+					'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
509
+					'handle_request_toggle_checkin',
510
+				),
511
+				'methods'         => WP_REST_Server::CREATABLE,
512
+				'hidden_endpoint' => $hidden_endpoint,
513
+				'args'            => array(
514
+					'force' => array(
515
+						'required'    => false,
516
+						'default'     => false,
517
+						'description' => __('Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
518
+							'event_espresso'),
519
+					),
520
+				),
521
+			),
522
+		);
523
+		return apply_filters(
524
+			'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
525
+			$this_versions_routes,
526
+			$version,
527
+			$hidden_endpoint
528
+		);
529
+	}
530
+
531
+
532
+
533
+	/**
534
+	 * Gets the query params that can be used when request one or many
535
+	 *
536
+	 * @param EEM_Base $model
537
+	 * @param string   $version
538
+	 * @return array
539
+	 */
540
+	protected function _get_response_selection_query_params(\EEM_Base $model, $version)
541
+	{
542
+		return apply_filters(
543
+			'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
544
+			array(
545
+				'include'   => array(
546
+					'required' => false,
547
+					'default'  => '*',
548
+				),
549
+				'calculate' => array(
550
+					'required' => false,
551
+					'default'  => '',
552
+					'enum'     => self::$_field_calculator->retrieve_calculated_fields_for_model($model),
553
+				),
554
+			),
555
+			$model,
556
+			$version
557
+		);
558
+	}
559
+
560
+
561
+
562
+	/**
563
+	 * Gets info about reading query params that are acceptable
564
+	 *
565
+	 * @param \EEM_Base $model eg 'Event' or 'Venue'
566
+	 * @param  string   $version
567
+	 * @return array    describing the args acceptable when querying this model
568
+	 * @throws \EE_Error
569
+	 */
570
+	protected function _get_read_query_params(\EEM_Base $model, $version)
571
+	{
572
+		$default_orderby = array();
573
+		foreach ($model->get_combined_primary_key_fields() as $key_field) {
574
+			$default_orderby[$key_field->get_name()] = 'ASC';
575
+		}
576
+		return array_merge(
577
+			$this->_get_response_selection_query_params($model, $version),
578
+			array(
579
+				'where'    => array(
580
+					'required' => false,
581
+					'default'  => array(),
582
+				),
583
+				'limit'    => array(
584
+					'required' => false,
585
+					'default'  => EED_Core_Rest_Api::get_default_query_limit(),
586
+				),
587
+				'order_by' => array(
588
+					'required' => false,
589
+					'default'  => $default_orderby,
590
+				),
591
+				'group_by' => array(
592
+					'required' => false,
593
+					'default'  => null,
594
+				),
595
+				'having'   => array(
596
+					'required' => false,
597
+					'default'  => null,
598
+				),
599
+				'caps'     => array(
600
+					'required' => false,
601
+					'default'  => EEM_Base::caps_read,
602
+				),
603
+			)
604
+		);
605
+	}
606
+
607
+
608
+
609
+	/**
610
+	 * Gets routes for the config
611
+	 *
612
+	 * @return array @see _register_model_routes
613
+	 * @deprecated since version 4.9.1
614
+	 */
615
+	protected function _register_config_routes()
616
+	{
617
+		$config_routes = array();
618
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
619
+			$config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version($version,
620
+				$hidden_endpoint);
621
+		}
622
+		return $config_routes;
623
+	}
624
+
625
+
626
+
627
+	/**
628
+	 * Gets routes for the config for the specified version
629
+	 *
630
+	 * @param string  $version
631
+	 * @param boolean $hidden_endpoint
632
+	 * @return array
633
+	 */
634
+	protected function _get_config_route_data_for_version($version, $hidden_endpoint)
635
+	{
636
+		return array(
637
+			'config'    => array(
638
+				array(
639
+					'callback'        => array(
640
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
641
+						'handle_request',
642
+					),
643
+					'methods'         => WP_REST_Server::READABLE,
644
+					'hidden_endpoint' => $hidden_endpoint,
645
+				),
646
+			),
647
+			'site_info' => array(
648
+				array(
649
+					'callback'        => array(
650
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
651
+						'handle_request_site_info',
652
+					),
653
+					'methods'         => WP_REST_Server::READABLE,
654
+					'hidden_endpoint' => $hidden_endpoint,
655
+				),
656
+			),
657
+		);
658
+	}
659
+
660
+
661
+
662
+	/**
663
+	 * Gets the meta info routes
664
+	 *
665
+	 * @return array @see _register_model_routes
666
+	 * @deprecated since version 4.9.1
667
+	 */
668
+	protected function _register_meta_routes()
669
+	{
670
+		$meta_routes = array();
671
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
672
+			$meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version($version,
673
+				$hidden_endpoint);
674
+		}
675
+		return $meta_routes;
676
+	}
677
+
678
+
679
+
680
+	/**
681
+	 * @param string  $version
682
+	 * @param boolean $hidden_endpoint
683
+	 * @return array
684
+	 */
685
+	protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
686
+	{
687
+		return array(
688
+			'resources' => array(
689
+				array(
690
+					'callback'        => array(
691
+						'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
692
+						'handle_request_models_meta',
693
+					),
694
+					'methods'         => WP_REST_Server::READABLE,
695
+					'hidden_endpoint' => $hidden_endpoint,
696
+				),
697
+			),
698
+		);
699
+	}
700
+
701
+
702
+
703
+	/**
704
+	 * Tries to hide old 4.6 endpoints from the
705
+	 *
706
+	 * @param array $route_data
707
+	 * @return array
708
+	 */
709
+	public static function hide_old_endpoints($route_data)
710
+	{
711
+		//allow API clients to override which endpoints get hidden, in case
712
+		//they want to discover particular endpoints
713
+		//also, we don't have access to the request so we have to just grab it from the superglobal
714
+		$force_show_ee_namespace = ltrim(
715
+			EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''),
716
+			'/'
717
+		);
718
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
719
+			foreach ($relative_urls as $endpoint => $routes) {
720
+				foreach ($routes as $route) {
721
+					//by default, hide "hidden_endpoint"s, unless the request indicates
722
+					//to $force_show_ee_namespace, in which case only show that one
723
+					//namespace's endpoints (and hide all others)
724
+					if (($route['hidden_endpoint'] && $force_show_ee_namespace === '')
725
+						|| ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
726
+					) {
727
+						$full_route = '/' . ltrim($namespace, '/') . '/' . ltrim($endpoint, '/');
728
+						unset($route_data[$full_route]);
729
+					}
730
+				}
731
+			}
732
+		}
733
+		return $route_data;
734
+	}
735
+
736
+
737
+
738
+	/**
739
+	 * Returns an array describing which versions of core support serving requests for.
740
+	 * Keys are core versions' major and minor version, and values are the
741
+	 * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
742
+	 * data by just removing a few models and fields from the responses. However, 4.15 might remove
743
+	 * the answers table entirely, in which case it would be very difficult for
744
+	 * it to serve 4.6-style responses.
745
+	 * Versions of core that are missing from this array are unknowns.
746
+	 * previous ver
747
+	 *
748
+	 * @return array
749
+	 */
750
+	public static function version_compatibilities()
751
+	{
752
+		return apply_filters(
753
+			'FHEE__EED_Core_REST_API__version_compatibilities',
754
+			array(
755
+				'4.8.29' => '4.8.29',
756
+				'4.8.33' => '4.8.29',
757
+				'4.8.34' => '4.8.29',
758
+				'4.8.36' => '4.8.29',
759
+			)
760
+		);
761
+	}
762
+
763
+
764
+
765
+	/**
766
+	 * Gets the latest API version served. Eg if there
767
+	 * are two versions served of the API, 4.8.29 and 4.8.32, and
768
+	 * we are on core version 4.8.34, it will return the string "4.8.32"
769
+	 *
770
+	 * @return string
771
+	 */
772
+	public static function latest_rest_api_version()
773
+	{
774
+		$versions_served = \EED_Core_Rest_Api::versions_served();
775
+		$versions_served_keys = array_keys($versions_served);
776
+		return end($versions_served_keys);
777
+	}
778
+
779
+
780
+
781
+	/**
782
+	 * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
783
+	 * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
784
+	 * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
785
+	 * We also indicate whether or not this version should be put in the index or not
786
+	 *
787
+	 * @return array keys are API version numbers (just major and minor numbers), and values
788
+	 * are whether or not they should be hidden
789
+	 */
790
+	public static function versions_served()
791
+	{
792
+		$versions_served = array();
793
+		$possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
794
+		$lowest_compatible_version = end($possibly_served_versions);
795
+		reset($possibly_served_versions);
796
+		$versions_served_historically = array_keys($possibly_served_versions);
797
+		$latest_version = end($versions_served_historically);
798
+		reset($versions_served_historically);
799
+		//for each version of core we have ever served:
800
+		foreach ($versions_served_historically as $key_versioned_endpoint) {
801
+			//if it's not above the current core version, and it's compatible with the current version of core
802
+			if ($key_versioned_endpoint == $latest_version) {
803
+				//don't hide the latest version in the index
804
+				$versions_served[$key_versioned_endpoint] = false;
805
+			} else if (
806
+				$key_versioned_endpoint < EED_Core_Rest_Api::core_version()
807
+				&& $key_versioned_endpoint >= $lowest_compatible_version
808
+			) {
809
+				//include, but hide, previous versions which are still supported
810
+				$versions_served[$key_versioned_endpoint] = true;
811
+			} elseif (
812
+			apply_filters(
813
+				'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
814
+				false,
815
+				$possibly_served_versions
816
+			)
817
+			) {
818
+				//if a version is no longer supported, don't include it in index or list of versions served
819
+				$versions_served[$key_versioned_endpoint] = true;
820
+			}
821
+		}
822
+		return $versions_served;
823
+	}
824
+
825
+
826
+
827
+	/**
828
+	 * Gets the major and minor version of EE core's version string
829
+	 *
830
+	 * @return string
831
+	 */
832
+	public static function core_version()
833
+	{
834
+		return apply_filters('FHEE__EED_Core_REST_API__core_version',
835
+			implode('.', array_slice(explode('.', espresso_version()), 0, 3)));
836
+	}
837
+
838
+
839
+
840
+	/**
841
+	 * Gets the default limit that should be used when querying for resources
842
+	 *
843
+	 * @return int
844
+	 */
845
+	public static function get_default_query_limit()
846
+	{
847
+		//we actually don't use a const because we want folks to always use
848
+		//this method, not the const directly
849
+		return apply_filters(
850
+			'FHEE__EED_Core_Rest_Api__get_default_query_limit',
851
+			50
852
+		);
853
+	}
854
+
855
+
856
+
857
+	/**
858
+	 *    run - initial module setup
859
+	 *
860
+	 * @access    public
861
+	 * @param  WP $WP
862
+	 * @return    void
863
+	 */
864
+	public function run($WP)
865
+	{
866
+	}
867 867
 
868 868
 
869 869
 
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -158,13 +158,13 @@  discard block
 block discarded – undo
158 158
      */
159 159
     protected static function _set_hooks_for_changes()
160 160
     {
161
-        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
161
+        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES.'rest_api'.DS.'changes'), false);
162 162
         foreach ($folder_contents as $classname_in_namespace => $filepath) {
163 163
             //ignore the base parent class
164 164
             if ($classname_in_namespace === 'Changes_In_Base') {
165 165
                 continue;
166 166
             }
167
-            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
167
+            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\'.$classname_in_namespace;
168 168
             if (class_exists($full_classname)) {
169 169
                 $instance_of_class = new $full_classname;
170 170
                 if ($instance_of_class instanceof Changes_In_Base) {
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
                         $model_name = isset($route['schema_callback'][0])
197 197
                             ? $route['schema_callback'][0]
198 198
                             : '';
199
-                        $version = isset( $route['schema_callback'][1])
199
+                        $version = isset($route['schema_callback'][1])
200 200
                             ? $route['schema_callback'][1]
201 201
                             : '';
202
-                        if (! empty($model_name) && ! empty($version)) {
203
-                            $route_args['schema'] = function () use ($model_name, $version) {
202
+                        if ( ! empty($model_name) && ! empty($version)) {
203
+                            $route_args['schema'] = function() use ($model_name, $version) {
204 204
                                 return ModelRead::handle_schema_request(
205 205
                                     $model_name,
206 206
                                     $version
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
     {
247 247
         //delete the saved EE REST API routes
248 248
         foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
249
-            delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
249
+            delete_option(EED_Core_Rest_Api::saved_routes_option_names.$version);
250 250
         }
251 251
     }
252 252
 
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
     {
266 266
         $ee_routes = array();
267 267
         foreach (self::versions_served() as $version => $hidden_endpoints) {
268
-            $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version($version,
268
+            $ee_routes[self::ee_api_namespace.$version] = self::_get_ee_route_data_for_version($version,
269 269
                 $hidden_endpoints);
270 270
         }
271 271
         return $ee_routes;
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
      */
284 284
     protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
285 285
     {
286
-        $ee_routes = get_option(self::saved_routes_option_names . $version, null);
286
+        $ee_routes = get_option(self::saved_routes_option_names.$version, null);
287 287
         if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
288 288
             $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
289 289
         }
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
                 $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
312 312
             )
313 313
         );
314
-        $option_name = self::saved_routes_option_names . $version;
314
+        $option_name = self::saved_routes_option_names.$version;
315 315
         if (get_option($option_name)) {
316 316
             update_option($option_name, $routes, true);
317 317
         } else {
@@ -388,13 +388,13 @@  discard block
 block discarded – undo
388 388
             $model = \EE_Registry::instance()->load_model($model_name);
389 389
 
390 390
             //if this isn't a valid model then let's skip iterate to the next item in the loop.
391
-            if (! $model instanceof EEM_Base) {
391
+            if ( ! $model instanceof EEM_Base) {
392 392
                 continue;
393 393
             }
394 394
 
395 395
             //yes we could just register one route for ALL models, but then they wouldn't show up in the index
396 396
             $plural_model_route = EEH_Inflector::pluralize_and_lower($model_name);
397
-            $singular_model_route = $plural_model_route . '/(?P<id>\d+)';
397
+            $singular_model_route = $plural_model_route.'/(?P<id>\d+)';
398 398
             $model_routes[$plural_model_route] = array(
399 399
                 array(
400 400
                     'callback'        => array(
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
                     'hidden_endpoint' => $hidden_endpoint,
406 406
                     'args'            => $this->_get_read_query_params($model, $version),
407 407
                     '_links'          => array(
408
-                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
408
+                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace.$version.$singular_model_route),
409 409
                     ),
410 410
                     'schema_callback' => array($model_name, $version)
411 411
                 ),
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
                     $relation_name,
442 442
                     $relation_obj
443 443
                 );
444
-                $model_routes[$singular_model_route . '/' . $related_model_name_endpoint_part] = array(
444
+                $model_routes[$singular_model_route.'/'.$related_model_name_endpoint_part] = array(
445 445
                     array(
446 446
                         'callback'        => array(
447 447
                             'EventEspresso\core\libraries\rest_api\controllers\model\Read',
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
     {
478 478
         $routes = array();
479 479
         foreach (self::versions_served() as $version => $hidden_endpoint) {
480
-            $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version($version,
480
+            $routes[self::ee_api_namespace.$version] = $this->_get_rpc_route_data_for_version($version,
481 481
                 $hidden_endpoint);
482 482
         }
483 483
         return $routes;
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
     {
609 609
         $config_routes = array();
610 610
         foreach (self::versions_served() as $version => $hidden_endpoint) {
611
-            $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version($version,
611
+            $config_routes[self::ee_api_namespace.$version] = $this->_get_config_route_data_for_version($version,
612 612
                 $hidden_endpoint);
613 613
         }
614 614
         return $config_routes;
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
     {
662 662
         $meta_routes = array();
663 663
         foreach (self::versions_served() as $version => $hidden_endpoint) {
664
-            $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version($version,
664
+            $meta_routes[self::ee_api_namespace.$version] = $this->_get_meta_route_data_for_version($version,
665 665
                 $hidden_endpoint);
666 666
         }
667 667
         return $meta_routes;
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
                     if (($route['hidden_endpoint'] && $force_show_ee_namespace === '')
717 717
                         || ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
718 718
                     ) {
719
-                        $full_route = '/' . ltrim($namespace, '/') . '/' . ltrim($endpoint, '/');
719
+                        $full_route = '/'.ltrim($namespace, '/').'/'.ltrim($endpoint, '/');
720 720
                         unset($route_data[$full_route]);
721 721
                     }
722 722
                 }
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 2 patches
Indentation   +1693 added lines, -1693 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\exceptions\InvalidDataTypeException;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -17,231 +17,231 @@  discard block
 block discarded – undo
17 17
 class EEH_Activation
18 18
 {
19 19
 
20
-    /**
21
-     * constant used to indicate a cron task is no longer in use
22
-     */
23
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
24
-
25
-    /**
26
-     * option name that will indicate whether or not we still
27
-     * need to create EE's folders in the uploads directory
28
-     * (because if EE was installed without file system access,
29
-     * we need to request credentials before we can create them)
30
-     */
31
-    const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
32
-
33
-    /**
34
-     * WP_User->ID
35
-     *
36
-     * @var int
37
-     */
38
-    private static $_default_creator_id;
39
-
40
-    /**
41
-     * indicates whether or not we've already verified core's default data during this request,
42
-     * because after migrations are done, any addons activated while in maintenance mode
43
-     * will want to setup their own default data, and they might hook into core's default data
44
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
45
-     * This prevents doing that for EVERY single addon.
46
-     *
47
-     * @var boolean
48
-     */
49
-    protected static $_initialized_db_content_already_in_this_request = false;
50
-
51
-    /**
52
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
53
-     */
54
-    private static $table_analysis;
55
-
56
-    /**
57
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
58
-     */
59
-    private static $table_manager;
60
-
61
-
62
-    /**
63
-     * @return \EventEspresso\core\services\database\TableAnalysis
64
-     */
65
-    public static function getTableAnalysis()
66
-    {
67
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
68
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
69
-        }
70
-        return self::$table_analysis;
71
-    }
72
-
73
-
74
-    /**
75
-     * @return \EventEspresso\core\services\database\TableManager
76
-     */
77
-    public static function getTableManager()
78
-    {
79
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
80
-            self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
81
-        }
82
-        return self::$table_manager;
83
-    }
84
-
85
-
86
-    /**
87
-     *    _ensure_table_name_has_prefix
88
-     *
89
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
90
-     * @access     public
91
-     * @static
92
-     * @param $table_name
93
-     * @return string
94
-     */
95
-    public static function ensure_table_name_has_prefix($table_name)
96
-    {
97
-        return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
98
-    }
99
-
100
-
101
-    /**
102
-     *    system_initialization
103
-     *    ensures the EE configuration settings are loaded with at least default options set
104
-     *    and that all critical EE pages have been generated with the appropriate shortcodes in place
105
-     *
106
-     * @access public
107
-     * @static
108
-     * @return void
109
-     */
110
-    public static function system_initialization()
111
-    {
112
-        EEH_Activation::reset_and_update_config();
113
-        //which is fired BEFORE activation of plugin anyways
114
-        EEH_Activation::verify_default_pages_exist();
115
-    }
116
-
117
-
118
-    /**
119
-     * Sets the database schema and creates folders. This should
120
-     * be called on plugin activation and reactivation
121
-     *
122
-     * @return boolean success, whether the database and folders are setup properly
123
-     * @throws \EE_Error
124
-     */
125
-    public static function initialize_db_and_folders()
126
-    {
127
-        $good_filesystem = EEH_Activation::create_upload_directories();
128
-        $good_db         = EEH_Activation::create_database_tables();
129
-        return $good_filesystem && $good_db;
130
-    }
131
-
132
-
133
-    /**
134
-     * assuming we have an up-to-date database schema, this will populate it
135
-     * with default and initial data. This should be called
136
-     * upon activation of a new plugin, reactivation, and at the end
137
-     * of running migration scripts
138
-     *
139
-     * @throws \EE_Error
140
-     */
141
-    public static function initialize_db_content()
142
-    {
143
-        //let's avoid doing all this logic repeatedly, especially when addons are requesting it
144
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
145
-            return;
146
-        }
147
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
148
-
149
-        EEH_Activation::initialize_system_questions();
150
-        EEH_Activation::insert_default_status_codes();
151
-        EEH_Activation::generate_default_message_templates();
152
-        EEH_Activation::create_no_ticket_prices_array();
153
-        EE_Registry::instance()->CAP->init_caps();
154
-
155
-        EEH_Activation::validate_messages_system();
156
-        EEH_Activation::insert_default_payment_methods();
157
-        //in case we've
158
-        EEH_Activation::remove_cron_tasks();
159
-        EEH_Activation::create_cron_tasks();
160
-        // remove all TXN locks since that is being done via extra meta now
161
-        delete_option('ee_locked_transactions');
162
-        //also, check for CAF default db content
163
-        do_action('AHEE__EEH_Activation__initialize_db_content');
164
-        //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
165
-        //which users really won't care about on initial activation
166
-        EE_Error::overwrite_success();
167
-    }
168
-
169
-
170
-    /**
171
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
172
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
173
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
174
-     * (null)
175
-     *
176
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
177
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
178
-     * @return array
179
-     * @throws \EE_Error
180
-     */
181
-    public static function get_cron_tasks($which_to_include)
182
-    {
183
-        $cron_tasks = apply_filters(
184
-            'FHEE__EEH_Activation__get_cron_tasks',
185
-            array(
186
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
20
+	/**
21
+	 * constant used to indicate a cron task is no longer in use
22
+	 */
23
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
24
+
25
+	/**
26
+	 * option name that will indicate whether or not we still
27
+	 * need to create EE's folders in the uploads directory
28
+	 * (because if EE was installed without file system access,
29
+	 * we need to request credentials before we can create them)
30
+	 */
31
+	const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
32
+
33
+	/**
34
+	 * WP_User->ID
35
+	 *
36
+	 * @var int
37
+	 */
38
+	private static $_default_creator_id;
39
+
40
+	/**
41
+	 * indicates whether or not we've already verified core's default data during this request,
42
+	 * because after migrations are done, any addons activated while in maintenance mode
43
+	 * will want to setup their own default data, and they might hook into core's default data
44
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
45
+	 * This prevents doing that for EVERY single addon.
46
+	 *
47
+	 * @var boolean
48
+	 */
49
+	protected static $_initialized_db_content_already_in_this_request = false;
50
+
51
+	/**
52
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
53
+	 */
54
+	private static $table_analysis;
55
+
56
+	/**
57
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
58
+	 */
59
+	private static $table_manager;
60
+
61
+
62
+	/**
63
+	 * @return \EventEspresso\core\services\database\TableAnalysis
64
+	 */
65
+	public static function getTableAnalysis()
66
+	{
67
+		if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
68
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
69
+		}
70
+		return self::$table_analysis;
71
+	}
72
+
73
+
74
+	/**
75
+	 * @return \EventEspresso\core\services\database\TableManager
76
+	 */
77
+	public static function getTableManager()
78
+	{
79
+		if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
80
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
81
+		}
82
+		return self::$table_manager;
83
+	}
84
+
85
+
86
+	/**
87
+	 *    _ensure_table_name_has_prefix
88
+	 *
89
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
90
+	 * @access     public
91
+	 * @static
92
+	 * @param $table_name
93
+	 * @return string
94
+	 */
95
+	public static function ensure_table_name_has_prefix($table_name)
96
+	{
97
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
98
+	}
99
+
100
+
101
+	/**
102
+	 *    system_initialization
103
+	 *    ensures the EE configuration settings are loaded with at least default options set
104
+	 *    and that all critical EE pages have been generated with the appropriate shortcodes in place
105
+	 *
106
+	 * @access public
107
+	 * @static
108
+	 * @return void
109
+	 */
110
+	public static function system_initialization()
111
+	{
112
+		EEH_Activation::reset_and_update_config();
113
+		//which is fired BEFORE activation of plugin anyways
114
+		EEH_Activation::verify_default_pages_exist();
115
+	}
116
+
117
+
118
+	/**
119
+	 * Sets the database schema and creates folders. This should
120
+	 * be called on plugin activation and reactivation
121
+	 *
122
+	 * @return boolean success, whether the database and folders are setup properly
123
+	 * @throws \EE_Error
124
+	 */
125
+	public static function initialize_db_and_folders()
126
+	{
127
+		$good_filesystem = EEH_Activation::create_upload_directories();
128
+		$good_db         = EEH_Activation::create_database_tables();
129
+		return $good_filesystem && $good_db;
130
+	}
131
+
132
+
133
+	/**
134
+	 * assuming we have an up-to-date database schema, this will populate it
135
+	 * with default and initial data. This should be called
136
+	 * upon activation of a new plugin, reactivation, and at the end
137
+	 * of running migration scripts
138
+	 *
139
+	 * @throws \EE_Error
140
+	 */
141
+	public static function initialize_db_content()
142
+	{
143
+		//let's avoid doing all this logic repeatedly, especially when addons are requesting it
144
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
145
+			return;
146
+		}
147
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
148
+
149
+		EEH_Activation::initialize_system_questions();
150
+		EEH_Activation::insert_default_status_codes();
151
+		EEH_Activation::generate_default_message_templates();
152
+		EEH_Activation::create_no_ticket_prices_array();
153
+		EE_Registry::instance()->CAP->init_caps();
154
+
155
+		EEH_Activation::validate_messages_system();
156
+		EEH_Activation::insert_default_payment_methods();
157
+		//in case we've
158
+		EEH_Activation::remove_cron_tasks();
159
+		EEH_Activation::create_cron_tasks();
160
+		// remove all TXN locks since that is being done via extra meta now
161
+		delete_option('ee_locked_transactions');
162
+		//also, check for CAF default db content
163
+		do_action('AHEE__EEH_Activation__initialize_db_content');
164
+		//also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
165
+		//which users really won't care about on initial activation
166
+		EE_Error::overwrite_success();
167
+	}
168
+
169
+
170
+	/**
171
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
172
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
173
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
174
+	 * (null)
175
+	 *
176
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
177
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
178
+	 * @return array
179
+	 * @throws \EE_Error
180
+	 */
181
+	public static function get_cron_tasks($which_to_include)
182
+	{
183
+		$cron_tasks = apply_filters(
184
+			'FHEE__EEH_Activation__get_cron_tasks',
185
+			array(
186
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
187 187
 //				'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
188
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
189
-                //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
190
-            )
191
-        );
192
-        if ($which_to_include === 'old') {
193
-            $cron_tasks = array_filter(
194
-                $cron_tasks,
195
-                function ($value) {
196
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
197
-                }
198
-            );
199
-        } elseif ($which_to_include === 'current') {
200
-            $cron_tasks = array_filter($cron_tasks);
201
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
202
-            throw new EE_Error(
203
-                sprintf(
204
-                    __(
205
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
206
-                        'event_espresso'
207
-                    ),
208
-                    $which_to_include
209
-                )
210
-            );
211
-        }
212
-        return $cron_tasks;
213
-    }
214
-
215
-
216
-    /**
217
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
218
-     *
219
-     * @throws \EE_Error
220
-     */
221
-    public static function create_cron_tasks()
222
-    {
223
-
224
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
225
-            if (! wp_next_scheduled($hook_name)) {
226
-                wp_schedule_event(time(), $frequency, $hook_name);
227
-            }
228
-        }
229
-
230
-    }
231
-
232
-
233
-    /**
234
-     * Remove the currently-existing and now-removed cron tasks.
235
-     *
236
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
237
-     * @throws \EE_Error
238
-     */
239
-    public static function remove_cron_tasks($remove_all = true)
240
-    {
241
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
242
-        $crons                = _get_cron_array();
243
-        $crons                = is_array($crons) ? $crons : array();
244
-        /* reminder of what $crons look like:
188
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
189
+				//there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
190
+			)
191
+		);
192
+		if ($which_to_include === 'old') {
193
+			$cron_tasks = array_filter(
194
+				$cron_tasks,
195
+				function ($value) {
196
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
197
+				}
198
+			);
199
+		} elseif ($which_to_include === 'current') {
200
+			$cron_tasks = array_filter($cron_tasks);
201
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
202
+			throw new EE_Error(
203
+				sprintf(
204
+					__(
205
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
206
+						'event_espresso'
207
+					),
208
+					$which_to_include
209
+				)
210
+			);
211
+		}
212
+		return $cron_tasks;
213
+	}
214
+
215
+
216
+	/**
217
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
218
+	 *
219
+	 * @throws \EE_Error
220
+	 */
221
+	public static function create_cron_tasks()
222
+	{
223
+
224
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
225
+			if (! wp_next_scheduled($hook_name)) {
226
+				wp_schedule_event(time(), $frequency, $hook_name);
227
+			}
228
+		}
229
+
230
+	}
231
+
232
+
233
+	/**
234
+	 * Remove the currently-existing and now-removed cron tasks.
235
+	 *
236
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
237
+	 * @throws \EE_Error
238
+	 */
239
+	public static function remove_cron_tasks($remove_all = true)
240
+	{
241
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
242
+		$crons                = _get_cron_array();
243
+		$crons                = is_array($crons) ? $crons : array();
244
+		/* reminder of what $crons look like:
245 245
          * Top-level keys are timestamps, and their values are arrays.
246 246
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
247 247
          * and their values are arrays.
@@ -258,965 +258,965 @@  discard block
 block discarded – undo
258 258
          *					...
259 259
          *      ...
260 260
          */
261
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
262
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
263
-            if (is_array($hooks_to_fire_at_time)) {
264
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
265
-                    if (isset($ee_cron_tasks_to_remove[$hook_name])
266
-                        && is_array($ee_cron_tasks_to_remove[$hook_name])
267
-                    ) {
268
-                        unset($crons[$timestamp][$hook_name]);
269
-                    }
270
-                }
271
-                //also take care of any empty cron timestamps.
272
-                if (empty($hooks_to_fire_at_time)) {
273
-                    unset($crons[$timestamp]);
274
-                }
275
-            }
276
-        }
277
-        _set_cron_array($crons);
278
-    }
279
-
280
-
281
-    /**
282
-     *    CPT_initialization
283
-     *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
284
-     *
285
-     * @access public
286
-     * @static
287
-     * @return void
288
-     */
289
-    public static function CPT_initialization()
290
-    {
291
-        // register Custom Post Types
292
-        EE_Registry::instance()->load_core('Register_CPTs');
293
-        flush_rewrite_rules();
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     *    reset_and_update_config
300
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
301
-     * If there is old calendar config data saved, then it will get converted on activation.
302
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
303
-     *
304
-     * @access public
305
-     * @static
306
-     * @return void
307
-     */
308
-    public static function reset_and_update_config()
309
-    {
310
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
311
-        add_filter(
312
-            'FHEE__EE_Config___load_core_config__config_settings',
313
-            array('EEH_Activation', 'migrate_old_config_data'),
314
-            10,
315
-            3
316
-        );
317
-        //EE_Config::reset();
318
-        if (! EE_Config::logging_enabled()) {
319
-            delete_option(EE_Config::LOG_NAME);
320
-        }
321
-    }
322
-
323
-
324
-    /**
325
-     *    load_calendar_config
326
-     *
327
-     * @access    public
328
-     * @return    void
329
-     */
330
-    public static function load_calendar_config()
331
-    {
332
-        // grab array of all plugin folders and loop thru it
333
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
334
-        if (empty($plugins)) {
335
-            return;
336
-        }
337
-        foreach ($plugins as $plugin_path) {
338
-            // grab plugin folder name from path
339
-            $plugin = basename($plugin_path);
340
-            // drill down to Espresso plugins
341
-            // then to calendar related plugins
342
-            if (
343
-                strpos($plugin, 'espresso') !== false
344
-                || strpos($plugin, 'Espresso') !== false
345
-                || strpos($plugin, 'ee4') !== false
346
-                || strpos($plugin, 'EE4') !== false
347
-                || strpos($plugin, 'calendar') !== false
348
-            ) {
349
-                // this is what we are looking for
350
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
351
-                // does it exist in this folder ?
352
-                if (is_readable($calendar_config)) {
353
-                    // YEAH! let's load it
354
-                    require_once($calendar_config);
355
-                }
356
-            }
357
-        }
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     *    _migrate_old_config_data
364
-     *
365
-     * @access    public
366
-     * @param array|stdClass $settings
367
-     * @param string         $config
368
-     * @param \EE_Config     $EE_Config
369
-     * @return \stdClass
370
-     */
371
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
372
-    {
373
-        $convert_from_array = array('addons');
374
-        // in case old settings were saved as an array
375
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
376
-            // convert existing settings to an object
377
-            $config_array = $settings;
378
-            $settings = new stdClass();
379
-            foreach ($config_array as $key => $value) {
380
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
381
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
382
-                } else {
383
-                    $settings->{$key} = $value;
384
-                }
385
-            }
386
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
387
-        }
388
-        return $settings;
389
-    }
390
-
391
-
392
-    /**
393
-     * deactivate_event_espresso
394
-     *
395
-     * @access public
396
-     * @static
397
-     * @return void
398
-     */
399
-    public static function deactivate_event_espresso()
400
-    {
401
-        // check permissions
402
-        if (current_user_can('activate_plugins')) {
403
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
404
-        }
405
-    }
406
-
407
-
408
-
409
-    /**
410
-     * verify_default_pages_exist
411
-     *
412
-     * @access public
413
-     * @static
414
-     * @return void
415
-     * @throws InvalidDataTypeException
416
-     */
417
-    public static function verify_default_pages_exist()
418
-    {
419
-        $critical_page_problem = false;
420
-        $critical_pages = array(
421
-            array(
422
-                'id'   => 'reg_page_id',
423
-                'name' => __('Registration Checkout', 'event_espresso'),
424
-                'post' => null,
425
-                'code' => 'ESPRESSO_CHECKOUT',
426
-            ),
427
-            array(
428
-                'id'   => 'txn_page_id',
429
-                'name' => __('Transactions', 'event_espresso'),
430
-                'post' => null,
431
-                'code' => 'ESPRESSO_TXN_PAGE',
432
-            ),
433
-            array(
434
-                'id'   => 'thank_you_page_id',
435
-                'name' => __('Thank You', 'event_espresso'),
436
-                'post' => null,
437
-                'code' => 'ESPRESSO_THANK_YOU',
438
-            ),
439
-            array(
440
-                'id'   => 'cancel_page_id',
441
-                'name' => __('Registration Cancelled', 'event_espresso'),
442
-                'post' => null,
443
-                'code' => 'ESPRESSO_CANCELLED',
444
-            ),
445
-        );
446
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
447
-        foreach ($critical_pages as $critical_page) {
448
-            // is critical page ID set in config ?
449
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
450
-                // attempt to find post by ID
451
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
452
-            }
453
-            // no dice?
454
-            if ($critical_page['post'] === null) {
455
-                // attempt to find post by title
456
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
457
-                // still nothing?
458
-                if ($critical_page['post'] === null) {
459
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
460
-                    // REALLY? Still nothing ??!?!?
461
-                    if ($critical_page['post'] === null) {
462
-                        $msg = __(
463
-                            'The Event Espresso critical page configuration settings could not be updated.',
464
-                            'event_espresso'
465
-                        );
466
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
467
-                        break;
468
-                    }
469
-                }
470
-            }
471
-            // track post_shortcodes
472
-            if ($critical_page['post']) {
473
-                EEH_Activation::_track_critical_page_post_shortcodes($critical_page);
474
-            }
475
-            // check that Post ID matches critical page ID in config
476
-            if (
477
-                isset($critical_page['post']->ID)
478
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
479
-            ) {
480
-                //update Config with post ID
481
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
482
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
483
-                    $msg = __(
484
-                        'The Event Espresso critical page configuration settings could not be updated.',
485
-                        'event_espresso'
486
-                    );
487
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
488
-                }
489
-            }
490
-            $critical_page_problem =
491
-                ! isset($critical_page['post']->post_status)
492
-                || $critical_page['post']->post_status !== 'publish'
493
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
494
-                    ? true
495
-                    : $critical_page_problem;
496
-        }
497
-        if ($critical_page_problem) {
498
-            new PersistentAdminNotice(
499
-                'critical_page_problem',
500
-                sprintf(
501
-                    esc_html__(
502
-                        'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
503
-                        'event_espresso'
504
-                    ),
505
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
506
-                    . __('Event Espresso Critical Pages Settings', 'event_espresso')
507
-                    . '</a>'
508
-                )
509
-            );
510
-        }
511
-        if (EE_Error::has_notices()) {
512
-            EE_Error::get_notices(false, true, true);
513
-        }
514
-    }
515
-
516
-
517
-
518
-    /**
519
-     * Returns the first post which uses the specified shortcode
520
-     *
521
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
522
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
523
-     *                             "[ESPRESSO_THANK_YOU"
524
-     *                             (we don't search for the closing shortcode bracket because they might have added
525
-     *                             parameter to the shortcode
526
-     * @return WP_Post or NULl
527
-     */
528
-    public static function get_page_by_ee_shortcode($ee_shortcode)
529
-    {
530
-        global $wpdb;
531
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
532
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
533
-        if ($post_id) {
534
-            return get_post($post_id);
535
-        } else {
536
-            return null;
537
-        }
538
-    }
539
-
540
-
541
-    /**
542
-     *    This function generates a post for critical espresso pages
543
-     *
544
-     * @access public
545
-     * @static
546
-     * @param array $critical_page
547
-     * @return array
548
-     */
549
-    public static function create_critical_page($critical_page)
550
-    {
551
-
552
-        $post_args = array(
553
-            'post_title'     => $critical_page['name'],
554
-            'post_status'    => 'publish',
555
-            'post_type'      => 'page',
556
-            'comment_status' => 'closed',
557
-            'post_content'   => '[' . $critical_page['code'] . ']',
558
-        );
559
-
560
-        $post_id = wp_insert_post($post_args);
561
-        if (! $post_id) {
562
-            $msg = sprintf(
563
-                __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
564
-                $critical_page['name']
565
-            );
566
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
567
-            return $critical_page;
568
-        }
569
-        // get newly created post's details
570
-        if (! $critical_page['post'] = get_post($post_id)) {
571
-            $msg = sprintf(
572
-                __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
573
-                $critical_page['name']
574
-            );
575
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
576
-        }
577
-
578
-        return $critical_page;
579
-
580
-    }
581
-
582
-
583
-
584
-
585
-
586
-    /**
587
-     *    This function adds a critical page's shortcode to the post_shortcodes array
588
-     *
589
-     * @access private
590
-     * @static
591
-     * @param array $critical_page
592
-     * @return void
593
-     */
594
-    private static function _track_critical_page_post_shortcodes($critical_page = array())
595
-    {
596
-        // check the goods
597
-        if ( ! $critical_page['post'] instanceof WP_Post) {
598
-            $msg = sprintf(
599
-                __(
600
-                    'The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.',
601
-                    'event_espresso'
602
-                ),
603
-                $critical_page['name']
604
-            );
605
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
606
-            return;
607
-        }
608
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
609
-        // map shortcode to post
610
-        $EE_Core_Config->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID;
611
-        // and make sure it's NOT added to the WP "Posts Page"
612
-        // name of the WP Posts Page
613
-        $posts_page = EE_Config::get_page_for_posts();
614
-        if (isset($EE_Core_Config->post_shortcodes[$posts_page])) {
615
-            unset($EE_Core_Config->post_shortcodes[$posts_page][$critical_page['code']]);
616
-        }
617
-        if ($posts_page !== 'posts' && isset($EE_Core_Config->post_shortcodes['posts'])) {
618
-            unset($EE_Core_Config->post_shortcodes['posts'][$critical_page['code']]);
619
-        }
620
-        // update post_shortcode CFG
621
-        if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
622
-            $msg = sprintf(
623
-                __(
624
-                    'The Event Espresso critical page shortcode for the %s page could not be configured properly.',
625
-                    'event_espresso'
626
-                ),
627
-                $critical_page['name']
628
-            );
629
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
630
-        }
631
-    }
632
-
633
-
634
-
635
-    /**
636
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
637
-     * The role being used to check is filterable.
638
-     *
639
-     * @since  4.6.0
640
-     * @global WPDB $wpdb
641
-     * @return mixed null|int WP_user ID or NULL
642
-     */
643
-    public static function get_default_creator_id()
644
-    {
645
-        global $wpdb;
646
-        if ( ! empty(self::$_default_creator_id)) {
647
-            return self::$_default_creator_id;
648
-        }/**/
649
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
650
-        //let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
651
-        $pre_filtered_id = apply_filters(
652
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
653
-            false,
654
-            $role_to_check
655
-        );
656
-        if ($pre_filtered_id !== false) {
657
-            return (int)$pre_filtered_id;
658
-        }
659
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
660
-        $query = $wpdb->prepare(
661
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
662
-            '%' . $role_to_check . '%'
663
-        );
664
-        $user_id = $wpdb->get_var($query);
665
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
666
-        if ($user_id && (int)$user_id) {
667
-            self::$_default_creator_id = (int)$user_id;
668
-            return self::$_default_creator_id;
669
-        } else {
670
-            return null;
671
-        }
672
-    }
673
-
674
-
675
-
676
-    /**
677
-     * used by EE and EE addons during plugin activation to create tables.
678
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
679
-     * but includes extra logic regarding activations.
680
-     *
681
-     * @access public
682
-     * @static
683
-     * @param string  $table_name              without the $wpdb->prefix
684
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
685
-     *                                         table query)
686
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
687
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
688
-     *                                         and new once this function is done (ie, you really do want to CREATE a
689
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
690
-     *                                         you just want to verify the table exists and matches this definition
691
-     *                                         (and if it HAS data in it you want to leave it be)
692
-     * @return void
693
-     * @throws EE_Error if there are database errors
694
-     */
695
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
696
-    {
697
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
698
-            return;
699
-        }
700
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
701
-        if ( ! function_exists('dbDelta')) {
702
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
703
-        }
704
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
705
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
706
-        // do we need to first delete an existing version of this table ?
707
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
708
-            // ok, delete the table... but ONLY if it's empty
709
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
710
-            // table is NOT empty, are you SURE you want to delete this table ???
711
-            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
712
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
713
-            } else if ( ! $deleted_safely) {
714
-                // so we should be more cautious rather than just dropping tables so easily
715
-                error_log(
716
-                    sprintf(
717
-                        __(
718
-                            'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
719
-                            'event_espresso'
720
-                        ),
721
-                        $wp_table_name,
722
-                        '<br/>',
723
-                        'espresso_db_update'
724
-                    )
725
-                );
726
-            }
727
-        }
728
-        $engine = str_replace('ENGINE=', '', $engine);
729
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
730
-    }
731
-
732
-
733
-
734
-    /**
735
-     *    add_column_if_it_doesn't_exist
736
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
737
-     *
738
-     * @access     public
739
-     * @static
740
-     * @deprecated instead use TableManager::addColumn()
741
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
742
-     * @param string $column_name
743
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
744
-     *                            'VARCHAR(10)'
745
-     * @return bool|int
746
-     */
747
-    public static function add_column_if_it_doesnt_exist(
748
-        $table_name,
749
-        $column_name,
750
-        $column_info = 'INT UNSIGNED NOT NULL'
751
-    ) {
752
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
753
-    }
754
-
755
-
756
-    /**
757
-     * get_fields_on_table
758
-     * Gets all the fields on the database table.
759
-     *
760
-     * @access     public
761
-     * @deprecated instead use TableManager::getTableColumns()
762
-     * @static
763
-     * @param string $table_name , without prefixed $wpdb->prefix
764
-     * @return array of database column names
765
-     */
766
-    public static function get_fields_on_table($table_name = null)
767
-    {
768
-        return \EEH_Activation::getTableManager()->getTableColumns($table_name);
769
-    }
770
-
771
-
772
-    /**
773
-     * db_table_is_empty
774
-     *
775
-     * @access     public\
776
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
777
-     * @static
778
-     * @param string $table_name
779
-     * @return bool
780
-     */
781
-    public static function db_table_is_empty($table_name)
782
-    {
783
-        return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
784
-    }
785
-
786
-
787
-    /**
788
-     * delete_db_table_if_empty
789
-     *
790
-     * @access public
791
-     * @static
792
-     * @param string $table_name
793
-     * @return bool | int
794
-     */
795
-    public static function delete_db_table_if_empty($table_name)
796
-    {
797
-        if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
798
-            return \EEH_Activation::getTableManager()->dropTable($table_name);
799
-        }
800
-        return false;
801
-    }
802
-
803
-
804
-    /**
805
-     * delete_unused_db_table
806
-     *
807
-     * @access     public
808
-     * @static
809
-     * @deprecated instead use TableManager::dropTable()
810
-     * @param string $table_name
811
-     * @return bool | int
812
-     */
813
-    public static function delete_unused_db_table($table_name)
814
-    {
815
-        return \EEH_Activation::getTableManager()->dropTable($table_name);
816
-    }
817
-
818
-
819
-    /**
820
-     * drop_index
821
-     *
822
-     * @access     public
823
-     * @static
824
-     * @deprecated instead use TableManager::dropIndex()
825
-     * @param string $table_name
826
-     * @param string $index_name
827
-     * @return bool | int
828
-     */
829
-    public static function drop_index($table_name, $index_name)
830
-    {
831
-        return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
832
-    }
833
-
834
-
835
-
836
-    /**
837
-     * create_database_tables
838
-     *
839
-     * @access public
840
-     * @static
841
-     * @throws EE_Error
842
-     * @return boolean success (whether database is setup properly or not)
843
-     */
844
-    public static function create_database_tables()
845
-    {
846
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
847
-        //find the migration script that sets the database to be compatible with the code
848
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
849
-        if ($dms_name) {
850
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
851
-            $current_data_migration_script->set_migrating(false);
852
-            $current_data_migration_script->schema_changes_before_migration();
853
-            $current_data_migration_script->schema_changes_after_migration();
854
-            if ($current_data_migration_script->get_errors()) {
855
-                if (WP_DEBUG) {
856
-                    foreach ($current_data_migration_script->get_errors() as $error) {
857
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
858
-                    }
859
-                } else {
860
-                    EE_Error::add_error(
861
-                        __(
862
-                            'There were errors creating the Event Espresso database tables and Event Espresso has been 
261
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
262
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
263
+			if (is_array($hooks_to_fire_at_time)) {
264
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
265
+					if (isset($ee_cron_tasks_to_remove[$hook_name])
266
+						&& is_array($ee_cron_tasks_to_remove[$hook_name])
267
+					) {
268
+						unset($crons[$timestamp][$hook_name]);
269
+					}
270
+				}
271
+				//also take care of any empty cron timestamps.
272
+				if (empty($hooks_to_fire_at_time)) {
273
+					unset($crons[$timestamp]);
274
+				}
275
+			}
276
+		}
277
+		_set_cron_array($crons);
278
+	}
279
+
280
+
281
+	/**
282
+	 *    CPT_initialization
283
+	 *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
284
+	 *
285
+	 * @access public
286
+	 * @static
287
+	 * @return void
288
+	 */
289
+	public static function CPT_initialization()
290
+	{
291
+		// register Custom Post Types
292
+		EE_Registry::instance()->load_core('Register_CPTs');
293
+		flush_rewrite_rules();
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 *    reset_and_update_config
300
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
301
+	 * If there is old calendar config data saved, then it will get converted on activation.
302
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
303
+	 *
304
+	 * @access public
305
+	 * @static
306
+	 * @return void
307
+	 */
308
+	public static function reset_and_update_config()
309
+	{
310
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
311
+		add_filter(
312
+			'FHEE__EE_Config___load_core_config__config_settings',
313
+			array('EEH_Activation', 'migrate_old_config_data'),
314
+			10,
315
+			3
316
+		);
317
+		//EE_Config::reset();
318
+		if (! EE_Config::logging_enabled()) {
319
+			delete_option(EE_Config::LOG_NAME);
320
+		}
321
+	}
322
+
323
+
324
+	/**
325
+	 *    load_calendar_config
326
+	 *
327
+	 * @access    public
328
+	 * @return    void
329
+	 */
330
+	public static function load_calendar_config()
331
+	{
332
+		// grab array of all plugin folders and loop thru it
333
+		$plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
334
+		if (empty($plugins)) {
335
+			return;
336
+		}
337
+		foreach ($plugins as $plugin_path) {
338
+			// grab plugin folder name from path
339
+			$plugin = basename($plugin_path);
340
+			// drill down to Espresso plugins
341
+			// then to calendar related plugins
342
+			if (
343
+				strpos($plugin, 'espresso') !== false
344
+				|| strpos($plugin, 'Espresso') !== false
345
+				|| strpos($plugin, 'ee4') !== false
346
+				|| strpos($plugin, 'EE4') !== false
347
+				|| strpos($plugin, 'calendar') !== false
348
+			) {
349
+				// this is what we are looking for
350
+				$calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
351
+				// does it exist in this folder ?
352
+				if (is_readable($calendar_config)) {
353
+					// YEAH! let's load it
354
+					require_once($calendar_config);
355
+				}
356
+			}
357
+		}
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 *    _migrate_old_config_data
364
+	 *
365
+	 * @access    public
366
+	 * @param array|stdClass $settings
367
+	 * @param string         $config
368
+	 * @param \EE_Config     $EE_Config
369
+	 * @return \stdClass
370
+	 */
371
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
372
+	{
373
+		$convert_from_array = array('addons');
374
+		// in case old settings were saved as an array
375
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
376
+			// convert existing settings to an object
377
+			$config_array = $settings;
378
+			$settings = new stdClass();
379
+			foreach ($config_array as $key => $value) {
380
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
381
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
382
+				} else {
383
+					$settings->{$key} = $value;
384
+				}
385
+			}
386
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
387
+		}
388
+		return $settings;
389
+	}
390
+
391
+
392
+	/**
393
+	 * deactivate_event_espresso
394
+	 *
395
+	 * @access public
396
+	 * @static
397
+	 * @return void
398
+	 */
399
+	public static function deactivate_event_espresso()
400
+	{
401
+		// check permissions
402
+		if (current_user_can('activate_plugins')) {
403
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
404
+		}
405
+	}
406
+
407
+
408
+
409
+	/**
410
+	 * verify_default_pages_exist
411
+	 *
412
+	 * @access public
413
+	 * @static
414
+	 * @return void
415
+	 * @throws InvalidDataTypeException
416
+	 */
417
+	public static function verify_default_pages_exist()
418
+	{
419
+		$critical_page_problem = false;
420
+		$critical_pages = array(
421
+			array(
422
+				'id'   => 'reg_page_id',
423
+				'name' => __('Registration Checkout', 'event_espresso'),
424
+				'post' => null,
425
+				'code' => 'ESPRESSO_CHECKOUT',
426
+			),
427
+			array(
428
+				'id'   => 'txn_page_id',
429
+				'name' => __('Transactions', 'event_espresso'),
430
+				'post' => null,
431
+				'code' => 'ESPRESSO_TXN_PAGE',
432
+			),
433
+			array(
434
+				'id'   => 'thank_you_page_id',
435
+				'name' => __('Thank You', 'event_espresso'),
436
+				'post' => null,
437
+				'code' => 'ESPRESSO_THANK_YOU',
438
+			),
439
+			array(
440
+				'id'   => 'cancel_page_id',
441
+				'name' => __('Registration Cancelled', 'event_espresso'),
442
+				'post' => null,
443
+				'code' => 'ESPRESSO_CANCELLED',
444
+			),
445
+		);
446
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
447
+		foreach ($critical_pages as $critical_page) {
448
+			// is critical page ID set in config ?
449
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
450
+				// attempt to find post by ID
451
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
452
+			}
453
+			// no dice?
454
+			if ($critical_page['post'] === null) {
455
+				// attempt to find post by title
456
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
457
+				// still nothing?
458
+				if ($critical_page['post'] === null) {
459
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
460
+					// REALLY? Still nothing ??!?!?
461
+					if ($critical_page['post'] === null) {
462
+						$msg = __(
463
+							'The Event Espresso critical page configuration settings could not be updated.',
464
+							'event_espresso'
465
+						);
466
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
467
+						break;
468
+					}
469
+				}
470
+			}
471
+			// track post_shortcodes
472
+			if ($critical_page['post']) {
473
+				EEH_Activation::_track_critical_page_post_shortcodes($critical_page);
474
+			}
475
+			// check that Post ID matches critical page ID in config
476
+			if (
477
+				isset($critical_page['post']->ID)
478
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
479
+			) {
480
+				//update Config with post ID
481
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
482
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
483
+					$msg = __(
484
+						'The Event Espresso critical page configuration settings could not be updated.',
485
+						'event_espresso'
486
+					);
487
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
488
+				}
489
+			}
490
+			$critical_page_problem =
491
+				! isset($critical_page['post']->post_status)
492
+				|| $critical_page['post']->post_status !== 'publish'
493
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
494
+					? true
495
+					: $critical_page_problem;
496
+		}
497
+		if ($critical_page_problem) {
498
+			new PersistentAdminNotice(
499
+				'critical_page_problem',
500
+				sprintf(
501
+					esc_html__(
502
+						'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
503
+						'event_espresso'
504
+					),
505
+					'<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
506
+					. __('Event Espresso Critical Pages Settings', 'event_espresso')
507
+					. '</a>'
508
+				)
509
+			);
510
+		}
511
+		if (EE_Error::has_notices()) {
512
+			EE_Error::get_notices(false, true, true);
513
+		}
514
+	}
515
+
516
+
517
+
518
+	/**
519
+	 * Returns the first post which uses the specified shortcode
520
+	 *
521
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
522
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
523
+	 *                             "[ESPRESSO_THANK_YOU"
524
+	 *                             (we don't search for the closing shortcode bracket because they might have added
525
+	 *                             parameter to the shortcode
526
+	 * @return WP_Post or NULl
527
+	 */
528
+	public static function get_page_by_ee_shortcode($ee_shortcode)
529
+	{
530
+		global $wpdb;
531
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
532
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
533
+		if ($post_id) {
534
+			return get_post($post_id);
535
+		} else {
536
+			return null;
537
+		}
538
+	}
539
+
540
+
541
+	/**
542
+	 *    This function generates a post for critical espresso pages
543
+	 *
544
+	 * @access public
545
+	 * @static
546
+	 * @param array $critical_page
547
+	 * @return array
548
+	 */
549
+	public static function create_critical_page($critical_page)
550
+	{
551
+
552
+		$post_args = array(
553
+			'post_title'     => $critical_page['name'],
554
+			'post_status'    => 'publish',
555
+			'post_type'      => 'page',
556
+			'comment_status' => 'closed',
557
+			'post_content'   => '[' . $critical_page['code'] . ']',
558
+		);
559
+
560
+		$post_id = wp_insert_post($post_args);
561
+		if (! $post_id) {
562
+			$msg = sprintf(
563
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
564
+				$critical_page['name']
565
+			);
566
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
567
+			return $critical_page;
568
+		}
569
+		// get newly created post's details
570
+		if (! $critical_page['post'] = get_post($post_id)) {
571
+			$msg = sprintf(
572
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
573
+				$critical_page['name']
574
+			);
575
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
576
+		}
577
+
578
+		return $critical_page;
579
+
580
+	}
581
+
582
+
583
+
584
+
585
+
586
+	/**
587
+	 *    This function adds a critical page's shortcode to the post_shortcodes array
588
+	 *
589
+	 * @access private
590
+	 * @static
591
+	 * @param array $critical_page
592
+	 * @return void
593
+	 */
594
+	private static function _track_critical_page_post_shortcodes($critical_page = array())
595
+	{
596
+		// check the goods
597
+		if ( ! $critical_page['post'] instanceof WP_Post) {
598
+			$msg = sprintf(
599
+				__(
600
+					'The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.',
601
+					'event_espresso'
602
+				),
603
+				$critical_page['name']
604
+			);
605
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
606
+			return;
607
+		}
608
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
609
+		// map shortcode to post
610
+		$EE_Core_Config->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID;
611
+		// and make sure it's NOT added to the WP "Posts Page"
612
+		// name of the WP Posts Page
613
+		$posts_page = EE_Config::get_page_for_posts();
614
+		if (isset($EE_Core_Config->post_shortcodes[$posts_page])) {
615
+			unset($EE_Core_Config->post_shortcodes[$posts_page][$critical_page['code']]);
616
+		}
617
+		if ($posts_page !== 'posts' && isset($EE_Core_Config->post_shortcodes['posts'])) {
618
+			unset($EE_Core_Config->post_shortcodes['posts'][$critical_page['code']]);
619
+		}
620
+		// update post_shortcode CFG
621
+		if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
622
+			$msg = sprintf(
623
+				__(
624
+					'The Event Espresso critical page shortcode for the %s page could not be configured properly.',
625
+					'event_espresso'
626
+				),
627
+				$critical_page['name']
628
+			);
629
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
630
+		}
631
+	}
632
+
633
+
634
+
635
+	/**
636
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
637
+	 * The role being used to check is filterable.
638
+	 *
639
+	 * @since  4.6.0
640
+	 * @global WPDB $wpdb
641
+	 * @return mixed null|int WP_user ID or NULL
642
+	 */
643
+	public static function get_default_creator_id()
644
+	{
645
+		global $wpdb;
646
+		if ( ! empty(self::$_default_creator_id)) {
647
+			return self::$_default_creator_id;
648
+		}/**/
649
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
650
+		//let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
651
+		$pre_filtered_id = apply_filters(
652
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
653
+			false,
654
+			$role_to_check
655
+		);
656
+		if ($pre_filtered_id !== false) {
657
+			return (int)$pre_filtered_id;
658
+		}
659
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
660
+		$query = $wpdb->prepare(
661
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
662
+			'%' . $role_to_check . '%'
663
+		);
664
+		$user_id = $wpdb->get_var($query);
665
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
666
+		if ($user_id && (int)$user_id) {
667
+			self::$_default_creator_id = (int)$user_id;
668
+			return self::$_default_creator_id;
669
+		} else {
670
+			return null;
671
+		}
672
+	}
673
+
674
+
675
+
676
+	/**
677
+	 * used by EE and EE addons during plugin activation to create tables.
678
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
679
+	 * but includes extra logic regarding activations.
680
+	 *
681
+	 * @access public
682
+	 * @static
683
+	 * @param string  $table_name              without the $wpdb->prefix
684
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
685
+	 *                                         table query)
686
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
687
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
688
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
689
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
690
+	 *                                         you just want to verify the table exists and matches this definition
691
+	 *                                         (and if it HAS data in it you want to leave it be)
692
+	 * @return void
693
+	 * @throws EE_Error if there are database errors
694
+	 */
695
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
696
+	{
697
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
698
+			return;
699
+		}
700
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
701
+		if ( ! function_exists('dbDelta')) {
702
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
703
+		}
704
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
705
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
706
+		// do we need to first delete an existing version of this table ?
707
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
708
+			// ok, delete the table... but ONLY if it's empty
709
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
710
+			// table is NOT empty, are you SURE you want to delete this table ???
711
+			if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
712
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
713
+			} else if ( ! $deleted_safely) {
714
+				// so we should be more cautious rather than just dropping tables so easily
715
+				error_log(
716
+					sprintf(
717
+						__(
718
+							'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
719
+							'event_espresso'
720
+						),
721
+						$wp_table_name,
722
+						'<br/>',
723
+						'espresso_db_update'
724
+					)
725
+				);
726
+			}
727
+		}
728
+		$engine = str_replace('ENGINE=', '', $engine);
729
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
730
+	}
731
+
732
+
733
+
734
+	/**
735
+	 *    add_column_if_it_doesn't_exist
736
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
737
+	 *
738
+	 * @access     public
739
+	 * @static
740
+	 * @deprecated instead use TableManager::addColumn()
741
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
742
+	 * @param string $column_name
743
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
744
+	 *                            'VARCHAR(10)'
745
+	 * @return bool|int
746
+	 */
747
+	public static function add_column_if_it_doesnt_exist(
748
+		$table_name,
749
+		$column_name,
750
+		$column_info = 'INT UNSIGNED NOT NULL'
751
+	) {
752
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
753
+	}
754
+
755
+
756
+	/**
757
+	 * get_fields_on_table
758
+	 * Gets all the fields on the database table.
759
+	 *
760
+	 * @access     public
761
+	 * @deprecated instead use TableManager::getTableColumns()
762
+	 * @static
763
+	 * @param string $table_name , without prefixed $wpdb->prefix
764
+	 * @return array of database column names
765
+	 */
766
+	public static function get_fields_on_table($table_name = null)
767
+	{
768
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
769
+	}
770
+
771
+
772
+	/**
773
+	 * db_table_is_empty
774
+	 *
775
+	 * @access     public\
776
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
777
+	 * @static
778
+	 * @param string $table_name
779
+	 * @return bool
780
+	 */
781
+	public static function db_table_is_empty($table_name)
782
+	{
783
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
784
+	}
785
+
786
+
787
+	/**
788
+	 * delete_db_table_if_empty
789
+	 *
790
+	 * @access public
791
+	 * @static
792
+	 * @param string $table_name
793
+	 * @return bool | int
794
+	 */
795
+	public static function delete_db_table_if_empty($table_name)
796
+	{
797
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
798
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
799
+		}
800
+		return false;
801
+	}
802
+
803
+
804
+	/**
805
+	 * delete_unused_db_table
806
+	 *
807
+	 * @access     public
808
+	 * @static
809
+	 * @deprecated instead use TableManager::dropTable()
810
+	 * @param string $table_name
811
+	 * @return bool | int
812
+	 */
813
+	public static function delete_unused_db_table($table_name)
814
+	{
815
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
816
+	}
817
+
818
+
819
+	/**
820
+	 * drop_index
821
+	 *
822
+	 * @access     public
823
+	 * @static
824
+	 * @deprecated instead use TableManager::dropIndex()
825
+	 * @param string $table_name
826
+	 * @param string $index_name
827
+	 * @return bool | int
828
+	 */
829
+	public static function drop_index($table_name, $index_name)
830
+	{
831
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
832
+	}
833
+
834
+
835
+
836
+	/**
837
+	 * create_database_tables
838
+	 *
839
+	 * @access public
840
+	 * @static
841
+	 * @throws EE_Error
842
+	 * @return boolean success (whether database is setup properly or not)
843
+	 */
844
+	public static function create_database_tables()
845
+	{
846
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
847
+		//find the migration script that sets the database to be compatible with the code
848
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
849
+		if ($dms_name) {
850
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
851
+			$current_data_migration_script->set_migrating(false);
852
+			$current_data_migration_script->schema_changes_before_migration();
853
+			$current_data_migration_script->schema_changes_after_migration();
854
+			if ($current_data_migration_script->get_errors()) {
855
+				if (WP_DEBUG) {
856
+					foreach ($current_data_migration_script->get_errors() as $error) {
857
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
858
+					}
859
+				} else {
860
+					EE_Error::add_error(
861
+						__(
862
+							'There were errors creating the Event Espresso database tables and Event Espresso has been 
863 863
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
864
-                            'event_espresso'
865
-                        )
866
-                    );
867
-                }
868
-                return false;
869
-            }
870
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
871
-        } else {
872
-            EE_Error::add_error(
873
-                __(
874
-                    'Could not determine most up-to-date data migration script from which to pull database schema
864
+							'event_espresso'
865
+						)
866
+					);
867
+				}
868
+				return false;
869
+			}
870
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
871
+		} else {
872
+			EE_Error::add_error(
873
+				__(
874
+					'Could not determine most up-to-date data migration script from which to pull database schema
875 875
                      structure. So database is probably not setup properly',
876
-                    'event_espresso'
877
-                ),
878
-                __FILE__,
879
-                __FUNCTION__,
880
-                __LINE__
881
-            );
882
-            return false;
883
-        }
884
-        return true;
885
-    }
886
-
887
-
888
-
889
-    /**
890
-     * initialize_system_questions
891
-     *
892
-     * @access public
893
-     * @static
894
-     * @return void
895
-     */
896
-    public static function initialize_system_questions()
897
-    {
898
-        // QUESTION GROUPS
899
-        global $wpdb;
900
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
901
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
902
-        // what we have
903
-        $question_groups = $wpdb->get_col($SQL);
904
-        // check the response
905
-        $question_groups = is_array($question_groups) ? $question_groups : array();
906
-        // what we should have
907
-        $QSG_systems = array(1, 2);
908
-        // loop thru what we should have and compare to what we have
909
-        foreach ($QSG_systems as $QSG_system) {
910
-            // reset values array
911
-            $QSG_values = array();
912
-            // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
913
-            if (! in_array("$QSG_system", $question_groups)) {
914
-                // add it
915
-                switch ($QSG_system) {
916
-                    case 1:
917
-                        $QSG_values = array(
918
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
919
-                            'QSG_identifier'      => 'personal-information-' . time(),
920
-                            'QSG_desc'            => '',
921
-                            'QSG_order'           => 1,
922
-                            'QSG_show_group_name' => 1,
923
-                            'QSG_show_group_desc' => 1,
924
-                            'QSG_system'          => EEM_Question_Group::system_personal,
925
-                            'QSG_deleted'         => 0,
926
-                        );
927
-                        break;
928
-                    case 2:
929
-                        $QSG_values = array(
930
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
931
-                            'QSG_identifier'      => 'address-information-' . time(),
932
-                            'QSG_desc'            => '',
933
-                            'QSG_order'           => 2,
934
-                            'QSG_show_group_name' => 1,
935
-                            'QSG_show_group_desc' => 1,
936
-                            'QSG_system'          => EEM_Question_Group::system_address,
937
-                            'QSG_deleted'         => 0,
938
-                        );
939
-                        break;
940
-                }
941
-                // make sure we have some values before inserting them
942
-                if (! empty($QSG_values)) {
943
-                    // insert system question
944
-                    $wpdb->insert(
945
-                        $table_name,
946
-                        $QSG_values,
947
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
948
-                    );
949
-                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
950
-                }
951
-            }
952
-        }
953
-        // QUESTIONS
954
-        global $wpdb;
955
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
956
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
957
-        // what we have
958
-        $questions = $wpdb->get_col($SQL);
959
-        // what we should have
960
-        $QST_systems = array(
961
-            'fname',
962
-            'lname',
963
-            'email',
964
-            'address',
965
-            'address2',
966
-            'city',
967
-            'country',
968
-            'state',
969
-            'zip',
970
-            'phone',
971
-        );
972
-        $order_for_group_1 = 1;
973
-        $order_for_group_2 = 1;
974
-        // loop thru what we should have and compare to what we have
975
-        foreach ($QST_systems as $QST_system) {
976
-            // reset values array
977
-            $QST_values = array();
978
-            // if we don't have what we should have
979
-            if (! in_array($QST_system, $questions)) {
980
-                // add it
981
-                switch ($QST_system) {
982
-                    case 'fname':
983
-                        $QST_values = array(
984
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
985
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
986
-                            'QST_system'        => 'fname',
987
-                            'QST_type'          => 'TEXT',
988
-                            'QST_required'      => 1,
989
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
990
-                            'QST_order'         => 1,
991
-                            'QST_admin_only'    => 0,
992
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
993
-                            'QST_wp_user'       => self::get_default_creator_id(),
994
-                            'QST_deleted'       => 0,
995
-                        );
996
-                        break;
997
-                    case 'lname':
998
-                        $QST_values = array(
999
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
1000
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
1001
-                            'QST_system'        => 'lname',
1002
-                            'QST_type'          => 'TEXT',
1003
-                            'QST_required'      => 1,
1004
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1005
-                            'QST_order'         => 2,
1006
-                            'QST_admin_only'    => 0,
1007
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1008
-                            'QST_wp_user'       => self::get_default_creator_id(),
1009
-                            'QST_deleted'       => 0,
1010
-                        );
1011
-                        break;
1012
-                    case 'email':
1013
-                        $QST_values = array(
1014
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
1015
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
1016
-                            'QST_system'        => 'email',
1017
-                            'QST_type'          => 'EMAIL',
1018
-                            'QST_required'      => 1,
1019
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1020
-                            'QST_order'         => 3,
1021
-                            'QST_admin_only'    => 0,
1022
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1023
-                            'QST_wp_user'       => self::get_default_creator_id(),
1024
-                            'QST_deleted'       => 0,
1025
-                        );
1026
-                        break;
1027
-                    case 'address':
1028
-                        $QST_values = array(
1029
-                            'QST_display_text'  => __('Address', 'event_espresso'),
1030
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
1031
-                            'QST_system'        => 'address',
1032
-                            'QST_type'          => 'TEXT',
1033
-                            'QST_required'      => 0,
1034
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1035
-                            'QST_order'         => 4,
1036
-                            'QST_admin_only'    => 0,
1037
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1038
-                            'QST_wp_user'       => self::get_default_creator_id(),
1039
-                            'QST_deleted'       => 0,
1040
-                        );
1041
-                        break;
1042
-                    case 'address2':
1043
-                        $QST_values = array(
1044
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
1045
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1046
-                            'QST_system'        => 'address2',
1047
-                            'QST_type'          => 'TEXT',
1048
-                            'QST_required'      => 0,
1049
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1050
-                            'QST_order'         => 5,
1051
-                            'QST_admin_only'    => 0,
1052
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1053
-                            'QST_wp_user'       => self::get_default_creator_id(),
1054
-                            'QST_deleted'       => 0,
1055
-                        );
1056
-                        break;
1057
-                    case 'city':
1058
-                        $QST_values = array(
1059
-                            'QST_display_text'  => __('City', 'event_espresso'),
1060
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1061
-                            'QST_system'        => 'city',
1062
-                            'QST_type'          => 'TEXT',
1063
-                            'QST_required'      => 0,
1064
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1065
-                            'QST_order'         => 6,
1066
-                            'QST_admin_only'    => 0,
1067
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1068
-                            'QST_wp_user'       => self::get_default_creator_id(),
1069
-                            'QST_deleted'       => 0,
1070
-                        );
1071
-                        break;
1072
-                    case 'country':
1073
-                        $QST_values = array(
1074
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1075
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1076
-                            'QST_system'        => 'country',
1077
-                            'QST_type'          => 'COUNTRY',
1078
-                            'QST_required'      => 0,
1079
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1080
-                            'QST_order'         => 7,
1081
-                            'QST_admin_only'    => 0,
1082
-                            'QST_wp_user'       => self::get_default_creator_id(),
1083
-                            'QST_deleted'       => 0,
1084
-                        );
1085
-                        break;
1086
-                    case 'state':
1087
-                        $QST_values = array(
1088
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1089
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1090
-                            'QST_system'        => 'state',
1091
-                            'QST_type'          => 'STATE',
1092
-                            'QST_required'      => 0,
1093
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1094
-                            'QST_order'         => 8,
1095
-                            'QST_admin_only'    => 0,
1096
-                            'QST_wp_user'       => self::get_default_creator_id(),
1097
-                            'QST_deleted'       => 0,
1098
-                        );
1099
-                        break;
1100
-                    case 'zip':
1101
-                        $QST_values = array(
1102
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1103
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1104
-                            'QST_system'        => 'zip',
1105
-                            'QST_type'          => 'TEXT',
1106
-                            'QST_required'      => 0,
1107
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1108
-                            'QST_order'         => 9,
1109
-                            'QST_admin_only'    => 0,
1110
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1111
-                            'QST_wp_user'       => self::get_default_creator_id(),
1112
-                            'QST_deleted'       => 0,
1113
-                        );
1114
-                        break;
1115
-                    case 'phone':
1116
-                        $QST_values = array(
1117
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1118
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1119
-                            'QST_system'        => 'phone',
1120
-                            'QST_type'          => 'TEXT',
1121
-                            'QST_required'      => 0,
1122
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1123
-                            'QST_order'         => 10,
1124
-                            'QST_admin_only'    => 0,
1125
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1126
-                            'QST_wp_user'       => self::get_default_creator_id(),
1127
-                            'QST_deleted'       => 0,
1128
-                        );
1129
-                        break;
1130
-                }
1131
-                if (! empty($QST_values)) {
1132
-                    // insert system question
1133
-                    $wpdb->insert(
1134
-                        $table_name,
1135
-                        $QST_values,
1136
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1137
-                    );
1138
-                    $QST_ID = $wpdb->insert_id;
1139
-                    // QUESTION GROUP QUESTIONS
1140
-                    if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1141
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1142
-                    } else {
1143
-                        $system_question_we_want = EEM_Question_Group::system_address;
1144
-                    }
1145
-                    if (isset($QSG_IDs[$system_question_we_want])) {
1146
-                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1147
-                    } else {
1148
-                        $id_col = EEM_Question_Group::instance()
1149
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1150
-                        if (is_array($id_col)) {
1151
-                            $QSG_ID = reset($id_col);
1152
-                        } else {
1153
-                            //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1154
-                            EE_Log::instance()->log(
1155
-                                __FILE__,
1156
-                                __FUNCTION__,
1157
-                                sprintf(
1158
-                                    __(
1159
-                                        'Could not associate question %1$s to a question group because no system question
876
+					'event_espresso'
877
+				),
878
+				__FILE__,
879
+				__FUNCTION__,
880
+				__LINE__
881
+			);
882
+			return false;
883
+		}
884
+		return true;
885
+	}
886
+
887
+
888
+
889
+	/**
890
+	 * initialize_system_questions
891
+	 *
892
+	 * @access public
893
+	 * @static
894
+	 * @return void
895
+	 */
896
+	public static function initialize_system_questions()
897
+	{
898
+		// QUESTION GROUPS
899
+		global $wpdb;
900
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
901
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
902
+		// what we have
903
+		$question_groups = $wpdb->get_col($SQL);
904
+		// check the response
905
+		$question_groups = is_array($question_groups) ? $question_groups : array();
906
+		// what we should have
907
+		$QSG_systems = array(1, 2);
908
+		// loop thru what we should have and compare to what we have
909
+		foreach ($QSG_systems as $QSG_system) {
910
+			// reset values array
911
+			$QSG_values = array();
912
+			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
913
+			if (! in_array("$QSG_system", $question_groups)) {
914
+				// add it
915
+				switch ($QSG_system) {
916
+					case 1:
917
+						$QSG_values = array(
918
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
919
+							'QSG_identifier'      => 'personal-information-' . time(),
920
+							'QSG_desc'            => '',
921
+							'QSG_order'           => 1,
922
+							'QSG_show_group_name' => 1,
923
+							'QSG_show_group_desc' => 1,
924
+							'QSG_system'          => EEM_Question_Group::system_personal,
925
+							'QSG_deleted'         => 0,
926
+						);
927
+						break;
928
+					case 2:
929
+						$QSG_values = array(
930
+							'QSG_name'            => __('Address Information', 'event_espresso'),
931
+							'QSG_identifier'      => 'address-information-' . time(),
932
+							'QSG_desc'            => '',
933
+							'QSG_order'           => 2,
934
+							'QSG_show_group_name' => 1,
935
+							'QSG_show_group_desc' => 1,
936
+							'QSG_system'          => EEM_Question_Group::system_address,
937
+							'QSG_deleted'         => 0,
938
+						);
939
+						break;
940
+				}
941
+				// make sure we have some values before inserting them
942
+				if (! empty($QSG_values)) {
943
+					// insert system question
944
+					$wpdb->insert(
945
+						$table_name,
946
+						$QSG_values,
947
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
948
+					);
949
+					$QSG_IDs[$QSG_system] = $wpdb->insert_id;
950
+				}
951
+			}
952
+		}
953
+		// QUESTIONS
954
+		global $wpdb;
955
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
956
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
957
+		// what we have
958
+		$questions = $wpdb->get_col($SQL);
959
+		// what we should have
960
+		$QST_systems = array(
961
+			'fname',
962
+			'lname',
963
+			'email',
964
+			'address',
965
+			'address2',
966
+			'city',
967
+			'country',
968
+			'state',
969
+			'zip',
970
+			'phone',
971
+		);
972
+		$order_for_group_1 = 1;
973
+		$order_for_group_2 = 1;
974
+		// loop thru what we should have and compare to what we have
975
+		foreach ($QST_systems as $QST_system) {
976
+			// reset values array
977
+			$QST_values = array();
978
+			// if we don't have what we should have
979
+			if (! in_array($QST_system, $questions)) {
980
+				// add it
981
+				switch ($QST_system) {
982
+					case 'fname':
983
+						$QST_values = array(
984
+							'QST_display_text'  => __('First Name', 'event_espresso'),
985
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
986
+							'QST_system'        => 'fname',
987
+							'QST_type'          => 'TEXT',
988
+							'QST_required'      => 1,
989
+							'QST_required_text' => __('This field is required', 'event_espresso'),
990
+							'QST_order'         => 1,
991
+							'QST_admin_only'    => 0,
992
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
993
+							'QST_wp_user'       => self::get_default_creator_id(),
994
+							'QST_deleted'       => 0,
995
+						);
996
+						break;
997
+					case 'lname':
998
+						$QST_values = array(
999
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
1000
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
1001
+							'QST_system'        => 'lname',
1002
+							'QST_type'          => 'TEXT',
1003
+							'QST_required'      => 1,
1004
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1005
+							'QST_order'         => 2,
1006
+							'QST_admin_only'    => 0,
1007
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1008
+							'QST_wp_user'       => self::get_default_creator_id(),
1009
+							'QST_deleted'       => 0,
1010
+						);
1011
+						break;
1012
+					case 'email':
1013
+						$QST_values = array(
1014
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
1015
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
1016
+							'QST_system'        => 'email',
1017
+							'QST_type'          => 'EMAIL',
1018
+							'QST_required'      => 1,
1019
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1020
+							'QST_order'         => 3,
1021
+							'QST_admin_only'    => 0,
1022
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1023
+							'QST_wp_user'       => self::get_default_creator_id(),
1024
+							'QST_deleted'       => 0,
1025
+						);
1026
+						break;
1027
+					case 'address':
1028
+						$QST_values = array(
1029
+							'QST_display_text'  => __('Address', 'event_espresso'),
1030
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
1031
+							'QST_system'        => 'address',
1032
+							'QST_type'          => 'TEXT',
1033
+							'QST_required'      => 0,
1034
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1035
+							'QST_order'         => 4,
1036
+							'QST_admin_only'    => 0,
1037
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1038
+							'QST_wp_user'       => self::get_default_creator_id(),
1039
+							'QST_deleted'       => 0,
1040
+						);
1041
+						break;
1042
+					case 'address2':
1043
+						$QST_values = array(
1044
+							'QST_display_text'  => __('Address2', 'event_espresso'),
1045
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1046
+							'QST_system'        => 'address2',
1047
+							'QST_type'          => 'TEXT',
1048
+							'QST_required'      => 0,
1049
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1050
+							'QST_order'         => 5,
1051
+							'QST_admin_only'    => 0,
1052
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1053
+							'QST_wp_user'       => self::get_default_creator_id(),
1054
+							'QST_deleted'       => 0,
1055
+						);
1056
+						break;
1057
+					case 'city':
1058
+						$QST_values = array(
1059
+							'QST_display_text'  => __('City', 'event_espresso'),
1060
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1061
+							'QST_system'        => 'city',
1062
+							'QST_type'          => 'TEXT',
1063
+							'QST_required'      => 0,
1064
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1065
+							'QST_order'         => 6,
1066
+							'QST_admin_only'    => 0,
1067
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1068
+							'QST_wp_user'       => self::get_default_creator_id(),
1069
+							'QST_deleted'       => 0,
1070
+						);
1071
+						break;
1072
+					case 'country':
1073
+						$QST_values = array(
1074
+							'QST_display_text'  => __('Country', 'event_espresso'),
1075
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1076
+							'QST_system'        => 'country',
1077
+							'QST_type'          => 'COUNTRY',
1078
+							'QST_required'      => 0,
1079
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1080
+							'QST_order'         => 7,
1081
+							'QST_admin_only'    => 0,
1082
+							'QST_wp_user'       => self::get_default_creator_id(),
1083
+							'QST_deleted'       => 0,
1084
+						);
1085
+						break;
1086
+					case 'state':
1087
+						$QST_values = array(
1088
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1089
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1090
+							'QST_system'        => 'state',
1091
+							'QST_type'          => 'STATE',
1092
+							'QST_required'      => 0,
1093
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1094
+							'QST_order'         => 8,
1095
+							'QST_admin_only'    => 0,
1096
+							'QST_wp_user'       => self::get_default_creator_id(),
1097
+							'QST_deleted'       => 0,
1098
+						);
1099
+						break;
1100
+					case 'zip':
1101
+						$QST_values = array(
1102
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1103
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1104
+							'QST_system'        => 'zip',
1105
+							'QST_type'          => 'TEXT',
1106
+							'QST_required'      => 0,
1107
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1108
+							'QST_order'         => 9,
1109
+							'QST_admin_only'    => 0,
1110
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1111
+							'QST_wp_user'       => self::get_default_creator_id(),
1112
+							'QST_deleted'       => 0,
1113
+						);
1114
+						break;
1115
+					case 'phone':
1116
+						$QST_values = array(
1117
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1118
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1119
+							'QST_system'        => 'phone',
1120
+							'QST_type'          => 'TEXT',
1121
+							'QST_required'      => 0,
1122
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1123
+							'QST_order'         => 10,
1124
+							'QST_admin_only'    => 0,
1125
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1126
+							'QST_wp_user'       => self::get_default_creator_id(),
1127
+							'QST_deleted'       => 0,
1128
+						);
1129
+						break;
1130
+				}
1131
+				if (! empty($QST_values)) {
1132
+					// insert system question
1133
+					$wpdb->insert(
1134
+						$table_name,
1135
+						$QST_values,
1136
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1137
+					);
1138
+					$QST_ID = $wpdb->insert_id;
1139
+					// QUESTION GROUP QUESTIONS
1140
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1141
+						$system_question_we_want = EEM_Question_Group::system_personal;
1142
+					} else {
1143
+						$system_question_we_want = EEM_Question_Group::system_address;
1144
+					}
1145
+					if (isset($QSG_IDs[$system_question_we_want])) {
1146
+						$QSG_ID = $QSG_IDs[$system_question_we_want];
1147
+					} else {
1148
+						$id_col = EEM_Question_Group::instance()
1149
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1150
+						if (is_array($id_col)) {
1151
+							$QSG_ID = reset($id_col);
1152
+						} else {
1153
+							//ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1154
+							EE_Log::instance()->log(
1155
+								__FILE__,
1156
+								__FUNCTION__,
1157
+								sprintf(
1158
+									__(
1159
+										'Could not associate question %1$s to a question group because no system question
1160 1160
                                          group existed',
1161
-                                        'event_espresso'
1162
-                                    ),
1163
-                                    $QST_ID),
1164
-                                'error');
1165
-                            continue;
1166
-                        }
1167
-                    }
1168
-                    // add system questions to groups
1169
-                    $wpdb->insert(
1170
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1171
-                        array(
1172
-                            'QSG_ID'    => $QSG_ID,
1173
-                            'QST_ID'    => $QST_ID,
1174
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1175
-                        ),
1176
-                        array('%d', '%d', '%d')
1177
-                    );
1178
-                }
1179
-            }
1180
-        }
1181
-    }
1182
-
1183
-
1184
-    /**
1185
-     * Makes sure the default payment method (Invoice) is active.
1186
-     * This used to be done automatically as part of constructing the old gateways config
1187
-     *
1188
-     * @throws \EE_Error
1189
-     */
1190
-    public static function insert_default_payment_methods()
1191
-    {
1192
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1193
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1194
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1195
-        } else {
1196
-            EEM_Payment_Method::instance()->verify_button_urls();
1197
-        }
1198
-    }
1199
-
1200
-    /**
1201
-     * insert_default_status_codes
1202
-     *
1203
-     * @access public
1204
-     * @static
1205
-     * @return void
1206
-     */
1207
-    public static function insert_default_status_codes()
1208
-    {
1209
-
1210
-        global $wpdb;
1211
-
1212
-        if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1213
-
1214
-            $table_name = EEM_Status::instance()->table();
1215
-
1216
-            $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1217
-            $wpdb->query($SQL);
1218
-
1219
-            $SQL = "INSERT INTO $table_name
1161
+										'event_espresso'
1162
+									),
1163
+									$QST_ID),
1164
+								'error');
1165
+							continue;
1166
+						}
1167
+					}
1168
+					// add system questions to groups
1169
+					$wpdb->insert(
1170
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1171
+						array(
1172
+							'QSG_ID'    => $QSG_ID,
1173
+							'QST_ID'    => $QST_ID,
1174
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1175
+						),
1176
+						array('%d', '%d', '%d')
1177
+					);
1178
+				}
1179
+			}
1180
+		}
1181
+	}
1182
+
1183
+
1184
+	/**
1185
+	 * Makes sure the default payment method (Invoice) is active.
1186
+	 * This used to be done automatically as part of constructing the old gateways config
1187
+	 *
1188
+	 * @throws \EE_Error
1189
+	 */
1190
+	public static function insert_default_payment_methods()
1191
+	{
1192
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1193
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1194
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1195
+		} else {
1196
+			EEM_Payment_Method::instance()->verify_button_urls();
1197
+		}
1198
+	}
1199
+
1200
+	/**
1201
+	 * insert_default_status_codes
1202
+	 *
1203
+	 * @access public
1204
+	 * @static
1205
+	 * @return void
1206
+	 */
1207
+	public static function insert_default_status_codes()
1208
+	{
1209
+
1210
+		global $wpdb;
1211
+
1212
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1213
+
1214
+			$table_name = EEM_Status::instance()->table();
1215
+
1216
+			$SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1217
+			$wpdb->query($SQL);
1218
+
1219
+			$SQL = "INSERT INTO $table_name
1220 1220
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1221 1221
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1222 1222
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1256,521 +1256,521 @@  discard block
 block discarded – undo
1256 1256
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1257 1257
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1258 1258
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1259
-            $wpdb->query($SQL);
1260
-
1261
-        }
1262
-
1263
-    }
1264
-
1265
-
1266
-    /**
1267
-     * create_upload_directories
1268
-     * Creates folders in the uploads directory to facilitate addons and templates
1269
-     *
1270
-     * @access public
1271
-     * @static
1272
-     * @return boolean success of verifying upload directories exist
1273
-     */
1274
-    public static function create_upload_directories()
1275
-    {
1276
-        // Create the required folders
1277
-        $folders = array(
1278
-            EVENT_ESPRESSO_TEMPLATE_DIR,
1279
-            EVENT_ESPRESSO_GATEWAY_DIR,
1280
-            EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1281
-            EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1282
-            EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1283
-        );
1284
-        foreach ($folders as $folder) {
1285
-            try {
1286
-                EEH_File::ensure_folder_exists_and_is_writable($folder);
1287
-                @ chmod($folder, 0755);
1288
-            } catch (EE_Error $e) {
1289
-                EE_Error::add_error(
1290
-                    sprintf(
1291
-                        __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1292
-                        $folder,
1293
-                        '<br />' . $e->getMessage()
1294
-                    ),
1295
-                    __FILE__, __FUNCTION__, __LINE__
1296
-                );
1297
-                //indicate we'll need to fix this later
1298
-                update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1299
-                return false;
1300
-            }
1301
-        }
1302
-        //just add the .htaccess file to the logs directory to begin with. Even if logging
1303
-        //is disabled, there might be activation errors recorded in there
1304
-        EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1305
-        //remember EE's folders are all good
1306
-        delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1307
-        return true;
1308
-    }
1309
-
1310
-    /**
1311
-     * Whether the upload directories need to be fixed or not.
1312
-     * If EE is installed but filesystem access isn't initially available,
1313
-     * we need to get the user's filesystem credentials and THEN create them,
1314
-     * so there might be period of time when EE is installed but its
1315
-     * upload directories aren't available. This indicates such a state
1316
-     *
1317
-     * @return boolean
1318
-     */
1319
-    public static function upload_directories_incomplete()
1320
-    {
1321
-        return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1322
-    }
1323
-
1324
-
1325
-    /**
1326
-     * generate_default_message_templates
1327
-     *
1328
-     * @static
1329
-     * @throws EE_Error
1330
-     * @return bool     true means new templates were created.
1331
-     *                  false means no templates were created.
1332
-     *                  This is NOT an error flag. To check for errors you will want
1333
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1334
-     */
1335
-    public static function generate_default_message_templates()
1336
-    {
1337
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1338
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1339
-        /*
1259
+			$wpdb->query($SQL);
1260
+
1261
+		}
1262
+
1263
+	}
1264
+
1265
+
1266
+	/**
1267
+	 * create_upload_directories
1268
+	 * Creates folders in the uploads directory to facilitate addons and templates
1269
+	 *
1270
+	 * @access public
1271
+	 * @static
1272
+	 * @return boolean success of verifying upload directories exist
1273
+	 */
1274
+	public static function create_upload_directories()
1275
+	{
1276
+		// Create the required folders
1277
+		$folders = array(
1278
+			EVENT_ESPRESSO_TEMPLATE_DIR,
1279
+			EVENT_ESPRESSO_GATEWAY_DIR,
1280
+			EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1281
+			EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1282
+			EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1283
+		);
1284
+		foreach ($folders as $folder) {
1285
+			try {
1286
+				EEH_File::ensure_folder_exists_and_is_writable($folder);
1287
+				@ chmod($folder, 0755);
1288
+			} catch (EE_Error $e) {
1289
+				EE_Error::add_error(
1290
+					sprintf(
1291
+						__('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1292
+						$folder,
1293
+						'<br />' . $e->getMessage()
1294
+					),
1295
+					__FILE__, __FUNCTION__, __LINE__
1296
+				);
1297
+				//indicate we'll need to fix this later
1298
+				update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1299
+				return false;
1300
+			}
1301
+		}
1302
+		//just add the .htaccess file to the logs directory to begin with. Even if logging
1303
+		//is disabled, there might be activation errors recorded in there
1304
+		EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1305
+		//remember EE's folders are all good
1306
+		delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1307
+		return true;
1308
+	}
1309
+
1310
+	/**
1311
+	 * Whether the upload directories need to be fixed or not.
1312
+	 * If EE is installed but filesystem access isn't initially available,
1313
+	 * we need to get the user's filesystem credentials and THEN create them,
1314
+	 * so there might be period of time when EE is installed but its
1315
+	 * upload directories aren't available. This indicates such a state
1316
+	 *
1317
+	 * @return boolean
1318
+	 */
1319
+	public static function upload_directories_incomplete()
1320
+	{
1321
+		return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1322
+	}
1323
+
1324
+
1325
+	/**
1326
+	 * generate_default_message_templates
1327
+	 *
1328
+	 * @static
1329
+	 * @throws EE_Error
1330
+	 * @return bool     true means new templates were created.
1331
+	 *                  false means no templates were created.
1332
+	 *                  This is NOT an error flag. To check for errors you will want
1333
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1334
+	 */
1335
+	public static function generate_default_message_templates()
1336
+	{
1337
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1338
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1339
+		/*
1340 1340
          * This first method is taking care of ensuring any default messengers
1341 1341
          * that should be made active and have templates generated are done.
1342 1342
          */
1343
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1344
-            $message_resource_manager
1345
-        );
1346
-        /**
1347
-         * This method is verifying there are no NEW default message types
1348
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1349
-         */
1350
-        $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1351
-            $message_resource_manager
1352
-        );
1353
-        //after all is done, let's persist these changes to the db.
1354
-        $message_resource_manager->update_has_activated_messengers_option();
1355
-        $message_resource_manager->update_active_messengers_option();
1356
-        // will return true if either of these are true.  Otherwise will return false.
1357
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1358
-    }
1359
-
1360
-
1361
-
1362
-    /**
1363
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1364
-     * @return array|bool
1365
-     * @throws \EE_Error
1366
-     */
1367
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1368
-        EE_Message_Resource_Manager $message_resource_manager
1369
-    ) {
1370
-        /** @type EE_messenger[] $active_messengers */
1371
-        $active_messengers = $message_resource_manager->active_messengers();
1372
-        $installed_message_types = $message_resource_manager->installed_message_types();
1373
-        $templates_created = false;
1374
-        foreach ($active_messengers as $active_messenger) {
1375
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1376
-            $default_message_type_names_to_activate = array();
1377
-            // looping through each default message type reported by the messenger
1378
-            // and setup the actual message types to activate.
1379
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1380
-                // if already active or has already been activated before we skip
1381
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1382
-                // we also skip if the message type is not installed.
1383
-                if (
1384
-                    $message_resource_manager->has_message_type_been_activated_for_messenger(
1385
-                        $default_message_type_name_for_messenger,
1386
-                        $active_messenger->name
1387
-                    )
1388
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1389
-                        $active_messenger->name,
1390
-                        $default_message_type_name_for_messenger
1391
-                    )
1392
-                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1393
-                ) {
1394
-                    continue;
1395
-                }
1396
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1397
-            }
1398
-            //let's activate!
1399
-            $message_resource_manager->ensure_message_types_are_active(
1400
-                $default_message_type_names_to_activate,
1401
-                $active_messenger->name,
1402
-                false
1403
-            );
1404
-            //activate the templates for these message types
1405
-            if ( ! empty($default_message_type_names_to_activate)) {
1406
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1407
-                    $active_messenger->name,
1408
-                    $default_message_type_names_for_messenger,
1409
-                    '',
1410
-                    true
1411
-                );
1412
-            }
1413
-        }
1414
-        return $templates_created;
1415
-    }
1416
-
1417
-
1418
-
1419
-    /**
1420
-     * This will activate and generate default messengers and default message types for those messengers.
1421
-     *
1422
-     * @param EE_message_Resource_Manager $message_resource_manager
1423
-     * @return array|bool  True means there were default messengers and message type templates generated.
1424
-     *                     False means that there were no templates generated
1425
-     *                     (which could simply mean there are no default message types for a messenger).
1426
-     * @throws EE_Error
1427
-     */
1428
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1429
-        EE_Message_Resource_Manager $message_resource_manager
1430
-    ) {
1431
-        /** @type EE_messenger[] $messengers_to_generate */
1432
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1433
-        $installed_message_types = $message_resource_manager->installed_message_types();
1434
-        $templates_generated = false;
1435
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1436
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1437
-            //verify the default message types match an installed message type.
1438
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1439
-                if (
1440
-                    ! isset($installed_message_types[$name])
1441
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1442
-                        $name,
1443
-                        $messenger_to_generate->name
1444
-                    )
1445
-                ) {
1446
-                    unset($default_message_type_names_for_messenger[$key]);
1447
-                }
1448
-            }
1449
-            // in previous iterations, the active_messengers option in the db
1450
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1451
-            // This comment is left here just in case we discover that we _do_ need to update before
1452
-            // passing off to create templates (after the refactor is done).
1453
-            // @todo remove this comment when determined not necessary.
1454
-            $message_resource_manager->activate_messenger(
1455
-                $messenger_to_generate->name,
1456
-                $default_message_type_names_for_messenger,
1457
-                false
1458
-            );
1459
-            //create any templates needing created (or will reactivate templates already generated as necessary).
1460
-            if ( ! empty($default_message_type_names_for_messenger)) {
1461
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1462
-                    $messenger_to_generate->name,
1463
-                    $default_message_type_names_for_messenger,
1464
-                    '',
1465
-                    true
1466
-                );
1467
-            }
1468
-        }
1469
-        return $templates_generated;
1470
-    }
1471
-
1472
-
1473
-    /**
1474
-     * This returns the default messengers to generate templates for on activation of EE.
1475
-     * It considers:
1476
-     * - whether a messenger is already active in the db.
1477
-     * - whether a messenger has been made active at any time in the past.
1478
-     *
1479
-     * @static
1480
-     * @param  EE_Message_Resource_Manager $message_resource_manager
1481
-     * @return EE_messenger[]
1482
-     */
1483
-    protected static function _get_default_messengers_to_generate_on_activation(
1484
-        EE_Message_Resource_Manager $message_resource_manager
1485
-    ) {
1486
-        $active_messengers    = $message_resource_manager->active_messengers();
1487
-        $installed_messengers = $message_resource_manager->installed_messengers();
1488
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1489
-
1490
-        $messengers_to_generate = array();
1491
-        foreach ($installed_messengers as $installed_messenger) {
1492
-            //if installed messenger is a messenger that should be activated on install
1493
-            //and is not already active
1494
-            //and has never been activated
1495
-            if (
1496
-                ! $installed_messenger->activate_on_install
1497
-                || isset($active_messengers[$installed_messenger->name])
1498
-                || isset($has_activated[$installed_messenger->name])
1499
-            ) {
1500
-                continue;
1501
-            }
1502
-            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1503
-        }
1504
-        return $messengers_to_generate;
1505
-    }
1506
-
1507
-
1508
-    /**
1509
-     * This simply validates active message types to ensure they actually match installed
1510
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1511
-     * rows are set inactive.
1512
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1513
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1514
-     * are still handled in here.
1515
-     *
1516
-     * @since 4.3.1
1517
-     * @return void
1518
-     */
1519
-    public static function validate_messages_system()
1520
-    {
1521
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1522
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1523
-        $message_resource_manager->validate_active_message_types_are_installed();
1524
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1525
-    }
1526
-
1527
-
1528
-    /**
1529
-     * create_no_ticket_prices_array
1530
-     *
1531
-     * @access public
1532
-     * @static
1533
-     * @return void
1534
-     */
1535
-    public static function create_no_ticket_prices_array()
1536
-    {
1537
-        // this creates an array for tracking events that have no active ticket prices created
1538
-        // this allows us to warn admins of the situation so that it can be corrected
1539
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1540
-        if (! $espresso_no_ticket_prices) {
1541
-            add_option('ee_no_ticket_prices', array(), '', false);
1542
-        }
1543
-    }
1544
-
1545
-
1546
-    /**
1547
-     * plugin_deactivation
1548
-     *
1549
-     * @access public
1550
-     * @static
1551
-     * @return void
1552
-     */
1553
-    public static function plugin_deactivation()
1554
-    {
1555
-    }
1556
-
1557
-
1558
-    /**
1559
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1560
-     * (like post meta or term relations)
1561
-     *
1562
-     * @global wpdb $wpdb
1563
-     * @throws \EE_Error
1564
-     */
1565
-    public static function delete_all_espresso_cpt_data()
1566
-    {
1567
-        global $wpdb;
1568
-        //get all the CPT post_types
1569
-        $ee_post_types = array();
1570
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1571
-            if (method_exists($model_name, 'instance')) {
1572
-                $model_obj = call_user_func(array($model_name, 'instance'));
1573
-                if ($model_obj instanceof EEM_CPT_Base) {
1574
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1575
-                }
1576
-            }
1577
-        }
1578
-        //get all our CPTs
1579
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1580
-        $cpt_ids = $wpdb->get_col($query);
1581
-        //delete each post meta and term relations too
1582
-        foreach ($cpt_ids as $post_id) {
1583
-            wp_delete_post($post_id, true);
1584
-        }
1585
-    }
1586
-
1587
-    /**
1588
-     * Deletes all EE custom tables
1589
-     *
1590
-     * @return array
1591
-     */
1592
-    public static function drop_espresso_tables()
1593
-    {
1594
-        $tables = array();
1595
-        // load registry
1596
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1597
-            if (method_exists($model_name, 'instance')) {
1598
-                $model_obj = call_user_func(array($model_name, 'instance'));
1599
-                if ($model_obj instanceof EEM_Base) {
1600
-                    foreach ($model_obj->get_tables() as $table) {
1601
-                        if (strpos($table->get_table_name(), 'esp_')
1602
-                            &&
1603
-                            (
1604
-                                is_main_site()//main site? nuke them all
1605
-                                || ! $table->is_global()//not main site,but not global either. nuke it
1606
-                            )
1607
-                        ) {
1608
-                            $tables[] = $table->get_table_name();
1609
-                        }
1610
-                    }
1611
-                }
1612
-            }
1613
-        }
1614
-
1615
-        //there are some tables whose models were removed.
1616
-        //they should be removed when removing all EE core's data
1617
-        $tables_without_models = array(
1618
-            'esp_promotion',
1619
-            'esp_promotion_applied',
1620
-            'esp_promotion_object',
1621
-            'esp_promotion_rule',
1622
-            'esp_rule',
1623
-        );
1624
-        foreach ($tables_without_models as $table) {
1625
-            $tables[] = $table;
1626
-        }
1627
-        return \EEH_Activation::getTableManager()->dropTables($tables);
1628
-    }
1629
-
1630
-
1631
-
1632
-    /**
1633
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1634
-     * each table name provided has a wpdb prefix attached, and that it exists.
1635
-     * Returns the list actually deleted
1636
-     *
1637
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1638
-     * @global WPDB $wpdb
1639
-     * @param array $table_names
1640
-     * @return array of table names which we deleted
1641
-     */
1642
-    public static function drop_tables($table_names)
1643
-    {
1644
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1645
-    }
1646
-
1647
-
1648
-
1649
-    /**
1650
-     * plugin_uninstall
1651
-     *
1652
-     * @access public
1653
-     * @static
1654
-     * @param bool $remove_all
1655
-     * @return void
1656
-     */
1657
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1658
-    {
1659
-        global $wpdb;
1660
-        self::drop_espresso_tables();
1661
-        $wp_options_to_delete = array(
1662
-            'ee_no_ticket_prices'                => true,
1663
-            'ee_active_messengers'               => true,
1664
-            'ee_has_activated_messenger'         => true,
1665
-            'ee_flush_rewrite_rules'             => true,
1666
-            'ee_config'                          => false,
1667
-            'ee_data_migration_current_db_state' => true,
1668
-            'ee_data_migration_mapping_'         => false,
1669
-            'ee_data_migration_script_'          => false,
1670
-            'ee_data_migrations'                 => true,
1671
-            'ee_dms_map'                         => false,
1672
-            'ee_notices'                         => true,
1673
-            'lang_file_check_'                   => false,
1674
-            'ee_maintenance_mode'                => true,
1675
-            'ee_ueip_optin'                      => true,
1676
-            'ee_ueip_has_notified'               => true,
1677
-            'ee_plugin_activation_errors'        => true,
1678
-            'ee_id_mapping_from'                 => false,
1679
-            'espresso_persistent_admin_notices'  => true,
1680
-            'ee_encryption_key'                  => true,
1681
-            'pue_force_upgrade_'                 => false,
1682
-            'pue_json_error_'                    => false,
1683
-            'pue_install_key_'                   => false,
1684
-            'pue_verification_error_'            => false,
1685
-            'pu_dismissed_upgrade_'              => false,
1686
-            'external_updates-'                  => false,
1687
-            'ee_extra_data'                      => true,
1688
-            'ee_ssn_'                            => false,
1689
-            'ee_rss_'                            => false,
1690
-            'ee_rte_n_tx_'                       => false,
1691
-            'ee_pers_admin_notices'              => true,
1692
-            'ee_job_parameters_'                 => false,
1693
-            'ee_upload_directories_incomplete'   => true,
1694
-            'ee_verified_db_collations'          => true,
1695
-        );
1696
-        if (is_main_site()) {
1697
-            $wp_options_to_delete['ee_network_config'] = true;
1698
-        }
1699
-        $undeleted_options = array();
1700
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1701
-            if ($no_wildcard) {
1702
-                if ( ! delete_option($option_name)) {
1703
-                    $undeleted_options[] = $option_name;
1704
-                }
1705
-            } else {
1706
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1707
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1708
-                    if ( ! delete_option($option_name_from_wildcard)) {
1709
-                        $undeleted_options[] = $option_name_from_wildcard;
1710
-                    }
1711
-                }
1712
-            }
1713
-        }
1714
-        //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1715
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1716
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1717
-            $db_update_sans_ee4 = array();
1718
-            foreach ($espresso_db_update as $version => $times_activated) {
1719
-                if ((string)$version[0] === '3') {//if its NON EE4
1720
-                    $db_update_sans_ee4[$version] = $times_activated;
1721
-                }
1722
-            }
1723
-            update_option('espresso_db_update', $db_update_sans_ee4);
1724
-        }
1725
-        $errors = '';
1726
-        if ( ! empty($undeleted_options)) {
1727
-            $errors .= sprintf(
1728
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1729
-                '<br/>',
1730
-                implode(',<br/>', $undeleted_options)
1731
-            );
1732
-        }
1733
-        if ( ! empty($errors)) {
1734
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1735
-        }
1736
-    }
1737
-
1738
-    /**
1739
-     * Gets the mysql error code from the last used query by wpdb
1740
-     *
1741
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1742
-     */
1743
-    public static function last_wpdb_error_code()
1744
-    {
1745
-        global $wpdb;
1746
-        if ($wpdb->use_mysqli) {
1747
-            return mysqli_errno($wpdb->dbh);
1748
-        } else {
1749
-            return mysql_errno($wpdb->dbh);
1750
-        }
1751
-    }
1752
-
1753
-    /**
1754
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1755
-     *
1756
-     * @global wpdb  $wpdb
1757
-     * @deprecated instead use TableAnalysis::tableExists()
1758
-     * @param string $table_name with or without $wpdb->prefix
1759
-     * @return boolean
1760
-     */
1761
-    public static function table_exists($table_name)
1762
-    {
1763
-        return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1764
-    }
1765
-
1766
-    /**
1767
-     * Resets the cache on EEH_Activation
1768
-     */
1769
-    public static function reset()
1770
-    {
1771
-        self::$_default_creator_id                             = null;
1772
-        self::$_initialized_db_content_already_in_this_request = false;
1773
-    }
1343
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1344
+			$message_resource_manager
1345
+		);
1346
+		/**
1347
+		 * This method is verifying there are no NEW default message types
1348
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1349
+		 */
1350
+		$new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1351
+			$message_resource_manager
1352
+		);
1353
+		//after all is done, let's persist these changes to the db.
1354
+		$message_resource_manager->update_has_activated_messengers_option();
1355
+		$message_resource_manager->update_active_messengers_option();
1356
+		// will return true if either of these are true.  Otherwise will return false.
1357
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1358
+	}
1359
+
1360
+
1361
+
1362
+	/**
1363
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1364
+	 * @return array|bool
1365
+	 * @throws \EE_Error
1366
+	 */
1367
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1368
+		EE_Message_Resource_Manager $message_resource_manager
1369
+	) {
1370
+		/** @type EE_messenger[] $active_messengers */
1371
+		$active_messengers = $message_resource_manager->active_messengers();
1372
+		$installed_message_types = $message_resource_manager->installed_message_types();
1373
+		$templates_created = false;
1374
+		foreach ($active_messengers as $active_messenger) {
1375
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1376
+			$default_message_type_names_to_activate = array();
1377
+			// looping through each default message type reported by the messenger
1378
+			// and setup the actual message types to activate.
1379
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1380
+				// if already active or has already been activated before we skip
1381
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1382
+				// we also skip if the message type is not installed.
1383
+				if (
1384
+					$message_resource_manager->has_message_type_been_activated_for_messenger(
1385
+						$default_message_type_name_for_messenger,
1386
+						$active_messenger->name
1387
+					)
1388
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1389
+						$active_messenger->name,
1390
+						$default_message_type_name_for_messenger
1391
+					)
1392
+					|| ! isset($installed_message_types[$default_message_type_name_for_messenger])
1393
+				) {
1394
+					continue;
1395
+				}
1396
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1397
+			}
1398
+			//let's activate!
1399
+			$message_resource_manager->ensure_message_types_are_active(
1400
+				$default_message_type_names_to_activate,
1401
+				$active_messenger->name,
1402
+				false
1403
+			);
1404
+			//activate the templates for these message types
1405
+			if ( ! empty($default_message_type_names_to_activate)) {
1406
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1407
+					$active_messenger->name,
1408
+					$default_message_type_names_for_messenger,
1409
+					'',
1410
+					true
1411
+				);
1412
+			}
1413
+		}
1414
+		return $templates_created;
1415
+	}
1416
+
1417
+
1418
+
1419
+	/**
1420
+	 * This will activate and generate default messengers and default message types for those messengers.
1421
+	 *
1422
+	 * @param EE_message_Resource_Manager $message_resource_manager
1423
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1424
+	 *                     False means that there were no templates generated
1425
+	 *                     (which could simply mean there are no default message types for a messenger).
1426
+	 * @throws EE_Error
1427
+	 */
1428
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1429
+		EE_Message_Resource_Manager $message_resource_manager
1430
+	) {
1431
+		/** @type EE_messenger[] $messengers_to_generate */
1432
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1433
+		$installed_message_types = $message_resource_manager->installed_message_types();
1434
+		$templates_generated = false;
1435
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1436
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1437
+			//verify the default message types match an installed message type.
1438
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1439
+				if (
1440
+					! isset($installed_message_types[$name])
1441
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1442
+						$name,
1443
+						$messenger_to_generate->name
1444
+					)
1445
+				) {
1446
+					unset($default_message_type_names_for_messenger[$key]);
1447
+				}
1448
+			}
1449
+			// in previous iterations, the active_messengers option in the db
1450
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1451
+			// This comment is left here just in case we discover that we _do_ need to update before
1452
+			// passing off to create templates (after the refactor is done).
1453
+			// @todo remove this comment when determined not necessary.
1454
+			$message_resource_manager->activate_messenger(
1455
+				$messenger_to_generate->name,
1456
+				$default_message_type_names_for_messenger,
1457
+				false
1458
+			);
1459
+			//create any templates needing created (or will reactivate templates already generated as necessary).
1460
+			if ( ! empty($default_message_type_names_for_messenger)) {
1461
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1462
+					$messenger_to_generate->name,
1463
+					$default_message_type_names_for_messenger,
1464
+					'',
1465
+					true
1466
+				);
1467
+			}
1468
+		}
1469
+		return $templates_generated;
1470
+	}
1471
+
1472
+
1473
+	/**
1474
+	 * This returns the default messengers to generate templates for on activation of EE.
1475
+	 * It considers:
1476
+	 * - whether a messenger is already active in the db.
1477
+	 * - whether a messenger has been made active at any time in the past.
1478
+	 *
1479
+	 * @static
1480
+	 * @param  EE_Message_Resource_Manager $message_resource_manager
1481
+	 * @return EE_messenger[]
1482
+	 */
1483
+	protected static function _get_default_messengers_to_generate_on_activation(
1484
+		EE_Message_Resource_Manager $message_resource_manager
1485
+	) {
1486
+		$active_messengers    = $message_resource_manager->active_messengers();
1487
+		$installed_messengers = $message_resource_manager->installed_messengers();
1488
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1489
+
1490
+		$messengers_to_generate = array();
1491
+		foreach ($installed_messengers as $installed_messenger) {
1492
+			//if installed messenger is a messenger that should be activated on install
1493
+			//and is not already active
1494
+			//and has never been activated
1495
+			if (
1496
+				! $installed_messenger->activate_on_install
1497
+				|| isset($active_messengers[$installed_messenger->name])
1498
+				|| isset($has_activated[$installed_messenger->name])
1499
+			) {
1500
+				continue;
1501
+			}
1502
+			$messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1503
+		}
1504
+		return $messengers_to_generate;
1505
+	}
1506
+
1507
+
1508
+	/**
1509
+	 * This simply validates active message types to ensure they actually match installed
1510
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1511
+	 * rows are set inactive.
1512
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1513
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1514
+	 * are still handled in here.
1515
+	 *
1516
+	 * @since 4.3.1
1517
+	 * @return void
1518
+	 */
1519
+	public static function validate_messages_system()
1520
+	{
1521
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1522
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1523
+		$message_resource_manager->validate_active_message_types_are_installed();
1524
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1525
+	}
1526
+
1527
+
1528
+	/**
1529
+	 * create_no_ticket_prices_array
1530
+	 *
1531
+	 * @access public
1532
+	 * @static
1533
+	 * @return void
1534
+	 */
1535
+	public static function create_no_ticket_prices_array()
1536
+	{
1537
+		// this creates an array for tracking events that have no active ticket prices created
1538
+		// this allows us to warn admins of the situation so that it can be corrected
1539
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1540
+		if (! $espresso_no_ticket_prices) {
1541
+			add_option('ee_no_ticket_prices', array(), '', false);
1542
+		}
1543
+	}
1544
+
1545
+
1546
+	/**
1547
+	 * plugin_deactivation
1548
+	 *
1549
+	 * @access public
1550
+	 * @static
1551
+	 * @return void
1552
+	 */
1553
+	public static function plugin_deactivation()
1554
+	{
1555
+	}
1556
+
1557
+
1558
+	/**
1559
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1560
+	 * (like post meta or term relations)
1561
+	 *
1562
+	 * @global wpdb $wpdb
1563
+	 * @throws \EE_Error
1564
+	 */
1565
+	public static function delete_all_espresso_cpt_data()
1566
+	{
1567
+		global $wpdb;
1568
+		//get all the CPT post_types
1569
+		$ee_post_types = array();
1570
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1571
+			if (method_exists($model_name, 'instance')) {
1572
+				$model_obj = call_user_func(array($model_name, 'instance'));
1573
+				if ($model_obj instanceof EEM_CPT_Base) {
1574
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1575
+				}
1576
+			}
1577
+		}
1578
+		//get all our CPTs
1579
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1580
+		$cpt_ids = $wpdb->get_col($query);
1581
+		//delete each post meta and term relations too
1582
+		foreach ($cpt_ids as $post_id) {
1583
+			wp_delete_post($post_id, true);
1584
+		}
1585
+	}
1586
+
1587
+	/**
1588
+	 * Deletes all EE custom tables
1589
+	 *
1590
+	 * @return array
1591
+	 */
1592
+	public static function drop_espresso_tables()
1593
+	{
1594
+		$tables = array();
1595
+		// load registry
1596
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1597
+			if (method_exists($model_name, 'instance')) {
1598
+				$model_obj = call_user_func(array($model_name, 'instance'));
1599
+				if ($model_obj instanceof EEM_Base) {
1600
+					foreach ($model_obj->get_tables() as $table) {
1601
+						if (strpos($table->get_table_name(), 'esp_')
1602
+							&&
1603
+							(
1604
+								is_main_site()//main site? nuke them all
1605
+								|| ! $table->is_global()//not main site,but not global either. nuke it
1606
+							)
1607
+						) {
1608
+							$tables[] = $table->get_table_name();
1609
+						}
1610
+					}
1611
+				}
1612
+			}
1613
+		}
1614
+
1615
+		//there are some tables whose models were removed.
1616
+		//they should be removed when removing all EE core's data
1617
+		$tables_without_models = array(
1618
+			'esp_promotion',
1619
+			'esp_promotion_applied',
1620
+			'esp_promotion_object',
1621
+			'esp_promotion_rule',
1622
+			'esp_rule',
1623
+		);
1624
+		foreach ($tables_without_models as $table) {
1625
+			$tables[] = $table;
1626
+		}
1627
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1628
+	}
1629
+
1630
+
1631
+
1632
+	/**
1633
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1634
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1635
+	 * Returns the list actually deleted
1636
+	 *
1637
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1638
+	 * @global WPDB $wpdb
1639
+	 * @param array $table_names
1640
+	 * @return array of table names which we deleted
1641
+	 */
1642
+	public static function drop_tables($table_names)
1643
+	{
1644
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1645
+	}
1646
+
1647
+
1648
+
1649
+	/**
1650
+	 * plugin_uninstall
1651
+	 *
1652
+	 * @access public
1653
+	 * @static
1654
+	 * @param bool $remove_all
1655
+	 * @return void
1656
+	 */
1657
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1658
+	{
1659
+		global $wpdb;
1660
+		self::drop_espresso_tables();
1661
+		$wp_options_to_delete = array(
1662
+			'ee_no_ticket_prices'                => true,
1663
+			'ee_active_messengers'               => true,
1664
+			'ee_has_activated_messenger'         => true,
1665
+			'ee_flush_rewrite_rules'             => true,
1666
+			'ee_config'                          => false,
1667
+			'ee_data_migration_current_db_state' => true,
1668
+			'ee_data_migration_mapping_'         => false,
1669
+			'ee_data_migration_script_'          => false,
1670
+			'ee_data_migrations'                 => true,
1671
+			'ee_dms_map'                         => false,
1672
+			'ee_notices'                         => true,
1673
+			'lang_file_check_'                   => false,
1674
+			'ee_maintenance_mode'                => true,
1675
+			'ee_ueip_optin'                      => true,
1676
+			'ee_ueip_has_notified'               => true,
1677
+			'ee_plugin_activation_errors'        => true,
1678
+			'ee_id_mapping_from'                 => false,
1679
+			'espresso_persistent_admin_notices'  => true,
1680
+			'ee_encryption_key'                  => true,
1681
+			'pue_force_upgrade_'                 => false,
1682
+			'pue_json_error_'                    => false,
1683
+			'pue_install_key_'                   => false,
1684
+			'pue_verification_error_'            => false,
1685
+			'pu_dismissed_upgrade_'              => false,
1686
+			'external_updates-'                  => false,
1687
+			'ee_extra_data'                      => true,
1688
+			'ee_ssn_'                            => false,
1689
+			'ee_rss_'                            => false,
1690
+			'ee_rte_n_tx_'                       => false,
1691
+			'ee_pers_admin_notices'              => true,
1692
+			'ee_job_parameters_'                 => false,
1693
+			'ee_upload_directories_incomplete'   => true,
1694
+			'ee_verified_db_collations'          => true,
1695
+		);
1696
+		if (is_main_site()) {
1697
+			$wp_options_to_delete['ee_network_config'] = true;
1698
+		}
1699
+		$undeleted_options = array();
1700
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1701
+			if ($no_wildcard) {
1702
+				if ( ! delete_option($option_name)) {
1703
+					$undeleted_options[] = $option_name;
1704
+				}
1705
+			} else {
1706
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1707
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1708
+					if ( ! delete_option($option_name_from_wildcard)) {
1709
+						$undeleted_options[] = $option_name_from_wildcard;
1710
+					}
1711
+				}
1712
+			}
1713
+		}
1714
+		//also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1715
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1716
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1717
+			$db_update_sans_ee4 = array();
1718
+			foreach ($espresso_db_update as $version => $times_activated) {
1719
+				if ((string)$version[0] === '3') {//if its NON EE4
1720
+					$db_update_sans_ee4[$version] = $times_activated;
1721
+				}
1722
+			}
1723
+			update_option('espresso_db_update', $db_update_sans_ee4);
1724
+		}
1725
+		$errors = '';
1726
+		if ( ! empty($undeleted_options)) {
1727
+			$errors .= sprintf(
1728
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1729
+				'<br/>',
1730
+				implode(',<br/>', $undeleted_options)
1731
+			);
1732
+		}
1733
+		if ( ! empty($errors)) {
1734
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1735
+		}
1736
+	}
1737
+
1738
+	/**
1739
+	 * Gets the mysql error code from the last used query by wpdb
1740
+	 *
1741
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1742
+	 */
1743
+	public static function last_wpdb_error_code()
1744
+	{
1745
+		global $wpdb;
1746
+		if ($wpdb->use_mysqli) {
1747
+			return mysqli_errno($wpdb->dbh);
1748
+		} else {
1749
+			return mysql_errno($wpdb->dbh);
1750
+		}
1751
+	}
1752
+
1753
+	/**
1754
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1755
+	 *
1756
+	 * @global wpdb  $wpdb
1757
+	 * @deprecated instead use TableAnalysis::tableExists()
1758
+	 * @param string $table_name with or without $wpdb->prefix
1759
+	 * @return boolean
1760
+	 */
1761
+	public static function table_exists($table_name)
1762
+	{
1763
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1764
+	}
1765
+
1766
+	/**
1767
+	 * Resets the cache on EEH_Activation
1768
+	 */
1769
+	public static function reset()
1770
+	{
1771
+		self::$_default_creator_id                             = null;
1772
+		self::$_initialized_db_content_already_in_this_request = false;
1773
+	}
1774 1774
 }
1775 1775
 // End of file EEH_Activation.helper.php
1776 1776
 // Location: /helpers/EEH_Activation.core.php
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
      */
65 65
     public static function getTableAnalysis()
66 66
     {
67
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
67
+        if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
68 68
             self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
69 69
         }
70 70
         return self::$table_analysis;
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      */
77 77
     public static function getTableManager()
78 78
     {
79
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
79
+        if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
80 80
             self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
81 81
         }
82 82
         return self::$table_manager;
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
         if ($which_to_include === 'old') {
193 193
             $cron_tasks = array_filter(
194 194
                 $cron_tasks,
195
-                function ($value) {
195
+                function($value) {
196 196
                     return $value === EEH_Activation::cron_task_no_longer_in_use;
197 197
                 }
198 198
             );
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
     {
223 223
 
224 224
         foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
225
-            if (! wp_next_scheduled($hook_name)) {
225
+            if ( ! wp_next_scheduled($hook_name)) {
226 226
                 wp_schedule_event(time(), $frequency, $hook_name);
227 227
             }
228 228
         }
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
             3
316 316
         );
317 317
         //EE_Config::reset();
318
-        if (! EE_Config::logging_enabled()) {
318
+        if ( ! EE_Config::logging_enabled()) {
319 319
             delete_option(EE_Config::LOG_NAME);
320 320
         }
321 321
     }
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
     public static function load_calendar_config()
331 331
     {
332 332
         // grab array of all plugin folders and loop thru it
333
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
333
+        $plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR);
334 334
         if (empty($plugins)) {
335 335
             return;
336 336
         }
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
                 || strpos($plugin, 'calendar') !== false
348 348
             ) {
349 349
                 // this is what we are looking for
350
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
350
+                $calendar_config = $plugin_path.DS.'EE_Calendar_Config.php';
351 351
                 // does it exist in this folder ?
352 352
                 if (is_readable($calendar_config)) {
353 353
                     // YEAH! let's load it
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
             ) {
480 480
                 //update Config with post ID
481 481
                 $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
482
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
482
+                if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
483 483
                     $msg = __(
484 484
                         'The Event Espresso critical page configuration settings could not be updated.',
485 485
                         'event_espresso'
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
                         'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
503 503
                         'event_espresso'
504 504
                     ),
505
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
505
+                    '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">'
506 506
                     . __('Event Espresso Critical Pages Settings', 'event_espresso')
507 507
                     . '</a>'
508 508
                 )
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
     public static function get_page_by_ee_shortcode($ee_shortcode)
529 529
     {
530 530
         global $wpdb;
531
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
531
+        $shortcode_and_opening_bracket = '['.$ee_shortcode;
532 532
         $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
533 533
         if ($post_id) {
534 534
             return get_post($post_id);
@@ -554,11 +554,11 @@  discard block
 block discarded – undo
554 554
             'post_status'    => 'publish',
555 555
             'post_type'      => 'page',
556 556
             'comment_status' => 'closed',
557
-            'post_content'   => '[' . $critical_page['code'] . ']',
557
+            'post_content'   => '['.$critical_page['code'].']',
558 558
         );
559 559
 
560 560
         $post_id = wp_insert_post($post_args);
561
-        if (! $post_id) {
561
+        if ( ! $post_id) {
562 562
             $msg = sprintf(
563 563
                 __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
564 564
                 $critical_page['name']
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
             return $critical_page;
568 568
         }
569 569
         // get newly created post's details
570
-        if (! $critical_page['post'] = get_post($post_id)) {
570
+        if ( ! $critical_page['post'] = get_post($post_id)) {
571 571
             $msg = sprintf(
572 572
                 __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
573 573
                 $critical_page['name']
@@ -654,17 +654,17 @@  discard block
 block discarded – undo
654 654
             $role_to_check
655 655
         );
656 656
         if ($pre_filtered_id !== false) {
657
-            return (int)$pre_filtered_id;
657
+            return (int) $pre_filtered_id;
658 658
         }
659 659
         $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
660 660
         $query = $wpdb->prepare(
661 661
             "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
662
-            '%' . $role_to_check . '%'
662
+            '%'.$role_to_check.'%'
663 663
         );
664 664
         $user_id = $wpdb->get_var($query);
665 665
         $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
666
-        if ($user_id && (int)$user_id) {
667
-            self::$_default_creator_id = (int)$user_id;
666
+        if ($user_id && (int) $user_id) {
667
+            self::$_default_creator_id = (int) $user_id;
668 668
             return self::$_default_creator_id;
669 669
         } else {
670 670
             return null;
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
         }
700 700
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
701 701
         if ( ! function_exists('dbDelta')) {
702
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
702
+            require_once(ABSPATH.'wp-admin/includes/upgrade.php');
703 703
         }
704 704
         $tableAnalysis = \EEH_Activation::getTableAnalysis();
705 705
         $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
@@ -910,13 +910,13 @@  discard block
 block discarded – undo
910 910
             // reset values array
911 911
             $QSG_values = array();
912 912
             // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
913
-            if (! in_array("$QSG_system", $question_groups)) {
913
+            if ( ! in_array("$QSG_system", $question_groups)) {
914 914
                 // add it
915 915
                 switch ($QSG_system) {
916 916
                     case 1:
917 917
                         $QSG_values = array(
918 918
                             'QSG_name'            => __('Personal Information', 'event_espresso'),
919
-                            'QSG_identifier'      => 'personal-information-' . time(),
919
+                            'QSG_identifier'      => 'personal-information-'.time(),
920 920
                             'QSG_desc'            => '',
921 921
                             'QSG_order'           => 1,
922 922
                             'QSG_show_group_name' => 1,
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
                     case 2:
929 929
                         $QSG_values = array(
930 930
                             'QSG_name'            => __('Address Information', 'event_espresso'),
931
-                            'QSG_identifier'      => 'address-information-' . time(),
931
+                            'QSG_identifier'      => 'address-information-'.time(),
932 932
                             'QSG_desc'            => '',
933 933
                             'QSG_order'           => 2,
934 934
                             'QSG_show_group_name' => 1,
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
                         break;
940 940
                 }
941 941
                 // make sure we have some values before inserting them
942
-                if (! empty($QSG_values)) {
942
+                if ( ! empty($QSG_values)) {
943 943
                     // insert system question
944 944
                     $wpdb->insert(
945 945
                         $table_name,
@@ -976,7 +976,7 @@  discard block
 block discarded – undo
976 976
             // reset values array
977 977
             $QST_values = array();
978 978
             // if we don't have what we should have
979
-            if (! in_array($QST_system, $questions)) {
979
+            if ( ! in_array($QST_system, $questions)) {
980 980
                 // add it
981 981
                 switch ($QST_system) {
982 982
                     case 'fname':
@@ -1128,7 +1128,7 @@  discard block
 block discarded – undo
1128 1128
                         );
1129 1129
                         break;
1130 1130
                 }
1131
-                if (! empty($QST_values)) {
1131
+                if ( ! empty($QST_values)) {
1132 1132
                     // insert system question
1133 1133
                     $wpdb->insert(
1134 1134
                         $table_name,
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
      */
1190 1190
     public static function insert_default_payment_methods()
1191 1191
     {
1192
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1192
+        if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1193 1193
             EE_Registry::instance()->load_lib('Payment_Method_Manager');
1194 1194
             EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1195 1195
         } else {
@@ -1277,9 +1277,9 @@  discard block
 block discarded – undo
1277 1277
         $folders = array(
1278 1278
             EVENT_ESPRESSO_TEMPLATE_DIR,
1279 1279
             EVENT_ESPRESSO_GATEWAY_DIR,
1280
-            EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1281
-            EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1282
-            EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1280
+            EVENT_ESPRESSO_UPLOAD_DIR.'logs/',
1281
+            EVENT_ESPRESSO_UPLOAD_DIR.'css/',
1282
+            EVENT_ESPRESSO_UPLOAD_DIR.'tickets/',
1283 1283
         );
1284 1284
         foreach ($folders as $folder) {
1285 1285
             try {
@@ -1290,7 +1290,7 @@  discard block
 block discarded – undo
1290 1290
                     sprintf(
1291 1291
                         __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1292 1292
                         $folder,
1293
-                        '<br />' . $e->getMessage()
1293
+                        '<br />'.$e->getMessage()
1294 1294
                     ),
1295 1295
                     __FILE__, __FUNCTION__, __LINE__
1296 1296
                 );
@@ -1301,7 +1301,7 @@  discard block
 block discarded – undo
1301 1301
         }
1302 1302
         //just add the .htaccess file to the logs directory to begin with. Even if logging
1303 1303
         //is disabled, there might be activation errors recorded in there
1304
-        EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1304
+        EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs/');
1305 1305
         //remember EE's folders are all good
1306 1306
         delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1307 1307
         return true;
@@ -1537,7 +1537,7 @@  discard block
 block discarded – undo
1537 1537
         // this creates an array for tracking events that have no active ticket prices created
1538 1538
         // this allows us to warn admins of the situation so that it can be corrected
1539 1539
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1540
-        if (! $espresso_no_ticket_prices) {
1540
+        if ( ! $espresso_no_ticket_prices) {
1541 1541
             add_option('ee_no_ticket_prices', array(), '', false);
1542 1542
         }
1543 1543
     }
@@ -1576,7 +1576,7 @@  discard block
 block discarded – undo
1576 1576
             }
1577 1577
         }
1578 1578
         //get all our CPTs
1579
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1579
+        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")";
1580 1580
         $cpt_ids = $wpdb->get_col($query);
1581 1581
         //delete each post meta and term relations too
1582 1582
         foreach ($cpt_ids as $post_id) {
@@ -1716,7 +1716,7 @@  discard block
 block discarded – undo
1716 1716
         if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1717 1717
             $db_update_sans_ee4 = array();
1718 1718
             foreach ($espresso_db_update as $version => $times_activated) {
1719
-                if ((string)$version[0] === '3') {//if its NON EE4
1719
+                if ((string) $version[0] === '3') {//if its NON EE4
1720 1720
                     $db_update_sans_ee4[$version] = $times_activated;
1721 1721
                 }
1722 1722
             }
Please login to merge, or discard this patch.