Completed
Branch FET-9222-rest-api-writes (1e6651)
by
unknown
81:25 queued 66:40
created
core/libraries/plugin_api/EE_Register_Capabilities.lib.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -47,33 +47,33 @@  discard block
 block discarded – undo
47 47
 	 * @throws EE_Error
48 48
 	 * @return void
49 49
 	 */
50
-	public static function register( $cap_reference = NULL, $setup_args = array() ) {
50
+	public static function register($cap_reference = NULL, $setup_args = array()) {
51 51
 		//required fields MUST be present, so let's make sure they are.
52
-		if ( ! isset( $cap_reference ) || ! is_array( $setup_args ) || empty( $setup_args['capabilities'] ) ) {
52
+		if ( ! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) {
53 53
 			throw new EE_Error(
54
-				__( 'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', 'event_espresso' )
54
+				__('In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', 'event_espresso')
55 55
 			);
56 56
 		}
57 57
 		//make sure we don't register twice
58
-		if( isset( self::$_registry[ $cap_reference ] ) ){
58
+		if (isset(self::$_registry[$cap_reference])) {
59 59
 			return;
60 60
 		}
61 61
 		//make sure this is not registered too late or too early.
62
-		if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' ) || did_action( 'AHEE__EE_System___detect_if_activation_or_upgrade__begin' ) ) {
63
-			EE_Error::doing_it_wrong( __METHOD__, sprintf( __('%s has been registered too late.  Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', 'event_espresso'), $cap_reference ), '4.5.0' );
62
+		if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) {
63
+			EE_Error::doing_it_wrong(__METHOD__, sprintf(__('%s has been registered too late.  Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', 'event_espresso'), $cap_reference), '4.5.0');
64 64
 		}
65 65
 		//some preliminary sanitization and setting to the $_registry property
66 66
 		self::$_registry[$cap_reference] = array(
67
-			'caps' => isset( $setup_args['capabilities'] ) && is_array( $setup_args['capabilities'] ) ? $setup_args['capabilities'] : array(),
68
-			'cap_maps' => isset( $setup_args['capability_maps'] ) ? $setup_args['capability_maps'] : array()
67
+			'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) ? $setup_args['capabilities'] : array(),
68
+			'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : array()
69 69
 		);
70 70
 		//set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once)
71
-		add_filter( 'FHEE__EE_Capabilities__init_caps_map__caps', array( 'EE_Register_Capabilities', 'register_capabilities' ), 10 );
71
+		add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array('EE_Register_Capabilities', 'register_capabilities'), 10);
72 72
 		//add filter for cap maps
73
-		add_filter( 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', array( 'EE_Register_Capabilities', 'register_cap_maps' ), 10 );
73
+		add_filter('FHEE__EE_Capabilities___set_meta_caps__meta_caps', array('EE_Register_Capabilities', 'register_cap_maps'), 10);
74 74
 		//init_role_caps to register new capabilities
75
-		if ( is_admin() ) {
76
-			EE_Registry::instance()->load_core( 'Capabilities' );
75
+		if (is_admin()) {
76
+			EE_Registry::instance()->load_core('Capabilities');
77 77
 			EE_Capabilities::instance()->init_caps();
78 78
 		}
79 79
 	}
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
 	 *
89 89
 	 * @return array merged in new caps.
90 90
 	 */
91
-	public static function register_capabilities( $incoming_caps ) {
92
-		foreach ( self::$_registry as $ref => $caps_and_cap_map ) {
93
-			$incoming_caps = array_merge_recursive( $incoming_caps, $caps_and_cap_map[ 'caps' ] );
91
+	public static function register_capabilities($incoming_caps) {
92
+		foreach (self::$_registry as $ref => $caps_and_cap_map) {
93
+			$incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']);
94 94
 		}
95 95
 		return $incoming_caps;
96 96
 	}
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
 	 * @return EE_Meta_Capability_Map[]
106 106
 	 * @throws EE_Error
107 107
 	 */
108
-	public static function register_cap_maps( $cap_maps ) {
108
+	public static function register_cap_maps($cap_maps) {
109 109
 		//loop through and instantiate cap maps.
110
-		foreach ( self::$_registry as $cap_reference => $setup ) {
111
-			if ( ! isset( $setup['cap_maps'] ) ) {
110
+		foreach (self::$_registry as $cap_reference => $setup) {
111
+			if ( ! isset($setup['cap_maps'])) {
112 112
 				continue;
113 113
 			}
114
-			foreach ( $setup['cap_maps'] as $cap_class => $args ) {
114
+			foreach ($setup['cap_maps'] as $cap_class => $args) {
115 115
 
116 116
 				/**
117 117
 				 * account for cases where capability maps may be indexed
@@ -138,19 +138,19 @@  discard block
 block discarded – undo
138 138
 				 * 	...
139 139
 				 * )
140 140
 				 */
141
-				if ( is_numeric( $cap_class ) ) {
142
-					$cap_class = key( $args );
141
+				if (is_numeric($cap_class)) {
142
+					$cap_class = key($args);
143 143
 					$args = $args[$cap_class];
144 144
 				}
145 145
 
146
-				if ( ! class_exists( $cap_class ) ) {
147
-					throw new EE_Error( sprintf( __( 'An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments', 'event_espresso' ), $cap_reference ) );
146
+				if ( ! class_exists($cap_class)) {
147
+					throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments', 'event_espresso'), $cap_reference));
148 148
 				}
149 149
 
150
-				if ( count( $args ) !== 2 ) {
151
-					throw new EE_Error( sprintf( __('An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments.  The array should have two values the first being a string and the second an array.', 'event_espresso' ), $cap_reference ) );
150
+				if (count($args) !== 2) {
151
+					throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments.  The array should have two values the first being a string and the second an array.', 'event_espresso'), $cap_reference));
152 152
 				}
153
-				$cap_maps[] = new $cap_class( $args[0], $args[1] );
153
+				$cap_maps[] = new $cap_class($args[0], $args[1]);
154 154
 			}
155 155
 		}
156 156
 		return $cap_maps;
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
 
160 160
 
161 161
 
162
-	public static function deregister( $cap_reference = NULL ) {
163
-		if ( !empty( self::$_registry[$cap_reference] ) ) {
164
-			unset( self::$_registry[ $cap_reference ] );
162
+	public static function deregister($cap_reference = NULL) {
163
+		if ( ! empty(self::$_registry[$cap_reference])) {
164
+			unset(self::$_registry[$cap_reference]);
165 165
 		}
166 166
 
167 167
 		//re init caps to grab the changes due to removed caps.
Please login to merge, or discard this patch.
core/EE_Deprecated.core.php 1 patch
Spacing   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
3
-	exit( 'No direct script access allowed' );
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 /**
6 6
  * ************************************************************************
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	$action_or_filter = 'action'
44 44
 ) {
45 45
 	$action_or_filter = $action_or_filter === 'action'
46
-		? esc_html__( 'action', 'event_espresso' )
47
-		: esc_html__( 'filter', 'event_espresso' );
46
+		? esc_html__('action', 'event_espresso')
47
+		: esc_html__('filter', 'event_espresso');
48 48
 	EE_Error::doing_it_wrong(
49 49
 		$deprecated_filter,
50 50
 		sprintf(
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
  * @param \EE_Checkout $checkout
69 69
  * @return string
70 70
  */
71
-function ee_deprecated__registration_checkout__button_text( $submit_button_text, EE_Checkout $checkout ) {
71
+function ee_deprecated__registration_checkout__button_text($submit_button_text, EE_Checkout $checkout) {
72 72
 	// list of old filters
73 73
 	$deprecated_filters = array(
74 74
 		'update_registration_details' => true,
@@ -78,16 +78,16 @@  discard block
 block discarded – undo
78 78
 		'proceed_to' => true,
79 79
 	);
80 80
 	// loop thru and call doing_it_wrong() or remove any that aren't being used
81
-	foreach ( $deprecated_filters as $deprecated_filter => $on ) {
81
+	foreach ($deprecated_filters as $deprecated_filter => $on) {
82 82
 		// was this filter called ?
83
-		if ( has_action( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter )) {
83
+		if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter)) {
84 84
 			// only display doing_it_wrong() notice to Event Admins during non-AJAX requests
85
-			if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter' ) && ! defined( 'DOING_AJAX' ) ) {
85
+			if (EE_Registry::instance()->CAP->current_user_can('ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter') && ! defined('DOING_AJAX')) {
86 86
 				EE_Error::doing_it_wrong(
87
-					'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
87
+					'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter,
88 88
 					sprintf(
89
-						__( 'The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso' ),
90
-						'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
89
+						__('The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso'),
90
+						'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter,
91 91
 						'<br />',
92 92
 						'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
93 93
 						'/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php'
@@ -96,24 +96,24 @@  discard block
 block discarded – undo
96 96
 				);
97 97
 			}
98 98
 		} else {
99
-			unset( $deprecated_filters[ $deprecated_filter ] );
99
+			unset($deprecated_filters[$deprecated_filter]);
100 100
 		}
101 101
 	}
102
-	if ( ! empty( $deprecated_filters )) {
103
-
104
-		if ( $checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset( $deprecated_filters[ 'update_registration_details' ] )) {
105
-			$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text );
106
-		} else if ( $checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset( $deprecated_filters[ 'process_payment' ] ) ) {
107
-			$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text );
108
-		} else if ( $checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset( $deprecated_filters[ 'finalize_registration' ] ) ) {
109
-			$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text );
102
+	if ( ! empty($deprecated_filters)) {
103
+
104
+		if ($checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) {
105
+			$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text);
106
+		} else if ($checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) {
107
+			$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text);
108
+		} else if ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) {
109
+			$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text);
110 110
 		}
111
-		if ( $checkout->next_step instanceof EE_SPCO_Reg_Step ) {
112
-			if ( $checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset( $deprecated_filters[ 'and_proceed_to_payment' ] ) ) {
113
-				$submit_button_text .= apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text );
111
+		if ($checkout->next_step instanceof EE_SPCO_Reg_Step) {
112
+			if ($checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) {
113
+				$submit_button_text .= apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text);
114 114
 			}
115
-			if ( $checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset( $deprecated_filters[ 'proceed_to' ] ) ) {
116
-				$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text ) . $checkout->next_step->name();
115
+			if ($checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) {
116
+				$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text).$checkout->next_step->name();
117 117
 			}
118 118
 		}
119 119
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	return $submit_button_text;
122 122
 
123 123
 }
124
-add_filter( 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2 );
124
+add_filter('FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2);
125 125
 
126 126
 
127 127
 
@@ -132,16 +132,16 @@  discard block
 block discarded – undo
132 132
  * @param \EE_Checkout $checkout
133 133
  * @param boolean $status_updates
134 134
  */
135
-function ee_deprecated_finalize_transaction( EE_Checkout $checkout, $status_updates ) {
135
+function ee_deprecated_finalize_transaction(EE_Checkout $checkout, $status_updates) {
136 136
 	$action_ref = NULL;
137
-	$action_ref = has_action( 'AHEE__EE_Transaction__finalize__new_transaction' ) ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref;
138
-	$action_ref = has_action( 'AHEE__EE_Transaction__finalize__all_transaction' ) ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref;
139
-	if ( $action_ref ) {
137
+	$action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction') ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref;
138
+	$action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction') ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref;
139
+	if ($action_ref) {
140 140
 
141 141
 		EE_Error::doing_it_wrong(
142 142
 			$action_ref,
143 143
 			sprintf(
144
-				__( 'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso' ),
144
+				__('This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso'),
145 145
 				'<br />',
146 146
 				'/core/business/EE_Transaction_Processor.class.php',
147 147
 				'AHEE__EE_Transaction_Processor__finalize',
@@ -151,39 +151,39 @@  discard block
 block discarded – undo
151 151
 			),
152 152
 			'4.6.0'
153 153
 		);
154
-		switch ( $action_ref ) {
154
+		switch ($action_ref) {
155 155
 			case 'AHEE__EE_Transaction__finalize__new_transaction' :
156
-				do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request );
156
+				do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request);
157 157
 				break;
158 158
 			case 'AHEE__EE_Transaction__finalize__all_transaction' :
159
-				do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array( 'new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates ), $checkout->admin_request );
159
+				do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates), $checkout->admin_request);
160 160
 				break;
161 161
 		}
162 162
 	}
163 163
 }
164
-add_action( 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2 );
164
+add_action('AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2);
165 165
 /**
166 166
  * ee_deprecated_finalize_registration
167 167
  *
168 168
  * @param EE_Registration $registration
169 169
  */
170
-function ee_deprecated_finalize_registration( EE_Registration $registration ) {
171
-	$action_ref = has_action( 'AHEE__EE_Registration__finalize__update_and_new_reg' ) ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL;
172
-	if ( $action_ref ) {
170
+function ee_deprecated_finalize_registration(EE_Registration $registration) {
171
+	$action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg') ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL;
172
+	if ($action_ref) {
173 173
 		EE_Error::doing_it_wrong(
174 174
 			$action_ref,
175 175
 			sprintf(
176
-				__( 'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso' ),
176
+				__('This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso'),
177 177
 				'<br />',
178 178
 				'/core/business/EE_Registration_Processor.class.php',
179 179
 				'AHEE__EE_Registration_Processor__trigger_registration_status_changed_hook'
180 180
 			),
181 181
 			'4.6.0'
182 182
 		);
183
-		do_action( 'AHEE__EE_Registration__finalize__update_and_new_reg', $registration, ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )));
183
+		do_action('AHEE__EE_Registration__finalize__update_and_new_reg', $registration, (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX)));
184 184
 	}
185 185
 }
186
-add_action( 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1 );
186
+add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1);
187 187
 
188 188
 
189 189
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
  * Called after EED_Module::set_hooks() and EED_Module::set_admin_hooks() was called.
192 192
  * Checks if any deprecated hooks were hooked-into and provide doing_it_wrong messages appropriately.
193 193
  */
194
-function ee_deprecated_hooks(){
194
+function ee_deprecated_hooks() {
195 195
 	/**
196 196
 	 * @var $hooks array where keys are hook names, and their values are array{
197 197
 	 *			@type string $version  when deprecated
@@ -202,25 +202,25 @@  discard block
 block discarded – undo
202 202
 	$hooks = array(
203 203
 		'AHEE__EE_System___do_setup_validations' => array(
204 204
 			'version' => '4.6.0',
205
-			'alternative' => __( 'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso' ),
205
+			'alternative' => __('Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso'),
206 206
 			'still_works' => FALSE
207 207
 		)
208 208
 	);
209
-	foreach( $hooks as $name => $deprecation_info ){
210
-		if( has_action( $name ) ){
209
+	foreach ($hooks as $name => $deprecation_info) {
210
+		if (has_action($name)) {
211 211
 			EE_Error::doing_it_wrong(
212 212
 				$name,
213 213
 				sprintf(
214
-					__('This filter is deprecated. %1$s%2$s','event_espresso'),
215
-					$deprecation_info[ 'still_works' ] ?  __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __( 'It has been completely removed.', 'event_espresso' ),
216
-					isset( $deprecation_info[ 'alternative' ] ) ? $deprecation_info[ 'alternative' ] : __( 'Please read the current EE4 documentation further or contact Support.', 'event_espresso' )
214
+					__('This filter is deprecated. %1$s%2$s', 'event_espresso'),
215
+					$deprecation_info['still_works'] ? __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __('It has been completely removed.', 'event_espresso'),
216
+					isset($deprecation_info['alternative']) ? $deprecation_info['alternative'] : __('Please read the current EE4 documentation further or contact Support.', 'event_espresso')
217 217
 				),
218
-				isset( $deprecation_info[ 'version' ] ) ? $deprecation_info[ 'version' ] : __( 'recently', 'event_espresso' )
218
+				isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso')
219 219
 			);
220 220
 		}
221 221
 	}
222 222
 }
223
-add_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks' );
223
+add_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks');
224 224
 
225 225
 
226 226
 
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
  * @return boolean
232 232
  */
233 233
 function ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() {
234
-	$in_use =  has_filter( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns' )
235
-			|| has_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save' );
236
-	if( $in_use ) {
234
+	$in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns')
235
+			|| has_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save');
236
+	if ($in_use) {
237 237
 		$msg = __(
238 238
 			'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.'
239 239
 			. 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,'
@@ -242,18 +242,18 @@  discard block
 block discarded – undo
242 242
 			'event_espresso' )
243 243
 		;
244 244
 		EE_Error::doing_it_wrong(
245
-			__CLASS__ . '::' . __FUNCTION__,
245
+			__CLASS__.'::'.__FUNCTION__,
246 246
 			$msg,
247 247
 			'4.8.32.rc.000'
248 248
 		);
249 249
 		//it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed
250
-		if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
251
-			EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
250
+		if (is_admin() && ! defined('DOING_AJAX')) {
251
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
252 252
 		}
253 253
 	}
254 254
 	return $in_use;
255 255
 }
256
-add_action( 'AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks' );
256
+add_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks');
257 257
 
258 258
 /**
259 259
  * @deprecated since 4.8.32.rc.000 because it has issues on https://events.codebasehq.com/projects/event-espresso/tickets/9165
@@ -262,34 +262,34 @@  discard block
 block discarded – undo
262 262
  * @param EE_Admin_Page $admin_page
263 263
  * @return void
264 264
  */
265
-function ee_deprecated_update_attendee_registration_form_old( $admin_page ) {
265
+function ee_deprecated_update_attendee_registration_form_old($admin_page) {
266 266
 	//check if the old hooks are in use. If not, do the default
267
-	if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
268
-		|| ! $admin_page instanceof EE_Admin_Page ) {
267
+	if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
268
+		|| ! $admin_page instanceof EE_Admin_Page) {
269 269
 		return;
270 270
 	}
271 271
 	$req_data = $admin_page->get_request_data();
272
-	$qstns = isset( $req_data['qstn'] ) ? $req_data['qstn'] : FALSE;
273
-	$REG_ID = isset( $req_data['_REG_ID'] ) ? absint( $req_data['_REG_ID'] ) : FALSE;
274
-	$qstns = apply_filters( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns );
275
-	if ( ! $REG_ID || ! $qstns ) {
276
-		EE_Error::add_error( __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
272
+	$qstns = isset($req_data['qstn']) ? $req_data['qstn'] : FALSE;
273
+	$REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : FALSE;
274
+	$qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns);
275
+	if ( ! $REG_ID || ! $qstns) {
276
+		EE_Error::add_error(__('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
277 277
 	}
278 278
 	$success = TRUE;
279 279
 
280 280
 	// allow others to get in on this awesome fun   :D
281
-	do_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns );
281
+	do_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns);
282 282
 	// loop thru questions... FINALLY!!!
283 283
 
284
-	foreach ( $qstns as $QST_ID => $qstn ) {
284
+	foreach ($qstns as $QST_ID => $qstn) {
285 285
 		//if $qstn isn't an array then it doesn't already have an answer, so let's create the answer
286
-		if ( !is_array($qstn) ) {
287
-			$success = $this->_save_new_answer( $REG_ID, $QST_ID, $qstn);
286
+		if ( ! is_array($qstn)) {
287
+			$success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn);
288 288
 			continue;
289 289
 		}
290 290
 
291 291
 
292
-		foreach ( $qstn as $ANS_ID => $ANS_value ) {
292
+		foreach ($qstn as $ANS_ID => $ANS_value) {
293 293
 			//get answer
294 294
 			$query_params = array(
295 295
 				0 => array(
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 				);
301 301
 			$answer = EEM_Answer::instance()->get_one($query_params);
302 302
 			//this MAY be an array but NOT have an answer because its multi select.  If so then we need to create the answer
303
-			if ( ! $answer instanceof EE_Answer ) {
303
+			if ( ! $answer instanceof EE_Answer) {
304 304
 				$set_values = array(
305 305
 					'QST_ID' => $QST_ID,
306 306
 					'REG_ID' => $REG_ID,
@@ -315,11 +315,11 @@  discard block
 block discarded – undo
315 315
 		}
316 316
 	}
317 317
 	$what = __('Registration Form', 'event_espresso');
318
-	$route = $REG_ID ? array( 'action' => 'view_registration', '_REG_ID' => $REG_ID ) : array( 'action' => 'default' );
319
-	$admin_page->redirect_after_action( $success, $what, __('updated', 'event_espresso'), $route );
318
+	$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default');
319
+	$admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route);
320 320
 	exit;
321 321
 }
322
-add_action( 'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1 );
322
+add_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1);
323 323
 /**
324 324
  * Render the registration admin page's custom questions area in the old fashion
325 325
  * and firing the old hooks. When this method is removed, we can probably also
@@ -332,31 +332,31 @@  discard block
 block discarded – undo
332 332
  * @return bool
333 333
  * @throws \EE_Error
334 334
  */
335
-function ee_deprecated_reg_questions_meta_box_old( $do_default_action, $admin_page, $registration ) {
335
+function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration) {
336 336
 	//check if the old hooks are in use. If not, do the default
337
-	if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
338
-		|| ! $admin_page instanceof EE_Admin_Page ) {
337
+	if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
338
+		|| ! $admin_page instanceof EE_Admin_Page) {
339 339
 		return $do_default_action;
340 340
 	}
341
-	add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array( $admin_page, 'form_before_question_group' ), 10, 1 );
342
-	add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array( $admin_page, 'form_after_question_group' ), 10, 1 );
343
-	add_filter( 'FHEE__EEH_Form_Fields__label_html', array( $admin_page, 'form_form_field_label_wrap' ), 10, 1 );
344
-	add_filter( 'FHEE__EEH_Form_Fields__input_html', array( $admin_page, 'form_form_field_input__wrap' ), 10, 1 );
341
+	add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array($admin_page, 'form_before_question_group'), 10, 1);
342
+	add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array($admin_page, 'form_after_question_group'), 10, 1);
343
+	add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1);
344
+	add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1);
345 345
 
346
-	$question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options( $registration, $registration->get('EVT_ID') );
346
+	$question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options($registration, $registration->get('EVT_ID'));
347 347
 
348
-	EE_Registry::instance()->load_helper( 'Form_Fields' );
348
+	EE_Registry::instance()->load_helper('Form_Fields');
349 349
 	$template_args = array(
350
-		'att_questions' => EEH_Form_Fields::generate_question_groups_html( $question_groups ),
350
+		'att_questions' => EEH_Form_Fields::generate_question_groups_html($question_groups),
351 351
 		'reg_questions_form_action' => 'edit_registration',
352 352
 		'REG_ID' => $registration->ID()
353 353
 	);
354
-	$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
355
-	echo EEH_Template::display_template( $template_path, $template_args, TRUE );
354
+	$template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
355
+	echo EEH_Template::display_template($template_path, $template_args, TRUE);
356 356
 	//indicate that we should not do the default admin page code
357 357
 	return false;
358 358
 }
359
-add_action( 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3 );
359
+add_action('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3);
360 360
 
361 361
 
362 362
 
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
 			'4.9.0'
398 398
 		);
399 399
 		/** @var EE_Message_Resource_Manager $message_resource_manager */
400
-		$message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' );
401
-		$messenger = $message_resource_manager->get_messenger( $messenger_name );
402
-		$message_type = $message_resource_manager->get_message_type( $message_type_name );
400
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
401
+		$messenger = $message_resource_manager->get_messenger($messenger_name);
402
+		$message_type = $message_resource_manager->get_message_type($message_type_name);
403 403
 		return EE_Registry::instance()->load_lib(
404 404
 			'Messages_Template_Defaults',
405 405
 			array(
@@ -464,15 +464,15 @@  discard block
 block discarded – undo
464 464
 	/**
465 465
 	 * @param string $method
466 466
 	 */
467
-	public function _class_is_deprecated( $method ) {
467
+	public function _class_is_deprecated($method) {
468 468
 		EE_Error::doing_it_wrong(
469
-			'EE_messages::' . $method,
470
-			__( 'EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.' ),
469
+			'EE_messages::'.$method,
470
+			__('EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.'),
471 471
 			'4.9.0',
472 472
 			'4.10.0.p'
473 473
 		);
474 474
 		// Please use EE_Message_Resource_Manager instead
475
-		$this->_message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' );
475
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
476 476
 	}
477 477
 
478 478
 
@@ -482,10 +482,10 @@  discard block
 block discarded – undo
482 482
 	 * @param string $messenger_name
483 483
 	 * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive
484 484
 	 */
485
-	public function ensure_messenger_is_active( $messenger_name ) {
485
+	public function ensure_messenger_is_active($messenger_name) {
486 486
 		// EE_messages has been deprecated
487
-		$this->_class_is_deprecated( __FUNCTION__ );
488
-		return $this->_message_resource_manager->ensure_messenger_is_active( $messenger_name );
487
+		$this->_class_is_deprecated(__FUNCTION__);
488
+		return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name);
489 489
 	}
490 490
 
491 491
 
@@ -497,10 +497,10 @@  discard block
 block discarded – undo
497 497
 	 * @return bool true if it got activated (or was active) and false if not.
498 498
 	 * @throws \EE_Error
499 499
 	 */
500
-	public function ensure_message_type_is_active( $message_type, $messenger ) {
500
+	public function ensure_message_type_is_active($message_type, $messenger) {
501 501
 		// EE_messages has been deprecated
502
-		$this->_class_is_deprecated( __FUNCTION__ );
503
-		return $this->_message_resource_manager->ensure_message_type_is_active( $message_type, $messenger );
502
+		$this->_class_is_deprecated(__FUNCTION__);
503
+		return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger);
504 504
 	}
505 505
 
506 506
 
@@ -513,10 +513,10 @@  discard block
 block discarded – undo
513 513
 	 *                                            they are already setup.)
514 514
 	 * @return boolean an array of generated templates or false if nothing generated/activated.
515 515
 	 */
516
-	public function activate_messenger( $messenger_name, $mts_to_activate = array() ) {
516
+	public function activate_messenger($messenger_name, $mts_to_activate = array()) {
517 517
 		// EE_messages has been deprecated
518
-		$this->_class_is_deprecated( __FUNCTION__ );
519
-		return $this->_message_resource_manager->activate_messenger( $messenger_name, $mts_to_activate );
518
+		$this->_class_is_deprecated(__FUNCTION__);
519
+		return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate);
520 520
 	}
521 521
 
522 522
 
@@ -528,10 +528,10 @@  discard block
 block discarded – undo
528 528
 	 *
529 529
 	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
530 530
 	 */
531
-	public function is_generating_messenger_and_active( EE_messenger $messenger, EE_message_type $message_type ) {
531
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) {
532 532
 		// EE_messages has been deprecated
533
-		$this->_class_is_deprecated( __FUNCTION__ );
534
-		return $this->_message_resource_manager->is_generating_messenger_and_active( $messenger, $message_type );
533
+		$this->_class_is_deprecated(__FUNCTION__);
534
+		return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type);
535 535
 	}
536 536
 
537 537
 
@@ -541,10 +541,10 @@  discard block
 block discarded – undo
541 541
 	 * @param string $messenger
542 542
 	 * @return EE_messenger | null
543 543
 	 */
544
-	public function get_messenger_if_active( $messenger ) {
544
+	public function get_messenger_if_active($messenger) {
545 545
 		// EE_messages has been deprecated
546
-		$this->_class_is_deprecated( __FUNCTION__ );
547
-		return $this->_message_resource_manager->get_active_messenger( $messenger );
546
+		$this->_class_is_deprecated(__FUNCTION__);
547
+		return $this->_message_resource_manager->get_active_messenger($messenger);
548 548
 	}
549 549
 
550 550
 
@@ -565,9 +565,9 @@  discard block
 block discarded – undo
565 565
 	 *                  'message_type' => null
566 566
 	 *                  )
567 567
 	 */
568
-	public function validate_for_use( EE_Message $message ) {
568
+	public function validate_for_use(EE_Message $message) {
569 569
 		// EE_messages has been deprecated
570
-		$this->_class_is_deprecated( __FUNCTION__ );
570
+		$this->_class_is_deprecated(__FUNCTION__);
571 571
 		return array(
572 572
 			'messenger'    => $message->messenger_object(),
573 573
 			'message_type' => $message->message_type_object(),
@@ -595,41 +595,41 @@  discard block
 block discarded – undo
595 595
 		$send = true
596 596
 	) {
597 597
 		// EE_messages has been deprecated
598
-		$this->_class_is_deprecated( __FUNCTION__ );
598
+		$this->_class_is_deprecated(__FUNCTION__);
599 599
 		/** @type EE_Messages_Processor $processor */
600
-		$processor = EE_Registry::instance()->load_lib( 'Messages_Processor' );
600
+		$processor = EE_Registry::instance()->load_lib('Messages_Processor');
601 601
 		$error = false;
602 602
 		//try to intelligently determine what method we'll call based on the incoming data.
603 603
 		//if generating and sending are different then generate and send immediately.
604
-		if ( ! empty( $sending_messenger ) && $sending_messenger != $generating_messenger && $send ) {
604
+		if ( ! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) {
605 605
 			//in the legacy system, when generating and sending were different, that means all the
606 606
 			//vars are already in the request object.  So let's just use that.
607 607
 			try {
608 608
 				/** @type EE_Message_To_Generate_From_Request $mtg */
609
-				$mtg = EE_Registry::instance()->load_lib( 'Message_To_Generate_From_Request' );
610
-				$processor->generate_and_send_now( $mtg );
611
-			} catch ( EE_Error $e ) {
609
+				$mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
610
+				$processor->generate_and_send_now($mtg);
611
+			} catch (EE_Error $e) {
612 612
 				$error_msg = __(
613 613
 					'Please note that a system message failed to send due to a technical issue.',
614 614
 					'event_espresso'
615 615
 				);
616 616
 				// add specific message for developers if WP_DEBUG in on
617
-				$error_msg .= '||' . $e->getMessage();
618
-				EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ );
617
+				$error_msg .= '||'.$e->getMessage();
618
+				EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
619 619
 				$error = true;
620 620
 			}
621 621
 		} else {
622
-			$processor->generate_for_all_active_messengers( $type, $vars, $send );
622
+			$processor->generate_for_all_active_messengers($type, $vars, $send);
623 623
 			//let's find out if there were any errors and how many successfully were queued.
624 624
 			$count_errors = $processor->get_queue()->count_STS_in_queue(
625
-				array( EEM_Message::status_failed, EEM_Message::status_debug_only )
625
+				array(EEM_Message::status_failed, EEM_Message::status_debug_only)
626 626
 			);
627
-			$count_queued = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_incomplete );
628
-			$count_retry = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_retry );
627
+			$count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete);
628
+			$count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry);
629 629
 			$count_errors = $count_errors + $count_retry;
630
-			if ( $count_errors > 0 ) {
630
+			if ($count_errors > 0) {
631 631
 				$error = true;
632
-				if ( $count_errors > 1 && $count_retry > 1 && $count_queued > 1 ) {
632
+				if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) {
633 633
 					$message = sprintf(
634 634
 						__(
635 635
 							'There were %d errors and %d messages successfully queued for generation and sending',
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 						$count_errors,
639 639
 						$count_queued
640 640
 					);
641
-				} elseif ( $count_errors > 1 && $count_queued === 1 ) {
641
+				} elseif ($count_errors > 1 && $count_queued === 1) {
642 642
 					$message = sprintf(
643 643
 						__(
644 644
 							'There were %d errors and %d message successfully queued for generation.',
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 						$count_errors,
648 648
 						$count_queued
649 649
 					);
650
-				} elseif ( $count_errors === 1 && $count_queued > 1 ) {
650
+				} elseif ($count_errors === 1 && $count_queued > 1) {
651 651
 					$message = sprintf(
652 652
 						__(
653 653
 							'There was %d error and %d messages successfully queued for generation.',
@@ -665,9 +665,9 @@  discard block
 block discarded – undo
665 665
 						$count_errors
666 666
 					);
667 667
 				}
668
-				EE_Error::add_error( $message, __FILE__, __FUNCTION__, __LINE__ );
668
+				EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__);
669 669
 			} else {
670
-				if ( $count_queued === 1 ) {
670
+				if ($count_queued === 1) {
671 671
 					$message = sprintf(
672 672
 						__(
673 673
 							'%d message successfully queued for generation.',
@@ -684,18 +684,18 @@  discard block
 block discarded – undo
684 684
 						$count_queued
685 685
 					);
686 686
 				}
687
-				EE_Error::add_success( $message );
687
+				EE_Error::add_success($message);
688 688
 			}
689 689
 		}
690 690
 		//if no error then return the generated message(s).
691
-		if ( ! $error && ! $send ) {
692
-			$generated_queue = $processor->generate_queue( false );
691
+		if ( ! $error && ! $send) {
692
+			$generated_queue = $processor->generate_queue(false);
693 693
 			//get message and return.
694 694
 			$generated_queue->get_message_repository()->rewind();
695 695
 			$messages = array();
696
-			while ( $generated_queue->get_message_repository()->valid() ) {
696
+			while ($generated_queue->get_message_repository()->valid()) {
697 697
 				$message = $generated_queue->get_message_repository()->current();
698
-				if ( $message instanceof EE_Message ) {
698
+				if ($message instanceof EE_Message) {
699 699
 					//set properties that might be expected by add-ons (backward compat)
700 700
 					$message->content = $message->content();
701 701
 					$message->template_pack = $message->get_template_pack();
@@ -720,10 +720,10 @@  discard block
 block discarded – undo
720 720
 	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular preview
721 721
 	 * @return string          The body of the message.
722 722
 	 */
723
-	public function preview_message( $type, $context, $messenger, $send = false ) {
723
+	public function preview_message($type, $context, $messenger, $send = false) {
724 724
 		// EE_messages has been deprecated
725
-		$this->_class_is_deprecated( __FUNCTION__ );
726
-		return EED_Messages::preview_message( $type, $context, $messenger, $send );
725
+		$this->_class_is_deprecated(__FUNCTION__);
726
+		return EED_Messages::preview_message($type, $context, $messenger, $send);
727 727
 	}
728 728
 
729 729
 
@@ -737,14 +737,14 @@  discard block
 block discarded – undo
737 737
 	 *
738 738
 	 * @return bool          success or fail.
739 739
 	 */
740
-	public function send_message_with_messenger_only( $messenger, $message_type, $message ) {
740
+	public function send_message_with_messenger_only($messenger, $message_type, $message) {
741 741
 		// EE_messages has been deprecated
742
-		$this->_class_is_deprecated( __FUNCTION__ );
742
+		$this->_class_is_deprecated(__FUNCTION__);
743 743
 		//setup for sending to new method.
744 744
 		/** @type EE_Messages_Queue $queue */
745
-		$queue = EE_Registry::instance()->load_lib( 'Messages_Queue' );
745
+		$queue = EE_Registry::instance()->load_lib('Messages_Queue');
746 746
 		//make sure we have a proper message object
747
-		if ( ! $message instanceof EE_Message && is_object( $message ) && isset( $message->content ) ) {
747
+		if ( ! $message instanceof EE_Message && is_object($message) && isset($message->content)) {
748 748
 			$msg = EE_Message_Factory::create(
749 749
 				array(
750 750
 					'MSG_messenger'    => $messenger,
@@ -756,15 +756,15 @@  discard block
 block discarded – undo
756 756
 		} else {
757 757
 			$msg = $message;
758 758
 		}
759
-		if ( ! $msg instanceof EE_Message ) {
759
+		if ( ! $msg instanceof EE_Message) {
760 760
 			return false;
761 761
 		}
762 762
 		//make sure any content in a content property (if not empty) is set on the MSG_content.
763
-		if ( ! empty( $msg->content ) ) {
764
-			$msg->set( 'MSG_content', $msg->content );
763
+		if ( ! empty($msg->content)) {
764
+			$msg->set('MSG_content', $msg->content);
765 765
 		}
766
-		$queue->add( $msg );
767
-		return EED_Messages::send_message_with_messenger_only( $messenger, $message_type, $queue );
766
+		$queue->add($msg);
767
+		return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue);
768 768
 	}
769 769
 
770 770
 
@@ -778,11 +778,11 @@  discard block
 block discarded – undo
778 778
 	 * @return array|object if creation is successful then we return an array of info, otherwise an error_object is returned.
779 779
 	 * @throws \EE_Error
780 780
 	 */
781
-	public function create_new_templates( $messenger, $message_type, $GRP_ID = 0, $is_global = false ) {
781
+	public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false) {
782 782
 		// EE_messages has been deprecated
783
-		$this->_class_is_deprecated( __FUNCTION__ );
784
-		EE_Registry::instance()->load_helper( 'MSG_Template' );
785
-		return EEH_MSG_Template::create_new_templates( $messenger, $message_type, $GRP_ID, $is_global );
783
+		$this->_class_is_deprecated(__FUNCTION__);
784
+		EE_Registry::instance()->load_helper('MSG_Template');
785
+		return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global);
786 786
 	}
787 787
 
788 788
 
@@ -793,11 +793,11 @@  discard block
 block discarded – undo
793 793
 	 * @param  string $message_type_name name of EE_message_type
794 794
 	 * @return array
795 795
 	 */
796
-	public function get_fields( $messenger_name, $message_type_name ) {
796
+	public function get_fields($messenger_name, $message_type_name) {
797 797
 		// EE_messages has been deprecated
798
-		$this->_class_is_deprecated( __FUNCTION__ );
799
-		EE_Registry::instance()->load_helper( 'MSG_Template' );
800
-		return EEH_MSG_Template::get_fields( $messenger_name, $message_type_name );
798
+		$this->_class_is_deprecated(__FUNCTION__);
799
+		EE_Registry::instance()->load_helper('MSG_Template');
800
+		return EEH_MSG_Template::get_fields($messenger_name, $message_type_name);
801 801
 	}
802 802
 
803 803
 
@@ -811,13 +811,13 @@  discard block
 block discarded – undo
811 811
 	 * @return array                    multidimensional array of messenger and message_type objects
812 812
 	 *                                    (messengers index, and message_type index);
813 813
 	 */
814
-	public function get_installed( $type = 'all', $skip_cache = false ) {
814
+	public function get_installed($type = 'all', $skip_cache = false) {
815 815
 		// EE_messages has been deprecated
816
-		$this->_class_is_deprecated( __FUNCTION__ );
817
-		if ( $skip_cache ) {
816
+		$this->_class_is_deprecated(__FUNCTION__);
817
+		if ($skip_cache) {
818 818
 			$this->_message_resource_manager->reset_active_messengers_and_message_types();
819 819
 		}
820
-		switch ( $type ) {
820
+		switch ($type) {
821 821
 			case 'messengers' :
822 822
 				return array(
823 823
 					'messenger' => $this->_message_resource_manager->installed_messengers(),
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 	 */
847 847
 	public function get_active_messengers() {
848 848
 		// EE_messages has been deprecated
849
-		$this->_class_is_deprecated( __FUNCTION__ );
849
+		$this->_class_is_deprecated(__FUNCTION__);
850 850
 		return $this->_message_resource_manager->active_messengers();
851 851
 	}
852 852
 
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 	 */
859 859
 	public function get_active_message_types() {
860 860
 		// EE_messages has been deprecated
861
-		$this->_class_is_deprecated( __FUNCTION__ );
861
+		$this->_class_is_deprecated(__FUNCTION__);
862 862
 		return $this->_message_resource_manager->list_of_active_message_types();
863 863
 	}
864 864
 
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
 	 */
871 871
 	public function get_active_message_type_objects() {
872 872
 		// EE_messages has been deprecated
873
-		$this->_class_is_deprecated( __FUNCTION__ );
873
+		$this->_class_is_deprecated(__FUNCTION__);
874 874
 		return $this->_message_resource_manager->get_active_message_type_objects();
875 875
 	}
876 876
 
@@ -882,10 +882,10 @@  discard block
 block discarded – undo
882 882
 	 * @param string $messenger The messenger being checked
883 883
 	 * @return EE_message_type[]    (or empty array if none present)
884 884
 	 */
885
-	public function get_active_message_types_per_messenger( $messenger ) {
885
+	public function get_active_message_types_per_messenger($messenger) {
886 886
 		// EE_messages has been deprecated
887
-		$this->_class_is_deprecated( __FUNCTION__ );
888
-		return $this->_message_resource_manager->get_active_message_types_for_messenger( $messenger );
887
+		$this->_class_is_deprecated(__FUNCTION__);
888
+		return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger);
889 889
 	}
890 890
 
891 891
 
@@ -896,10 +896,10 @@  discard block
 block discarded – undo
896 896
 	 * @param string $message_type The string should correspond to a message type.
897 897
 	 * @return EE_message_type|null
898 898
 	 */
899
-	public function get_active_message_type( $messenger, $message_type ) {
899
+	public function get_active_message_type($messenger, $message_type) {
900 900
 		// EE_messages has been deprecated
901
-		$this->_class_is_deprecated( __FUNCTION__ );
902
-		return $this->_message_resource_manager->get_active_message_type_for_messenger( $messenger, $message_type );
901
+		$this->_class_is_deprecated(__FUNCTION__);
902
+		return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type);
903 903
 	}
904 904
 
905 905
 
@@ -910,7 +910,7 @@  discard block
 block discarded – undo
910 910
 	 */
911 911
 	public function get_installed_message_types() {
912 912
 		// EE_messages has been deprecated
913
-		$this->_class_is_deprecated( __FUNCTION__ );
913
+		$this->_class_is_deprecated(__FUNCTION__);
914 914
 		return $this->_message_resource_manager->installed_message_types();
915 915
 	}
916 916
 
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
 	 */
923 923
 	public function get_installed_messengers() {
924 924
 		// EE_messages has been deprecated
925
-		$this->_class_is_deprecated( __FUNCTION__ );
925
+		$this->_class_is_deprecated(__FUNCTION__);
926 926
 		return $this->_message_resource_manager->installed_messengers();
927 927
 	}
928 928
 
@@ -933,10 +933,10 @@  discard block
 block discarded – undo
933 933
 	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by message type.
934 934
 	 * @return array
935 935
 	 */
936
-	public function get_all_contexts( $slugs_only = true ) {
936
+	public function get_all_contexts($slugs_only = true) {
937 937
 		// EE_messages has been deprecated
938
-		$this->_class_is_deprecated( __FUNCTION__ );
939
-		return $this->_message_resource_manager->get_all_contexts( $slugs_only );
938
+		$this->_class_is_deprecated(__FUNCTION__);
939
+		return $this->_message_resource_manager->get_all_contexts($slugs_only);
940 940
 	}
941 941
 
942 942
 
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
 add_filter(
996 996
 	'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
997 997
 	function($event_list_iframe_css) {
998
-		if ( ! has_filter( 'FHEE__EventsArchiveIframe__event_list_iframe__css' )) {
998
+		if ( ! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) {
999 999
 			return $event_list_iframe_css;
1000 1000
 		}
1001 1001
 		deprecated_espresso_action_or_filter_doing_it_wrong(
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
 add_filter(
1016 1016
 	'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1017 1017
 	function($event_list_iframe_js) {
1018
-		if ( ! has_filter( 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js' )) {
1018
+		if ( ! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) {
1019 1019
 			return $event_list_iframe_js;
1020 1020
 		}
1021 1021
 		deprecated_espresso_action_or_filter_doing_it_wrong(
Please login to merge, or discard this patch.
core/EE_Capabilities.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
      * @since                        4.5.0
806 806
      *
807 807
      * @param string $meta_cap   What meta capability is this mapping.
808
-     * @param array  $map_values array {
808
+     * @param string[]  $map_values array {
809 809
      *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
810 810
      *                           capabilities that don't get mapped to.
811 811
      *
@@ -880,8 +880,8 @@  discard block
 block discarded – undo
880 880
      * @since 4.6.x
881 881
      *
882 882
      * @param $caps
883
-     * @param $cap
884
-     * @param $user_id
883
+     * @param string $cap
884
+     * @param integer $user_id
885 885
      * @param $args
886 886
      *
887 887
      * @return array
Please login to merge, or discard this patch.
Indentation   +1175 added lines, -1175 removed lines patch added patch discarded remove patch
@@ -17,800 +17,800 @@  discard block
 block discarded – undo
17 17
 final class EE_Capabilities extends EE_Base
18 18
 {
19 19
 
20
-    /**
21
-     * the name of the wp option used to store caps previously initialized
22
-     */
23
-    const option_name = 'ee_caps_initialized';
24
-
25
-    /**
26
-     * instance of EE_Capabilities object
27
-     *
28
-     * @var EE_Capabilities
29
-     */
30
-    private static $_instance;
31
-
32
-
33
-    /**
34
-     * This is a map of caps that correspond to a default WP_Role.
35
-     * Array is indexed by Role and values are ee capabilities.
36
-     *
37
-     * @since 4.5.0
38
-     *
39
-     * @var array
40
-     */
41
-    private $_caps_map = array();
42
-
43
-
44
-    /**
45
-     * This used to hold an array of EE_Meta_Capability_Map objects that define the granular capabilities mapped to for
46
-     * a user depending on context.
47
-     *
48
-     * @var EE_Meta_Capability_Map[]
49
-     */
50
-    private $_meta_caps = array();
51
-
52
-
53
-    /**
54
-     * singleton method used to instantiate class object
55
-     *
56
-     * @since 4.5.0
57
-     *
58
-     * @return EE_Capabilities
59
-     */
60
-    public static function instance()
61
-    {
62
-        //check if instantiated, and if not do so.
63
-        if (! self::$_instance instanceof EE_Capabilities) {
64
-            self::$_instance = new self();
65
-        }
66
-        return self::$_instance;
67
-    }
68
-
69
-
70
-    /**
71
-     * private constructor
72
-     *
73
-     * @since 4.5.0
74
-     *
75
-     * @return \EE_Capabilities
76
-     */
77
-    private function __construct()
78
-    {
79
-    }
80
-
81
-
82
-    /**
83
-     * This delays the initialization of the capabilities class until EE_System core is loaded and ready.
84
-     *
85
-     * @param bool $reset allows for resetting the default capabilities saved on roles.  Note that this doesn't
86
-     *                    actually REMOVE any capabilities from existing roles, it just resaves defaults roles and
87
-     *                    ensures that they are up to date.
88
-     *
89
-     *
90
-     * @since 4.5.0
91
-     * @return void
92
-     */
93
-    public function init_caps($reset = false)
94
-    {
95
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
96
-            $this->_caps_map = $this->_init_caps_map();
97
-            $this->init_role_caps($reset);
98
-            $this->_set_meta_caps();
99
-        }
100
-    }
101
-
102
-
103
-    /**
104
-     * This sets the meta caps property.
105
-     * @since 4.5.0
106
-     *
107
-     * @return void
108
-     */
109
-    private function _set_meta_caps()
110
-    {
111
-        //make sure we're only ever initializing the default _meta_caps array once if it's empty.
112
-        $this->_meta_caps = $this->_get_default_meta_caps_array();
113
-        $this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps);
114
-        //add filter for map_meta_caps but only if models can query.
115
-        if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
116
-            add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
117
-        }
118
-    }
119
-
120
-
121
-    /**
122
-     * This builds and returns the default meta_caps array only once.
123
-     *
124
-     * @since  4.8.28.rc.012
125
-     * @return array
126
-     * @throws \EE_Error
127
-     */
128
-    private function _get_default_meta_caps_array()
129
-    {
130
-        static $default_meta_caps = array();
131
-        if (empty($default_meta_caps)) {
132
-            $default_meta_caps = array(
133
-                //edits
134
-                new EE_Meta_Capability_Map_Edit(
135
-                    'ee_edit_event',
136
-                    array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')
137
-                ),
138
-                new EE_Meta_Capability_Map_Edit(
139
-                    'ee_edit_venue',
140
-                    array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')
141
-                ),
142
-                new EE_Meta_Capability_Map_Edit(
143
-                    'ee_edit_registration',
144
-                    array('Registration', '', 'ee_edit_others_registrations', '')
145
-                ),
146
-                new EE_Meta_Capability_Map_Edit(
147
-                    'ee_edit_checkin',
148
-                    array('Registration', '', 'ee_edit_others_checkins', '')
149
-                ),
150
-                new EE_Meta_Capability_Map_Messages_Cap(
151
-                    'ee_edit_message',
152
-                    array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')
153
-                ),
154
-                new EE_Meta_Capability_Map_Edit(
155
-                    'ee_edit_default_ticket',
156
-                    array('Ticket', '', 'ee_edit_others_default_tickets', '')
157
-                ),
158
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
159
-                    'ee_edit_question',
160
-                    array('Question', '', '', 'ee_edit_system_questions')
161
-                ),
162
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
163
-                    'ee_edit_question_group',
164
-                    array('Question_Group', '', '', 'ee_edit_system_question_groups')
165
-                ),
166
-                new EE_Meta_Capability_Map_Edit(
167
-                    'ee_edit_payment_method',
168
-                    array('Payment_Method', '', 'ee_edit_others_payment_methods', '')
169
-                ),
170
-                //reads
171
-                new EE_Meta_Capability_Map_Read(
172
-                    'ee_read_event',
173
-                    array('Event', '', 'ee_read_others_events', 'ee_read_private_events')
174
-                ),
175
-                new EE_Meta_Capability_Map_Read(
176
-                    'ee_read_venue',
177
-                    array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')
178
-                ),
179
-                new EE_Meta_Capability_Map_Read(
180
-                    'ee_read_registration',
181
-                    array('Registration', '', '', 'ee_edit_others_registrations')
182
-                ),
183
-                new EE_Meta_Capability_Map_Read(
184
-                    'ee_read_checkin',
185
-                    array('Registration', '', '', 'ee_read_others_checkins')
186
-                ),
187
-                new EE_Meta_Capability_Map_Messages_Cap(
188
-                    'ee_read_message',
189
-                    array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')
190
-                ),
191
-                new EE_Meta_Capability_Map_Read(
192
-                    'ee_read_default_ticket',
193
-                    array('Ticket', '', '', 'ee_read_others_default_tickets')
194
-                ),
195
-                new EE_Meta_Capability_Map_Read(
196
-                    'ee_read_payment_method',
197
-                    array('Payment_Method', '', '', 'ee_read_others_payment_methods')),
198
-
199
-                //deletes
200
-                new EE_Meta_Capability_Map_Delete(
201
-                    'ee_delete_event',
202
-                    array(
203
-                        'Event',
204
-                        'ee_delete_published_events',
205
-                        'ee_delete_others_events',
206
-                        'ee_delete_private_events',
207
-                    )
208
-                ),
209
-                new EE_Meta_Capability_Map_Delete(
210
-                    'ee_delete_venue',
211
-                    array(
212
-                        'Venue',
213
-                        'ee_delete_published_venues',
214
-                        'ee_delete_others_venues',
215
-                        'ee_delete_private_venues',
216
-                    )
217
-                ),
218
-                new EE_Meta_Capability_Map_Delete(
219
-                    'ee_delete_registration',
220
-                    array('Registration', '', 'ee_delete_others_registrations', '')
221
-                ),
222
-                new EE_Meta_Capability_Map_Delete(
223
-                    'ee_delete_checkin',
224
-                    array('Registration', '', 'ee_delete_others_checkins', '')
225
-                ),
226
-                new EE_Meta_Capability_Map_Messages_Cap(
227
-                    'ee_delete_message',
228
-                    array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')
229
-                ),
230
-                new EE_Meta_Capability_Map_Delete(
231
-                    'ee_delete_default_ticket',
232
-                    array('Ticket', '', 'ee_delete_others_default_tickets', '')
233
-                ),
234
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
235
-                    'ee_delete_question',
236
-                    array('Question', '', '', 'delete_system_questions')
237
-                ),
238
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
239
-                    'ee_delete_question_group',
240
-                    array('Question_Group', '', '', 'delete_system_question_groups')
241
-                ),
242
-                new EE_Meta_Capability_Map_Delete(
243
-                    'ee_delete_payment_method',
244
-                    array('Payment_Method', '', 'ee_delete_others_payment_methods', '')
245
-                ),
246
-            );
247
-        }
248
-        return $default_meta_caps;
249
-    }
250
-
251
-
252
-    /**
253
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
254
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
255
-     *
256
-     * The actual logic is carried out by implementer classes in their definition of _map_meta_caps.
257
-     *
258
-     * @since 4.5.0
259
-     * @see   wp-includes/capabilities.php
260
-     *
261
-     * @param array  $caps    actual users capabilities
262
-     * @param string $cap     initial capability name that is being checked (the "map" key)
263
-     * @param int    $user_id The user id
264
-     * @param array  $args    Adds context to the cap. Typically the object ID.
265
-     * @return array actual users capabilities
266
-     * @throws EE_Error
267
-     */
268
-    public function map_meta_caps($caps, $cap, $user_id, $args)
269
-    {
270
-        if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
271
-            //loop through our _meta_caps array
272
-            foreach ($this->_meta_caps as $meta_map) {
273
-                if (! $meta_map instanceof EE_Meta_Capability_Map) {
274
-                    continue;
275
-                }
276
-                // don't load models if there is no object ID in the args
277
-                if(!empty($args[0])){
278
-                    $meta_map->ensure_is_model();
279
-                }
280
-                $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
281
-            }
282
-        }
283
-        return $caps;
284
-    }
285
-
286
-
287
-    /**
288
-     * This sets up and returns the initial capabilities map for Event Espresso
289
-     *
290
-     * @since 4.5.0
291
-     *
292
-     * @return array
293
-     */
294
-    private function _init_caps_map()
295
-    {
296
-        $caps = array(
297
-            'administrator'           => array(
298
-                //basic access
299
-                'ee_read_ee',
300
-                //gateways
301
-                /**
302
-                 * note that with payment method capabilities, although we've implemented
303
-                 * capability mapping which will be used for accessing payment methods owned by
304
-                 * other users.  This is not fully implemented yet in the payment method ui.
305
-                 * Currently only the "plural" caps are in active use.
306
-                 * (Specific payment method caps are in use as well).
307
-                 **/
308
-                'ee_manage_gateways',
309
-                'ee_read_payment_method',
310
-                'ee_read_payment_methods',
311
-                'ee_read_others_payment_methods',
312
-                'ee_edit_payment_method',
313
-                'ee_edit_payment_methods',
314
-                'ee_edit_others_payment_methods',
315
-                'ee_delete_payment_method',
316
-                'ee_delete_payment_methods',
317
-                //events
318
-                'ee_publish_events',
319
-                'ee_read_private_events',
320
-                'ee_read_others_events',
321
-                'ee_read_event',
322
-                'ee_read_events',
323
-                'ee_edit_event',
324
-                'ee_edit_events',
325
-                'ee_edit_published_events',
326
-                'ee_edit_others_events',
327
-                'ee_edit_private_events',
328
-                'ee_delete_published_events',
329
-                'ee_delete_private_events',
330
-                'ee_delete_event',
331
-                'ee_delete_events',
332
-                'ee_delete_others_events',
333
-                //event categories
334
-                'ee_manage_event_categories',
335
-                'ee_edit_event_category',
336
-                'ee_delete_event_category',
337
-                'ee_assign_event_category',
338
-                //venues
339
-                'ee_publish_venues',
340
-                'ee_read_venue',
341
-                'ee_read_venues',
342
-                'ee_read_others_venues',
343
-                'ee_read_private_venues',
344
-                'ee_edit_venue',
345
-                'ee_edit_venues',
346
-                'ee_edit_others_venues',
347
-                'ee_edit_published_venues',
348
-                'ee_edit_private_venues',
349
-                'ee_delete_venue',
350
-                'ee_delete_venues',
351
-                'ee_delete_others_venues',
352
-                'ee_delete_private_venues',
353
-                'ee_delete_published_venues',
354
-                //venue categories
355
-                'ee_manage_venue_categories',
356
-                'ee_edit_venue_category',
357
-                'ee_delete_venue_category',
358
-                'ee_assign_venue_category',
359
-                //contacts
360
-                'ee_read_contact',
361
-                'ee_read_contacts',
362
-                'ee_edit_contact',
363
-                'ee_edit_contacts',
364
-                'ee_delete_contact',
365
-                'ee_delete_contacts',
366
-                //registrations
367
-                'ee_read_registration',
368
-                'ee_read_registrations',
369
-                'ee_read_others_registrations',
370
-                'ee_edit_registration',
371
-                'ee_edit_registrations',
372
-                'ee_edit_others_registrations',
373
-                'ee_delete_registration',
374
-                'ee_delete_registrations',
375
-                //checkins
376
-                'ee_read_checkin',
377
-                'ee_read_others_checkins',
378
-                'ee_read_checkins',
379
-                'ee_edit_checkin',
380
-                'ee_edit_checkins',
381
-                'ee_edit_others_checkins',
382
-                'ee_delete_checkin',
383
-                'ee_delete_checkins',
384
-                'ee_delete_others_checkins',
385
-                //transactions && payments
386
-                'ee_read_transaction',
387
-                'ee_read_transactions',
388
-                'ee_edit_payments',
389
-                'ee_delete_payments',
390
-                //messages
391
-                'ee_read_message',
392
-                'ee_read_messages',
393
-                'ee_read_others_messages',
394
-                'ee_read_global_messages',
395
-                'ee_edit_global_messages',
396
-                'ee_edit_message',
397
-                'ee_edit_messages',
398
-                'ee_edit_others_messages',
399
-                'ee_delete_message',
400
-                'ee_delete_messages',
401
-                'ee_delete_others_messages',
402
-                'ee_delete_global_messages',
403
-                'ee_send_message',
404
-                //tickets
405
-                'ee_read_default_ticket',
406
-                'ee_read_default_tickets',
407
-                'ee_read_others_default_tickets',
408
-                'ee_edit_default_ticket',
409
-                'ee_edit_default_tickets',
410
-                'ee_edit_others_default_tickets',
411
-                'ee_delete_default_ticket',
412
-                'ee_delete_default_tickets',
413
-                'ee_delete_others_default_tickets',
414
-                //prices
415
-                'ee_edit_default_price',
416
-                'ee_edit_default_prices',
417
-                'ee_delete_default_price',
418
-                'ee_delete_default_prices',
419
-                'ee_edit_default_price_type',
420
-                'ee_edit_default_price_types',
421
-                'ee_delete_default_price_type',
422
-                'ee_delete_default_price_types',
423
-                'ee_read_default_prices',
424
-                'ee_read_default_price_types',
425
-                //registration form
426
-                'ee_edit_question',
427
-                'ee_edit_questions',
428
-                'ee_edit_system_questions',
429
-                'ee_read_questions',
430
-                'ee_delete_question',
431
-                'ee_delete_questions',
432
-                'ee_edit_question_group',
433
-                'ee_edit_question_groups',
434
-                'ee_read_question_groups',
435
-                'ee_edit_system_question_groups',
436
-                'ee_delete_question_group',
437
-                'ee_delete_question_groups',
438
-                //event_type taxonomy
439
-                'ee_assign_event_type',
440
-                'ee_manage_event_types',
441
-                'ee_edit_event_type',
442
-                'ee_delete_event_type',
443
-            ),
444
-            'ee_events_administrator' => array(
445
-                //core wp caps
446
-                'read',
447
-                'read_private_pages',
448
-                'read_private_posts',
449
-                'edit_users',
450
-                'edit_posts',
451
-                'edit_pages',
452
-                'edit_published_posts',
453
-                'edit_published_pages',
454
-                'edit_private_pages',
455
-                'edit_private_posts',
456
-                'edit_others_posts',
457
-                'edit_others_pages',
458
-                'publish_posts',
459
-                'publish_pages',
460
-                'delete_posts',
461
-                'delete_pages',
462
-                'delete_private_pages',
463
-                'delete_private_posts',
464
-                'delete_published_pages',
465
-                'delete_published_posts',
466
-                'delete_others_posts',
467
-                'delete_others_pages',
468
-                'manage_categories',
469
-                'manage_links',
470
-                'moderate_comments',
471
-                'unfiltered_html',
472
-                'upload_files',
473
-                'export',
474
-                'import',
475
-                'list_users',
476
-                'level_1', //required if user with this role shows up in author dropdowns
477
-                //basic ee access
478
-                'ee_read_ee',
479
-                //events
480
-                'ee_publish_events',
481
-                'ee_read_private_events',
482
-                'ee_read_others_events',
483
-                'ee_read_event',
484
-                'ee_read_events',
485
-                'ee_edit_event',
486
-                'ee_edit_events',
487
-                'ee_edit_published_events',
488
-                'ee_edit_others_events',
489
-                'ee_edit_private_events',
490
-                'ee_delete_published_events',
491
-                'ee_delete_private_events',
492
-                'ee_delete_event',
493
-                'ee_delete_events',
494
-                'ee_delete_others_events',
495
-                //event categories
496
-                'ee_manage_event_categories',
497
-                'ee_edit_event_category',
498
-                'ee_delete_event_category',
499
-                'ee_assign_event_category',
500
-                //venues
501
-                'ee_publish_venues',
502
-                'ee_read_venue',
503
-                'ee_read_venues',
504
-                'ee_read_others_venues',
505
-                'ee_read_private_venues',
506
-                'ee_edit_venue',
507
-                'ee_edit_venues',
508
-                'ee_edit_others_venues',
509
-                'ee_edit_published_venues',
510
-                'ee_edit_private_venues',
511
-                'ee_delete_venue',
512
-                'ee_delete_venues',
513
-                'ee_delete_others_venues',
514
-                'ee_delete_private_venues',
515
-                'ee_delete_published_venues',
516
-                //venue categories
517
-                'ee_manage_venue_categories',
518
-                'ee_edit_venue_category',
519
-                'ee_delete_venue_category',
520
-                'ee_assign_venue_category',
521
-                //contacts
522
-                'ee_read_contact',
523
-                'ee_read_contacts',
524
-                'ee_edit_contact',
525
-                'ee_edit_contacts',
526
-                'ee_delete_contact',
527
-                'ee_delete_contacts',
528
-                //registrations
529
-                'ee_read_registration',
530
-                'ee_read_registrations',
531
-                'ee_read_others_registrations',
532
-                'ee_edit_registration',
533
-                'ee_edit_registrations',
534
-                'ee_edit_others_registrations',
535
-                'ee_delete_registration',
536
-                'ee_delete_registrations',
537
-                //checkins
538
-                'ee_read_checkin',
539
-                'ee_read_others_checkins',
540
-                'ee_read_checkins',
541
-                'ee_edit_checkin',
542
-                'ee_edit_checkins',
543
-                'ee_edit_others_checkins',
544
-                'ee_delete_checkin',
545
-                'ee_delete_checkins',
546
-                'ee_delete_others_checkins',
547
-                //transactions && payments
548
-                'ee_read_transaction',
549
-                'ee_read_transactions',
550
-                'ee_edit_payments',
551
-                'ee_delete_payments',
552
-                //messages
553
-                'ee_read_message',
554
-                'ee_read_messages',
555
-                'ee_read_others_messages',
556
-                'ee_read_global_messages',
557
-                'ee_edit_global_messages',
558
-                'ee_edit_message',
559
-                'ee_edit_messages',
560
-                'ee_edit_others_messages',
561
-                'ee_delete_message',
562
-                'ee_delete_messages',
563
-                'ee_delete_others_messages',
564
-                'ee_delete_global_messages',
565
-                'ee_send_message',
566
-                //tickets
567
-                'ee_read_default_ticket',
568
-                'ee_read_default_tickets',
569
-                'ee_read_others_default_tickets',
570
-                'ee_edit_default_ticket',
571
-                'ee_edit_default_tickets',
572
-                'ee_edit_others_default_tickets',
573
-                'ee_delete_default_ticket',
574
-                'ee_delete_default_tickets',
575
-                'ee_delete_others_default_tickets',
576
-                //prices
577
-                'ee_edit_default_price',
578
-                'ee_edit_default_prices',
579
-                'ee_delete_default_price',
580
-                'ee_delete_default_prices',
581
-                'ee_edit_default_price_type',
582
-                'ee_edit_default_price_types',
583
-                'ee_delete_default_price_type',
584
-                'ee_delete_default_price_types',
585
-                'ee_read_default_prices',
586
-                'ee_read_default_price_types',
587
-                //registration form
588
-                'ee_edit_question',
589
-                'ee_edit_questions',
590
-                'ee_edit_system_questions',
591
-                'ee_read_questions',
592
-                'ee_delete_question',
593
-                'ee_delete_questions',
594
-                'ee_edit_question_group',
595
-                'ee_edit_question_groups',
596
-                'ee_read_question_groups',
597
-                'ee_edit_system_question_groups',
598
-                'ee_delete_question_group',
599
-                'ee_delete_question_groups',
600
-                //event_type taxonomy
601
-                'ee_assign_event_type',
602
-                'ee_manage_event_types',
603
-                'ee_edit_event_type',
604
-                'ee_delete_event_type',
605
-            )
606
-        );
607
-        $caps = apply_filters('FHEE__EE_Capabilities__init_caps_map__caps', $caps);
608
-        return $caps;
609
-    }
610
-
611
-
612
-    /**
613
-     * This adds all the default caps to roles as registered in the _caps_map property.
614
-     *
615
-     * @since 4.5.0
616
-     *
617
-     * @param bool  $reset      allows for resetting the default capabilities saved on roles.  Note that this doesn't
618
-     *                          actually REMOVE any capabilities from existing roles, it just resaves defaults roles
619
-     *                          and ensures that they are up to date.
620
-     * @param array $custom_map Optional.  Can be used to send a custom map of roles and capabilities for setting them
621
-     *                          up.  Note that this should ONLY be called on activation hook or some other one-time
622
-     *                          task otherwise the caps will be added on every request.
623
-     *
624
-     * @return void
625
-     */
626
-    public function init_role_caps($reset = false, $custom_map = array())
627
-    {
628
-        $caps_map = empty($custom_map) ? $this->_caps_map : $custom_map;
629
-        //first let's determine if these caps have already been set.
630
-        $caps_set_before = get_option(self::option_name, array());
631
-        //if not reset, see what caps are new for each role. if they're new, add them.
632
-        foreach ($caps_map as $role => $caps_for_role) {
633
-            foreach ($caps_for_role as $cap) {
634
-                //first check we haven't already added this cap before, or it's a reset
635
-                if ($reset || ! isset($caps_set_before[ $role ]) || ! in_array($cap, $caps_set_before[ $role ])) {
636
-                    if ($this->add_cap_to_role($role, $cap)) {
637
-                        $caps_set_before[ $role ][] = $cap;
638
-                    }
639
-                }
640
-            }
641
-        }
642
-        //now let's just save the cap that has been set.
643
-        update_option(self::option_name, $caps_set_before);
644
-        do_action('AHEE__EE_Capabilities__init_role_caps__complete', $caps_set_before);
645
-    }
646
-
647
-
648
-    /**
649
-     * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
650
-     * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
651
-     * this is a wrapper for $wp_role->add_cap()
652
-     *
653
-     * @see   wp-includes/capabilities.php
654
-     *
655
-     * @since 4.5.0
656
-     *
657
-     * @param string $role  A WordPress role the capability is being added to
658
-     * @param string $cap   The capability being added to the role
659
-     * @param bool   $grant Whether to grant access to this cap on this role.
660
-     *
661
-     * @return bool
662
-     */
663
-    public function add_cap_to_role($role, $cap, $grant = true)
664
-    {
665
-        $role_object = get_role($role);
666
-        //if the role isn't available then we create it.
667
-        if (! $role_object instanceof WP_Role) {
668
-            //if a plugin wants to create a specific role name then they should create the role before
669
-            //EE_Capabilities does.  Otherwise this function will create the role name from the slug:
670
-            // - removes any `ee_` namespacing from the start of the slug.
671
-            // - replaces `_` with ` ` (empty space).
672
-            // - sentence case on the resulting string.
673
-            $role_label = ucwords(str_replace('_', ' ', str_replace('ee_', '', $role)));
674
-            $role_object = add_role($role, $role_label);
675
-        }
676
-        if ($role_object instanceof WP_Role) {
677
-            $role_object->add_cap($cap, $grant);
678
-            return true;
679
-        }
680
-        return false;
681
-    }
682
-
683
-
684
-    /**
685
-     * Functions similarly to add_cap_to_role except removes cap from given role.
686
-     * Wrapper for $wp_role->remove_cap()
687
-     *
688
-     * @see   wp-includes/capabilities.php
689
-     * @since 4.5.0
690
-     *
691
-     * @param string $role A WordPress role the capability is being removed from.
692
-     * @param string $cap  The capability being removed
693
-     *
694
-     * @return void
695
-     */
696
-    public function remove_cap_from_role($role, $cap)
697
-    {
698
-        $role = get_role($role);
699
-        if ($role instanceof WP_Role) {
700
-            $role->remove_cap($cap);
701
-        }
702
-    }
703
-
704
-
705
-    /**
706
-     * Wrapper for the native WP current_user_can() method.
707
-     * This is provided as a handy method for a couple things:
708
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
709
-     * write those filters wherever current_user_can is called).
710
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
711
-     *
712
-     * @since 4.5.0
713
-     *
714
-     * @param string $cap     The cap being checked.
715
-     * @param string $context The context where the current_user_can is being called from.
716
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
717
-     *                        filters.
718
-     *
719
-     * @return bool  Whether user can or not.
720
-     */
721
-    public function current_user_can($cap, $context, $id = 0)
722
-    {
723
-        //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
724
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
725
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap,
726
-            $id);
727
-        return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap);
728
-    }
729
-
730
-
731
-    /**
732
-     * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
733
-     *
734
-     * @param int|WP_User $user    Either the user_id or a WP_User object
735
-     * @param string      $cap     The capability string being checked
736
-     * @param string      $context The context where the user_can is being called from (used in filters).
737
-     * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
738
-     *                             filters)
739
-     *
740
-     * @return bool Whether user can or not.
741
-     */
742
-    public function user_can($user, $cap, $context, $id = 0)
743
-    {
744
-        //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
745
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
746
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user,
747
-            $id);
748
-        return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap);
749
-    }
750
-
751
-
752
-    /**
753
-     * Wrapper for the native WP current_user_can_for_blog() method.
754
-     * This is provided as a handy method for a couple things:
755
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
756
-     * write those filters wherever current_user_can is called).
757
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
758
-     *
759
-     * @since 4.5.0
760
-     *
761
-     * @param int    $blog_id The blog id that is being checked for.
762
-     * @param string $cap     The cap being checked.
763
-     * @param string $context The context where the current_user_can is being called from.
764
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
765
-     *                        filters.
766
-     *
767
-     * @return bool  Whether user can or not.
768
-     */
769
-    public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
770
-    {
771
-        $user_can = ! empty($id)
772
-            ? current_user_can_for_blog($blog_id, $cap, $id)
773
-            : current_user_can($blog_id, $cap);
774
-        //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
775
-        $user_can = apply_filters(
776
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
777
-            $user_can,
778
-            $blog_id,
779
-            $cap,
780
-            $id
781
-        );
782
-        $user_can = apply_filters(
783
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
784
-            $user_can,
785
-            $context,
786
-            $blog_id,
787
-            $cap,
788
-            $id
789
-        );
790
-        return $user_can;
791
-    }
792
-
793
-
794
-    /**
795
-     * This helper method just returns an array of registered EE capabilities.
796
-     * Note this array is filtered.  It is assumed that all available EE capabilities are assigned to the administrator
797
-     * role.
798
-     *
799
-     * @since 4.5.0
800
-     *
801
-     * @param string $role If empty then the entire role/capability map is returned.  Otherwise just the capabilities
802
-     *                     for the given role are returned.
803
-     *
804
-     * @return array
805
-     */
806
-    public function get_ee_capabilities($role = 'administrator')
807
-    {
808
-        $capabilities = $this->_init_caps_map();
809
-        if (empty($role)) {
810
-            return $capabilities;
811
-        }
812
-        return isset($capabilities[ $role ]) ? $capabilities[ $role ] : array();
813
-    }
20
+	/**
21
+	 * the name of the wp option used to store caps previously initialized
22
+	 */
23
+	const option_name = 'ee_caps_initialized';
24
+
25
+	/**
26
+	 * instance of EE_Capabilities object
27
+	 *
28
+	 * @var EE_Capabilities
29
+	 */
30
+	private static $_instance;
31
+
32
+
33
+	/**
34
+	 * This is a map of caps that correspond to a default WP_Role.
35
+	 * Array is indexed by Role and values are ee capabilities.
36
+	 *
37
+	 * @since 4.5.0
38
+	 *
39
+	 * @var array
40
+	 */
41
+	private $_caps_map = array();
42
+
43
+
44
+	/**
45
+	 * This used to hold an array of EE_Meta_Capability_Map objects that define the granular capabilities mapped to for
46
+	 * a user depending on context.
47
+	 *
48
+	 * @var EE_Meta_Capability_Map[]
49
+	 */
50
+	private $_meta_caps = array();
51
+
52
+
53
+	/**
54
+	 * singleton method used to instantiate class object
55
+	 *
56
+	 * @since 4.5.0
57
+	 *
58
+	 * @return EE_Capabilities
59
+	 */
60
+	public static function instance()
61
+	{
62
+		//check if instantiated, and if not do so.
63
+		if (! self::$_instance instanceof EE_Capabilities) {
64
+			self::$_instance = new self();
65
+		}
66
+		return self::$_instance;
67
+	}
68
+
69
+
70
+	/**
71
+	 * private constructor
72
+	 *
73
+	 * @since 4.5.0
74
+	 *
75
+	 * @return \EE_Capabilities
76
+	 */
77
+	private function __construct()
78
+	{
79
+	}
80
+
81
+
82
+	/**
83
+	 * This delays the initialization of the capabilities class until EE_System core is loaded and ready.
84
+	 *
85
+	 * @param bool $reset allows for resetting the default capabilities saved on roles.  Note that this doesn't
86
+	 *                    actually REMOVE any capabilities from existing roles, it just resaves defaults roles and
87
+	 *                    ensures that they are up to date.
88
+	 *
89
+	 *
90
+	 * @since 4.5.0
91
+	 * @return void
92
+	 */
93
+	public function init_caps($reset = false)
94
+	{
95
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
96
+			$this->_caps_map = $this->_init_caps_map();
97
+			$this->init_role_caps($reset);
98
+			$this->_set_meta_caps();
99
+		}
100
+	}
101
+
102
+
103
+	/**
104
+	 * This sets the meta caps property.
105
+	 * @since 4.5.0
106
+	 *
107
+	 * @return void
108
+	 */
109
+	private function _set_meta_caps()
110
+	{
111
+		//make sure we're only ever initializing the default _meta_caps array once if it's empty.
112
+		$this->_meta_caps = $this->_get_default_meta_caps_array();
113
+		$this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps);
114
+		//add filter for map_meta_caps but only if models can query.
115
+		if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
116
+			add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
117
+		}
118
+	}
119
+
120
+
121
+	/**
122
+	 * This builds and returns the default meta_caps array only once.
123
+	 *
124
+	 * @since  4.8.28.rc.012
125
+	 * @return array
126
+	 * @throws \EE_Error
127
+	 */
128
+	private function _get_default_meta_caps_array()
129
+	{
130
+		static $default_meta_caps = array();
131
+		if (empty($default_meta_caps)) {
132
+			$default_meta_caps = array(
133
+				//edits
134
+				new EE_Meta_Capability_Map_Edit(
135
+					'ee_edit_event',
136
+					array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')
137
+				),
138
+				new EE_Meta_Capability_Map_Edit(
139
+					'ee_edit_venue',
140
+					array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')
141
+				),
142
+				new EE_Meta_Capability_Map_Edit(
143
+					'ee_edit_registration',
144
+					array('Registration', '', 'ee_edit_others_registrations', '')
145
+				),
146
+				new EE_Meta_Capability_Map_Edit(
147
+					'ee_edit_checkin',
148
+					array('Registration', '', 'ee_edit_others_checkins', '')
149
+				),
150
+				new EE_Meta_Capability_Map_Messages_Cap(
151
+					'ee_edit_message',
152
+					array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')
153
+				),
154
+				new EE_Meta_Capability_Map_Edit(
155
+					'ee_edit_default_ticket',
156
+					array('Ticket', '', 'ee_edit_others_default_tickets', '')
157
+				),
158
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
159
+					'ee_edit_question',
160
+					array('Question', '', '', 'ee_edit_system_questions')
161
+				),
162
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
163
+					'ee_edit_question_group',
164
+					array('Question_Group', '', '', 'ee_edit_system_question_groups')
165
+				),
166
+				new EE_Meta_Capability_Map_Edit(
167
+					'ee_edit_payment_method',
168
+					array('Payment_Method', '', 'ee_edit_others_payment_methods', '')
169
+				),
170
+				//reads
171
+				new EE_Meta_Capability_Map_Read(
172
+					'ee_read_event',
173
+					array('Event', '', 'ee_read_others_events', 'ee_read_private_events')
174
+				),
175
+				new EE_Meta_Capability_Map_Read(
176
+					'ee_read_venue',
177
+					array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')
178
+				),
179
+				new EE_Meta_Capability_Map_Read(
180
+					'ee_read_registration',
181
+					array('Registration', '', '', 'ee_edit_others_registrations')
182
+				),
183
+				new EE_Meta_Capability_Map_Read(
184
+					'ee_read_checkin',
185
+					array('Registration', '', '', 'ee_read_others_checkins')
186
+				),
187
+				new EE_Meta_Capability_Map_Messages_Cap(
188
+					'ee_read_message',
189
+					array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')
190
+				),
191
+				new EE_Meta_Capability_Map_Read(
192
+					'ee_read_default_ticket',
193
+					array('Ticket', '', '', 'ee_read_others_default_tickets')
194
+				),
195
+				new EE_Meta_Capability_Map_Read(
196
+					'ee_read_payment_method',
197
+					array('Payment_Method', '', '', 'ee_read_others_payment_methods')),
198
+
199
+				//deletes
200
+				new EE_Meta_Capability_Map_Delete(
201
+					'ee_delete_event',
202
+					array(
203
+						'Event',
204
+						'ee_delete_published_events',
205
+						'ee_delete_others_events',
206
+						'ee_delete_private_events',
207
+					)
208
+				),
209
+				new EE_Meta_Capability_Map_Delete(
210
+					'ee_delete_venue',
211
+					array(
212
+						'Venue',
213
+						'ee_delete_published_venues',
214
+						'ee_delete_others_venues',
215
+						'ee_delete_private_venues',
216
+					)
217
+				),
218
+				new EE_Meta_Capability_Map_Delete(
219
+					'ee_delete_registration',
220
+					array('Registration', '', 'ee_delete_others_registrations', '')
221
+				),
222
+				new EE_Meta_Capability_Map_Delete(
223
+					'ee_delete_checkin',
224
+					array('Registration', '', 'ee_delete_others_checkins', '')
225
+				),
226
+				new EE_Meta_Capability_Map_Messages_Cap(
227
+					'ee_delete_message',
228
+					array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')
229
+				),
230
+				new EE_Meta_Capability_Map_Delete(
231
+					'ee_delete_default_ticket',
232
+					array('Ticket', '', 'ee_delete_others_default_tickets', '')
233
+				),
234
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
235
+					'ee_delete_question',
236
+					array('Question', '', '', 'delete_system_questions')
237
+				),
238
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
239
+					'ee_delete_question_group',
240
+					array('Question_Group', '', '', 'delete_system_question_groups')
241
+				),
242
+				new EE_Meta_Capability_Map_Delete(
243
+					'ee_delete_payment_method',
244
+					array('Payment_Method', '', 'ee_delete_others_payment_methods', '')
245
+				),
246
+			);
247
+		}
248
+		return $default_meta_caps;
249
+	}
250
+
251
+
252
+	/**
253
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
254
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
255
+	 *
256
+	 * The actual logic is carried out by implementer classes in their definition of _map_meta_caps.
257
+	 *
258
+	 * @since 4.5.0
259
+	 * @see   wp-includes/capabilities.php
260
+	 *
261
+	 * @param array  $caps    actual users capabilities
262
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
263
+	 * @param int    $user_id The user id
264
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
265
+	 * @return array actual users capabilities
266
+	 * @throws EE_Error
267
+	 */
268
+	public function map_meta_caps($caps, $cap, $user_id, $args)
269
+	{
270
+		if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
271
+			//loop through our _meta_caps array
272
+			foreach ($this->_meta_caps as $meta_map) {
273
+				if (! $meta_map instanceof EE_Meta_Capability_Map) {
274
+					continue;
275
+				}
276
+				// don't load models if there is no object ID in the args
277
+				if(!empty($args[0])){
278
+					$meta_map->ensure_is_model();
279
+				}
280
+				$caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
281
+			}
282
+		}
283
+		return $caps;
284
+	}
285
+
286
+
287
+	/**
288
+	 * This sets up and returns the initial capabilities map for Event Espresso
289
+	 *
290
+	 * @since 4.5.0
291
+	 *
292
+	 * @return array
293
+	 */
294
+	private function _init_caps_map()
295
+	{
296
+		$caps = array(
297
+			'administrator'           => array(
298
+				//basic access
299
+				'ee_read_ee',
300
+				//gateways
301
+				/**
302
+				 * note that with payment method capabilities, although we've implemented
303
+				 * capability mapping which will be used for accessing payment methods owned by
304
+				 * other users.  This is not fully implemented yet in the payment method ui.
305
+				 * Currently only the "plural" caps are in active use.
306
+				 * (Specific payment method caps are in use as well).
307
+				 **/
308
+				'ee_manage_gateways',
309
+				'ee_read_payment_method',
310
+				'ee_read_payment_methods',
311
+				'ee_read_others_payment_methods',
312
+				'ee_edit_payment_method',
313
+				'ee_edit_payment_methods',
314
+				'ee_edit_others_payment_methods',
315
+				'ee_delete_payment_method',
316
+				'ee_delete_payment_methods',
317
+				//events
318
+				'ee_publish_events',
319
+				'ee_read_private_events',
320
+				'ee_read_others_events',
321
+				'ee_read_event',
322
+				'ee_read_events',
323
+				'ee_edit_event',
324
+				'ee_edit_events',
325
+				'ee_edit_published_events',
326
+				'ee_edit_others_events',
327
+				'ee_edit_private_events',
328
+				'ee_delete_published_events',
329
+				'ee_delete_private_events',
330
+				'ee_delete_event',
331
+				'ee_delete_events',
332
+				'ee_delete_others_events',
333
+				//event categories
334
+				'ee_manage_event_categories',
335
+				'ee_edit_event_category',
336
+				'ee_delete_event_category',
337
+				'ee_assign_event_category',
338
+				//venues
339
+				'ee_publish_venues',
340
+				'ee_read_venue',
341
+				'ee_read_venues',
342
+				'ee_read_others_venues',
343
+				'ee_read_private_venues',
344
+				'ee_edit_venue',
345
+				'ee_edit_venues',
346
+				'ee_edit_others_venues',
347
+				'ee_edit_published_venues',
348
+				'ee_edit_private_venues',
349
+				'ee_delete_venue',
350
+				'ee_delete_venues',
351
+				'ee_delete_others_venues',
352
+				'ee_delete_private_venues',
353
+				'ee_delete_published_venues',
354
+				//venue categories
355
+				'ee_manage_venue_categories',
356
+				'ee_edit_venue_category',
357
+				'ee_delete_venue_category',
358
+				'ee_assign_venue_category',
359
+				//contacts
360
+				'ee_read_contact',
361
+				'ee_read_contacts',
362
+				'ee_edit_contact',
363
+				'ee_edit_contacts',
364
+				'ee_delete_contact',
365
+				'ee_delete_contacts',
366
+				//registrations
367
+				'ee_read_registration',
368
+				'ee_read_registrations',
369
+				'ee_read_others_registrations',
370
+				'ee_edit_registration',
371
+				'ee_edit_registrations',
372
+				'ee_edit_others_registrations',
373
+				'ee_delete_registration',
374
+				'ee_delete_registrations',
375
+				//checkins
376
+				'ee_read_checkin',
377
+				'ee_read_others_checkins',
378
+				'ee_read_checkins',
379
+				'ee_edit_checkin',
380
+				'ee_edit_checkins',
381
+				'ee_edit_others_checkins',
382
+				'ee_delete_checkin',
383
+				'ee_delete_checkins',
384
+				'ee_delete_others_checkins',
385
+				//transactions && payments
386
+				'ee_read_transaction',
387
+				'ee_read_transactions',
388
+				'ee_edit_payments',
389
+				'ee_delete_payments',
390
+				//messages
391
+				'ee_read_message',
392
+				'ee_read_messages',
393
+				'ee_read_others_messages',
394
+				'ee_read_global_messages',
395
+				'ee_edit_global_messages',
396
+				'ee_edit_message',
397
+				'ee_edit_messages',
398
+				'ee_edit_others_messages',
399
+				'ee_delete_message',
400
+				'ee_delete_messages',
401
+				'ee_delete_others_messages',
402
+				'ee_delete_global_messages',
403
+				'ee_send_message',
404
+				//tickets
405
+				'ee_read_default_ticket',
406
+				'ee_read_default_tickets',
407
+				'ee_read_others_default_tickets',
408
+				'ee_edit_default_ticket',
409
+				'ee_edit_default_tickets',
410
+				'ee_edit_others_default_tickets',
411
+				'ee_delete_default_ticket',
412
+				'ee_delete_default_tickets',
413
+				'ee_delete_others_default_tickets',
414
+				//prices
415
+				'ee_edit_default_price',
416
+				'ee_edit_default_prices',
417
+				'ee_delete_default_price',
418
+				'ee_delete_default_prices',
419
+				'ee_edit_default_price_type',
420
+				'ee_edit_default_price_types',
421
+				'ee_delete_default_price_type',
422
+				'ee_delete_default_price_types',
423
+				'ee_read_default_prices',
424
+				'ee_read_default_price_types',
425
+				//registration form
426
+				'ee_edit_question',
427
+				'ee_edit_questions',
428
+				'ee_edit_system_questions',
429
+				'ee_read_questions',
430
+				'ee_delete_question',
431
+				'ee_delete_questions',
432
+				'ee_edit_question_group',
433
+				'ee_edit_question_groups',
434
+				'ee_read_question_groups',
435
+				'ee_edit_system_question_groups',
436
+				'ee_delete_question_group',
437
+				'ee_delete_question_groups',
438
+				//event_type taxonomy
439
+				'ee_assign_event_type',
440
+				'ee_manage_event_types',
441
+				'ee_edit_event_type',
442
+				'ee_delete_event_type',
443
+			),
444
+			'ee_events_administrator' => array(
445
+				//core wp caps
446
+				'read',
447
+				'read_private_pages',
448
+				'read_private_posts',
449
+				'edit_users',
450
+				'edit_posts',
451
+				'edit_pages',
452
+				'edit_published_posts',
453
+				'edit_published_pages',
454
+				'edit_private_pages',
455
+				'edit_private_posts',
456
+				'edit_others_posts',
457
+				'edit_others_pages',
458
+				'publish_posts',
459
+				'publish_pages',
460
+				'delete_posts',
461
+				'delete_pages',
462
+				'delete_private_pages',
463
+				'delete_private_posts',
464
+				'delete_published_pages',
465
+				'delete_published_posts',
466
+				'delete_others_posts',
467
+				'delete_others_pages',
468
+				'manage_categories',
469
+				'manage_links',
470
+				'moderate_comments',
471
+				'unfiltered_html',
472
+				'upload_files',
473
+				'export',
474
+				'import',
475
+				'list_users',
476
+				'level_1', //required if user with this role shows up in author dropdowns
477
+				//basic ee access
478
+				'ee_read_ee',
479
+				//events
480
+				'ee_publish_events',
481
+				'ee_read_private_events',
482
+				'ee_read_others_events',
483
+				'ee_read_event',
484
+				'ee_read_events',
485
+				'ee_edit_event',
486
+				'ee_edit_events',
487
+				'ee_edit_published_events',
488
+				'ee_edit_others_events',
489
+				'ee_edit_private_events',
490
+				'ee_delete_published_events',
491
+				'ee_delete_private_events',
492
+				'ee_delete_event',
493
+				'ee_delete_events',
494
+				'ee_delete_others_events',
495
+				//event categories
496
+				'ee_manage_event_categories',
497
+				'ee_edit_event_category',
498
+				'ee_delete_event_category',
499
+				'ee_assign_event_category',
500
+				//venues
501
+				'ee_publish_venues',
502
+				'ee_read_venue',
503
+				'ee_read_venues',
504
+				'ee_read_others_venues',
505
+				'ee_read_private_venues',
506
+				'ee_edit_venue',
507
+				'ee_edit_venues',
508
+				'ee_edit_others_venues',
509
+				'ee_edit_published_venues',
510
+				'ee_edit_private_venues',
511
+				'ee_delete_venue',
512
+				'ee_delete_venues',
513
+				'ee_delete_others_venues',
514
+				'ee_delete_private_venues',
515
+				'ee_delete_published_venues',
516
+				//venue categories
517
+				'ee_manage_venue_categories',
518
+				'ee_edit_venue_category',
519
+				'ee_delete_venue_category',
520
+				'ee_assign_venue_category',
521
+				//contacts
522
+				'ee_read_contact',
523
+				'ee_read_contacts',
524
+				'ee_edit_contact',
525
+				'ee_edit_contacts',
526
+				'ee_delete_contact',
527
+				'ee_delete_contacts',
528
+				//registrations
529
+				'ee_read_registration',
530
+				'ee_read_registrations',
531
+				'ee_read_others_registrations',
532
+				'ee_edit_registration',
533
+				'ee_edit_registrations',
534
+				'ee_edit_others_registrations',
535
+				'ee_delete_registration',
536
+				'ee_delete_registrations',
537
+				//checkins
538
+				'ee_read_checkin',
539
+				'ee_read_others_checkins',
540
+				'ee_read_checkins',
541
+				'ee_edit_checkin',
542
+				'ee_edit_checkins',
543
+				'ee_edit_others_checkins',
544
+				'ee_delete_checkin',
545
+				'ee_delete_checkins',
546
+				'ee_delete_others_checkins',
547
+				//transactions && payments
548
+				'ee_read_transaction',
549
+				'ee_read_transactions',
550
+				'ee_edit_payments',
551
+				'ee_delete_payments',
552
+				//messages
553
+				'ee_read_message',
554
+				'ee_read_messages',
555
+				'ee_read_others_messages',
556
+				'ee_read_global_messages',
557
+				'ee_edit_global_messages',
558
+				'ee_edit_message',
559
+				'ee_edit_messages',
560
+				'ee_edit_others_messages',
561
+				'ee_delete_message',
562
+				'ee_delete_messages',
563
+				'ee_delete_others_messages',
564
+				'ee_delete_global_messages',
565
+				'ee_send_message',
566
+				//tickets
567
+				'ee_read_default_ticket',
568
+				'ee_read_default_tickets',
569
+				'ee_read_others_default_tickets',
570
+				'ee_edit_default_ticket',
571
+				'ee_edit_default_tickets',
572
+				'ee_edit_others_default_tickets',
573
+				'ee_delete_default_ticket',
574
+				'ee_delete_default_tickets',
575
+				'ee_delete_others_default_tickets',
576
+				//prices
577
+				'ee_edit_default_price',
578
+				'ee_edit_default_prices',
579
+				'ee_delete_default_price',
580
+				'ee_delete_default_prices',
581
+				'ee_edit_default_price_type',
582
+				'ee_edit_default_price_types',
583
+				'ee_delete_default_price_type',
584
+				'ee_delete_default_price_types',
585
+				'ee_read_default_prices',
586
+				'ee_read_default_price_types',
587
+				//registration form
588
+				'ee_edit_question',
589
+				'ee_edit_questions',
590
+				'ee_edit_system_questions',
591
+				'ee_read_questions',
592
+				'ee_delete_question',
593
+				'ee_delete_questions',
594
+				'ee_edit_question_group',
595
+				'ee_edit_question_groups',
596
+				'ee_read_question_groups',
597
+				'ee_edit_system_question_groups',
598
+				'ee_delete_question_group',
599
+				'ee_delete_question_groups',
600
+				//event_type taxonomy
601
+				'ee_assign_event_type',
602
+				'ee_manage_event_types',
603
+				'ee_edit_event_type',
604
+				'ee_delete_event_type',
605
+			)
606
+		);
607
+		$caps = apply_filters('FHEE__EE_Capabilities__init_caps_map__caps', $caps);
608
+		return $caps;
609
+	}
610
+
611
+
612
+	/**
613
+	 * This adds all the default caps to roles as registered in the _caps_map property.
614
+	 *
615
+	 * @since 4.5.0
616
+	 *
617
+	 * @param bool  $reset      allows for resetting the default capabilities saved on roles.  Note that this doesn't
618
+	 *                          actually REMOVE any capabilities from existing roles, it just resaves defaults roles
619
+	 *                          and ensures that they are up to date.
620
+	 * @param array $custom_map Optional.  Can be used to send a custom map of roles and capabilities for setting them
621
+	 *                          up.  Note that this should ONLY be called on activation hook or some other one-time
622
+	 *                          task otherwise the caps will be added on every request.
623
+	 *
624
+	 * @return void
625
+	 */
626
+	public function init_role_caps($reset = false, $custom_map = array())
627
+	{
628
+		$caps_map = empty($custom_map) ? $this->_caps_map : $custom_map;
629
+		//first let's determine if these caps have already been set.
630
+		$caps_set_before = get_option(self::option_name, array());
631
+		//if not reset, see what caps are new for each role. if they're new, add them.
632
+		foreach ($caps_map as $role => $caps_for_role) {
633
+			foreach ($caps_for_role as $cap) {
634
+				//first check we haven't already added this cap before, or it's a reset
635
+				if ($reset || ! isset($caps_set_before[ $role ]) || ! in_array($cap, $caps_set_before[ $role ])) {
636
+					if ($this->add_cap_to_role($role, $cap)) {
637
+						$caps_set_before[ $role ][] = $cap;
638
+					}
639
+				}
640
+			}
641
+		}
642
+		//now let's just save the cap that has been set.
643
+		update_option(self::option_name, $caps_set_before);
644
+		do_action('AHEE__EE_Capabilities__init_role_caps__complete', $caps_set_before);
645
+	}
646
+
647
+
648
+	/**
649
+	 * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
650
+	 * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
651
+	 * this is a wrapper for $wp_role->add_cap()
652
+	 *
653
+	 * @see   wp-includes/capabilities.php
654
+	 *
655
+	 * @since 4.5.0
656
+	 *
657
+	 * @param string $role  A WordPress role the capability is being added to
658
+	 * @param string $cap   The capability being added to the role
659
+	 * @param bool   $grant Whether to grant access to this cap on this role.
660
+	 *
661
+	 * @return bool
662
+	 */
663
+	public function add_cap_to_role($role, $cap, $grant = true)
664
+	{
665
+		$role_object = get_role($role);
666
+		//if the role isn't available then we create it.
667
+		if (! $role_object instanceof WP_Role) {
668
+			//if a plugin wants to create a specific role name then they should create the role before
669
+			//EE_Capabilities does.  Otherwise this function will create the role name from the slug:
670
+			// - removes any `ee_` namespacing from the start of the slug.
671
+			// - replaces `_` with ` ` (empty space).
672
+			// - sentence case on the resulting string.
673
+			$role_label = ucwords(str_replace('_', ' ', str_replace('ee_', '', $role)));
674
+			$role_object = add_role($role, $role_label);
675
+		}
676
+		if ($role_object instanceof WP_Role) {
677
+			$role_object->add_cap($cap, $grant);
678
+			return true;
679
+		}
680
+		return false;
681
+	}
682
+
683
+
684
+	/**
685
+	 * Functions similarly to add_cap_to_role except removes cap from given role.
686
+	 * Wrapper for $wp_role->remove_cap()
687
+	 *
688
+	 * @see   wp-includes/capabilities.php
689
+	 * @since 4.5.0
690
+	 *
691
+	 * @param string $role A WordPress role the capability is being removed from.
692
+	 * @param string $cap  The capability being removed
693
+	 *
694
+	 * @return void
695
+	 */
696
+	public function remove_cap_from_role($role, $cap)
697
+	{
698
+		$role = get_role($role);
699
+		if ($role instanceof WP_Role) {
700
+			$role->remove_cap($cap);
701
+		}
702
+	}
703
+
704
+
705
+	/**
706
+	 * Wrapper for the native WP current_user_can() method.
707
+	 * This is provided as a handy method for a couple things:
708
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
709
+	 * write those filters wherever current_user_can is called).
710
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
711
+	 *
712
+	 * @since 4.5.0
713
+	 *
714
+	 * @param string $cap     The cap being checked.
715
+	 * @param string $context The context where the current_user_can is being called from.
716
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
717
+	 *                        filters.
718
+	 *
719
+	 * @return bool  Whether user can or not.
720
+	 */
721
+	public function current_user_can($cap, $context, $id = 0)
722
+	{
723
+		//apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
724
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
725
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap,
726
+			$id);
727
+		return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap);
728
+	}
729
+
730
+
731
+	/**
732
+	 * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
733
+	 *
734
+	 * @param int|WP_User $user    Either the user_id or a WP_User object
735
+	 * @param string      $cap     The capability string being checked
736
+	 * @param string      $context The context where the user_can is being called from (used in filters).
737
+	 * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
738
+	 *                             filters)
739
+	 *
740
+	 * @return bool Whether user can or not.
741
+	 */
742
+	public function user_can($user, $cap, $context, $id = 0)
743
+	{
744
+		//apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
745
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
746
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user,
747
+			$id);
748
+		return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap);
749
+	}
750
+
751
+
752
+	/**
753
+	 * Wrapper for the native WP current_user_can_for_blog() method.
754
+	 * This is provided as a handy method for a couple things:
755
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
756
+	 * write those filters wherever current_user_can is called).
757
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
758
+	 *
759
+	 * @since 4.5.0
760
+	 *
761
+	 * @param int    $blog_id The blog id that is being checked for.
762
+	 * @param string $cap     The cap being checked.
763
+	 * @param string $context The context where the current_user_can is being called from.
764
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
765
+	 *                        filters.
766
+	 *
767
+	 * @return bool  Whether user can or not.
768
+	 */
769
+	public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
770
+	{
771
+		$user_can = ! empty($id)
772
+			? current_user_can_for_blog($blog_id, $cap, $id)
773
+			: current_user_can($blog_id, $cap);
774
+		//apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
775
+		$user_can = apply_filters(
776
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
777
+			$user_can,
778
+			$blog_id,
779
+			$cap,
780
+			$id
781
+		);
782
+		$user_can = apply_filters(
783
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
784
+			$user_can,
785
+			$context,
786
+			$blog_id,
787
+			$cap,
788
+			$id
789
+		);
790
+		return $user_can;
791
+	}
792
+
793
+
794
+	/**
795
+	 * This helper method just returns an array of registered EE capabilities.
796
+	 * Note this array is filtered.  It is assumed that all available EE capabilities are assigned to the administrator
797
+	 * role.
798
+	 *
799
+	 * @since 4.5.0
800
+	 *
801
+	 * @param string $role If empty then the entire role/capability map is returned.  Otherwise just the capabilities
802
+	 *                     for the given role are returned.
803
+	 *
804
+	 * @return array
805
+	 */
806
+	public function get_ee_capabilities($role = 'administrator')
807
+	{
808
+		$capabilities = $this->_init_caps_map();
809
+		if (empty($role)) {
810
+			return $capabilities;
811
+		}
812
+		return isset($capabilities[ $role ]) ? $capabilities[ $role ] : array();
813
+	}
814 814
 }
815 815
 
816 816
 
@@ -827,142 +827,142 @@  discard block
 block discarded – undo
827 827
 abstract class EE_Meta_Capability_Map
828 828
 {
829 829
 
830
-    public $meta_cap;
831
-
832
-    /**
833
-     * @var EEM_Base
834
-     */
835
-    protected $_model;
836
-
837
-    protected $_model_name;
838
-
839
-    public $published_cap = '';
840
-
841
-    public $others_cap = '';
842
-
843
-    public $private_cap = '';
844
-
845
-
846
-    /**
847
-     * constructor.
848
-     * Receives the setup arguments for the map.
849
-     *
850
-     * @since                        4.5.0
851
-     *
852
-     * @param string $meta_cap   What meta capability is this mapping.
853
-     * @param array  $map_values array {
854
-     *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
855
-     *                           capabilities that don't get mapped to.
856
-     *
857
-     * @type         $map_values [0] string A string representing the model name. Required.  String's
858
-     *                               should always be used when Menu Maps are registered via the
859
-     *                               plugin API as models are not allowed to be instantiated when
860
-     *                               in maintenance mode 2 (migrations).
861
-     * @type         $map_values [1] string represents the capability used for published. Optional.
862
-     * @type         $map_values [2] string represents the capability used for "others". Optional.
863
-     * @type         $map_values [3] string represents the capability used for private. Optional.
864
-     *                               }
865
-     * @throws EE_Error
866
-     */
867
-    public function __construct($meta_cap, $map_values)
868
-    {
869
-        $this->meta_cap = $meta_cap;
870
-        //verify there are four args in the $map_values array;
871
-        if (count($map_values) !== 4) {
872
-            throw new EE_Error(
873
-                sprintf(
874
-                    __(
875
-                        'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
876
-                        'event_espresso'
877
-                    ),
878
-                    '<br>' . print_r($map_values, true)
879
-                )
880
-            );
881
-        }
882
-        //set properties
883
-        $this->_model = null;
884
-        $this->_model_name = $map_values[0];
885
-        $this->published_cap = (string)$map_values[1];
886
-        $this->others_cap = (string)$map_values[2];
887
-        $this->private_cap = (string)$map_values[3];
888
-    }
889
-
890
-    /**
891
-     * Makes it so this object stops filtering caps
892
-     */
893
-    public function remove_filters()
894
-    {
895
-        remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
896
-    }
897
-
898
-
899
-    /**
900
-     * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
901
-     *
902
-     * @since 4.5.0
903
-     * @throws EE_Error
904
-     *
905
-     * @return void
906
-     */
907
-    public function ensure_is_model()
908
-    {
909
-        //is it already instantiated?
910
-        if ($this->_model instanceof EEM_Base) {
911
-            return;
912
-        }
913
-        //ensure model name is string
914
-        $this->_model_name = (string)$this->_model_name;
915
-        //error proof if the name has EEM in it
916
-        $this->_model_name = str_replace('EEM', '', $this->_model_name);
917
-        $this->_model = EE_Registry::instance()->load_model($this->_model_name);
918
-        if (! $this->_model instanceof EEM_Base) {
919
-            throw new EE_Error(
920
-                sprintf(
921
-                    __(
922
-                        'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class.   Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s',
923
-                        'event_espresso'
924
-                    ),
925
-                    get_class($this),
926
-                    $this->_model
927
-                )
928
-            );
929
-        }
930
-    }
931
-
932
-
933
-    /**
934
-     *
935
-     * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
936
-     * @since 4.6.x
937
-     *
938
-     * @param $caps
939
-     * @param $cap
940
-     * @param $user_id
941
-     * @param $args
942
-     *
943
-     * @return array
944
-     */
945
-    public function map_meta_caps($caps, $cap, $user_id, $args)
946
-    {
947
-        return $this->_map_meta_caps($caps, $cap, $user_id, $args);
948
-    }
949
-
950
-
951
-    /**
952
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
953
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
954
-     *
955
-     * @since 4.5.0
956
-     * @see   wp-includes/capabilities.php
957
-     *
958
-     * @param array  $caps    actual users capabilities
959
-     * @param string $cap     initial capability name that is being checked (the "map" key)
960
-     * @param int    $user_id The user id
961
-     * @param array  $args    Adds context to the cap. Typically the object ID.
962
-     *
963
-     * @return array   actual users capabilities
964
-     */
965
-    abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
830
+	public $meta_cap;
831
+
832
+	/**
833
+	 * @var EEM_Base
834
+	 */
835
+	protected $_model;
836
+
837
+	protected $_model_name;
838
+
839
+	public $published_cap = '';
840
+
841
+	public $others_cap = '';
842
+
843
+	public $private_cap = '';
844
+
845
+
846
+	/**
847
+	 * constructor.
848
+	 * Receives the setup arguments for the map.
849
+	 *
850
+	 * @since                        4.5.0
851
+	 *
852
+	 * @param string $meta_cap   What meta capability is this mapping.
853
+	 * @param array  $map_values array {
854
+	 *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
855
+	 *                           capabilities that don't get mapped to.
856
+	 *
857
+	 * @type         $map_values [0] string A string representing the model name. Required.  String's
858
+	 *                               should always be used when Menu Maps are registered via the
859
+	 *                               plugin API as models are not allowed to be instantiated when
860
+	 *                               in maintenance mode 2 (migrations).
861
+	 * @type         $map_values [1] string represents the capability used for published. Optional.
862
+	 * @type         $map_values [2] string represents the capability used for "others". Optional.
863
+	 * @type         $map_values [3] string represents the capability used for private. Optional.
864
+	 *                               }
865
+	 * @throws EE_Error
866
+	 */
867
+	public function __construct($meta_cap, $map_values)
868
+	{
869
+		$this->meta_cap = $meta_cap;
870
+		//verify there are four args in the $map_values array;
871
+		if (count($map_values) !== 4) {
872
+			throw new EE_Error(
873
+				sprintf(
874
+					__(
875
+						'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
876
+						'event_espresso'
877
+					),
878
+					'<br>' . print_r($map_values, true)
879
+				)
880
+			);
881
+		}
882
+		//set properties
883
+		$this->_model = null;
884
+		$this->_model_name = $map_values[0];
885
+		$this->published_cap = (string)$map_values[1];
886
+		$this->others_cap = (string)$map_values[2];
887
+		$this->private_cap = (string)$map_values[3];
888
+	}
889
+
890
+	/**
891
+	 * Makes it so this object stops filtering caps
892
+	 */
893
+	public function remove_filters()
894
+	{
895
+		remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
896
+	}
897
+
898
+
899
+	/**
900
+	 * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
901
+	 *
902
+	 * @since 4.5.0
903
+	 * @throws EE_Error
904
+	 *
905
+	 * @return void
906
+	 */
907
+	public function ensure_is_model()
908
+	{
909
+		//is it already instantiated?
910
+		if ($this->_model instanceof EEM_Base) {
911
+			return;
912
+		}
913
+		//ensure model name is string
914
+		$this->_model_name = (string)$this->_model_name;
915
+		//error proof if the name has EEM in it
916
+		$this->_model_name = str_replace('EEM', '', $this->_model_name);
917
+		$this->_model = EE_Registry::instance()->load_model($this->_model_name);
918
+		if (! $this->_model instanceof EEM_Base) {
919
+			throw new EE_Error(
920
+				sprintf(
921
+					__(
922
+						'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class.   Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s',
923
+						'event_espresso'
924
+					),
925
+					get_class($this),
926
+					$this->_model
927
+				)
928
+			);
929
+		}
930
+	}
931
+
932
+
933
+	/**
934
+	 *
935
+	 * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
936
+	 * @since 4.6.x
937
+	 *
938
+	 * @param $caps
939
+	 * @param $cap
940
+	 * @param $user_id
941
+	 * @param $args
942
+	 *
943
+	 * @return array
944
+	 */
945
+	public function map_meta_caps($caps, $cap, $user_id, $args)
946
+	{
947
+		return $this->_map_meta_caps($caps, $cap, $user_id, $args);
948
+	}
949
+
950
+
951
+	/**
952
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
953
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
954
+	 *
955
+	 * @since 4.5.0
956
+	 * @see   wp-includes/capabilities.php
957
+	 *
958
+	 * @param array  $caps    actual users capabilities
959
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
960
+	 * @param int    $user_id The user id
961
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
962
+	 *
963
+	 * @return array   actual users capabilities
964
+	 */
965
+	abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
966 966
 }
967 967
 
968 968
 
@@ -978,83 +978,83 @@  discard block
 block discarded – undo
978 978
 class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map
979 979
 {
980 980
 
981
-    /**
982
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
983
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
984
-     *
985
-     * @since 4.5.0
986
-     * @see   wp-includes/capabilities.php
987
-     *
988
-     * @param array  $caps    actual users capabilities
989
-     * @param string $cap     initial capability name that is being checked (the "map" key)
990
-     * @param int    $user_id The user id
991
-     * @param array  $args    Adds context to the cap. Typically the object ID.
992
-     *
993
-     * @return array   actual users capabilities
994
-     */
995
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
996
-    {
997
-        //only process if we're checking our mapped_cap
998
-        if ($cap !== $this->meta_cap) {
999
-            return $caps;
1000
-        }
1001
-
1002
-        //cast $user_id to int for later explicit comparisons
1003
-        $user_id = (int) $user_id;
1004
-
1005
-        /** @var EE_Base_Class $obj */
1006
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1007
-        //if no obj then let's just do cap
1008
-        if (! $obj instanceof EE_Base_Class) {
1009
-            $caps[] = $cap;
1010
-            return $caps;
1011
-        }
1012
-        if ($obj instanceof EE_CPT_Base) {
1013
-            //if the item author is set and the user is the author...
1014
-            if ($obj->wp_user() && $user_id === $obj->wp_user()) {
1015
-                if (empty($this->published_cap)) {
1016
-                    $caps[] = $cap;
1017
-                } else {
1018
-                    //if obj is published...
1019
-                    if ($obj->status() === 'publish') {
1020
-                        $caps[] = $this->published_cap;
1021
-                    } else {
1022
-                        $caps[] = $cap;
1023
-                    }
1024
-                }
1025
-            } else {
1026
-                //the user is trying to edit someone else's obj
1027
-                if (! empty($this->others_cap)) {
1028
-                    $caps[] = $this->others_cap;
1029
-                }
1030
-                if (! empty($this->published_cap) && $obj->status() === 'publish') {
1031
-                    $caps[] = $this->published_cap;
1032
-                } elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1033
-                    $caps[] = $this->private_cap;
1034
-                }
1035
-            }
1036
-        } else {
1037
-            //not a cpt object so handled differently
1038
-            $has_cap = false;
1039
-            try {
1040
-                $has_cap = method_exists($obj, 'wp_user')
1041
-                    && $obj->wp_user()
1042
-                    && $obj->wp_user() === $user_id;
1043
-            } catch (Exception $e) {
1044
-                if (WP_DEBUG) {
1045
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1046
-                }
1047
-            }
1048
-            if ($has_cap) {
1049
-                $caps[] = $cap;
1050
-            } else {
1051
-                if (! empty($this->others_cap)) {
1052
-                    $caps[] = $this->others_cap;
1053
-                }
1054
-            }
1055
-        }
1056
-        return $caps;
1057
-    }
981
+	/**
982
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
983
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
984
+	 *
985
+	 * @since 4.5.0
986
+	 * @see   wp-includes/capabilities.php
987
+	 *
988
+	 * @param array  $caps    actual users capabilities
989
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
990
+	 * @param int    $user_id The user id
991
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
992
+	 *
993
+	 * @return array   actual users capabilities
994
+	 */
995
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
996
+	{
997
+		//only process if we're checking our mapped_cap
998
+		if ($cap !== $this->meta_cap) {
999
+			return $caps;
1000
+		}
1001
+
1002
+		//cast $user_id to int for later explicit comparisons
1003
+		$user_id = (int) $user_id;
1004
+
1005
+		/** @var EE_Base_Class $obj */
1006
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1007
+		//if no obj then let's just do cap
1008
+		if (! $obj instanceof EE_Base_Class) {
1009
+			$caps[] = $cap;
1010
+			return $caps;
1011
+		}
1012
+		if ($obj instanceof EE_CPT_Base) {
1013
+			//if the item author is set and the user is the author...
1014
+			if ($obj->wp_user() && $user_id === $obj->wp_user()) {
1015
+				if (empty($this->published_cap)) {
1016
+					$caps[] = $cap;
1017
+				} else {
1018
+					//if obj is published...
1019
+					if ($obj->status() === 'publish') {
1020
+						$caps[] = $this->published_cap;
1021
+					} else {
1022
+						$caps[] = $cap;
1023
+					}
1024
+				}
1025
+			} else {
1026
+				//the user is trying to edit someone else's obj
1027
+				if (! empty($this->others_cap)) {
1028
+					$caps[] = $this->others_cap;
1029
+				}
1030
+				if (! empty($this->published_cap) && $obj->status() === 'publish') {
1031
+					$caps[] = $this->published_cap;
1032
+				} elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1033
+					$caps[] = $this->private_cap;
1034
+				}
1035
+			}
1036
+		} else {
1037
+			//not a cpt object so handled differently
1038
+			$has_cap = false;
1039
+			try {
1040
+				$has_cap = method_exists($obj, 'wp_user')
1041
+					&& $obj->wp_user()
1042
+					&& $obj->wp_user() === $user_id;
1043
+			} catch (Exception $e) {
1044
+				if (WP_DEBUG) {
1045
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1046
+				}
1047
+			}
1048
+			if ($has_cap) {
1049
+				$caps[] = $cap;
1050
+			} else {
1051
+				if (! empty($this->others_cap)) {
1052
+					$caps[] = $this->others_cap;
1053
+				}
1054
+			}
1055
+		}
1056
+		return $caps;
1057
+	}
1058 1058
 }
1059 1059
 
1060 1060
 
@@ -1071,24 +1071,24 @@  discard block
 block discarded – undo
1071 1071
 class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit
1072 1072
 {
1073 1073
 
1074
-    /**
1075
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1076
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1077
-     *
1078
-     * @since 4.5.0
1079
-     * @see   wp-includes/capabilities.php
1080
-     *
1081
-     * @param array  $caps    actual users capabilities
1082
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1083
-     * @param int    $user_id The user id
1084
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1085
-     *
1086
-     * @return array   actual users capabilities
1087
-     */
1088
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1089
-    {
1090
-        return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1091
-    }
1074
+	/**
1075
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1076
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1077
+	 *
1078
+	 * @since 4.5.0
1079
+	 * @see   wp-includes/capabilities.php
1080
+	 *
1081
+	 * @param array  $caps    actual users capabilities
1082
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1083
+	 * @param int    $user_id The user id
1084
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1085
+	 *
1086
+	 * @return array   actual users capabilities
1087
+	 */
1088
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1089
+	{
1090
+		return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1091
+	}
1092 1092
 }
1093 1093
 
1094 1094
 
@@ -1104,75 +1104,75 @@  discard block
 block discarded – undo
1104 1104
 class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map
1105 1105
 {
1106 1106
 
1107
-    /**
1108
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1109
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1110
-     *
1111
-     * @since 4.5.0
1112
-     * @see   wp-includes/capabilities.php
1113
-     *
1114
-     * @param array  $caps    actual users capabilities
1115
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1116
-     * @param int    $user_id The user id
1117
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1118
-     *
1119
-     * @return array   actual users capabilities
1120
-     */
1121
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1122
-    {
1123
-        //only process if we're checking our mapped cap;
1124
-        if ($cap !== $this->meta_cap) {
1125
-            return $caps;
1126
-        }
1127
-
1128
-        //cast $user_id to int for later explicit comparisons
1129
-        $user_id = (int) $user_id;
1130
-
1131
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1132
-        //if no obj then let's just do cap
1133
-        if (! $obj instanceof EE_Base_Class) {
1134
-            $caps[] = $cap;
1135
-            return $caps;
1136
-        }
1137
-        if ($obj instanceof EE_CPT_Base) {
1138
-            $status_obj = get_post_status_object($obj->status());
1139
-            if ($status_obj->public) {
1140
-                $caps[] = $cap;
1141
-                return $caps;
1142
-            }
1143
-            //if the item author is set and the user is the author...
1144
-            if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1145
-                $caps[] = $cap;
1146
-            } elseif ($status_obj->private && ! empty($this->private_cap)) {
1147
-                //the user is trying to view someone else's obj
1148
-                $caps[] = $this->private_cap;
1149
-            } elseif (! empty($this->others_cap)) {
1150
-                $caps[] = $this->others_cap;
1151
-            } else {
1152
-                $caps[] = $cap;
1153
-            }
1154
-        } else {
1155
-            //not a cpt object so handled differently
1156
-            $has_cap = false;
1157
-            try {
1158
-                $has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $obj->wp_user() === $user_id;
1159
-            } catch (Exception $e) {
1160
-                if (WP_DEBUG) {
1161
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1162
-                }
1163
-            }
1164
-            if ($has_cap) {
1165
-                $caps[] = $cap;
1166
-            } elseif (! empty($this->private_cap)) {
1167
-                $caps[] = $this->private_cap;
1168
-            } elseif (! empty($this->others_cap)) {
1169
-                $caps[] = $this->others_cap;
1170
-            } else {
1171
-                $caps[] = $cap;
1172
-            }
1173
-        }
1174
-        return $caps;
1175
-    }
1107
+	/**
1108
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1109
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1110
+	 *
1111
+	 * @since 4.5.0
1112
+	 * @see   wp-includes/capabilities.php
1113
+	 *
1114
+	 * @param array  $caps    actual users capabilities
1115
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1116
+	 * @param int    $user_id The user id
1117
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1118
+	 *
1119
+	 * @return array   actual users capabilities
1120
+	 */
1121
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1122
+	{
1123
+		//only process if we're checking our mapped cap;
1124
+		if ($cap !== $this->meta_cap) {
1125
+			return $caps;
1126
+		}
1127
+
1128
+		//cast $user_id to int for later explicit comparisons
1129
+		$user_id = (int) $user_id;
1130
+
1131
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1132
+		//if no obj then let's just do cap
1133
+		if (! $obj instanceof EE_Base_Class) {
1134
+			$caps[] = $cap;
1135
+			return $caps;
1136
+		}
1137
+		if ($obj instanceof EE_CPT_Base) {
1138
+			$status_obj = get_post_status_object($obj->status());
1139
+			if ($status_obj->public) {
1140
+				$caps[] = $cap;
1141
+				return $caps;
1142
+			}
1143
+			//if the item author is set and the user is the author...
1144
+			if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1145
+				$caps[] = $cap;
1146
+			} elseif ($status_obj->private && ! empty($this->private_cap)) {
1147
+				//the user is trying to view someone else's obj
1148
+				$caps[] = $this->private_cap;
1149
+			} elseif (! empty($this->others_cap)) {
1150
+				$caps[] = $this->others_cap;
1151
+			} else {
1152
+				$caps[] = $cap;
1153
+			}
1154
+		} else {
1155
+			//not a cpt object so handled differently
1156
+			$has_cap = false;
1157
+			try {
1158
+				$has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $obj->wp_user() === $user_id;
1159
+			} catch (Exception $e) {
1160
+				if (WP_DEBUG) {
1161
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1162
+				}
1163
+			}
1164
+			if ($has_cap) {
1165
+				$caps[] = $cap;
1166
+			} elseif (! empty($this->private_cap)) {
1167
+				$caps[] = $this->private_cap;
1168
+			} elseif (! empty($this->others_cap)) {
1169
+				$caps[] = $this->others_cap;
1170
+			} else {
1171
+				$caps[] = $cap;
1172
+			}
1173
+		}
1174
+		return $caps;
1175
+	}
1176 1176
 }
1177 1177
 
1178 1178
 
@@ -1189,52 +1189,52 @@  discard block
 block discarded – undo
1189 1189
 class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map
1190 1190
 {
1191 1191
 
1192
-    /**
1193
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1194
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1195
-     *
1196
-     * @since 4.5.0
1197
-     * @see   wp-includes/capabilities.php
1198
-     *
1199
-     * @param array  $caps    actual users capabilities
1200
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1201
-     * @param int    $user_id The user id
1202
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1203
-     *
1204
-     * @return array   actual users capabilities
1205
-     */
1206
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1207
-    {
1208
-        //only process if we're checking our mapped_cap
1209
-        if ($cap !== $this->meta_cap) {
1210
-            return $caps;
1211
-        }
1212
-
1213
-        //cast $user_id to int for later explicit comparisons
1214
-        $user_id = (int) $user_id;
1215
-
1216
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1217
-        //if no obj then let's just do cap
1218
-        if (! $obj instanceof EE_Message_Template_Group) {
1219
-            $caps[] = $cap;
1220
-            return $caps;
1221
-        }
1222
-        $is_global = $obj->is_global();
1223
-        if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1224
-            if ($is_global) {
1225
-                $caps[] = $this->private_cap;
1226
-            } else {
1227
-                $caps[] = $cap;
1228
-            }
1229
-        } else {
1230
-            if ($is_global) {
1231
-                $caps[] = $this->private_cap;
1232
-            } else {
1233
-                $caps[] = $this->others_cap;
1234
-            }
1235
-        }
1236
-        return $caps;
1237
-    }
1192
+	/**
1193
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1194
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1195
+	 *
1196
+	 * @since 4.5.0
1197
+	 * @see   wp-includes/capabilities.php
1198
+	 *
1199
+	 * @param array  $caps    actual users capabilities
1200
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1201
+	 * @param int    $user_id The user id
1202
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1203
+	 *
1204
+	 * @return array   actual users capabilities
1205
+	 */
1206
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1207
+	{
1208
+		//only process if we're checking our mapped_cap
1209
+		if ($cap !== $this->meta_cap) {
1210
+			return $caps;
1211
+		}
1212
+
1213
+		//cast $user_id to int for later explicit comparisons
1214
+		$user_id = (int) $user_id;
1215
+
1216
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1217
+		//if no obj then let's just do cap
1218
+		if (! $obj instanceof EE_Message_Template_Group) {
1219
+			$caps[] = $cap;
1220
+			return $caps;
1221
+		}
1222
+		$is_global = $obj->is_global();
1223
+		if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1224
+			if ($is_global) {
1225
+				$caps[] = $this->private_cap;
1226
+			} else {
1227
+				$caps[] = $cap;
1228
+			}
1229
+		} else {
1230
+			if ($is_global) {
1231
+				$caps[] = $this->private_cap;
1232
+			} else {
1233
+				$caps[] = $this->others_cap;
1234
+			}
1235
+		}
1236
+		return $caps;
1237
+	}
1238 1238
 }
1239 1239
 
1240 1240
 
@@ -1251,41 +1251,41 @@  discard block
 block discarded – undo
1251 1251
 class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map
1252 1252
 {
1253 1253
 
1254
-    /**
1255
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1256
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1257
-     *
1258
-     * @since 4.5.0
1259
-     * @see   wp-includes/capabilities.php
1260
-     *
1261
-     * @param array  $caps    actual users capabilities
1262
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1263
-     * @param int    $user_id The user id
1264
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1265
-     *
1266
-     * @return array   actual users capabilities
1267
-     */
1268
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1269
-    {
1270
-        //only process if we're checking our mapped_cap
1271
-        if ($cap !== $this->meta_cap) {
1272
-            return $caps;
1273
-        }
1274
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1275
-        //if no obj then let's just do cap
1276
-        if (! $obj instanceof EE_Base_Class) {
1277
-            $caps[] = $cap;
1278
-            return $caps;
1279
-        }
1280
-        $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1281
-        $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1282
-        if ($is_system) {
1283
-            $caps[] = $this->private_cap;
1284
-        } else {
1285
-            $caps[] = $cap;
1286
-        }
1287
-        return $caps;
1288
-    }
1254
+	/**
1255
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1256
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1257
+	 *
1258
+	 * @since 4.5.0
1259
+	 * @see   wp-includes/capabilities.php
1260
+	 *
1261
+	 * @param array  $caps    actual users capabilities
1262
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1263
+	 * @param int    $user_id The user id
1264
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1265
+	 *
1266
+	 * @return array   actual users capabilities
1267
+	 */
1268
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1269
+	{
1270
+		//only process if we're checking our mapped_cap
1271
+		if ($cap !== $this->meta_cap) {
1272
+			return $caps;
1273
+		}
1274
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1275
+		//if no obj then let's just do cap
1276
+		if (! $obj instanceof EE_Base_Class) {
1277
+			$caps[] = $cap;
1278
+			return $caps;
1279
+		}
1280
+		$is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1281
+		$is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1282
+		if ($is_system) {
1283
+			$caps[] = $this->private_cap;
1284
+		} else {
1285
+			$caps[] = $cap;
1286
+		}
1287
+		return $caps;
1288
+	}
1289 1289
 
1290 1290
 
1291 1291
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
     public static function instance()
61 61
     {
62 62
         //check if instantiated, and if not do so.
63
-        if (! self::$_instance instanceof EE_Capabilities) {
63
+        if ( ! self::$_instance instanceof EE_Capabilities) {
64 64
             self::$_instance = new self();
65 65
         }
66 66
         return self::$_instance;
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         $this->_meta_caps = $this->_get_default_meta_caps_array();
113 113
         $this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps);
114 114
         //add filter for map_meta_caps but only if models can query.
115
-        if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
115
+        if ( ! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
116 116
             add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
117 117
         }
118 118
     }
@@ -270,11 +270,11 @@  discard block
 block discarded – undo
270 270
         if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
271 271
             //loop through our _meta_caps array
272 272
             foreach ($this->_meta_caps as $meta_map) {
273
-                if (! $meta_map instanceof EE_Meta_Capability_Map) {
273
+                if ( ! $meta_map instanceof EE_Meta_Capability_Map) {
274 274
                     continue;
275 275
                 }
276 276
                 // don't load models if there is no object ID in the args
277
-                if(!empty($args[0])){
277
+                if ( ! empty($args[0])) {
278 278
                     $meta_map->ensure_is_model();
279 279
                 }
280 280
                 $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
@@ -632,9 +632,9 @@  discard block
 block discarded – undo
632 632
         foreach ($caps_map as $role => $caps_for_role) {
633 633
             foreach ($caps_for_role as $cap) {
634 634
                 //first check we haven't already added this cap before, or it's a reset
635
-                if ($reset || ! isset($caps_set_before[ $role ]) || ! in_array($cap, $caps_set_before[ $role ])) {
635
+                if ($reset || ! isset($caps_set_before[$role]) || ! in_array($cap, $caps_set_before[$role])) {
636 636
                     if ($this->add_cap_to_role($role, $cap)) {
637
-                        $caps_set_before[ $role ][] = $cap;
637
+                        $caps_set_before[$role][] = $cap;
638 638
                     }
639 639
                 }
640 640
             }
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
     {
665 665
         $role_object = get_role($role);
666 666
         //if the role isn't available then we create it.
667
-        if (! $role_object instanceof WP_Role) {
667
+        if ( ! $role_object instanceof WP_Role) {
668 668
             //if a plugin wants to create a specific role name then they should create the role before
669 669
             //EE_Capabilities does.  Otherwise this function will create the role name from the slug:
670 670
             // - removes any `ee_` namespacing from the start of the slug.
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
     public function current_user_can($cap, $context, $id = 0)
722 722
     {
723 723
         //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
724
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
724
+        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__'.$context, $cap, $id);
725 725
         $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap,
726 726
             $id);
727 727
         return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap);
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
     public function user_can($user, $cap, $context, $id = 0)
743 743
     {
744 744
         //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
745
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
745
+        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__'.$context, $cap, $user, $id);
746 746
         $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user,
747 747
             $id);
748 748
         return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap);
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
             : current_user_can($blog_id, $cap);
774 774
         //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
775 775
         $user_can = apply_filters(
776
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
776
+            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__'.$context,
777 777
             $user_can,
778 778
             $blog_id,
779 779
             $cap,
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
         if (empty($role)) {
810 810
             return $capabilities;
811 811
         }
812
-        return isset($capabilities[ $role ]) ? $capabilities[ $role ] : array();
812
+        return isset($capabilities[$role]) ? $capabilities[$role] : array();
813 813
     }
814 814
 }
815 815
 
@@ -875,16 +875,16 @@  discard block
 block discarded – undo
875 875
                         'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
876 876
                         'event_espresso'
877 877
                     ),
878
-                    '<br>' . print_r($map_values, true)
878
+                    '<br>'.print_r($map_values, true)
879 879
                 )
880 880
             );
881 881
         }
882 882
         //set properties
883 883
         $this->_model = null;
884 884
         $this->_model_name = $map_values[0];
885
-        $this->published_cap = (string)$map_values[1];
886
-        $this->others_cap = (string)$map_values[2];
887
-        $this->private_cap = (string)$map_values[3];
885
+        $this->published_cap = (string) $map_values[1];
886
+        $this->others_cap = (string) $map_values[2];
887
+        $this->private_cap = (string) $map_values[3];
888 888
     }
889 889
 
890 890
     /**
@@ -911,11 +911,11 @@  discard block
 block discarded – undo
911 911
             return;
912 912
         }
913 913
         //ensure model name is string
914
-        $this->_model_name = (string)$this->_model_name;
914
+        $this->_model_name = (string) $this->_model_name;
915 915
         //error proof if the name has EEM in it
916 916
         $this->_model_name = str_replace('EEM', '', $this->_model_name);
917 917
         $this->_model = EE_Registry::instance()->load_model($this->_model_name);
918
-        if (! $this->_model instanceof EEM_Base) {
918
+        if ( ! $this->_model instanceof EEM_Base) {
919 919
             throw new EE_Error(
920 920
                 sprintf(
921 921
                     __(
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
         /** @var EE_Base_Class $obj */
1006 1006
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1007 1007
         //if no obj then let's just do cap
1008
-        if (! $obj instanceof EE_Base_Class) {
1008
+        if ( ! $obj instanceof EE_Base_Class) {
1009 1009
             $caps[] = $cap;
1010 1010
             return $caps;
1011 1011
         }
@@ -1024,12 +1024,12 @@  discard block
 block discarded – undo
1024 1024
                 }
1025 1025
             } else {
1026 1026
                 //the user is trying to edit someone else's obj
1027
-                if (! empty($this->others_cap)) {
1027
+                if ( ! empty($this->others_cap)) {
1028 1028
                     $caps[] = $this->others_cap;
1029 1029
                 }
1030
-                if (! empty($this->published_cap) && $obj->status() === 'publish') {
1030
+                if ( ! empty($this->published_cap) && $obj->status() === 'publish') {
1031 1031
                     $caps[] = $this->published_cap;
1032
-                } elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1032
+                } elseif ( ! empty($this->private_cap) && $obj->status() === 'private') {
1033 1033
                     $caps[] = $this->private_cap;
1034 1034
                 }
1035 1035
             }
@@ -1048,7 +1048,7 @@  discard block
 block discarded – undo
1048 1048
             if ($has_cap) {
1049 1049
                 $caps[] = $cap;
1050 1050
             } else {
1051
-                if (! empty($this->others_cap)) {
1051
+                if ( ! empty($this->others_cap)) {
1052 1052
                     $caps[] = $this->others_cap;
1053 1053
                 }
1054 1054
             }
@@ -1130,7 +1130,7 @@  discard block
 block discarded – undo
1130 1130
 
1131 1131
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1132 1132
         //if no obj then let's just do cap
1133
-        if (! $obj instanceof EE_Base_Class) {
1133
+        if ( ! $obj instanceof EE_Base_Class) {
1134 1134
             $caps[] = $cap;
1135 1135
             return $caps;
1136 1136
         }
@@ -1146,7 +1146,7 @@  discard block
 block discarded – undo
1146 1146
             } elseif ($status_obj->private && ! empty($this->private_cap)) {
1147 1147
                 //the user is trying to view someone else's obj
1148 1148
                 $caps[] = $this->private_cap;
1149
-            } elseif (! empty($this->others_cap)) {
1149
+            } elseif ( ! empty($this->others_cap)) {
1150 1150
                 $caps[] = $this->others_cap;
1151 1151
             } else {
1152 1152
                 $caps[] = $cap;
@@ -1163,9 +1163,9 @@  discard block
 block discarded – undo
1163 1163
             }
1164 1164
             if ($has_cap) {
1165 1165
                 $caps[] = $cap;
1166
-            } elseif (! empty($this->private_cap)) {
1166
+            } elseif ( ! empty($this->private_cap)) {
1167 1167
                 $caps[] = $this->private_cap;
1168
-            } elseif (! empty($this->others_cap)) {
1168
+            } elseif ( ! empty($this->others_cap)) {
1169 1169
                 $caps[] = $this->others_cap;
1170 1170
             } else {
1171 1171
                 $caps[] = $cap;
@@ -1215,7 +1215,7 @@  discard block
 block discarded – undo
1215 1215
 
1216 1216
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1217 1217
         //if no obj then let's just do cap
1218
-        if (! $obj instanceof EE_Message_Template_Group) {
1218
+        if ( ! $obj instanceof EE_Message_Template_Group) {
1219 1219
             $caps[] = $cap;
1220 1220
             return $caps;
1221 1221
         }
@@ -1273,7 +1273,7 @@  discard block
 block discarded – undo
1273 1273
         }
1274 1274
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1275 1275
         //if no obj then let's just do cap
1276
-        if (! $obj instanceof EE_Base_Class) {
1276
+        if ( ! $obj instanceof EE_Base_Class) {
1277 1277
             $caps[] = $cap;
1278 1278
             return $caps;
1279 1279
         }
Please login to merge, or discard this patch.
caffeinated/brewing_regular.php 1 patch
Indentation   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\services\database\TableAnalysis;
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
  * the purpose of this file is to simply contain any action/filter hook callbacks etc for specific aspects of EE
@@ -27,277 +27,277 @@  discard block
 block discarded – undo
27 27
 class EE_Brewing_Regular extends EE_BASE
28 28
 {
29 29
 
30
-    /**
31
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
32
-     */
33
-    protected $_table_analysis;
34
-
35
-
36
-
37
-    /**
38
-     * EE_Brewing_Regular constructor.
39
-     */
40
-    public function __construct(TableAnalysis $table_analysis)
41
-    {
42
-        $this->_table_analysis = $table_analysis;
43
-        if (defined('EE_CAFF_PATH')) {
44
-            // activation
45
-            add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
46
-            // load caff init
47
-            add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
48
-            // remove the "powered by" credit link from receipts and invoices
49
-            add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
50
-            // add caffeinated modules
51
-            add_filter(
52
-                'FHEE__EE_Config__register_modules__modules_to_register',
53
-                array($this, 'caffeinated_modules_to_register')
54
-            );
55
-            // load caff scripts
56
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
57
-            add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
58
-            add_filter(
59
-                'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
60
-                array($this, 'caf_payment_methods')
61
-            );
62
-            // caffeinated constructed
63
-            do_action('AHEE__EE_Brewing_Regular__construct__complete');
64
-            //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
65
-            add_filter('FHEE__ee_show_affiliate_links', '__return_false');
66
-        }
67
-    }
68
-
69
-
70
-
71
-    /**
72
-     * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
73
-     *
74
-     * @param array $paths original helper paths array
75
-     * @return array             new array of paths
76
-     */
77
-    public function caf_helper_paths($paths)
78
-    {
79
-        $paths[] = EE_CAF_CORE . 'helpers' . DS;
80
-        return $paths;
81
-    }
82
-
83
-
84
-
85
-    /**
86
-     * Upon brand-new activation, if this is a new activation of CAF, we want to add
87
-     * some global prices that will show off EE4's capabilities. However, if they're upgrading
88
-     * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
89
-     * This action should only be called when EE 4.x.0.P is initially activated.
90
-     * Right now the only CAF content are these global prices. If there's more in the future, then
91
-     * we should probably create a caf file to contain it all instead just a function like this.
92
-     * Right now, we ASSUME the only price types in the system are default ones
93
-     *
94
-     * @global wpdb $wpdb
95
-     */
96
-    public function initialize_caf_db_content()
97
-    {
98
-        global $wpdb;
99
-        //use same method of getting creator id as the version introducing the change
100
-        $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
101
-        $price_type_table = $wpdb->prefix . "esp_price_type";
102
-        $price_table = $wpdb->prefix . "esp_price";
103
-        if ($this->_get_table_analysis()->tableExists($price_type_table)) {
104
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
105
-            $tax_price_type_count = $wpdb->get_var($SQL);
106
-            if ($tax_price_type_count <= 1) {
107
-                $wpdb->insert(
108
-                    $price_type_table,
109
-                    array(
110
-                        'PRT_name'       => __("Regional Tax", "event_espresso"),
111
-                        'PBT_ID'         => 4,
112
-                        'PRT_is_percent' => true,
113
-                        'PRT_order'      => 60,
114
-                        'PRT_deleted'    => false,
115
-                        'PRT_wp_user'    => $default_creator_id,
116
-                    ),
117
-                    array(
118
-                        '%s',//PRT_name
119
-                        '%d',//PBT_id
120
-                        '%d',//PRT_is_percent
121
-                        '%d',//PRT_order
122
-                        '%d',//PRT_deleted
123
-                        '%d', //PRT_wp_user
124
-                    )
125
-                );
126
-                //federal tax
127
-                $result = $wpdb->insert(
128
-                    $price_type_table,
129
-                    array(
130
-                        'PRT_name'       => __("Federal Tax", "event_espresso"),
131
-                        'PBT_ID'         => 4,
132
-                        'PRT_is_percent' => true,
133
-                        'PRT_order'      => 70,
134
-                        'PRT_deleted'    => false,
135
-                        'PRT_wp_user'    => $default_creator_id,
136
-                    ),
137
-                    array(
138
-                        '%s',//PRT_name
139
-                        '%d',//PBT_id
140
-                        '%d',//PRT_is_percent
141
-                        '%d',//PRT_order
142
-                        '%d',//PRT_deleted
143
-                        '%d' //PRT_wp_user
144
-                    )
145
-                );
146
-                if ($result) {
147
-                    $wpdb->insert(
148
-                        $price_table,
149
-                        array(
150
-                            'PRT_ID'         => $wpdb->insert_id,
151
-                            'PRC_amount'     => 15.00,
152
-                            'PRC_name'       => __("Sales Tax", "event_espresso"),
153
-                            'PRC_desc'       => '',
154
-                            'PRC_is_default' => true,
155
-                            'PRC_overrides'  => null,
156
-                            'PRC_deleted'    => false,
157
-                            'PRC_order'      => 50,
158
-                            'PRC_parent'     => null,
159
-                            'PRC_wp_user'    => $default_creator_id,
160
-                        ),
161
-                        array(
162
-                            '%d',//PRT_id
163
-                            '%f',//PRC_amount
164
-                            '%s',//PRC_name
165
-                            '%s',//PRC_desc
166
-                            '%d',//PRC_is_default
167
-                            '%d',//PRC_overrides
168
-                            '%d',//PRC_deleted
169
-                            '%d',//PRC_order
170
-                            '%d',//PRC_parent
171
-                            '%d' //PRC_wp_user
172
-                        )
173
-                    );
174
-                }
175
-            }
176
-        }
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     *    caffeinated_modules_to_register
183
-     *
184
-     * @access public
185
-     * @param array $modules_to_register
186
-     * @return array
187
-     */
188
-    public function caffeinated_modules_to_register($modules_to_register = array())
189
-    {
190
-        if (is_readable(EE_CAFF_PATH . 'modules')) {
191
-            $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
192
-            if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
193
-                $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
194
-            }
195
-        }
196
-        return $modules_to_register;
197
-    }
198
-
199
-
200
-
201
-    public function caffeinated_init()
202
-    {
203
-        // EE_Register_CPTs hooks
204
-        add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10);
205
-        add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10);
206
-        add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10);
207
-        EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false);
208
-        // caffeinated_init__complete hook
209
-        do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
210
-    }
211
-
212
-
213
-
214
-    public function enqueue_caffeinated_scripts()
215
-    {
216
-        // sound of crickets...
217
-    }
218
-
219
-
220
-
221
-    /**
222
-     * callbacks below here
223
-     *
224
-     * @param array $taxonomy_array
225
-     * @return array
226
-     */
227
-    public function filter_taxonomies(array $taxonomy_array)
228
-    {
229
-        $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
230
-        return $taxonomy_array;
231
-    }
232
-
233
-
234
-
235
-    /**
236
-     * @param array $cpt_array
237
-     * @return mixed
238
-     */
239
-    public function filter_cpts(array $cpt_array)
240
-    {
241
-        $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
242
-        return $cpt_array;
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * @param array $menuitems
249
-     * @return array
250
-     */
251
-    public function nav_metabox_items(array $menuitems)
252
-    {
253
-        $menuitems[] = array(
254
-            'title'       => __('Venue List', 'event_espresso'),
255
-            'url'         => get_post_type_archive_link('espresso_venues'),
256
-            'description' => __('Archive page for all venues.', 'event_espresso'),
257
-        );
258
-        return $menuitems;
259
-    }
260
-
261
-
262
-
263
-    /**
264
-     * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods
265
-     *
266
-     * @param array $payment_method_paths
267
-     * @return array values are folder paths to payment method folders
268
-     */
269
-    public function caf_payment_methods($payment_method_paths)
270
-    {
271
-        $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
272
-        $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths);
273
-        return $payment_method_paths;
274
-    }
275
-
276
-
277
-
278
-    /**
279
-     * Gets the injected table analyzer, or throws an exception
280
-     *
281
-     * @return TableAnalysis
282
-     * @throws \EE_Error
283
-     */
284
-    protected function _get_table_analysis()
285
-    {
286
-        if ($this->_table_analysis instanceof TableAnalysis) {
287
-            return $this->_table_analysis;
288
-        } else {
289
-            throw new \EE_Error(
290
-                sprintf(
291
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
292
-                    get_class($this)
293
-                )
294
-            );
295
-        }
296
-    }
30
+	/**
31
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
32
+	 */
33
+	protected $_table_analysis;
34
+
35
+
36
+
37
+	/**
38
+	 * EE_Brewing_Regular constructor.
39
+	 */
40
+	public function __construct(TableAnalysis $table_analysis)
41
+	{
42
+		$this->_table_analysis = $table_analysis;
43
+		if (defined('EE_CAFF_PATH')) {
44
+			// activation
45
+			add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
46
+			// load caff init
47
+			add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
48
+			// remove the "powered by" credit link from receipts and invoices
49
+			add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
50
+			// add caffeinated modules
51
+			add_filter(
52
+				'FHEE__EE_Config__register_modules__modules_to_register',
53
+				array($this, 'caffeinated_modules_to_register')
54
+			);
55
+			// load caff scripts
56
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
57
+			add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
58
+			add_filter(
59
+				'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
60
+				array($this, 'caf_payment_methods')
61
+			);
62
+			// caffeinated constructed
63
+			do_action('AHEE__EE_Brewing_Regular__construct__complete');
64
+			//seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
65
+			add_filter('FHEE__ee_show_affiliate_links', '__return_false');
66
+		}
67
+	}
68
+
69
+
70
+
71
+	/**
72
+	 * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
73
+	 *
74
+	 * @param array $paths original helper paths array
75
+	 * @return array             new array of paths
76
+	 */
77
+	public function caf_helper_paths($paths)
78
+	{
79
+		$paths[] = EE_CAF_CORE . 'helpers' . DS;
80
+		return $paths;
81
+	}
82
+
83
+
84
+
85
+	/**
86
+	 * Upon brand-new activation, if this is a new activation of CAF, we want to add
87
+	 * some global prices that will show off EE4's capabilities. However, if they're upgrading
88
+	 * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
89
+	 * This action should only be called when EE 4.x.0.P is initially activated.
90
+	 * Right now the only CAF content are these global prices. If there's more in the future, then
91
+	 * we should probably create a caf file to contain it all instead just a function like this.
92
+	 * Right now, we ASSUME the only price types in the system are default ones
93
+	 *
94
+	 * @global wpdb $wpdb
95
+	 */
96
+	public function initialize_caf_db_content()
97
+	{
98
+		global $wpdb;
99
+		//use same method of getting creator id as the version introducing the change
100
+		$default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
101
+		$price_type_table = $wpdb->prefix . "esp_price_type";
102
+		$price_table = $wpdb->prefix . "esp_price";
103
+		if ($this->_get_table_analysis()->tableExists($price_type_table)) {
104
+			$SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
105
+			$tax_price_type_count = $wpdb->get_var($SQL);
106
+			if ($tax_price_type_count <= 1) {
107
+				$wpdb->insert(
108
+					$price_type_table,
109
+					array(
110
+						'PRT_name'       => __("Regional Tax", "event_espresso"),
111
+						'PBT_ID'         => 4,
112
+						'PRT_is_percent' => true,
113
+						'PRT_order'      => 60,
114
+						'PRT_deleted'    => false,
115
+						'PRT_wp_user'    => $default_creator_id,
116
+					),
117
+					array(
118
+						'%s',//PRT_name
119
+						'%d',//PBT_id
120
+						'%d',//PRT_is_percent
121
+						'%d',//PRT_order
122
+						'%d',//PRT_deleted
123
+						'%d', //PRT_wp_user
124
+					)
125
+				);
126
+				//federal tax
127
+				$result = $wpdb->insert(
128
+					$price_type_table,
129
+					array(
130
+						'PRT_name'       => __("Federal Tax", "event_espresso"),
131
+						'PBT_ID'         => 4,
132
+						'PRT_is_percent' => true,
133
+						'PRT_order'      => 70,
134
+						'PRT_deleted'    => false,
135
+						'PRT_wp_user'    => $default_creator_id,
136
+					),
137
+					array(
138
+						'%s',//PRT_name
139
+						'%d',//PBT_id
140
+						'%d',//PRT_is_percent
141
+						'%d',//PRT_order
142
+						'%d',//PRT_deleted
143
+						'%d' //PRT_wp_user
144
+					)
145
+				);
146
+				if ($result) {
147
+					$wpdb->insert(
148
+						$price_table,
149
+						array(
150
+							'PRT_ID'         => $wpdb->insert_id,
151
+							'PRC_amount'     => 15.00,
152
+							'PRC_name'       => __("Sales Tax", "event_espresso"),
153
+							'PRC_desc'       => '',
154
+							'PRC_is_default' => true,
155
+							'PRC_overrides'  => null,
156
+							'PRC_deleted'    => false,
157
+							'PRC_order'      => 50,
158
+							'PRC_parent'     => null,
159
+							'PRC_wp_user'    => $default_creator_id,
160
+						),
161
+						array(
162
+							'%d',//PRT_id
163
+							'%f',//PRC_amount
164
+							'%s',//PRC_name
165
+							'%s',//PRC_desc
166
+							'%d',//PRC_is_default
167
+							'%d',//PRC_overrides
168
+							'%d',//PRC_deleted
169
+							'%d',//PRC_order
170
+							'%d',//PRC_parent
171
+							'%d' //PRC_wp_user
172
+						)
173
+					);
174
+				}
175
+			}
176
+		}
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 *    caffeinated_modules_to_register
183
+	 *
184
+	 * @access public
185
+	 * @param array $modules_to_register
186
+	 * @return array
187
+	 */
188
+	public function caffeinated_modules_to_register($modules_to_register = array())
189
+	{
190
+		if (is_readable(EE_CAFF_PATH . 'modules')) {
191
+			$caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
192
+			if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
193
+				$modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
194
+			}
195
+		}
196
+		return $modules_to_register;
197
+	}
198
+
199
+
200
+
201
+	public function caffeinated_init()
202
+	{
203
+		// EE_Register_CPTs hooks
204
+		add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10);
205
+		add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10);
206
+		add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10);
207
+		EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false);
208
+		// caffeinated_init__complete hook
209
+		do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
210
+	}
211
+
212
+
213
+
214
+	public function enqueue_caffeinated_scripts()
215
+	{
216
+		// sound of crickets...
217
+	}
218
+
219
+
220
+
221
+	/**
222
+	 * callbacks below here
223
+	 *
224
+	 * @param array $taxonomy_array
225
+	 * @return array
226
+	 */
227
+	public function filter_taxonomies(array $taxonomy_array)
228
+	{
229
+		$taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
230
+		return $taxonomy_array;
231
+	}
232
+
233
+
234
+
235
+	/**
236
+	 * @param array $cpt_array
237
+	 * @return mixed
238
+	 */
239
+	public function filter_cpts(array $cpt_array)
240
+	{
241
+		$cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
242
+		return $cpt_array;
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * @param array $menuitems
249
+	 * @return array
250
+	 */
251
+	public function nav_metabox_items(array $menuitems)
252
+	{
253
+		$menuitems[] = array(
254
+			'title'       => __('Venue List', 'event_espresso'),
255
+			'url'         => get_post_type_archive_link('espresso_venues'),
256
+			'description' => __('Archive page for all venues.', 'event_espresso'),
257
+		);
258
+		return $menuitems;
259
+	}
260
+
261
+
262
+
263
+	/**
264
+	 * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods
265
+	 *
266
+	 * @param array $payment_method_paths
267
+	 * @return array values are folder paths to payment method folders
268
+	 */
269
+	public function caf_payment_methods($payment_method_paths)
270
+	{
271
+		$caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
272
+		$payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths);
273
+		return $payment_method_paths;
274
+	}
275
+
276
+
277
+
278
+	/**
279
+	 * Gets the injected table analyzer, or throws an exception
280
+	 *
281
+	 * @return TableAnalysis
282
+	 * @throws \EE_Error
283
+	 */
284
+	protected function _get_table_analysis()
285
+	{
286
+		if ($this->_table_analysis instanceof TableAnalysis) {
287
+			return $this->_table_analysis;
288
+		} else {
289
+			throw new \EE_Error(
290
+				sprintf(
291
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
292
+					get_class($this)
293
+				)
294
+			);
295
+		}
296
+	}
297 297
 }
298 298
 
299 299
 
300 300
 
301 301
 $brewing = new EE_Brewing_Regular(
302
-    EE_Registry::instance()->create('TableAnalysis', array(), true)
302
+	EE_Registry::instance()->create('TableAnalysis', array(), true)
303 303
 );
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_Payment_Method_Manager.lib.php 1 patch
Indentation   +407 added lines, -407 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -17,407 +17,407 @@  discard block
 block discarded – undo
17 17
 class EE_Payment_Method_Manager
18 18
 {
19 19
 
20
-    /**
21
-     *    instance of the EE_Payment_Method_Manager object
22
-     *
23
-     * @var    $_instance
24
-     * @access    private
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * @var array keys are classnames without 'EE_PMT_', values are their filepaths
30
-     */
31
-    protected $_payment_method_types = array();
32
-
33
-
34
-
35
-    /**
36
-     * @singleton method used to instantiate class object
37
-     * @access    public
38
-     * @return EE_Payment_Method_Manager instance
39
-     */
40
-    public static function instance()
41
-    {
42
-        // check if class object is instantiated, and instantiated properly
43
-        if ( ! self::$_instance instanceof EE_Payment_Method_Manager) {
44
-            self::$_instance = new self();
45
-        }
46
-        EE_Registry::instance()->load_lib('PMT_Base');
47
-        return self::$_instance;
48
-    }
49
-
50
-
51
-
52
-    /**
53
-     * Resets the instance and returns a new one
54
-     *
55
-     * @return EE_Payment_Method_Manager
56
-     */
57
-    public static function reset()
58
-    {
59
-        self::$_instance = null;
60
-        return self::instance();
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * If necessary, re-register payment methods
67
-     *
68
-     * @param boolean $force_recheck whether to recheck for payment method types,
69
-     *                               or just re-use the PMTs we found last time we checked during this request (if
70
-     *                               we have not yet checked during this request, then we need to check anyways)
71
-     */
72
-    public function maybe_register_payment_methods($force_recheck = false)
73
-    {
74
-        if ( ! $this->_payment_method_types || $force_recheck) {
75
-            $this->_register_payment_methods();
76
-            //if in admin lets ensure caps are set.
77
-            if (is_admin()) {
78
-                add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps'));
79
-                EE_Registry::instance()->CAP->init_caps();
80
-            }
81
-        }
82
-    }
83
-
84
-
85
-
86
-    /**
87
-     *        register_payment_methods
88
-     *
89
-     * @return array
90
-     */
91
-    protected function _register_payment_methods()
92
-    {
93
-        // grab list of installed modules
94
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
95
-        // filter list of modules to register
96
-        $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
97
-            $pm_to_register);
98
-        // loop through folders
99
-        foreach ($pm_to_register as $pm_path) {
100
-            $this->register_payment_method($pm_path);
101
-        }
102
-        do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
103
-        // filter list of installed modules
104
-        //keep them organized alphabetically by the payment method type's name
105
-        ksort($this->_payment_method_types);
106
-        return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
107
-            $this->_payment_method_types);
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     *    register_payment_method- makes core aware of this payment method
114
-     *
115
-     * @access public
116
-     * @param string $payment_method_path - full path up to and including payment method folder
117
-     * @return boolean
118
-     */
119
-    public function register_payment_method($payment_method_path = '')
120
-    {
121
-        do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
122
-        $module_ext = '.pm.php';
123
-        // make all separators match
124
-        $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS);
125
-        // grab and sanitize module name
126
-        $module_dir = basename($payment_method_path);
127
-        // create classname from module directory name
128
-        $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir));
129
-        // add class prefix
130
-        $module_class = 'EE_PMT_' . $module;
131
-        // does the module exist ?
132
-        if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) {
133
-            $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.',
134
-                'event_espresso'), $module);
135
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
136
-            return false;
137
-        }
138
-        if (WP_DEBUG === true) {
139
-            EEH_Debug_Tools::instance()->start_timer();
140
-        }
141
-        // load the module class file
142
-        require_once($payment_method_path . DS . $module_class . $module_ext);
143
-        if (WP_DEBUG === true) {
144
-            EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class");
145
-        }
146
-        // verify that class exists
147
-        if ( ! class_exists($module_class)) {
148
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
149
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
150
-            return false;
151
-        }
152
-        // add to array of registered modules
153
-        $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext;
154
-        return true;
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * Checks if a payment method has been registered, and if so includes it
161
-     *
162
-     * @param string  $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_')
163
-     * @param boolean $force_recheck       whether to force re-checking for new payment method types
164
-     * @return boolean
165
-     */
166
-    public function payment_method_type_exists($payment_method_name, $force_recheck = false)
167
-    {
168
-        if (
169
-            $force_recheck
170
-            || ! is_array($this->_payment_method_types)
171
-            || ! isset($this->_payment_method_types[$payment_method_name])
172
-        ) {
173
-            $this->maybe_register_payment_methods($force_recheck);
174
-        }
175
-        if (isset($this->_payment_method_types[$payment_method_name])) {
176
-            require_once($this->_payment_method_types[$payment_method_name]);
177
-            return true;
178
-        } else {
179
-            return false;
180
-        }
181
-    }
182
-
183
-
184
-
185
-    /**
186
-     * Returns all the classnames of the various payment method types
187
-     *
188
-     * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names'
189
-     *                               (what you'd find in wp_esp_payment_method.PMD_type)
190
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
191
-     * @return array
192
-     */
193
-    public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
194
-    {
195
-        $this->maybe_register_payment_methods($force_recheck);
196
-        if ($with_prefixes) {
197
-            $classnames = array_keys($this->_payment_method_types);
198
-            $payment_methods = array();
199
-            foreach ($classnames as $classname) {
200
-                $payment_methods[] = $this->payment_method_class_from_type($classname);
201
-            }
202
-            return $payment_methods;
203
-        } else {
204
-            return array_keys($this->_payment_method_types);
205
-        }
206
-    }
207
-
208
-
209
-
210
-    /**
211
-     * Gets an object of each payment method type, none of which are bound to a
212
-     * payment method instance
213
-     *
214
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
215
-     * @return EE_PMT_Base[]
216
-     */
217
-    public function payment_method_types($force_recheck = false)
218
-    {
219
-        $this->maybe_register_payment_methods($force_recheck);
220
-        $pmt_objs = array();
221
-        foreach ($this->payment_method_type_names(true) as $classname) {
222
-            $pmt_objs[] = new $classname;
223
-        }
224
-        return $pmt_objs;
225
-    }
226
-
227
-
228
-
229
-    /**
230
-     * Changes the payment method's classname into the payment method type's name
231
-     * (as used on the payment method's table's PMD_type field)
232
-     *
233
-     * @param string $classname
234
-     * @return string
235
-     */
236
-    public function payment_method_type_sans_class_prefix($classname)
237
-    {
238
-        return str_replace("EE_PMT_", "", $classname);
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * Does the opposite of payment-method_type_sans_prefix
245
-     *
246
-     * @param string $type
247
-     * @return string
248
-     */
249
-    public function payment_method_class_from_type($type)
250
-    {
251
-        $this->maybe_register_payment_methods();
252
-        return "EE_PMT_" . $type;
253
-    }
254
-
255
-
256
-
257
-    /**
258
-     * Activates a payment method of the given type.
259
-     *
260
-     * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
261
-     * @return \EE_Payment_Method
262
-     * @throws \EE_Error
263
-     */
264
-    public function activate_a_payment_method_of_type($payment_method_type)
265
-    {
266
-        $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
267
-        if ( ! $payment_method instanceof EE_Payment_Method) {
268
-            $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
269
-            if (class_exists($pm_type_class)) {
270
-                /** @var $pm_type_obj EE_PMT_Base */
271
-                $pm_type_obj = new $pm_type_class;
272
-                $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
273
-                if ( ! $payment_method) {
274
-                    $payment_method = $this->create_payment_method_of_type($pm_type_obj);
275
-                }
276
-                $payment_method->set_type($payment_method_type);
277
-                $this->initialize_payment_method($payment_method);
278
-            } else {
279
-                throw new EE_Error(
280
-                    sprintf(
281
-                        __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'),
282
-                        $pm_type_class)
283
-                );
284
-            }
285
-        }
286
-        $payment_method->set_active();
287
-        $payment_method->save();
288
-        $this->set_usable_currencies_on_payment_method($payment_method);
289
-        if ($payment_method->type() === 'Invoice') {
290
-            /** @type EE_Message_Resource_Manager $message_resource_manager */
291
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
292
-            $message_resource_manager->ensure_message_type_is_active('invoice', 'html');
293
-            $message_resource_manager->ensure_messenger_is_active('pdf');
294
-            EE_Error::add_persistent_admin_notice(
295
-                'invoice_pm_requirements_notice',
296
-                sprintf(
297
-                    __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.',
298
-                        'event_espresso'),
299
-                    '<a href="' . admin_url('admin.php?page=espresso_messages') . '">',
300
-                    '</a>'
301
-                ),
302
-                true
303
-            );
304
-        }
305
-        return $payment_method;
306
-    }
307
-
308
-
309
-
310
-    /**
311
-     * Creates a payment method of the specified type. Does not save it.
312
-     *
313
-     * @global WP_User    $current_user
314
-     * @param EE_PMT_Base $pm_type_obj
315
-     * @return EE_Payment_Method
316
-     * @throws \EE_Error
317
-     */
318
-    public function create_payment_method_of_type($pm_type_obj)
319
-    {
320
-        global $current_user;
321
-        $payment_method = EE_Payment_Method::new_instance(
322
-            array(
323
-                'PMD_type'       => $pm_type_obj->system_name(),
324
-                'PMD_name'       => $pm_type_obj->pretty_name(),
325
-                'PMD_admin_name' => $pm_type_obj->pretty_name(),
326
-                'PMD_slug'       => $pm_type_obj->system_name(),//automatically converted to slug
327
-                'PMD_wp_user'    => $current_user->ID,
328
-                'PMD_order'      => EEM_Payment_Method::instance()->count(
329
-                        array(array('PMD_type' => array('!=', 'Admin_Only')))
330
-                    ) * 10,
331
-            )
332
-        );
333
-        return $payment_method;
334
-    }
335
-
336
-
337
-
338
-    /**
339
-     * Sets the initial payment method properties (including extra meta)
340
-     *
341
-     * @param EE_Payment_Method $payment_method
342
-     * @return EE_Payment_Method
343
-     * @throws \EE_Error
344
-     */
345
-    public function initialize_payment_method($payment_method)
346
-    {
347
-        $pm_type_obj = $payment_method->type_obj();
348
-        $payment_method->set_description($pm_type_obj->default_description());
349
-        if ( ! $payment_method->button_url()) {
350
-            $payment_method->set_button_url($pm_type_obj->default_button_url());
351
-        }
352
-        //now add setup its default extra meta properties
353
-        $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
354
-        if ( ! empty($extra_metas)) {
355
-            //verify the payment method has an ID before adding extra meta
356
-            if ( ! $payment_method->ID()) {
357
-                $payment_method->save();
358
-            }
359
-            foreach ($extra_metas as $meta_name => $input) {
360
-                $payment_method->update_extra_meta($meta_name, $input->raw_value());
361
-            }
362
-        }
363
-        return $payment_method;
364
-    }
365
-
366
-
367
-
368
-    /**
369
-     * Makes sure the payment method is related to the specified payment method
370
-     *
371
-     * @param EE_Payment_Method $payment_method
372
-     * @return EE_Payment_Method
373
-     * @throws \EE_Error
374
-     */
375
-    public function set_usable_currencies_on_payment_method($payment_method)
376
-    {
377
-        foreach ($payment_method->get_all_usable_currencies() as $currency_obj) {
378
-            $payment_method->_add_relation_to($currency_obj, 'Currency');
379
-        }
380
-        return $payment_method;
381
-    }
382
-
383
-
384
-
385
-    /**
386
-     * Deactivates a payment method of the given payment method slug.
387
-     *
388
-     * @param string $payment_method_slug The slug for the payment method to deactivate.
389
-     * @return int count of rows updated.
390
-     */
391
-    public function deactivate_payment_method($payment_method_slug)
392
-    {
393
-        EE_Log::instance()->log(
394
-            __FILE__,
395
-            __FUNCTION__,
396
-            sprintf(
397
-                __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'),
398
-                $payment_method_slug
399
-            ),
400
-            'payment_method_change'
401
-        );
402
-        $count_updated = EEM_Payment_Method::instance()->update(
403
-            array('PMD_scope' => array()),
404
-            array(array('PMD_slug' => $payment_method_slug))
405
-        );
406
-        return $count_updated;
407
-    }
408
-
409
-
410
-
411
-    /**
412
-     * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method
413
-     * access caps.
414
-     *
415
-     * @param array $caps capabilities being filtered
416
-     * @return array
417
-     */
418
-    public function add_payment_method_caps($caps)
419
-    {
420
-        /* add dynamic caps from payment methods
20
+	/**
21
+	 *    instance of the EE_Payment_Method_Manager object
22
+	 *
23
+	 * @var    $_instance
24
+	 * @access    private
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * @var array keys are classnames without 'EE_PMT_', values are their filepaths
30
+	 */
31
+	protected $_payment_method_types = array();
32
+
33
+
34
+
35
+	/**
36
+	 * @singleton method used to instantiate class object
37
+	 * @access    public
38
+	 * @return EE_Payment_Method_Manager instance
39
+	 */
40
+	public static function instance()
41
+	{
42
+		// check if class object is instantiated, and instantiated properly
43
+		if ( ! self::$_instance instanceof EE_Payment_Method_Manager) {
44
+			self::$_instance = new self();
45
+		}
46
+		EE_Registry::instance()->load_lib('PMT_Base');
47
+		return self::$_instance;
48
+	}
49
+
50
+
51
+
52
+	/**
53
+	 * Resets the instance and returns a new one
54
+	 *
55
+	 * @return EE_Payment_Method_Manager
56
+	 */
57
+	public static function reset()
58
+	{
59
+		self::$_instance = null;
60
+		return self::instance();
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * If necessary, re-register payment methods
67
+	 *
68
+	 * @param boolean $force_recheck whether to recheck for payment method types,
69
+	 *                               or just re-use the PMTs we found last time we checked during this request (if
70
+	 *                               we have not yet checked during this request, then we need to check anyways)
71
+	 */
72
+	public function maybe_register_payment_methods($force_recheck = false)
73
+	{
74
+		if ( ! $this->_payment_method_types || $force_recheck) {
75
+			$this->_register_payment_methods();
76
+			//if in admin lets ensure caps are set.
77
+			if (is_admin()) {
78
+				add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps'));
79
+				EE_Registry::instance()->CAP->init_caps();
80
+			}
81
+		}
82
+	}
83
+
84
+
85
+
86
+	/**
87
+	 *        register_payment_methods
88
+	 *
89
+	 * @return array
90
+	 */
91
+	protected function _register_payment_methods()
92
+	{
93
+		// grab list of installed modules
94
+		$pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
95
+		// filter list of modules to register
96
+		$pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
97
+			$pm_to_register);
98
+		// loop through folders
99
+		foreach ($pm_to_register as $pm_path) {
100
+			$this->register_payment_method($pm_path);
101
+		}
102
+		do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
103
+		// filter list of installed modules
104
+		//keep them organized alphabetically by the payment method type's name
105
+		ksort($this->_payment_method_types);
106
+		return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
107
+			$this->_payment_method_types);
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 *    register_payment_method- makes core aware of this payment method
114
+	 *
115
+	 * @access public
116
+	 * @param string $payment_method_path - full path up to and including payment method folder
117
+	 * @return boolean
118
+	 */
119
+	public function register_payment_method($payment_method_path = '')
120
+	{
121
+		do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
122
+		$module_ext = '.pm.php';
123
+		// make all separators match
124
+		$payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS);
125
+		// grab and sanitize module name
126
+		$module_dir = basename($payment_method_path);
127
+		// create classname from module directory name
128
+		$module = str_replace(' ', '_', str_replace('_', ' ', $module_dir));
129
+		// add class prefix
130
+		$module_class = 'EE_PMT_' . $module;
131
+		// does the module exist ?
132
+		if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) {
133
+			$msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.',
134
+				'event_espresso'), $module);
135
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
136
+			return false;
137
+		}
138
+		if (WP_DEBUG === true) {
139
+			EEH_Debug_Tools::instance()->start_timer();
140
+		}
141
+		// load the module class file
142
+		require_once($payment_method_path . DS . $module_class . $module_ext);
143
+		if (WP_DEBUG === true) {
144
+			EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class");
145
+		}
146
+		// verify that class exists
147
+		if ( ! class_exists($module_class)) {
148
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
149
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
150
+			return false;
151
+		}
152
+		// add to array of registered modules
153
+		$this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext;
154
+		return true;
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * Checks if a payment method has been registered, and if so includes it
161
+	 *
162
+	 * @param string  $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_')
163
+	 * @param boolean $force_recheck       whether to force re-checking for new payment method types
164
+	 * @return boolean
165
+	 */
166
+	public function payment_method_type_exists($payment_method_name, $force_recheck = false)
167
+	{
168
+		if (
169
+			$force_recheck
170
+			|| ! is_array($this->_payment_method_types)
171
+			|| ! isset($this->_payment_method_types[$payment_method_name])
172
+		) {
173
+			$this->maybe_register_payment_methods($force_recheck);
174
+		}
175
+		if (isset($this->_payment_method_types[$payment_method_name])) {
176
+			require_once($this->_payment_method_types[$payment_method_name]);
177
+			return true;
178
+		} else {
179
+			return false;
180
+		}
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * Returns all the classnames of the various payment method types
187
+	 *
188
+	 * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names'
189
+	 *                               (what you'd find in wp_esp_payment_method.PMD_type)
190
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
191
+	 * @return array
192
+	 */
193
+	public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
194
+	{
195
+		$this->maybe_register_payment_methods($force_recheck);
196
+		if ($with_prefixes) {
197
+			$classnames = array_keys($this->_payment_method_types);
198
+			$payment_methods = array();
199
+			foreach ($classnames as $classname) {
200
+				$payment_methods[] = $this->payment_method_class_from_type($classname);
201
+			}
202
+			return $payment_methods;
203
+		} else {
204
+			return array_keys($this->_payment_method_types);
205
+		}
206
+	}
207
+
208
+
209
+
210
+	/**
211
+	 * Gets an object of each payment method type, none of which are bound to a
212
+	 * payment method instance
213
+	 *
214
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
215
+	 * @return EE_PMT_Base[]
216
+	 */
217
+	public function payment_method_types($force_recheck = false)
218
+	{
219
+		$this->maybe_register_payment_methods($force_recheck);
220
+		$pmt_objs = array();
221
+		foreach ($this->payment_method_type_names(true) as $classname) {
222
+			$pmt_objs[] = new $classname;
223
+		}
224
+		return $pmt_objs;
225
+	}
226
+
227
+
228
+
229
+	/**
230
+	 * Changes the payment method's classname into the payment method type's name
231
+	 * (as used on the payment method's table's PMD_type field)
232
+	 *
233
+	 * @param string $classname
234
+	 * @return string
235
+	 */
236
+	public function payment_method_type_sans_class_prefix($classname)
237
+	{
238
+		return str_replace("EE_PMT_", "", $classname);
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * Does the opposite of payment-method_type_sans_prefix
245
+	 *
246
+	 * @param string $type
247
+	 * @return string
248
+	 */
249
+	public function payment_method_class_from_type($type)
250
+	{
251
+		$this->maybe_register_payment_methods();
252
+		return "EE_PMT_" . $type;
253
+	}
254
+
255
+
256
+
257
+	/**
258
+	 * Activates a payment method of the given type.
259
+	 *
260
+	 * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
261
+	 * @return \EE_Payment_Method
262
+	 * @throws \EE_Error
263
+	 */
264
+	public function activate_a_payment_method_of_type($payment_method_type)
265
+	{
266
+		$payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
267
+		if ( ! $payment_method instanceof EE_Payment_Method) {
268
+			$pm_type_class = $this->payment_method_class_from_type($payment_method_type);
269
+			if (class_exists($pm_type_class)) {
270
+				/** @var $pm_type_obj EE_PMT_Base */
271
+				$pm_type_obj = new $pm_type_class;
272
+				$payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
273
+				if ( ! $payment_method) {
274
+					$payment_method = $this->create_payment_method_of_type($pm_type_obj);
275
+				}
276
+				$payment_method->set_type($payment_method_type);
277
+				$this->initialize_payment_method($payment_method);
278
+			} else {
279
+				throw new EE_Error(
280
+					sprintf(
281
+						__('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'),
282
+						$pm_type_class)
283
+				);
284
+			}
285
+		}
286
+		$payment_method->set_active();
287
+		$payment_method->save();
288
+		$this->set_usable_currencies_on_payment_method($payment_method);
289
+		if ($payment_method->type() === 'Invoice') {
290
+			/** @type EE_Message_Resource_Manager $message_resource_manager */
291
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
292
+			$message_resource_manager->ensure_message_type_is_active('invoice', 'html');
293
+			$message_resource_manager->ensure_messenger_is_active('pdf');
294
+			EE_Error::add_persistent_admin_notice(
295
+				'invoice_pm_requirements_notice',
296
+				sprintf(
297
+					__('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.',
298
+						'event_espresso'),
299
+					'<a href="' . admin_url('admin.php?page=espresso_messages') . '">',
300
+					'</a>'
301
+				),
302
+				true
303
+			);
304
+		}
305
+		return $payment_method;
306
+	}
307
+
308
+
309
+
310
+	/**
311
+	 * Creates a payment method of the specified type. Does not save it.
312
+	 *
313
+	 * @global WP_User    $current_user
314
+	 * @param EE_PMT_Base $pm_type_obj
315
+	 * @return EE_Payment_Method
316
+	 * @throws \EE_Error
317
+	 */
318
+	public function create_payment_method_of_type($pm_type_obj)
319
+	{
320
+		global $current_user;
321
+		$payment_method = EE_Payment_Method::new_instance(
322
+			array(
323
+				'PMD_type'       => $pm_type_obj->system_name(),
324
+				'PMD_name'       => $pm_type_obj->pretty_name(),
325
+				'PMD_admin_name' => $pm_type_obj->pretty_name(),
326
+				'PMD_slug'       => $pm_type_obj->system_name(),//automatically converted to slug
327
+				'PMD_wp_user'    => $current_user->ID,
328
+				'PMD_order'      => EEM_Payment_Method::instance()->count(
329
+						array(array('PMD_type' => array('!=', 'Admin_Only')))
330
+					) * 10,
331
+			)
332
+		);
333
+		return $payment_method;
334
+	}
335
+
336
+
337
+
338
+	/**
339
+	 * Sets the initial payment method properties (including extra meta)
340
+	 *
341
+	 * @param EE_Payment_Method $payment_method
342
+	 * @return EE_Payment_Method
343
+	 * @throws \EE_Error
344
+	 */
345
+	public function initialize_payment_method($payment_method)
346
+	{
347
+		$pm_type_obj = $payment_method->type_obj();
348
+		$payment_method->set_description($pm_type_obj->default_description());
349
+		if ( ! $payment_method->button_url()) {
350
+			$payment_method->set_button_url($pm_type_obj->default_button_url());
351
+		}
352
+		//now add setup its default extra meta properties
353
+		$extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
354
+		if ( ! empty($extra_metas)) {
355
+			//verify the payment method has an ID before adding extra meta
356
+			if ( ! $payment_method->ID()) {
357
+				$payment_method->save();
358
+			}
359
+			foreach ($extra_metas as $meta_name => $input) {
360
+				$payment_method->update_extra_meta($meta_name, $input->raw_value());
361
+			}
362
+		}
363
+		return $payment_method;
364
+	}
365
+
366
+
367
+
368
+	/**
369
+	 * Makes sure the payment method is related to the specified payment method
370
+	 *
371
+	 * @param EE_Payment_Method $payment_method
372
+	 * @return EE_Payment_Method
373
+	 * @throws \EE_Error
374
+	 */
375
+	public function set_usable_currencies_on_payment_method($payment_method)
376
+	{
377
+		foreach ($payment_method->get_all_usable_currencies() as $currency_obj) {
378
+			$payment_method->_add_relation_to($currency_obj, 'Currency');
379
+		}
380
+		return $payment_method;
381
+	}
382
+
383
+
384
+
385
+	/**
386
+	 * Deactivates a payment method of the given payment method slug.
387
+	 *
388
+	 * @param string $payment_method_slug The slug for the payment method to deactivate.
389
+	 * @return int count of rows updated.
390
+	 */
391
+	public function deactivate_payment_method($payment_method_slug)
392
+	{
393
+		EE_Log::instance()->log(
394
+			__FILE__,
395
+			__FUNCTION__,
396
+			sprintf(
397
+				__('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'),
398
+				$payment_method_slug
399
+			),
400
+			'payment_method_change'
401
+		);
402
+		$count_updated = EEM_Payment_Method::instance()->update(
403
+			array('PMD_scope' => array()),
404
+			array(array('PMD_slug' => $payment_method_slug))
405
+		);
406
+		return $count_updated;
407
+	}
408
+
409
+
410
+
411
+	/**
412
+	 * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method
413
+	 * access caps.
414
+	 *
415
+	 * @param array $caps capabilities being filtered
416
+	 * @return array
417
+	 */
418
+	public function add_payment_method_caps($caps)
419
+	{
420
+		/* add dynamic caps from payment methods
421 421
          * at the time of writing, october 20 2014, these are the caps added:
422 422
          * ee_payment_method_admin_only
423 423
          * ee_payment_method_aim
@@ -431,10 +431,10 @@  discard block
 block discarded – undo
431 431
          * their related capability automatically added too, so long as they are
432 432
          * registered properly using EE_Register_Payment_Method::register()
433 433
          */
434
-        foreach ($this->payment_method_types() as $payment_method_type_obj) {
435
-            $caps['administrator'][] = $payment_method_type_obj->cap_name();
436
-        }
437
-        return $caps;
438
-    }
434
+		foreach ($this->payment_method_types() as $payment_method_type_obj) {
435
+			$caps['administrator'][] = $payment_method_type_obj->cap_name();
436
+		}
437
+		return $caps;
438
+	}
439 439
 
440 440
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 1 patch
Indentation   +1653 added lines, -1653 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -14,244 +14,244 @@  discard block
 block discarded – undo
14 14
 class EEH_Activation
15 15
 {
16 16
 
17
-    /**
18
-     * constant used to indicate a cron task is no longer in use
19
-     */
20
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
21
-
22
-    /**
23
-     * option name that will indicate whether or not we still
24
-     * need to create EE's folders in the uploads directory
25
-     * (because if EE was installed without file system access,
26
-     * we need to request credentials before we can create them)
27
-     */
28
-    const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
29
-
30
-    /**
31
-     * WP_User->ID
32
-     *
33
-     * @var int
34
-     */
35
-    private static $_default_creator_id;
36
-
37
-    /**
38
-     * indicates whether or not we've already verified core's default data during this request,
39
-     * because after migrations are done, any addons activated while in maintenance mode
40
-     * will want to setup their own default data, and they might hook into core's default data
41
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
42
-     * This prevents doing that for EVERY single addon.
43
-     *
44
-     * @var boolean
45
-     */
46
-    protected static $_initialized_db_content_already_in_this_request = false;
47
-
48
-    /**
49
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
50
-     */
51
-    private static $table_analysis;
52
-
53
-    /**
54
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
55
-     */
56
-    private static $table_manager;
57
-
58
-
59
-    /**
60
-     * @return \EventEspresso\core\services\database\TableAnalysis
61
-     */
62
-    public static function getTableAnalysis()
63
-    {
64
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
65
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
66
-        }
67
-        return self::$table_analysis;
68
-    }
69
-
70
-
71
-    /**
72
-     * @return \EventEspresso\core\services\database\TableManager
73
-     */
74
-    public static function getTableManager()
75
-    {
76
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
77
-            self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
78
-        }
79
-        return self::$table_manager;
80
-    }
81
-
82
-
83
-    /**
84
-     *    _ensure_table_name_has_prefix
85
-     *
86
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
-     * @access     public
88
-     * @static
89
-     * @param $table_name
90
-     * @return string
91
-     */
92
-    public static function ensure_table_name_has_prefix($table_name)
93
-    {
94
-        return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
95
-    }
96
-
97
-
98
-    /**
99
-     *    system_initialization
100
-     *    ensures the EE configuration settings are loaded with at least default options set
101
-     *    and that all critical EE pages have been generated with the appropriate shortcodes in place
102
-     *
103
-     * @access public
104
-     * @static
105
-     * @return void
106
-     */
107
-    public static function system_initialization()
108
-    {
109
-        EEH_Activation::reset_and_update_config();
110
-        //which is fired BEFORE activation of plugin anyways
111
-        EEH_Activation::verify_default_pages_exist();
112
-    }
113
-
114
-
115
-    /**
116
-     * Sets the database schema and creates folders. This should
117
-     * be called on plugin activation and reactivation
118
-     *
119
-     * @return boolean success, whether the database and folders are setup properly
120
-     * @throws \EE_Error
121
-     */
122
-    public static function initialize_db_and_folders()
123
-    {
124
-        $good_filesystem = EEH_Activation::create_upload_directories();
125
-        $good_db         = EEH_Activation::create_database_tables();
126
-        return $good_filesystem && $good_db;
127
-    }
128
-
129
-
130
-    /**
131
-     * assuming we have an up-to-date database schema, this will populate it
132
-     * with default and initial data. This should be called
133
-     * upon activation of a new plugin, reactivation, and at the end
134
-     * of running migration scripts
135
-     *
136
-     * @throws \EE_Error
137
-     */
138
-    public static function initialize_db_content()
139
-    {
140
-        //let's avoid doing all this logic repeatedly, especially when addons are requesting it
141
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
142
-            return;
143
-        }
144
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
145
-
146
-        EEH_Activation::initialize_system_questions();
147
-        EEH_Activation::insert_default_status_codes();
148
-        EEH_Activation::generate_default_message_templates();
149
-        EEH_Activation::create_no_ticket_prices_array();
150
-        EE_Registry::instance()->CAP->init_caps();
151
-
152
-        EEH_Activation::validate_messages_system();
153
-        EEH_Activation::insert_default_payment_methods();
154
-        //in case we've
155
-        EEH_Activation::remove_cron_tasks();
156
-        EEH_Activation::create_cron_tasks();
157
-        // remove all TXN locks since that is being done via extra meta now
158
-        delete_option('ee_locked_transactions');
159
-        //also, check for CAF default db content
160
-        do_action('AHEE__EEH_Activation__initialize_db_content');
161
-        //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
162
-        //which users really won't care about on initial activation
163
-        EE_Error::overwrite_success();
164
-    }
165
-
166
-
167
-    /**
168
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
169
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
170
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
171
-     * (null)
172
-     *
173
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
174
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
175
-     * @return array
176
-     * @throws \EE_Error
177
-     */
178
-    public static function get_cron_tasks($which_to_include)
179
-    {
180
-        $cron_tasks = apply_filters(
181
-            'FHEE__EEH_Activation__get_cron_tasks',
182
-            array(
183
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
17
+	/**
18
+	 * constant used to indicate a cron task is no longer in use
19
+	 */
20
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
21
+
22
+	/**
23
+	 * option name that will indicate whether or not we still
24
+	 * need to create EE's folders in the uploads directory
25
+	 * (because if EE was installed without file system access,
26
+	 * we need to request credentials before we can create them)
27
+	 */
28
+	const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
29
+
30
+	/**
31
+	 * WP_User->ID
32
+	 *
33
+	 * @var int
34
+	 */
35
+	private static $_default_creator_id;
36
+
37
+	/**
38
+	 * indicates whether or not we've already verified core's default data during this request,
39
+	 * because after migrations are done, any addons activated while in maintenance mode
40
+	 * will want to setup their own default data, and they might hook into core's default data
41
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
42
+	 * This prevents doing that for EVERY single addon.
43
+	 *
44
+	 * @var boolean
45
+	 */
46
+	protected static $_initialized_db_content_already_in_this_request = false;
47
+
48
+	/**
49
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
50
+	 */
51
+	private static $table_analysis;
52
+
53
+	/**
54
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
55
+	 */
56
+	private static $table_manager;
57
+
58
+
59
+	/**
60
+	 * @return \EventEspresso\core\services\database\TableAnalysis
61
+	 */
62
+	public static function getTableAnalysis()
63
+	{
64
+		if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
65
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
66
+		}
67
+		return self::$table_analysis;
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return \EventEspresso\core\services\database\TableManager
73
+	 */
74
+	public static function getTableManager()
75
+	{
76
+		if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
77
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
78
+		}
79
+		return self::$table_manager;
80
+	}
81
+
82
+
83
+	/**
84
+	 *    _ensure_table_name_has_prefix
85
+	 *
86
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
+	 * @access     public
88
+	 * @static
89
+	 * @param $table_name
90
+	 * @return string
91
+	 */
92
+	public static function ensure_table_name_has_prefix($table_name)
93
+	{
94
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
95
+	}
96
+
97
+
98
+	/**
99
+	 *    system_initialization
100
+	 *    ensures the EE configuration settings are loaded with at least default options set
101
+	 *    and that all critical EE pages have been generated with the appropriate shortcodes in place
102
+	 *
103
+	 * @access public
104
+	 * @static
105
+	 * @return void
106
+	 */
107
+	public static function system_initialization()
108
+	{
109
+		EEH_Activation::reset_and_update_config();
110
+		//which is fired BEFORE activation of plugin anyways
111
+		EEH_Activation::verify_default_pages_exist();
112
+	}
113
+
114
+
115
+	/**
116
+	 * Sets the database schema and creates folders. This should
117
+	 * be called on plugin activation and reactivation
118
+	 *
119
+	 * @return boolean success, whether the database and folders are setup properly
120
+	 * @throws \EE_Error
121
+	 */
122
+	public static function initialize_db_and_folders()
123
+	{
124
+		$good_filesystem = EEH_Activation::create_upload_directories();
125
+		$good_db         = EEH_Activation::create_database_tables();
126
+		return $good_filesystem && $good_db;
127
+	}
128
+
129
+
130
+	/**
131
+	 * assuming we have an up-to-date database schema, this will populate it
132
+	 * with default and initial data. This should be called
133
+	 * upon activation of a new plugin, reactivation, and at the end
134
+	 * of running migration scripts
135
+	 *
136
+	 * @throws \EE_Error
137
+	 */
138
+	public static function initialize_db_content()
139
+	{
140
+		//let's avoid doing all this logic repeatedly, especially when addons are requesting it
141
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
142
+			return;
143
+		}
144
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
145
+
146
+		EEH_Activation::initialize_system_questions();
147
+		EEH_Activation::insert_default_status_codes();
148
+		EEH_Activation::generate_default_message_templates();
149
+		EEH_Activation::create_no_ticket_prices_array();
150
+		EE_Registry::instance()->CAP->init_caps();
151
+
152
+		EEH_Activation::validate_messages_system();
153
+		EEH_Activation::insert_default_payment_methods();
154
+		//in case we've
155
+		EEH_Activation::remove_cron_tasks();
156
+		EEH_Activation::create_cron_tasks();
157
+		// remove all TXN locks since that is being done via extra meta now
158
+		delete_option('ee_locked_transactions');
159
+		//also, check for CAF default db content
160
+		do_action('AHEE__EEH_Activation__initialize_db_content');
161
+		//also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
162
+		//which users really won't care about on initial activation
163
+		EE_Error::overwrite_success();
164
+	}
165
+
166
+
167
+	/**
168
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
169
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
170
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
171
+	 * (null)
172
+	 *
173
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
174
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
175
+	 * @return array
176
+	 * @throws \EE_Error
177
+	 */
178
+	public static function get_cron_tasks($which_to_include)
179
+	{
180
+		$cron_tasks = apply_filters(
181
+			'FHEE__EEH_Activation__get_cron_tasks',
182
+			array(
183
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
184 184
 //				'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
185
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
186
-                //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
187
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
188
-            )
189
-        );
190
-        if ($which_to_include === 'old') {
191
-            $cron_tasks = array_filter(
192
-                $cron_tasks,
193
-                function ($value) {
194
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
195
-                }
196
-            );
197
-        } elseif ($which_to_include === 'current') {
198
-            $cron_tasks = array_filter($cron_tasks);
199
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
200
-            throw new EE_Error(
201
-                sprintf(
202
-                    __(
203
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
204
-                        'event_espresso'
205
-                    ),
206
-                    $which_to_include
207
-                )
208
-            );
209
-        }
210
-        return $cron_tasks;
211
-    }
212
-
213
-
214
-    /**
215
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
216
-     *
217
-     * @throws \EE_Error
218
-     */
219
-    public static function create_cron_tasks()
220
-    {
221
-
222
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
223
-            if (! wp_next_scheduled($hook_name)) {
224
-                /**
225
-                 * This allows client code to define the initial start timestamp for this schedule.
226
-                 */
227
-                if (is_array($frequency)
228
-                    && count($frequency) === 2
229
-                    && isset($frequency[0], $frequency[1])
230
-                ) {
231
-                    $start_timestamp = $frequency[0];
232
-                    $frequency = $frequency[1];
233
-                } else {
234
-                    $start_timestamp = time();
235
-                }
236
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
237
-            }
238
-        }
239
-
240
-    }
241
-
242
-
243
-    /**
244
-     * Remove the currently-existing and now-removed cron tasks.
245
-     *
246
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
247
-     * @throws \EE_Error
248
-     */
249
-    public static function remove_cron_tasks($remove_all = true)
250
-    {
251
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
252
-        $crons                = _get_cron_array();
253
-        $crons                = is_array($crons) ? $crons : array();
254
-        /* reminder of what $crons look like:
185
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
186
+				//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
187
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
188
+			)
189
+		);
190
+		if ($which_to_include === 'old') {
191
+			$cron_tasks = array_filter(
192
+				$cron_tasks,
193
+				function ($value) {
194
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
195
+				}
196
+			);
197
+		} elseif ($which_to_include === 'current') {
198
+			$cron_tasks = array_filter($cron_tasks);
199
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
200
+			throw new EE_Error(
201
+				sprintf(
202
+					__(
203
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
204
+						'event_espresso'
205
+					),
206
+					$which_to_include
207
+				)
208
+			);
209
+		}
210
+		return $cron_tasks;
211
+	}
212
+
213
+
214
+	/**
215
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
216
+	 *
217
+	 * @throws \EE_Error
218
+	 */
219
+	public static function create_cron_tasks()
220
+	{
221
+
222
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
223
+			if (! wp_next_scheduled($hook_name)) {
224
+				/**
225
+				 * This allows client code to define the initial start timestamp for this schedule.
226
+				 */
227
+				if (is_array($frequency)
228
+					&& count($frequency) === 2
229
+					&& isset($frequency[0], $frequency[1])
230
+				) {
231
+					$start_timestamp = $frequency[0];
232
+					$frequency = $frequency[1];
233
+				} else {
234
+					$start_timestamp = time();
235
+				}
236
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
237
+			}
238
+		}
239
+
240
+	}
241
+
242
+
243
+	/**
244
+	 * Remove the currently-existing and now-removed cron tasks.
245
+	 *
246
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
247
+	 * @throws \EE_Error
248
+	 */
249
+	public static function remove_cron_tasks($remove_all = true)
250
+	{
251
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
252
+		$crons                = _get_cron_array();
253
+		$crons                = is_array($crons) ? $crons : array();
254
+		/* reminder of what $crons look like:
255 255
          * Top-level keys are timestamps, and their values are arrays.
256 256
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
257 257
          * and their values are arrays.
@@ -268,912 +268,912 @@  discard block
 block discarded – undo
268 268
          *					...
269 269
          *      ...
270 270
          */
271
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
272
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
273
-            if (is_array($hooks_to_fire_at_time)) {
274
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
275
-                    if (isset($ee_cron_tasks_to_remove[$hook_name])
276
-                        && is_array($ee_cron_tasks_to_remove[$hook_name])
277
-                    ) {
278
-                        unset($crons[$timestamp][$hook_name]);
279
-                    }
280
-                }
281
-                //also take care of any empty cron timestamps.
282
-                if (empty($hooks_to_fire_at_time)) {
283
-                    unset($crons[$timestamp]);
284
-                }
285
-            }
286
-        }
287
-        _set_cron_array($crons);
288
-    }
289
-
290
-
291
-    /**
292
-     *    CPT_initialization
293
-     *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
294
-     *
295
-     * @access public
296
-     * @static
297
-     * @return void
298
-     */
299
-    public static function CPT_initialization()
300
-    {
301
-        // register Custom Post Types
302
-        EE_Registry::instance()->load_core('Register_CPTs');
303
-        flush_rewrite_rules();
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     *    reset_and_update_config
310
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
311
-     * If there is old calendar config data saved, then it will get converted on activation.
312
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
313
-     *
314
-     * @access public
315
-     * @static
316
-     * @return void
317
-     */
318
-    public static function reset_and_update_config()
319
-    {
320
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
321
-        add_filter(
322
-            'FHEE__EE_Config___load_core_config__config_settings',
323
-            array('EEH_Activation', 'migrate_old_config_data'),
324
-            10,
325
-            3
326
-        );
327
-        //EE_Config::reset();
328
-        if (! EE_Config::logging_enabled()) {
329
-            delete_option(EE_Config::LOG_NAME);
330
-        }
331
-    }
332
-
333
-
334
-    /**
335
-     *    load_calendar_config
336
-     *
337
-     * @access    public
338
-     * @return    void
339
-     */
340
-    public static function load_calendar_config()
341
-    {
342
-        // grab array of all plugin folders and loop thru it
343
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
344
-        if (empty($plugins)) {
345
-            return;
346
-        }
347
-        foreach ($plugins as $plugin_path) {
348
-            // grab plugin folder name from path
349
-            $plugin = basename($plugin_path);
350
-            // drill down to Espresso plugins
351
-            // then to calendar related plugins
352
-            if (
353
-                strpos($plugin, 'espresso') !== false
354
-                || strpos($plugin, 'Espresso') !== false
355
-                || strpos($plugin, 'ee4') !== false
356
-                || strpos($plugin, 'EE4') !== false
357
-                || strpos($plugin, 'calendar') !== false
358
-            ) {
359
-                // this is what we are looking for
360
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
361
-                // does it exist in this folder ?
362
-                if (is_readable($calendar_config)) {
363
-                    // YEAH! let's load it
364
-                    require_once($calendar_config);
365
-                }
366
-            }
367
-        }
368
-    }
369
-
370
-
371
-
372
-    /**
373
-     *    _migrate_old_config_data
374
-     *
375
-     * @access    public
376
-     * @param array|stdClass $settings
377
-     * @param string         $config
378
-     * @param \EE_Config     $EE_Config
379
-     * @return \stdClass
380
-     */
381
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
382
-    {
383
-        $convert_from_array = array('addons');
384
-        // in case old settings were saved as an array
385
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
386
-            // convert existing settings to an object
387
-            $config_array = $settings;
388
-            $settings = new stdClass();
389
-            foreach ($config_array as $key => $value) {
390
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
391
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
392
-                } else {
393
-                    $settings->{$key} = $value;
394
-                }
395
-            }
396
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
397
-        }
398
-        return $settings;
399
-    }
400
-
401
-
402
-    /**
403
-     * deactivate_event_espresso
404
-     *
405
-     * @access public
406
-     * @static
407
-     * @return void
408
-     */
409
-    public static function deactivate_event_espresso()
410
-    {
411
-        // check permissions
412
-        if (current_user_can('activate_plugins')) {
413
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
414
-        }
415
-    }
416
-
417
-
418
-
419
-
420
-
421
-    /**
422
-     * verify_default_pages_exist
423
-     *
424
-     * @access public
425
-     * @static
426
-     * @return void
427
-     */
428
-    public static function verify_default_pages_exist()
429
-    {
430
-        $critical_page_problem = false;
431
-        $critical_pages = array(
432
-            array(
433
-                'id'   => 'reg_page_id',
434
-                'name' => __('Registration Checkout', 'event_espresso'),
435
-                'post' => null,
436
-                'code' => 'ESPRESSO_CHECKOUT',
437
-            ),
438
-            array(
439
-                'id'   => 'txn_page_id',
440
-                'name' => __('Transactions', 'event_espresso'),
441
-                'post' => null,
442
-                'code' => 'ESPRESSO_TXN_PAGE',
443
-            ),
444
-            array(
445
-                'id'   => 'thank_you_page_id',
446
-                'name' => __('Thank You', 'event_espresso'),
447
-                'post' => null,
448
-                'code' => 'ESPRESSO_THANK_YOU',
449
-            ),
450
-            array(
451
-                'id'   => 'cancel_page_id',
452
-                'name' => __('Registration Cancelled', 'event_espresso'),
453
-                'post' => null,
454
-                'code' => 'ESPRESSO_CANCELLED',
455
-            ),
456
-        );
457
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
458
-        foreach ($critical_pages as $critical_page) {
459
-            // is critical page ID set in config ?
460
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
461
-                // attempt to find post by ID
462
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
463
-            }
464
-            // no dice?
465
-            if ($critical_page['post'] === null) {
466
-                // attempt to find post by title
467
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
468
-                // still nothing?
469
-                if ($critical_page['post'] === null) {
470
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
471
-                    // REALLY? Still nothing ??!?!?
472
-                    if ($critical_page['post'] === null) {
473
-                        $msg = __(
474
-                            'The Event Espresso critical page configuration settings could not be updated.',
475
-                            'event_espresso'
476
-                        );
477
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
478
-                        break;
479
-                    }
480
-                }
481
-            }
482
-            // check that Post ID matches critical page ID in config
483
-            if (
484
-                isset($critical_page['post']->ID)
485
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
486
-            ) {
487
-                //update Config with post ID
488
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
489
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
490
-                    $msg = __(
491
-                        'The Event Espresso critical page configuration settings could not be updated.',
492
-                        'event_espresso'
493
-                    );
494
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
495
-                }
496
-            }
497
-            $critical_page_problem =
498
-                ! isset($critical_page['post']->post_status)
499
-                || $critical_page['post']->post_status !== 'publish'
500
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
501
-                    ? true
502
-                    : $critical_page_problem;
503
-        }
504
-        if ($critical_page_problem) {
505
-            $msg = sprintf(
506
-                __(
507
-                    'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
508
-                    'event_espresso'
509
-                ),
510
-                '<a href="'
511
-                . admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
512
-                . '">'
513
-                . __('Event Espresso Critical Pages Settings', 'event_espresso')
514
-                . '</a>'
515
-            );
516
-            EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
517
-        }
518
-        if (EE_Error::has_notices()) {
519
-            EE_Error::get_notices(false, true, true);
520
-        }
521
-    }
522
-
523
-
524
-
525
-    /**
526
-     * Returns the first post which uses the specified shortcode
527
-     *
528
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
529
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
530
-     *                             "[ESPRESSO_THANK_YOU"
531
-     *                             (we don't search for the closing shortcode bracket because they might have added
532
-     *                             parameter to the shortcode
533
-     * @return WP_Post or NULl
534
-     */
535
-    public static function get_page_by_ee_shortcode($ee_shortcode)
536
-    {
537
-        global $wpdb;
538
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
539
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
540
-        if ($post_id) {
541
-            return get_post($post_id);
542
-        } else {
543
-            return null;
544
-        }
545
-    }
546
-
547
-
548
-    /**
549
-     *    This function generates a post for critical espresso pages
550
-     *
551
-     * @access public
552
-     * @static
553
-     * @param array $critical_page
554
-     * @return array
555
-     */
556
-    public static function create_critical_page($critical_page)
557
-    {
558
-
559
-        $post_args = array(
560
-            'post_title'     => $critical_page['name'],
561
-            'post_status'    => 'publish',
562
-            'post_type'      => 'page',
563
-            'comment_status' => 'closed',
564
-            'post_content'   => '[' . $critical_page['code'] . ']',
565
-        );
566
-
567
-        $post_id = wp_insert_post($post_args);
568
-        if (! $post_id) {
569
-            $msg = sprintf(
570
-                __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
571
-                $critical_page['name']
572
-            );
573
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
574
-            return $critical_page;
575
-        }
576
-        // get newly created post's details
577
-        if (! $critical_page['post'] = get_post($post_id)) {
578
-            $msg = sprintf(
579
-                __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
580
-                $critical_page['name']
581
-            );
582
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
583
-        }
584
-
585
-        return $critical_page;
586
-
587
-    }
588
-
589
-
590
-
591
-
592
-    /**
593
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
594
-     * The role being used to check is filterable.
595
-     *
596
-     * @since  4.6.0
597
-     * @global WPDB $wpdb
598
-     * @return mixed null|int WP_user ID or NULL
599
-     */
600
-    public static function get_default_creator_id()
601
-    {
602
-        global $wpdb;
603
-        if ( ! empty(self::$_default_creator_id)) {
604
-            return self::$_default_creator_id;
605
-        }/**/
606
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
607
-        //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.
608
-        $pre_filtered_id = apply_filters(
609
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
610
-            false,
611
-            $role_to_check
612
-        );
613
-        if ($pre_filtered_id !== false) {
614
-            return (int)$pre_filtered_id;
615
-        }
616
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
617
-        $query = $wpdb->prepare(
618
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
619
-            '%' . $role_to_check . '%'
620
-        );
621
-        $user_id = $wpdb->get_var($query);
622
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
623
-        if ($user_id && (int)$user_id) {
624
-            self::$_default_creator_id = (int)$user_id;
625
-            return self::$_default_creator_id;
626
-        } else {
627
-            return null;
628
-        }
629
-    }
630
-
631
-
632
-
633
-    /**
634
-     * used by EE and EE addons during plugin activation to create tables.
635
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
636
-     * but includes extra logic regarding activations.
637
-     *
638
-     * @access public
639
-     * @static
640
-     * @param string  $table_name              without the $wpdb->prefix
641
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
642
-     *                                         table query)
643
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
644
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
645
-     *                                         and new once this function is done (ie, you really do want to CREATE a
646
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
647
-     *                                         you just want to verify the table exists and matches this definition
648
-     *                                         (and if it HAS data in it you want to leave it be)
649
-     * @return void
650
-     * @throws EE_Error if there are database errors
651
-     */
652
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
653
-    {
654
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
655
-            return;
656
-        }
657
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
658
-        if ( ! function_exists('dbDelta')) {
659
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
660
-        }
661
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
662
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
663
-        // do we need to first delete an existing version of this table ?
664
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
665
-            // ok, delete the table... but ONLY if it's empty
666
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
667
-            // table is NOT empty, are you SURE you want to delete this table ???
668
-            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
669
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
670
-            } else if ( ! $deleted_safely) {
671
-                // so we should be more cautious rather than just dropping tables so easily
672
-                error_log(
673
-                    sprintf(
674
-                        __(
675
-                            '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.',
676
-                            'event_espresso'
677
-                        ),
678
-                        $wp_table_name,
679
-                        '<br/>',
680
-                        'espresso_db_update'
681
-                    )
682
-                );
683
-            }
684
-        }
685
-        $engine = str_replace('ENGINE=', '', $engine);
686
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
687
-    }
688
-
689
-
690
-
691
-    /**
692
-     *    add_column_if_it_doesn't_exist
693
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
694
-     *
695
-     * @access     public
696
-     * @static
697
-     * @deprecated instead use TableManager::addColumn()
698
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
699
-     * @param string $column_name
700
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
701
-     *                            'VARCHAR(10)'
702
-     * @return bool|int
703
-     */
704
-    public static function add_column_if_it_doesnt_exist(
705
-        $table_name,
706
-        $column_name,
707
-        $column_info = 'INT UNSIGNED NOT NULL'
708
-    ) {
709
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
710
-    }
711
-
712
-
713
-    /**
714
-     * get_fields_on_table
715
-     * Gets all the fields on the database table.
716
-     *
717
-     * @access     public
718
-     * @deprecated instead use TableManager::getTableColumns()
719
-     * @static
720
-     * @param string $table_name , without prefixed $wpdb->prefix
721
-     * @return array of database column names
722
-     */
723
-    public static function get_fields_on_table($table_name = null)
724
-    {
725
-        return \EEH_Activation::getTableManager()->getTableColumns($table_name);
726
-    }
727
-
728
-
729
-    /**
730
-     * db_table_is_empty
731
-     *
732
-     * @access     public\
733
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
734
-     * @static
735
-     * @param string $table_name
736
-     * @return bool
737
-     */
738
-    public static function db_table_is_empty($table_name)
739
-    {
740
-        return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
741
-    }
742
-
743
-
744
-    /**
745
-     * delete_db_table_if_empty
746
-     *
747
-     * @access public
748
-     * @static
749
-     * @param string $table_name
750
-     * @return bool | int
751
-     */
752
-    public static function delete_db_table_if_empty($table_name)
753
-    {
754
-        if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
755
-            return \EEH_Activation::getTableManager()->dropTable($table_name);
756
-        }
757
-        return false;
758
-    }
759
-
760
-
761
-    /**
762
-     * delete_unused_db_table
763
-     *
764
-     * @access     public
765
-     * @static
766
-     * @deprecated instead use TableManager::dropTable()
767
-     * @param string $table_name
768
-     * @return bool | int
769
-     */
770
-    public static function delete_unused_db_table($table_name)
771
-    {
772
-        return \EEH_Activation::getTableManager()->dropTable($table_name);
773
-    }
774
-
775
-
776
-    /**
777
-     * drop_index
778
-     *
779
-     * @access     public
780
-     * @static
781
-     * @deprecated instead use TableManager::dropIndex()
782
-     * @param string $table_name
783
-     * @param string $index_name
784
-     * @return bool | int
785
-     */
786
-    public static function drop_index($table_name, $index_name)
787
-    {
788
-        return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
789
-    }
790
-
791
-
792
-
793
-    /**
794
-     * create_database_tables
795
-     *
796
-     * @access public
797
-     * @static
798
-     * @throws EE_Error
799
-     * @return boolean success (whether database is setup properly or not)
800
-     */
801
-    public static function create_database_tables()
802
-    {
803
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
804
-        //find the migration script that sets the database to be compatible with the code
805
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
806
-        if ($dms_name) {
807
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
808
-            $current_data_migration_script->set_migrating(false);
809
-            $current_data_migration_script->schema_changes_before_migration();
810
-            $current_data_migration_script->schema_changes_after_migration();
811
-            if ($current_data_migration_script->get_errors()) {
812
-                if (WP_DEBUG) {
813
-                    foreach ($current_data_migration_script->get_errors() as $error) {
814
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
815
-                    }
816
-                } else {
817
-                    EE_Error::add_error(
818
-                        __(
819
-                            'There were errors creating the Event Espresso database tables and Event Espresso has been 
271
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
272
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
273
+			if (is_array($hooks_to_fire_at_time)) {
274
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
275
+					if (isset($ee_cron_tasks_to_remove[$hook_name])
276
+						&& is_array($ee_cron_tasks_to_remove[$hook_name])
277
+					) {
278
+						unset($crons[$timestamp][$hook_name]);
279
+					}
280
+				}
281
+				//also take care of any empty cron timestamps.
282
+				if (empty($hooks_to_fire_at_time)) {
283
+					unset($crons[$timestamp]);
284
+				}
285
+			}
286
+		}
287
+		_set_cron_array($crons);
288
+	}
289
+
290
+
291
+	/**
292
+	 *    CPT_initialization
293
+	 *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
294
+	 *
295
+	 * @access public
296
+	 * @static
297
+	 * @return void
298
+	 */
299
+	public static function CPT_initialization()
300
+	{
301
+		// register Custom Post Types
302
+		EE_Registry::instance()->load_core('Register_CPTs');
303
+		flush_rewrite_rules();
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 *    reset_and_update_config
310
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
311
+	 * If there is old calendar config data saved, then it will get converted on activation.
312
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
313
+	 *
314
+	 * @access public
315
+	 * @static
316
+	 * @return void
317
+	 */
318
+	public static function reset_and_update_config()
319
+	{
320
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
321
+		add_filter(
322
+			'FHEE__EE_Config___load_core_config__config_settings',
323
+			array('EEH_Activation', 'migrate_old_config_data'),
324
+			10,
325
+			3
326
+		);
327
+		//EE_Config::reset();
328
+		if (! EE_Config::logging_enabled()) {
329
+			delete_option(EE_Config::LOG_NAME);
330
+		}
331
+	}
332
+
333
+
334
+	/**
335
+	 *    load_calendar_config
336
+	 *
337
+	 * @access    public
338
+	 * @return    void
339
+	 */
340
+	public static function load_calendar_config()
341
+	{
342
+		// grab array of all plugin folders and loop thru it
343
+		$plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
344
+		if (empty($plugins)) {
345
+			return;
346
+		}
347
+		foreach ($plugins as $plugin_path) {
348
+			// grab plugin folder name from path
349
+			$plugin = basename($plugin_path);
350
+			// drill down to Espresso plugins
351
+			// then to calendar related plugins
352
+			if (
353
+				strpos($plugin, 'espresso') !== false
354
+				|| strpos($plugin, 'Espresso') !== false
355
+				|| strpos($plugin, 'ee4') !== false
356
+				|| strpos($plugin, 'EE4') !== false
357
+				|| strpos($plugin, 'calendar') !== false
358
+			) {
359
+				// this is what we are looking for
360
+				$calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
361
+				// does it exist in this folder ?
362
+				if (is_readable($calendar_config)) {
363
+					// YEAH! let's load it
364
+					require_once($calendar_config);
365
+				}
366
+			}
367
+		}
368
+	}
369
+
370
+
371
+
372
+	/**
373
+	 *    _migrate_old_config_data
374
+	 *
375
+	 * @access    public
376
+	 * @param array|stdClass $settings
377
+	 * @param string         $config
378
+	 * @param \EE_Config     $EE_Config
379
+	 * @return \stdClass
380
+	 */
381
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
382
+	{
383
+		$convert_from_array = array('addons');
384
+		// in case old settings were saved as an array
385
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
386
+			// convert existing settings to an object
387
+			$config_array = $settings;
388
+			$settings = new stdClass();
389
+			foreach ($config_array as $key => $value) {
390
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
391
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
392
+				} else {
393
+					$settings->{$key} = $value;
394
+				}
395
+			}
396
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
397
+		}
398
+		return $settings;
399
+	}
400
+
401
+
402
+	/**
403
+	 * deactivate_event_espresso
404
+	 *
405
+	 * @access public
406
+	 * @static
407
+	 * @return void
408
+	 */
409
+	public static function deactivate_event_espresso()
410
+	{
411
+		// check permissions
412
+		if (current_user_can('activate_plugins')) {
413
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
414
+		}
415
+	}
416
+
417
+
418
+
419
+
420
+
421
+	/**
422
+	 * verify_default_pages_exist
423
+	 *
424
+	 * @access public
425
+	 * @static
426
+	 * @return void
427
+	 */
428
+	public static function verify_default_pages_exist()
429
+	{
430
+		$critical_page_problem = false;
431
+		$critical_pages = array(
432
+			array(
433
+				'id'   => 'reg_page_id',
434
+				'name' => __('Registration Checkout', 'event_espresso'),
435
+				'post' => null,
436
+				'code' => 'ESPRESSO_CHECKOUT',
437
+			),
438
+			array(
439
+				'id'   => 'txn_page_id',
440
+				'name' => __('Transactions', 'event_espresso'),
441
+				'post' => null,
442
+				'code' => 'ESPRESSO_TXN_PAGE',
443
+			),
444
+			array(
445
+				'id'   => 'thank_you_page_id',
446
+				'name' => __('Thank You', 'event_espresso'),
447
+				'post' => null,
448
+				'code' => 'ESPRESSO_THANK_YOU',
449
+			),
450
+			array(
451
+				'id'   => 'cancel_page_id',
452
+				'name' => __('Registration Cancelled', 'event_espresso'),
453
+				'post' => null,
454
+				'code' => 'ESPRESSO_CANCELLED',
455
+			),
456
+		);
457
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
458
+		foreach ($critical_pages as $critical_page) {
459
+			// is critical page ID set in config ?
460
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
461
+				// attempt to find post by ID
462
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
463
+			}
464
+			// no dice?
465
+			if ($critical_page['post'] === null) {
466
+				// attempt to find post by title
467
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
468
+				// still nothing?
469
+				if ($critical_page['post'] === null) {
470
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
471
+					// REALLY? Still nothing ??!?!?
472
+					if ($critical_page['post'] === null) {
473
+						$msg = __(
474
+							'The Event Espresso critical page configuration settings could not be updated.',
475
+							'event_espresso'
476
+						);
477
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
478
+						break;
479
+					}
480
+				}
481
+			}
482
+			// check that Post ID matches critical page ID in config
483
+			if (
484
+				isset($critical_page['post']->ID)
485
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
486
+			) {
487
+				//update Config with post ID
488
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
489
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
490
+					$msg = __(
491
+						'The Event Espresso critical page configuration settings could not be updated.',
492
+						'event_espresso'
493
+					);
494
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
495
+				}
496
+			}
497
+			$critical_page_problem =
498
+				! isset($critical_page['post']->post_status)
499
+				|| $critical_page['post']->post_status !== 'publish'
500
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
501
+					? true
502
+					: $critical_page_problem;
503
+		}
504
+		if ($critical_page_problem) {
505
+			$msg = sprintf(
506
+				__(
507
+					'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
508
+					'event_espresso'
509
+				),
510
+				'<a href="'
511
+				. admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
512
+				. '">'
513
+				. __('Event Espresso Critical Pages Settings', 'event_espresso')
514
+				. '</a>'
515
+			);
516
+			EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
517
+		}
518
+		if (EE_Error::has_notices()) {
519
+			EE_Error::get_notices(false, true, true);
520
+		}
521
+	}
522
+
523
+
524
+
525
+	/**
526
+	 * Returns the first post which uses the specified shortcode
527
+	 *
528
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
529
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
530
+	 *                             "[ESPRESSO_THANK_YOU"
531
+	 *                             (we don't search for the closing shortcode bracket because they might have added
532
+	 *                             parameter to the shortcode
533
+	 * @return WP_Post or NULl
534
+	 */
535
+	public static function get_page_by_ee_shortcode($ee_shortcode)
536
+	{
537
+		global $wpdb;
538
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
539
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
540
+		if ($post_id) {
541
+			return get_post($post_id);
542
+		} else {
543
+			return null;
544
+		}
545
+	}
546
+
547
+
548
+	/**
549
+	 *    This function generates a post for critical espresso pages
550
+	 *
551
+	 * @access public
552
+	 * @static
553
+	 * @param array $critical_page
554
+	 * @return array
555
+	 */
556
+	public static function create_critical_page($critical_page)
557
+	{
558
+
559
+		$post_args = array(
560
+			'post_title'     => $critical_page['name'],
561
+			'post_status'    => 'publish',
562
+			'post_type'      => 'page',
563
+			'comment_status' => 'closed',
564
+			'post_content'   => '[' . $critical_page['code'] . ']',
565
+		);
566
+
567
+		$post_id = wp_insert_post($post_args);
568
+		if (! $post_id) {
569
+			$msg = sprintf(
570
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
571
+				$critical_page['name']
572
+			);
573
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
574
+			return $critical_page;
575
+		}
576
+		// get newly created post's details
577
+		if (! $critical_page['post'] = get_post($post_id)) {
578
+			$msg = sprintf(
579
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
580
+				$critical_page['name']
581
+			);
582
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
583
+		}
584
+
585
+		return $critical_page;
586
+
587
+	}
588
+
589
+
590
+
591
+
592
+	/**
593
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
594
+	 * The role being used to check is filterable.
595
+	 *
596
+	 * @since  4.6.0
597
+	 * @global WPDB $wpdb
598
+	 * @return mixed null|int WP_user ID or NULL
599
+	 */
600
+	public static function get_default_creator_id()
601
+	{
602
+		global $wpdb;
603
+		if ( ! empty(self::$_default_creator_id)) {
604
+			return self::$_default_creator_id;
605
+		}/**/
606
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
607
+		//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.
608
+		$pre_filtered_id = apply_filters(
609
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
610
+			false,
611
+			$role_to_check
612
+		);
613
+		if ($pre_filtered_id !== false) {
614
+			return (int)$pre_filtered_id;
615
+		}
616
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
617
+		$query = $wpdb->prepare(
618
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
619
+			'%' . $role_to_check . '%'
620
+		);
621
+		$user_id = $wpdb->get_var($query);
622
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
623
+		if ($user_id && (int)$user_id) {
624
+			self::$_default_creator_id = (int)$user_id;
625
+			return self::$_default_creator_id;
626
+		} else {
627
+			return null;
628
+		}
629
+	}
630
+
631
+
632
+
633
+	/**
634
+	 * used by EE and EE addons during plugin activation to create tables.
635
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
636
+	 * but includes extra logic regarding activations.
637
+	 *
638
+	 * @access public
639
+	 * @static
640
+	 * @param string  $table_name              without the $wpdb->prefix
641
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
642
+	 *                                         table query)
643
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
644
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
645
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
646
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
647
+	 *                                         you just want to verify the table exists and matches this definition
648
+	 *                                         (and if it HAS data in it you want to leave it be)
649
+	 * @return void
650
+	 * @throws EE_Error if there are database errors
651
+	 */
652
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
653
+	{
654
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
655
+			return;
656
+		}
657
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
658
+		if ( ! function_exists('dbDelta')) {
659
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
660
+		}
661
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
662
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
663
+		// do we need to first delete an existing version of this table ?
664
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
665
+			// ok, delete the table... but ONLY if it's empty
666
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
667
+			// table is NOT empty, are you SURE you want to delete this table ???
668
+			if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
669
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
670
+			} else if ( ! $deleted_safely) {
671
+				// so we should be more cautious rather than just dropping tables so easily
672
+				error_log(
673
+					sprintf(
674
+						__(
675
+							'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.',
676
+							'event_espresso'
677
+						),
678
+						$wp_table_name,
679
+						'<br/>',
680
+						'espresso_db_update'
681
+					)
682
+				);
683
+			}
684
+		}
685
+		$engine = str_replace('ENGINE=', '', $engine);
686
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
687
+	}
688
+
689
+
690
+
691
+	/**
692
+	 *    add_column_if_it_doesn't_exist
693
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
694
+	 *
695
+	 * @access     public
696
+	 * @static
697
+	 * @deprecated instead use TableManager::addColumn()
698
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
699
+	 * @param string $column_name
700
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
701
+	 *                            'VARCHAR(10)'
702
+	 * @return bool|int
703
+	 */
704
+	public static function add_column_if_it_doesnt_exist(
705
+		$table_name,
706
+		$column_name,
707
+		$column_info = 'INT UNSIGNED NOT NULL'
708
+	) {
709
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
710
+	}
711
+
712
+
713
+	/**
714
+	 * get_fields_on_table
715
+	 * Gets all the fields on the database table.
716
+	 *
717
+	 * @access     public
718
+	 * @deprecated instead use TableManager::getTableColumns()
719
+	 * @static
720
+	 * @param string $table_name , without prefixed $wpdb->prefix
721
+	 * @return array of database column names
722
+	 */
723
+	public static function get_fields_on_table($table_name = null)
724
+	{
725
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
726
+	}
727
+
728
+
729
+	/**
730
+	 * db_table_is_empty
731
+	 *
732
+	 * @access     public\
733
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
734
+	 * @static
735
+	 * @param string $table_name
736
+	 * @return bool
737
+	 */
738
+	public static function db_table_is_empty($table_name)
739
+	{
740
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
741
+	}
742
+
743
+
744
+	/**
745
+	 * delete_db_table_if_empty
746
+	 *
747
+	 * @access public
748
+	 * @static
749
+	 * @param string $table_name
750
+	 * @return bool | int
751
+	 */
752
+	public static function delete_db_table_if_empty($table_name)
753
+	{
754
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
755
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
756
+		}
757
+		return false;
758
+	}
759
+
760
+
761
+	/**
762
+	 * delete_unused_db_table
763
+	 *
764
+	 * @access     public
765
+	 * @static
766
+	 * @deprecated instead use TableManager::dropTable()
767
+	 * @param string $table_name
768
+	 * @return bool | int
769
+	 */
770
+	public static function delete_unused_db_table($table_name)
771
+	{
772
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
773
+	}
774
+
775
+
776
+	/**
777
+	 * drop_index
778
+	 *
779
+	 * @access     public
780
+	 * @static
781
+	 * @deprecated instead use TableManager::dropIndex()
782
+	 * @param string $table_name
783
+	 * @param string $index_name
784
+	 * @return bool | int
785
+	 */
786
+	public static function drop_index($table_name, $index_name)
787
+	{
788
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
789
+	}
790
+
791
+
792
+
793
+	/**
794
+	 * create_database_tables
795
+	 *
796
+	 * @access public
797
+	 * @static
798
+	 * @throws EE_Error
799
+	 * @return boolean success (whether database is setup properly or not)
800
+	 */
801
+	public static function create_database_tables()
802
+	{
803
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
804
+		//find the migration script that sets the database to be compatible with the code
805
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
806
+		if ($dms_name) {
807
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
808
+			$current_data_migration_script->set_migrating(false);
809
+			$current_data_migration_script->schema_changes_before_migration();
810
+			$current_data_migration_script->schema_changes_after_migration();
811
+			if ($current_data_migration_script->get_errors()) {
812
+				if (WP_DEBUG) {
813
+					foreach ($current_data_migration_script->get_errors() as $error) {
814
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
815
+					}
816
+				} else {
817
+					EE_Error::add_error(
818
+						__(
819
+							'There were errors creating the Event Espresso database tables and Event Espresso has been 
820 820
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
821
-                            'event_espresso'
822
-                        )
823
-                    );
824
-                }
825
-                return false;
826
-            }
827
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
828
-        } else {
829
-            EE_Error::add_error(
830
-                __(
831
-                    'Could not determine most up-to-date data migration script from which to pull database schema
821
+							'event_espresso'
822
+						)
823
+					);
824
+				}
825
+				return false;
826
+			}
827
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
828
+		} else {
829
+			EE_Error::add_error(
830
+				__(
831
+					'Could not determine most up-to-date data migration script from which to pull database schema
832 832
                      structure. So database is probably not setup properly',
833
-                    'event_espresso'
834
-                ),
835
-                __FILE__,
836
-                __FUNCTION__,
837
-                __LINE__
838
-            );
839
-            return false;
840
-        }
841
-        return true;
842
-    }
843
-
844
-
845
-
846
-    /**
847
-     * initialize_system_questions
848
-     *
849
-     * @access public
850
-     * @static
851
-     * @return void
852
-     */
853
-    public static function initialize_system_questions()
854
-    {
855
-        // QUESTION GROUPS
856
-        global $wpdb;
857
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
858
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
859
-        // what we have
860
-        $question_groups = $wpdb->get_col($SQL);
861
-        // check the response
862
-        $question_groups = is_array($question_groups) ? $question_groups : array();
863
-        // what we should have
864
-        $QSG_systems = array(1, 2);
865
-        // loop thru what we should have and compare to what we have
866
-        foreach ($QSG_systems as $QSG_system) {
867
-            // reset values array
868
-            $QSG_values = array();
869
-            // 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)
870
-            if (! in_array("$QSG_system", $question_groups)) {
871
-                // add it
872
-                switch ($QSG_system) {
873
-                    case 1:
874
-                        $QSG_values = array(
875
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
876
-                            'QSG_identifier'      => 'personal-information-' . time(),
877
-                            'QSG_desc'            => '',
878
-                            'QSG_order'           => 1,
879
-                            'QSG_show_group_name' => 1,
880
-                            'QSG_show_group_desc' => 1,
881
-                            'QSG_system'          => EEM_Question_Group::system_personal,
882
-                            'QSG_deleted'         => 0,
883
-                        );
884
-                        break;
885
-                    case 2:
886
-                        $QSG_values = array(
887
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
888
-                            'QSG_identifier'      => 'address-information-' . time(),
889
-                            'QSG_desc'            => '',
890
-                            'QSG_order'           => 2,
891
-                            'QSG_show_group_name' => 1,
892
-                            'QSG_show_group_desc' => 1,
893
-                            'QSG_system'          => EEM_Question_Group::system_address,
894
-                            'QSG_deleted'         => 0,
895
-                        );
896
-                        break;
897
-                }
898
-                // make sure we have some values before inserting them
899
-                if (! empty($QSG_values)) {
900
-                    // insert system question
901
-                    $wpdb->insert(
902
-                        $table_name,
903
-                        $QSG_values,
904
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
905
-                    );
906
-                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
907
-                }
908
-            }
909
-        }
910
-        // QUESTIONS
911
-        global $wpdb;
912
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
913
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
914
-        // what we have
915
-        $questions = $wpdb->get_col($SQL);
916
-        // what we should have
917
-        $QST_systems = array(
918
-            'fname',
919
-            'lname',
920
-            'email',
921
-            'address',
922
-            'address2',
923
-            'city',
924
-            'country',
925
-            'state',
926
-            'zip',
927
-            'phone',
928
-        );
929
-        $order_for_group_1 = 1;
930
-        $order_for_group_2 = 1;
931
-        // loop thru what we should have and compare to what we have
932
-        foreach ($QST_systems as $QST_system) {
933
-            // reset values array
934
-            $QST_values = array();
935
-            // if we don't have what we should have
936
-            if (! in_array($QST_system, $questions)) {
937
-                // add it
938
-                switch ($QST_system) {
939
-                    case 'fname':
940
-                        $QST_values = array(
941
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
942
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
943
-                            'QST_system'        => 'fname',
944
-                            'QST_type'          => 'TEXT',
945
-                            'QST_required'      => 1,
946
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
947
-                            'QST_order'         => 1,
948
-                            'QST_admin_only'    => 0,
949
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
950
-                            'QST_wp_user'       => self::get_default_creator_id(),
951
-                            'QST_deleted'       => 0,
952
-                        );
953
-                        break;
954
-                    case 'lname':
955
-                        $QST_values = array(
956
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
957
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
958
-                            'QST_system'        => 'lname',
959
-                            'QST_type'          => 'TEXT',
960
-                            'QST_required'      => 1,
961
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
962
-                            'QST_order'         => 2,
963
-                            'QST_admin_only'    => 0,
964
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
965
-                            'QST_wp_user'       => self::get_default_creator_id(),
966
-                            'QST_deleted'       => 0,
967
-                        );
968
-                        break;
969
-                    case 'email':
970
-                        $QST_values = array(
971
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
972
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
973
-                            'QST_system'        => 'email',
974
-                            'QST_type'          => 'EMAIL',
975
-                            'QST_required'      => 1,
976
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
977
-                            'QST_order'         => 3,
978
-                            'QST_admin_only'    => 0,
979
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
980
-                            'QST_wp_user'       => self::get_default_creator_id(),
981
-                            'QST_deleted'       => 0,
982
-                        );
983
-                        break;
984
-                    case 'address':
985
-                        $QST_values = array(
986
-                            'QST_display_text'  => __('Address', 'event_espresso'),
987
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
988
-                            'QST_system'        => 'address',
989
-                            'QST_type'          => 'TEXT',
990
-                            'QST_required'      => 0,
991
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
992
-                            'QST_order'         => 4,
993
-                            'QST_admin_only'    => 0,
994
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
995
-                            'QST_wp_user'       => self::get_default_creator_id(),
996
-                            'QST_deleted'       => 0,
997
-                        );
998
-                        break;
999
-                    case 'address2':
1000
-                        $QST_values = array(
1001
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
1002
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1003
-                            'QST_system'        => 'address2',
1004
-                            'QST_type'          => 'TEXT',
1005
-                            'QST_required'      => 0,
1006
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1007
-                            'QST_order'         => 5,
1008
-                            'QST_admin_only'    => 0,
1009
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1010
-                            'QST_wp_user'       => self::get_default_creator_id(),
1011
-                            'QST_deleted'       => 0,
1012
-                        );
1013
-                        break;
1014
-                    case 'city':
1015
-                        $QST_values = array(
1016
-                            'QST_display_text'  => __('City', 'event_espresso'),
1017
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1018
-                            'QST_system'        => 'city',
1019
-                            'QST_type'          => 'TEXT',
1020
-                            'QST_required'      => 0,
1021
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1022
-                            'QST_order'         => 6,
1023
-                            'QST_admin_only'    => 0,
1024
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1025
-                            'QST_wp_user'       => self::get_default_creator_id(),
1026
-                            'QST_deleted'       => 0,
1027
-                        );
1028
-                        break;
1029
-                    case 'country':
1030
-                        $QST_values = array(
1031
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1032
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1033
-                            'QST_system'        => 'country',
1034
-                            'QST_type'          => 'COUNTRY',
1035
-                            'QST_required'      => 0,
1036
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1037
-                            'QST_order'         => 7,
1038
-                            'QST_admin_only'    => 0,
1039
-                            'QST_wp_user'       => self::get_default_creator_id(),
1040
-                            'QST_deleted'       => 0,
1041
-                        );
1042
-                        break;
1043
-                    case 'state':
1044
-                        $QST_values = array(
1045
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1046
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1047
-                            'QST_system'        => 'state',
1048
-                            'QST_type'          => 'STATE',
1049
-                            'QST_required'      => 0,
1050
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1051
-                            'QST_order'         => 8,
1052
-                            'QST_admin_only'    => 0,
1053
-                            'QST_wp_user'       => self::get_default_creator_id(),
1054
-                            'QST_deleted'       => 0,
1055
-                        );
1056
-                        break;
1057
-                    case 'zip':
1058
-                        $QST_values = array(
1059
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1060
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1061
-                            'QST_system'        => 'zip',
1062
-                            'QST_type'          => 'TEXT',
1063
-                            'QST_required'      => 0,
1064
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1065
-                            'QST_order'         => 9,
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 'phone':
1073
-                        $QST_values = array(
1074
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1075
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1076
-                            'QST_system'        => 'phone',
1077
-                            'QST_type'          => 'TEXT',
1078
-                            'QST_required'      => 0,
1079
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1080
-                            'QST_order'         => 10,
1081
-                            'QST_admin_only'    => 0,
1082
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1083
-                            'QST_wp_user'       => self::get_default_creator_id(),
1084
-                            'QST_deleted'       => 0,
1085
-                        );
1086
-                        break;
1087
-                }
1088
-                if (! empty($QST_values)) {
1089
-                    // insert system question
1090
-                    $wpdb->insert(
1091
-                        $table_name,
1092
-                        $QST_values,
1093
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1094
-                    );
1095
-                    $QST_ID = $wpdb->insert_id;
1096
-                    // QUESTION GROUP QUESTIONS
1097
-                    if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1098
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1099
-                    } else {
1100
-                        $system_question_we_want = EEM_Question_Group::system_address;
1101
-                    }
1102
-                    if (isset($QSG_IDs[$system_question_we_want])) {
1103
-                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1104
-                    } else {
1105
-                        $id_col = EEM_Question_Group::instance()
1106
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1107
-                        if (is_array($id_col)) {
1108
-                            $QSG_ID = reset($id_col);
1109
-                        } else {
1110
-                            //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
1111
-                            EE_Log::instance()->log(
1112
-                                __FILE__,
1113
-                                __FUNCTION__,
1114
-                                sprintf(
1115
-                                    __(
1116
-                                        'Could not associate question %1$s to a question group because no system question
833
+					'event_espresso'
834
+				),
835
+				__FILE__,
836
+				__FUNCTION__,
837
+				__LINE__
838
+			);
839
+			return false;
840
+		}
841
+		return true;
842
+	}
843
+
844
+
845
+
846
+	/**
847
+	 * initialize_system_questions
848
+	 *
849
+	 * @access public
850
+	 * @static
851
+	 * @return void
852
+	 */
853
+	public static function initialize_system_questions()
854
+	{
855
+		// QUESTION GROUPS
856
+		global $wpdb;
857
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
858
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
859
+		// what we have
860
+		$question_groups = $wpdb->get_col($SQL);
861
+		// check the response
862
+		$question_groups = is_array($question_groups) ? $question_groups : array();
863
+		// what we should have
864
+		$QSG_systems = array(1, 2);
865
+		// loop thru what we should have and compare to what we have
866
+		foreach ($QSG_systems as $QSG_system) {
867
+			// reset values array
868
+			$QSG_values = array();
869
+			// 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)
870
+			if (! in_array("$QSG_system", $question_groups)) {
871
+				// add it
872
+				switch ($QSG_system) {
873
+					case 1:
874
+						$QSG_values = array(
875
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
876
+							'QSG_identifier'      => 'personal-information-' . time(),
877
+							'QSG_desc'            => '',
878
+							'QSG_order'           => 1,
879
+							'QSG_show_group_name' => 1,
880
+							'QSG_show_group_desc' => 1,
881
+							'QSG_system'          => EEM_Question_Group::system_personal,
882
+							'QSG_deleted'         => 0,
883
+						);
884
+						break;
885
+					case 2:
886
+						$QSG_values = array(
887
+							'QSG_name'            => __('Address Information', 'event_espresso'),
888
+							'QSG_identifier'      => 'address-information-' . time(),
889
+							'QSG_desc'            => '',
890
+							'QSG_order'           => 2,
891
+							'QSG_show_group_name' => 1,
892
+							'QSG_show_group_desc' => 1,
893
+							'QSG_system'          => EEM_Question_Group::system_address,
894
+							'QSG_deleted'         => 0,
895
+						);
896
+						break;
897
+				}
898
+				// make sure we have some values before inserting them
899
+				if (! empty($QSG_values)) {
900
+					// insert system question
901
+					$wpdb->insert(
902
+						$table_name,
903
+						$QSG_values,
904
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
905
+					);
906
+					$QSG_IDs[$QSG_system] = $wpdb->insert_id;
907
+				}
908
+			}
909
+		}
910
+		// QUESTIONS
911
+		global $wpdb;
912
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
913
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
914
+		// what we have
915
+		$questions = $wpdb->get_col($SQL);
916
+		// what we should have
917
+		$QST_systems = array(
918
+			'fname',
919
+			'lname',
920
+			'email',
921
+			'address',
922
+			'address2',
923
+			'city',
924
+			'country',
925
+			'state',
926
+			'zip',
927
+			'phone',
928
+		);
929
+		$order_for_group_1 = 1;
930
+		$order_for_group_2 = 1;
931
+		// loop thru what we should have and compare to what we have
932
+		foreach ($QST_systems as $QST_system) {
933
+			// reset values array
934
+			$QST_values = array();
935
+			// if we don't have what we should have
936
+			if (! in_array($QST_system, $questions)) {
937
+				// add it
938
+				switch ($QST_system) {
939
+					case 'fname':
940
+						$QST_values = array(
941
+							'QST_display_text'  => __('First Name', 'event_espresso'),
942
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
943
+							'QST_system'        => 'fname',
944
+							'QST_type'          => 'TEXT',
945
+							'QST_required'      => 1,
946
+							'QST_required_text' => __('This field is required', 'event_espresso'),
947
+							'QST_order'         => 1,
948
+							'QST_admin_only'    => 0,
949
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
950
+							'QST_wp_user'       => self::get_default_creator_id(),
951
+							'QST_deleted'       => 0,
952
+						);
953
+						break;
954
+					case 'lname':
955
+						$QST_values = array(
956
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
957
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
958
+							'QST_system'        => 'lname',
959
+							'QST_type'          => 'TEXT',
960
+							'QST_required'      => 1,
961
+							'QST_required_text' => __('This field is required', 'event_espresso'),
962
+							'QST_order'         => 2,
963
+							'QST_admin_only'    => 0,
964
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
965
+							'QST_wp_user'       => self::get_default_creator_id(),
966
+							'QST_deleted'       => 0,
967
+						);
968
+						break;
969
+					case 'email':
970
+						$QST_values = array(
971
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
972
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
973
+							'QST_system'        => 'email',
974
+							'QST_type'          => 'EMAIL',
975
+							'QST_required'      => 1,
976
+							'QST_required_text' => __('This field is required', 'event_espresso'),
977
+							'QST_order'         => 3,
978
+							'QST_admin_only'    => 0,
979
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
980
+							'QST_wp_user'       => self::get_default_creator_id(),
981
+							'QST_deleted'       => 0,
982
+						);
983
+						break;
984
+					case 'address':
985
+						$QST_values = array(
986
+							'QST_display_text'  => __('Address', 'event_espresso'),
987
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
988
+							'QST_system'        => 'address',
989
+							'QST_type'          => 'TEXT',
990
+							'QST_required'      => 0,
991
+							'QST_required_text' => __('This field is required', 'event_espresso'),
992
+							'QST_order'         => 4,
993
+							'QST_admin_only'    => 0,
994
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
995
+							'QST_wp_user'       => self::get_default_creator_id(),
996
+							'QST_deleted'       => 0,
997
+						);
998
+						break;
999
+					case 'address2':
1000
+						$QST_values = array(
1001
+							'QST_display_text'  => __('Address2', 'event_espresso'),
1002
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1003
+							'QST_system'        => 'address2',
1004
+							'QST_type'          => 'TEXT',
1005
+							'QST_required'      => 0,
1006
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1007
+							'QST_order'         => 5,
1008
+							'QST_admin_only'    => 0,
1009
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1010
+							'QST_wp_user'       => self::get_default_creator_id(),
1011
+							'QST_deleted'       => 0,
1012
+						);
1013
+						break;
1014
+					case 'city':
1015
+						$QST_values = array(
1016
+							'QST_display_text'  => __('City', 'event_espresso'),
1017
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1018
+							'QST_system'        => 'city',
1019
+							'QST_type'          => 'TEXT',
1020
+							'QST_required'      => 0,
1021
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1022
+							'QST_order'         => 6,
1023
+							'QST_admin_only'    => 0,
1024
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1025
+							'QST_wp_user'       => self::get_default_creator_id(),
1026
+							'QST_deleted'       => 0,
1027
+						);
1028
+						break;
1029
+					case 'country':
1030
+						$QST_values = array(
1031
+							'QST_display_text'  => __('Country', 'event_espresso'),
1032
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1033
+							'QST_system'        => 'country',
1034
+							'QST_type'          => 'COUNTRY',
1035
+							'QST_required'      => 0,
1036
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1037
+							'QST_order'         => 7,
1038
+							'QST_admin_only'    => 0,
1039
+							'QST_wp_user'       => self::get_default_creator_id(),
1040
+							'QST_deleted'       => 0,
1041
+						);
1042
+						break;
1043
+					case 'state':
1044
+						$QST_values = array(
1045
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1046
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1047
+							'QST_system'        => 'state',
1048
+							'QST_type'          => 'STATE',
1049
+							'QST_required'      => 0,
1050
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1051
+							'QST_order'         => 8,
1052
+							'QST_admin_only'    => 0,
1053
+							'QST_wp_user'       => self::get_default_creator_id(),
1054
+							'QST_deleted'       => 0,
1055
+						);
1056
+						break;
1057
+					case 'zip':
1058
+						$QST_values = array(
1059
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1060
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1061
+							'QST_system'        => 'zip',
1062
+							'QST_type'          => 'TEXT',
1063
+							'QST_required'      => 0,
1064
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1065
+							'QST_order'         => 9,
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 'phone':
1073
+						$QST_values = array(
1074
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1075
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1076
+							'QST_system'        => 'phone',
1077
+							'QST_type'          => 'TEXT',
1078
+							'QST_required'      => 0,
1079
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1080
+							'QST_order'         => 10,
1081
+							'QST_admin_only'    => 0,
1082
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1083
+							'QST_wp_user'       => self::get_default_creator_id(),
1084
+							'QST_deleted'       => 0,
1085
+						);
1086
+						break;
1087
+				}
1088
+				if (! empty($QST_values)) {
1089
+					// insert system question
1090
+					$wpdb->insert(
1091
+						$table_name,
1092
+						$QST_values,
1093
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1094
+					);
1095
+					$QST_ID = $wpdb->insert_id;
1096
+					// QUESTION GROUP QUESTIONS
1097
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1098
+						$system_question_we_want = EEM_Question_Group::system_personal;
1099
+					} else {
1100
+						$system_question_we_want = EEM_Question_Group::system_address;
1101
+					}
1102
+					if (isset($QSG_IDs[$system_question_we_want])) {
1103
+						$QSG_ID = $QSG_IDs[$system_question_we_want];
1104
+					} else {
1105
+						$id_col = EEM_Question_Group::instance()
1106
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1107
+						if (is_array($id_col)) {
1108
+							$QSG_ID = reset($id_col);
1109
+						} else {
1110
+							//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
1111
+							EE_Log::instance()->log(
1112
+								__FILE__,
1113
+								__FUNCTION__,
1114
+								sprintf(
1115
+									__(
1116
+										'Could not associate question %1$s to a question group because no system question
1117 1117
                                          group existed',
1118
-                                        'event_espresso'
1119
-                                    ),
1120
-                                    $QST_ID),
1121
-                                'error');
1122
-                            continue;
1123
-                        }
1124
-                    }
1125
-                    // add system questions to groups
1126
-                    $wpdb->insert(
1127
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1128
-                        array(
1129
-                            'QSG_ID'    => $QSG_ID,
1130
-                            'QST_ID'    => $QST_ID,
1131
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1132
-                        ),
1133
-                        array('%d', '%d', '%d')
1134
-                    );
1135
-                }
1136
-            }
1137
-        }
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * Makes sure the default payment method (Invoice) is active.
1143
-     * This used to be done automatically as part of constructing the old gateways config
1144
-     *
1145
-     * @throws \EE_Error
1146
-     */
1147
-    public static function insert_default_payment_methods()
1148
-    {
1149
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1150
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1151
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1152
-        } else {
1153
-            EEM_Payment_Method::instance()->verify_button_urls();
1154
-        }
1155
-    }
1156
-
1157
-    /**
1158
-     * insert_default_status_codes
1159
-     *
1160
-     * @access public
1161
-     * @static
1162
-     * @return void
1163
-     */
1164
-    public static function insert_default_status_codes()
1165
-    {
1166
-
1167
-        global $wpdb;
1168
-
1169
-        if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1170
-
1171
-            $table_name = EEM_Status::instance()->table();
1172
-
1173
-            $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' );";
1174
-            $wpdb->query($SQL);
1175
-
1176
-            $SQL = "INSERT INTO $table_name
1118
+										'event_espresso'
1119
+									),
1120
+									$QST_ID),
1121
+								'error');
1122
+							continue;
1123
+						}
1124
+					}
1125
+					// add system questions to groups
1126
+					$wpdb->insert(
1127
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1128
+						array(
1129
+							'QSG_ID'    => $QSG_ID,
1130
+							'QST_ID'    => $QST_ID,
1131
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1132
+						),
1133
+						array('%d', '%d', '%d')
1134
+					);
1135
+				}
1136
+			}
1137
+		}
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * Makes sure the default payment method (Invoice) is active.
1143
+	 * This used to be done automatically as part of constructing the old gateways config
1144
+	 *
1145
+	 * @throws \EE_Error
1146
+	 */
1147
+	public static function insert_default_payment_methods()
1148
+	{
1149
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1150
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1151
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1152
+		} else {
1153
+			EEM_Payment_Method::instance()->verify_button_urls();
1154
+		}
1155
+	}
1156
+
1157
+	/**
1158
+	 * insert_default_status_codes
1159
+	 *
1160
+	 * @access public
1161
+	 * @static
1162
+	 * @return void
1163
+	 */
1164
+	public static function insert_default_status_codes()
1165
+	{
1166
+
1167
+		global $wpdb;
1168
+
1169
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1170
+
1171
+			$table_name = EEM_Status::instance()->table();
1172
+
1173
+			$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' );";
1174
+			$wpdb->query($SQL);
1175
+
1176
+			$SQL = "INSERT INTO $table_name
1177 1177
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1178 1178
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1179 1179
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1213,521 +1213,521 @@  discard block
 block discarded – undo
1213 1213
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1214 1214
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1215 1215
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1216
-            $wpdb->query($SQL);
1217
-
1218
-        }
1219
-
1220
-    }
1221
-
1222
-
1223
-    /**
1224
-     * create_upload_directories
1225
-     * Creates folders in the uploads directory to facilitate addons and templates
1226
-     *
1227
-     * @access public
1228
-     * @static
1229
-     * @return boolean success of verifying upload directories exist
1230
-     */
1231
-    public static function create_upload_directories()
1232
-    {
1233
-        // Create the required folders
1234
-        $folders = array(
1235
-            EVENT_ESPRESSO_TEMPLATE_DIR,
1236
-            EVENT_ESPRESSO_GATEWAY_DIR,
1237
-            EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1238
-            EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1239
-            EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1240
-        );
1241
-        foreach ($folders as $folder) {
1242
-            try {
1243
-                EEH_File::ensure_folder_exists_and_is_writable($folder);
1244
-                @ chmod($folder, 0755);
1245
-            } catch (EE_Error $e) {
1246
-                EE_Error::add_error(
1247
-                    sprintf(
1248
-                        __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1249
-                        $folder,
1250
-                        '<br />' . $e->getMessage()
1251
-                    ),
1252
-                    __FILE__, __FUNCTION__, __LINE__
1253
-                );
1254
-                //indicate we'll need to fix this later
1255
-                update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1256
-                return false;
1257
-            }
1258
-        }
1259
-        //just add the .htaccess file to the logs directory to begin with. Even if logging
1260
-        //is disabled, there might be activation errors recorded in there
1261
-        EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1262
-        //remember EE's folders are all good
1263
-        delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1264
-        return true;
1265
-    }
1266
-
1267
-    /**
1268
-     * Whether the upload directories need to be fixed or not.
1269
-     * If EE is installed but filesystem access isn't initially available,
1270
-     * we need to get the user's filesystem credentials and THEN create them,
1271
-     * so there might be period of time when EE is installed but its
1272
-     * upload directories aren't available. This indicates such a state
1273
-     *
1274
-     * @return boolean
1275
-     */
1276
-    public static function upload_directories_incomplete()
1277
-    {
1278
-        return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1279
-    }
1280
-
1281
-
1282
-    /**
1283
-     * generate_default_message_templates
1284
-     *
1285
-     * @static
1286
-     * @throws EE_Error
1287
-     * @return bool     true means new templates were created.
1288
-     *                  false means no templates were created.
1289
-     *                  This is NOT an error flag. To check for errors you will want
1290
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1291
-     */
1292
-    public static function generate_default_message_templates()
1293
-    {
1294
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1295
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1296
-        /*
1216
+			$wpdb->query($SQL);
1217
+
1218
+		}
1219
+
1220
+	}
1221
+
1222
+
1223
+	/**
1224
+	 * create_upload_directories
1225
+	 * Creates folders in the uploads directory to facilitate addons and templates
1226
+	 *
1227
+	 * @access public
1228
+	 * @static
1229
+	 * @return boolean success of verifying upload directories exist
1230
+	 */
1231
+	public static function create_upload_directories()
1232
+	{
1233
+		// Create the required folders
1234
+		$folders = array(
1235
+			EVENT_ESPRESSO_TEMPLATE_DIR,
1236
+			EVENT_ESPRESSO_GATEWAY_DIR,
1237
+			EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1238
+			EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1239
+			EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1240
+		);
1241
+		foreach ($folders as $folder) {
1242
+			try {
1243
+				EEH_File::ensure_folder_exists_and_is_writable($folder);
1244
+				@ chmod($folder, 0755);
1245
+			} catch (EE_Error $e) {
1246
+				EE_Error::add_error(
1247
+					sprintf(
1248
+						__('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1249
+						$folder,
1250
+						'<br />' . $e->getMessage()
1251
+					),
1252
+					__FILE__, __FUNCTION__, __LINE__
1253
+				);
1254
+				//indicate we'll need to fix this later
1255
+				update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1256
+				return false;
1257
+			}
1258
+		}
1259
+		//just add the .htaccess file to the logs directory to begin with. Even if logging
1260
+		//is disabled, there might be activation errors recorded in there
1261
+		EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1262
+		//remember EE's folders are all good
1263
+		delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1264
+		return true;
1265
+	}
1266
+
1267
+	/**
1268
+	 * Whether the upload directories need to be fixed or not.
1269
+	 * If EE is installed but filesystem access isn't initially available,
1270
+	 * we need to get the user's filesystem credentials and THEN create them,
1271
+	 * so there might be period of time when EE is installed but its
1272
+	 * upload directories aren't available. This indicates such a state
1273
+	 *
1274
+	 * @return boolean
1275
+	 */
1276
+	public static function upload_directories_incomplete()
1277
+	{
1278
+		return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1279
+	}
1280
+
1281
+
1282
+	/**
1283
+	 * generate_default_message_templates
1284
+	 *
1285
+	 * @static
1286
+	 * @throws EE_Error
1287
+	 * @return bool     true means new templates were created.
1288
+	 *                  false means no templates were created.
1289
+	 *                  This is NOT an error flag. To check for errors you will want
1290
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1291
+	 */
1292
+	public static function generate_default_message_templates()
1293
+	{
1294
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1295
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1296
+		/*
1297 1297
          * This first method is taking care of ensuring any default messengers
1298 1298
          * that should be made active and have templates generated are done.
1299 1299
          */
1300
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1301
-            $message_resource_manager
1302
-        );
1303
-        /**
1304
-         * This method is verifying there are no NEW default message types
1305
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1306
-         */
1307
-        $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1308
-            $message_resource_manager
1309
-        );
1310
-        //after all is done, let's persist these changes to the db.
1311
-        $message_resource_manager->update_has_activated_messengers_option();
1312
-        $message_resource_manager->update_active_messengers_option();
1313
-        // will return true if either of these are true.  Otherwise will return false.
1314
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1315
-    }
1316
-
1317
-
1318
-
1319
-    /**
1320
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1321
-     * @return array|bool
1322
-     * @throws \EE_Error
1323
-     */
1324
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1325
-        EE_Message_Resource_Manager $message_resource_manager
1326
-    ) {
1327
-        /** @type EE_messenger[] $active_messengers */
1328
-        $active_messengers = $message_resource_manager->active_messengers();
1329
-        $installed_message_types = $message_resource_manager->installed_message_types();
1330
-        $templates_created = false;
1331
-        foreach ($active_messengers as $active_messenger) {
1332
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1333
-            $default_message_type_names_to_activate = array();
1334
-            // looping through each default message type reported by the messenger
1335
-            // and setup the actual message types to activate.
1336
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1337
-                // if already active or has already been activated before we skip
1338
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1339
-                // we also skip if the message type is not installed.
1340
-                if (
1341
-                    $message_resource_manager->has_message_type_been_activated_for_messenger(
1342
-                        $default_message_type_name_for_messenger,
1343
-                        $active_messenger->name
1344
-                    )
1345
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1346
-                        $active_messenger->name,
1347
-                        $default_message_type_name_for_messenger
1348
-                    )
1349
-                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1350
-                ) {
1351
-                    continue;
1352
-                }
1353
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1354
-            }
1355
-            //let's activate!
1356
-            $message_resource_manager->ensure_message_types_are_active(
1357
-                $default_message_type_names_to_activate,
1358
-                $active_messenger->name,
1359
-                false
1360
-            );
1361
-            //activate the templates for these message types
1362
-            if ( ! empty($default_message_type_names_to_activate)) {
1363
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1364
-                    $active_messenger->name,
1365
-                    $default_message_type_names_for_messenger,
1366
-                    '',
1367
-                    true
1368
-                );
1369
-            }
1370
-        }
1371
-        return $templates_created;
1372
-    }
1373
-
1374
-
1375
-
1376
-    /**
1377
-     * This will activate and generate default messengers and default message types for those messengers.
1378
-     *
1379
-     * @param EE_message_Resource_Manager $message_resource_manager
1380
-     * @return array|bool  True means there were default messengers and message type templates generated.
1381
-     *                     False means that there were no templates generated
1382
-     *                     (which could simply mean there are no default message types for a messenger).
1383
-     * @throws EE_Error
1384
-     */
1385
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1386
-        EE_Message_Resource_Manager $message_resource_manager
1387
-    ) {
1388
-        /** @type EE_messenger[] $messengers_to_generate */
1389
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1390
-        $installed_message_types = $message_resource_manager->installed_message_types();
1391
-        $templates_generated = false;
1392
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1393
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1394
-            //verify the default message types match an installed message type.
1395
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1396
-                if (
1397
-                    ! isset($installed_message_types[$name])
1398
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1399
-                        $name,
1400
-                        $messenger_to_generate->name
1401
-                    )
1402
-                ) {
1403
-                    unset($default_message_type_names_for_messenger[$key]);
1404
-                }
1405
-            }
1406
-            // in previous iterations, the active_messengers option in the db
1407
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1408
-            // This comment is left here just in case we discover that we _do_ need to update before
1409
-            // passing off to create templates (after the refactor is done).
1410
-            // @todo remove this comment when determined not necessary.
1411
-            $message_resource_manager->activate_messenger(
1412
-                $messenger_to_generate->name,
1413
-                $default_message_type_names_for_messenger,
1414
-                false
1415
-            );
1416
-            //create any templates needing created (or will reactivate templates already generated as necessary).
1417
-            if ( ! empty($default_message_type_names_for_messenger)) {
1418
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1419
-                    $messenger_to_generate->name,
1420
-                    $default_message_type_names_for_messenger,
1421
-                    '',
1422
-                    true
1423
-                );
1424
-            }
1425
-        }
1426
-        return $templates_generated;
1427
-    }
1428
-
1429
-
1430
-    /**
1431
-     * This returns the default messengers to generate templates for on activation of EE.
1432
-     * It considers:
1433
-     * - whether a messenger is already active in the db.
1434
-     * - whether a messenger has been made active at any time in the past.
1435
-     *
1436
-     * @static
1437
-     * @param  EE_Message_Resource_Manager $message_resource_manager
1438
-     * @return EE_messenger[]
1439
-     */
1440
-    protected static function _get_default_messengers_to_generate_on_activation(
1441
-        EE_Message_Resource_Manager $message_resource_manager
1442
-    ) {
1443
-        $active_messengers    = $message_resource_manager->active_messengers();
1444
-        $installed_messengers = $message_resource_manager->installed_messengers();
1445
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1446
-
1447
-        $messengers_to_generate = array();
1448
-        foreach ($installed_messengers as $installed_messenger) {
1449
-            //if installed messenger is a messenger that should be activated on install
1450
-            //and is not already active
1451
-            //and has never been activated
1452
-            if (
1453
-                ! $installed_messenger->activate_on_install
1454
-                || isset($active_messengers[$installed_messenger->name])
1455
-                || isset($has_activated[$installed_messenger->name])
1456
-            ) {
1457
-                continue;
1458
-            }
1459
-            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1460
-        }
1461
-        return $messengers_to_generate;
1462
-    }
1463
-
1464
-
1465
-    /**
1466
-     * This simply validates active message types to ensure they actually match installed
1467
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1468
-     * rows are set inactive.
1469
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1470
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1471
-     * are still handled in here.
1472
-     *
1473
-     * @since 4.3.1
1474
-     * @return void
1475
-     */
1476
-    public static function validate_messages_system()
1477
-    {
1478
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1479
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1480
-        $message_resource_manager->validate_active_message_types_are_installed();
1481
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1482
-    }
1483
-
1484
-
1485
-    /**
1486
-     * create_no_ticket_prices_array
1487
-     *
1488
-     * @access public
1489
-     * @static
1490
-     * @return void
1491
-     */
1492
-    public static function create_no_ticket_prices_array()
1493
-    {
1494
-        // this creates an array for tracking events that have no active ticket prices created
1495
-        // this allows us to warn admins of the situation so that it can be corrected
1496
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1497
-        if (! $espresso_no_ticket_prices) {
1498
-            add_option('ee_no_ticket_prices', array(), '', false);
1499
-        }
1500
-    }
1501
-
1502
-
1503
-    /**
1504
-     * plugin_deactivation
1505
-     *
1506
-     * @access public
1507
-     * @static
1508
-     * @return void
1509
-     */
1510
-    public static function plugin_deactivation()
1511
-    {
1512
-    }
1513
-
1514
-
1515
-    /**
1516
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1517
-     * (like post meta or term relations)
1518
-     *
1519
-     * @global wpdb $wpdb
1520
-     * @throws \EE_Error
1521
-     */
1522
-    public static function delete_all_espresso_cpt_data()
1523
-    {
1524
-        global $wpdb;
1525
-        //get all the CPT post_types
1526
-        $ee_post_types = array();
1527
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1528
-            if (method_exists($model_name, 'instance')) {
1529
-                $model_obj = call_user_func(array($model_name, 'instance'));
1530
-                if ($model_obj instanceof EEM_CPT_Base) {
1531
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1532
-                }
1533
-            }
1534
-        }
1535
-        //get all our CPTs
1536
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1537
-        $cpt_ids = $wpdb->get_col($query);
1538
-        //delete each post meta and term relations too
1539
-        foreach ($cpt_ids as $post_id) {
1540
-            wp_delete_post($post_id, true);
1541
-        }
1542
-    }
1543
-
1544
-    /**
1545
-     * Deletes all EE custom tables
1546
-     *
1547
-     * @return array
1548
-     */
1549
-    public static function drop_espresso_tables()
1550
-    {
1551
-        $tables = array();
1552
-        // load registry
1553
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1554
-            if (method_exists($model_name, 'instance')) {
1555
-                $model_obj = call_user_func(array($model_name, 'instance'));
1556
-                if ($model_obj instanceof EEM_Base) {
1557
-                    foreach ($model_obj->get_tables() as $table) {
1558
-                        if (strpos($table->get_table_name(), 'esp_')
1559
-                            &&
1560
-                            (
1561
-                                is_main_site()//main site? nuke them all
1562
-                                || ! $table->is_global()//not main site,but not global either. nuke it
1563
-                            )
1564
-                        ) {
1565
-                            $tables[] = $table->get_table_name();
1566
-                        }
1567
-                    }
1568
-                }
1569
-            }
1570
-        }
1571
-
1572
-        //there are some tables whose models were removed.
1573
-        //they should be removed when removing all EE core's data
1574
-        $tables_without_models = array(
1575
-            'esp_promotion',
1576
-            'esp_promotion_applied',
1577
-            'esp_promotion_object',
1578
-            'esp_promotion_rule',
1579
-            'esp_rule',
1580
-        );
1581
-        foreach ($tables_without_models as $table) {
1582
-            $tables[] = $table;
1583
-        }
1584
-        return \EEH_Activation::getTableManager()->dropTables($tables);
1585
-    }
1586
-
1587
-
1588
-
1589
-    /**
1590
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1591
-     * each table name provided has a wpdb prefix attached, and that it exists.
1592
-     * Returns the list actually deleted
1593
-     *
1594
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1595
-     * @global WPDB $wpdb
1596
-     * @param array $table_names
1597
-     * @return array of table names which we deleted
1598
-     */
1599
-    public static function drop_tables($table_names)
1600
-    {
1601
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1602
-    }
1603
-
1604
-
1605
-
1606
-    /**
1607
-     * plugin_uninstall
1608
-     *
1609
-     * @access public
1610
-     * @static
1611
-     * @param bool $remove_all
1612
-     * @return void
1613
-     */
1614
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1615
-    {
1616
-        global $wpdb;
1617
-        self::drop_espresso_tables();
1618
-        $wp_options_to_delete = array(
1619
-            'ee_no_ticket_prices'                => true,
1620
-            'ee_active_messengers'               => true,
1621
-            'ee_has_activated_messenger'         => true,
1622
-            'ee_flush_rewrite_rules'             => true,
1623
-            'ee_config'                          => false,
1624
-            'ee_data_migration_current_db_state' => true,
1625
-            'ee_data_migration_mapping_'         => false,
1626
-            'ee_data_migration_script_'          => false,
1627
-            'ee_data_migrations'                 => true,
1628
-            'ee_dms_map'                         => false,
1629
-            'ee_notices'                         => true,
1630
-            'lang_file_check_'                   => false,
1631
-            'ee_maintenance_mode'                => true,
1632
-            'ee_ueip_optin'                      => true,
1633
-            'ee_ueip_has_notified'               => true,
1634
-            'ee_plugin_activation_errors'        => true,
1635
-            'ee_id_mapping_from'                 => false,
1636
-            'espresso_persistent_admin_notices'  => true,
1637
-            'ee_encryption_key'                  => true,
1638
-            'pue_force_upgrade_'                 => false,
1639
-            'pue_json_error_'                    => false,
1640
-            'pue_install_key_'                   => false,
1641
-            'pue_verification_error_'            => false,
1642
-            'pu_dismissed_upgrade_'              => false,
1643
-            'external_updates-'                  => false,
1644
-            'ee_extra_data'                      => true,
1645
-            'ee_ssn_'                            => false,
1646
-            'ee_rss_'                            => false,
1647
-            'ee_rte_n_tx_'                       => false,
1648
-            'ee_pers_admin_notices'              => true,
1649
-            'ee_job_parameters_'                 => false,
1650
-            'ee_upload_directories_incomplete'   => true,
1651
-            'ee_verified_db_collations'          => true,
1652
-        );
1653
-        if (is_main_site()) {
1654
-            $wp_options_to_delete['ee_network_config'] = true;
1655
-        }
1656
-        $undeleted_options = array();
1657
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1658
-            if ($no_wildcard) {
1659
-                if ( ! delete_option($option_name)) {
1660
-                    $undeleted_options[] = $option_name;
1661
-                }
1662
-            } else {
1663
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1664
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1665
-                    if ( ! delete_option($option_name_from_wildcard)) {
1666
-                        $undeleted_options[] = $option_name_from_wildcard;
1667
-                    }
1668
-                }
1669
-            }
1670
-        }
1671
-        //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1672
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1673
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1674
-            $db_update_sans_ee4 = array();
1675
-            foreach ($espresso_db_update as $version => $times_activated) {
1676
-                if ((string)$version[0] === '3') {//if its NON EE4
1677
-                    $db_update_sans_ee4[$version] = $times_activated;
1678
-                }
1679
-            }
1680
-            update_option('espresso_db_update', $db_update_sans_ee4);
1681
-        }
1682
-        $errors = '';
1683
-        if ( ! empty($undeleted_options)) {
1684
-            $errors .= sprintf(
1685
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1686
-                '<br/>',
1687
-                implode(',<br/>', $undeleted_options)
1688
-            );
1689
-        }
1690
-        if ( ! empty($errors)) {
1691
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1692
-        }
1693
-    }
1694
-
1695
-    /**
1696
-     * Gets the mysql error code from the last used query by wpdb
1697
-     *
1698
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1699
-     */
1700
-    public static function last_wpdb_error_code()
1701
-    {
1702
-        global $wpdb;
1703
-        if ($wpdb->use_mysqli) {
1704
-            return mysqli_errno($wpdb->dbh);
1705
-        } else {
1706
-            return mysql_errno($wpdb->dbh);
1707
-        }
1708
-    }
1709
-
1710
-    /**
1711
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1712
-     *
1713
-     * @global wpdb  $wpdb
1714
-     * @deprecated instead use TableAnalysis::tableExists()
1715
-     * @param string $table_name with or without $wpdb->prefix
1716
-     * @return boolean
1717
-     */
1718
-    public static function table_exists($table_name)
1719
-    {
1720
-        return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1721
-    }
1722
-
1723
-    /**
1724
-     * Resets the cache on EEH_Activation
1725
-     */
1726
-    public static function reset()
1727
-    {
1728
-        self::$_default_creator_id                             = null;
1729
-        self::$_initialized_db_content_already_in_this_request = false;
1730
-    }
1300
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1301
+			$message_resource_manager
1302
+		);
1303
+		/**
1304
+		 * This method is verifying there are no NEW default message types
1305
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1306
+		 */
1307
+		$new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1308
+			$message_resource_manager
1309
+		);
1310
+		//after all is done, let's persist these changes to the db.
1311
+		$message_resource_manager->update_has_activated_messengers_option();
1312
+		$message_resource_manager->update_active_messengers_option();
1313
+		// will return true if either of these are true.  Otherwise will return false.
1314
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1315
+	}
1316
+
1317
+
1318
+
1319
+	/**
1320
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1321
+	 * @return array|bool
1322
+	 * @throws \EE_Error
1323
+	 */
1324
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1325
+		EE_Message_Resource_Manager $message_resource_manager
1326
+	) {
1327
+		/** @type EE_messenger[] $active_messengers */
1328
+		$active_messengers = $message_resource_manager->active_messengers();
1329
+		$installed_message_types = $message_resource_manager->installed_message_types();
1330
+		$templates_created = false;
1331
+		foreach ($active_messengers as $active_messenger) {
1332
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1333
+			$default_message_type_names_to_activate = array();
1334
+			// looping through each default message type reported by the messenger
1335
+			// and setup the actual message types to activate.
1336
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1337
+				// if already active or has already been activated before we skip
1338
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1339
+				// we also skip if the message type is not installed.
1340
+				if (
1341
+					$message_resource_manager->has_message_type_been_activated_for_messenger(
1342
+						$default_message_type_name_for_messenger,
1343
+						$active_messenger->name
1344
+					)
1345
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1346
+						$active_messenger->name,
1347
+						$default_message_type_name_for_messenger
1348
+					)
1349
+					|| ! isset($installed_message_types[$default_message_type_name_for_messenger])
1350
+				) {
1351
+					continue;
1352
+				}
1353
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1354
+			}
1355
+			//let's activate!
1356
+			$message_resource_manager->ensure_message_types_are_active(
1357
+				$default_message_type_names_to_activate,
1358
+				$active_messenger->name,
1359
+				false
1360
+			);
1361
+			//activate the templates for these message types
1362
+			if ( ! empty($default_message_type_names_to_activate)) {
1363
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1364
+					$active_messenger->name,
1365
+					$default_message_type_names_for_messenger,
1366
+					'',
1367
+					true
1368
+				);
1369
+			}
1370
+		}
1371
+		return $templates_created;
1372
+	}
1373
+
1374
+
1375
+
1376
+	/**
1377
+	 * This will activate and generate default messengers and default message types for those messengers.
1378
+	 *
1379
+	 * @param EE_message_Resource_Manager $message_resource_manager
1380
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1381
+	 *                     False means that there were no templates generated
1382
+	 *                     (which could simply mean there are no default message types for a messenger).
1383
+	 * @throws EE_Error
1384
+	 */
1385
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1386
+		EE_Message_Resource_Manager $message_resource_manager
1387
+	) {
1388
+		/** @type EE_messenger[] $messengers_to_generate */
1389
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1390
+		$installed_message_types = $message_resource_manager->installed_message_types();
1391
+		$templates_generated = false;
1392
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1393
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1394
+			//verify the default message types match an installed message type.
1395
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1396
+				if (
1397
+					! isset($installed_message_types[$name])
1398
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1399
+						$name,
1400
+						$messenger_to_generate->name
1401
+					)
1402
+				) {
1403
+					unset($default_message_type_names_for_messenger[$key]);
1404
+				}
1405
+			}
1406
+			// in previous iterations, the active_messengers option in the db
1407
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1408
+			// This comment is left here just in case we discover that we _do_ need to update before
1409
+			// passing off to create templates (after the refactor is done).
1410
+			// @todo remove this comment when determined not necessary.
1411
+			$message_resource_manager->activate_messenger(
1412
+				$messenger_to_generate->name,
1413
+				$default_message_type_names_for_messenger,
1414
+				false
1415
+			);
1416
+			//create any templates needing created (or will reactivate templates already generated as necessary).
1417
+			if ( ! empty($default_message_type_names_for_messenger)) {
1418
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1419
+					$messenger_to_generate->name,
1420
+					$default_message_type_names_for_messenger,
1421
+					'',
1422
+					true
1423
+				);
1424
+			}
1425
+		}
1426
+		return $templates_generated;
1427
+	}
1428
+
1429
+
1430
+	/**
1431
+	 * This returns the default messengers to generate templates for on activation of EE.
1432
+	 * It considers:
1433
+	 * - whether a messenger is already active in the db.
1434
+	 * - whether a messenger has been made active at any time in the past.
1435
+	 *
1436
+	 * @static
1437
+	 * @param  EE_Message_Resource_Manager $message_resource_manager
1438
+	 * @return EE_messenger[]
1439
+	 */
1440
+	protected static function _get_default_messengers_to_generate_on_activation(
1441
+		EE_Message_Resource_Manager $message_resource_manager
1442
+	) {
1443
+		$active_messengers    = $message_resource_manager->active_messengers();
1444
+		$installed_messengers = $message_resource_manager->installed_messengers();
1445
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1446
+
1447
+		$messengers_to_generate = array();
1448
+		foreach ($installed_messengers as $installed_messenger) {
1449
+			//if installed messenger is a messenger that should be activated on install
1450
+			//and is not already active
1451
+			//and has never been activated
1452
+			if (
1453
+				! $installed_messenger->activate_on_install
1454
+				|| isset($active_messengers[$installed_messenger->name])
1455
+				|| isset($has_activated[$installed_messenger->name])
1456
+			) {
1457
+				continue;
1458
+			}
1459
+			$messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1460
+		}
1461
+		return $messengers_to_generate;
1462
+	}
1463
+
1464
+
1465
+	/**
1466
+	 * This simply validates active message types to ensure they actually match installed
1467
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1468
+	 * rows are set inactive.
1469
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1470
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1471
+	 * are still handled in here.
1472
+	 *
1473
+	 * @since 4.3.1
1474
+	 * @return void
1475
+	 */
1476
+	public static function validate_messages_system()
1477
+	{
1478
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1479
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1480
+		$message_resource_manager->validate_active_message_types_are_installed();
1481
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1482
+	}
1483
+
1484
+
1485
+	/**
1486
+	 * create_no_ticket_prices_array
1487
+	 *
1488
+	 * @access public
1489
+	 * @static
1490
+	 * @return void
1491
+	 */
1492
+	public static function create_no_ticket_prices_array()
1493
+	{
1494
+		// this creates an array for tracking events that have no active ticket prices created
1495
+		// this allows us to warn admins of the situation so that it can be corrected
1496
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1497
+		if (! $espresso_no_ticket_prices) {
1498
+			add_option('ee_no_ticket_prices', array(), '', false);
1499
+		}
1500
+	}
1501
+
1502
+
1503
+	/**
1504
+	 * plugin_deactivation
1505
+	 *
1506
+	 * @access public
1507
+	 * @static
1508
+	 * @return void
1509
+	 */
1510
+	public static function plugin_deactivation()
1511
+	{
1512
+	}
1513
+
1514
+
1515
+	/**
1516
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1517
+	 * (like post meta or term relations)
1518
+	 *
1519
+	 * @global wpdb $wpdb
1520
+	 * @throws \EE_Error
1521
+	 */
1522
+	public static function delete_all_espresso_cpt_data()
1523
+	{
1524
+		global $wpdb;
1525
+		//get all the CPT post_types
1526
+		$ee_post_types = array();
1527
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1528
+			if (method_exists($model_name, 'instance')) {
1529
+				$model_obj = call_user_func(array($model_name, 'instance'));
1530
+				if ($model_obj instanceof EEM_CPT_Base) {
1531
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1532
+				}
1533
+			}
1534
+		}
1535
+		//get all our CPTs
1536
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1537
+		$cpt_ids = $wpdb->get_col($query);
1538
+		//delete each post meta and term relations too
1539
+		foreach ($cpt_ids as $post_id) {
1540
+			wp_delete_post($post_id, true);
1541
+		}
1542
+	}
1543
+
1544
+	/**
1545
+	 * Deletes all EE custom tables
1546
+	 *
1547
+	 * @return array
1548
+	 */
1549
+	public static function drop_espresso_tables()
1550
+	{
1551
+		$tables = array();
1552
+		// load registry
1553
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1554
+			if (method_exists($model_name, 'instance')) {
1555
+				$model_obj = call_user_func(array($model_name, 'instance'));
1556
+				if ($model_obj instanceof EEM_Base) {
1557
+					foreach ($model_obj->get_tables() as $table) {
1558
+						if (strpos($table->get_table_name(), 'esp_')
1559
+							&&
1560
+							(
1561
+								is_main_site()//main site? nuke them all
1562
+								|| ! $table->is_global()//not main site,but not global either. nuke it
1563
+							)
1564
+						) {
1565
+							$tables[] = $table->get_table_name();
1566
+						}
1567
+					}
1568
+				}
1569
+			}
1570
+		}
1571
+
1572
+		//there are some tables whose models were removed.
1573
+		//they should be removed when removing all EE core's data
1574
+		$tables_without_models = array(
1575
+			'esp_promotion',
1576
+			'esp_promotion_applied',
1577
+			'esp_promotion_object',
1578
+			'esp_promotion_rule',
1579
+			'esp_rule',
1580
+		);
1581
+		foreach ($tables_without_models as $table) {
1582
+			$tables[] = $table;
1583
+		}
1584
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1585
+	}
1586
+
1587
+
1588
+
1589
+	/**
1590
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1591
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1592
+	 * Returns the list actually deleted
1593
+	 *
1594
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1595
+	 * @global WPDB $wpdb
1596
+	 * @param array $table_names
1597
+	 * @return array of table names which we deleted
1598
+	 */
1599
+	public static function drop_tables($table_names)
1600
+	{
1601
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1602
+	}
1603
+
1604
+
1605
+
1606
+	/**
1607
+	 * plugin_uninstall
1608
+	 *
1609
+	 * @access public
1610
+	 * @static
1611
+	 * @param bool $remove_all
1612
+	 * @return void
1613
+	 */
1614
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1615
+	{
1616
+		global $wpdb;
1617
+		self::drop_espresso_tables();
1618
+		$wp_options_to_delete = array(
1619
+			'ee_no_ticket_prices'                => true,
1620
+			'ee_active_messengers'               => true,
1621
+			'ee_has_activated_messenger'         => true,
1622
+			'ee_flush_rewrite_rules'             => true,
1623
+			'ee_config'                          => false,
1624
+			'ee_data_migration_current_db_state' => true,
1625
+			'ee_data_migration_mapping_'         => false,
1626
+			'ee_data_migration_script_'          => false,
1627
+			'ee_data_migrations'                 => true,
1628
+			'ee_dms_map'                         => false,
1629
+			'ee_notices'                         => true,
1630
+			'lang_file_check_'                   => false,
1631
+			'ee_maintenance_mode'                => true,
1632
+			'ee_ueip_optin'                      => true,
1633
+			'ee_ueip_has_notified'               => true,
1634
+			'ee_plugin_activation_errors'        => true,
1635
+			'ee_id_mapping_from'                 => false,
1636
+			'espresso_persistent_admin_notices'  => true,
1637
+			'ee_encryption_key'                  => true,
1638
+			'pue_force_upgrade_'                 => false,
1639
+			'pue_json_error_'                    => false,
1640
+			'pue_install_key_'                   => false,
1641
+			'pue_verification_error_'            => false,
1642
+			'pu_dismissed_upgrade_'              => false,
1643
+			'external_updates-'                  => false,
1644
+			'ee_extra_data'                      => true,
1645
+			'ee_ssn_'                            => false,
1646
+			'ee_rss_'                            => false,
1647
+			'ee_rte_n_tx_'                       => false,
1648
+			'ee_pers_admin_notices'              => true,
1649
+			'ee_job_parameters_'                 => false,
1650
+			'ee_upload_directories_incomplete'   => true,
1651
+			'ee_verified_db_collations'          => true,
1652
+		);
1653
+		if (is_main_site()) {
1654
+			$wp_options_to_delete['ee_network_config'] = true;
1655
+		}
1656
+		$undeleted_options = array();
1657
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1658
+			if ($no_wildcard) {
1659
+				if ( ! delete_option($option_name)) {
1660
+					$undeleted_options[] = $option_name;
1661
+				}
1662
+			} else {
1663
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1664
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1665
+					if ( ! delete_option($option_name_from_wildcard)) {
1666
+						$undeleted_options[] = $option_name_from_wildcard;
1667
+					}
1668
+				}
1669
+			}
1670
+		}
1671
+		//also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1672
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1673
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1674
+			$db_update_sans_ee4 = array();
1675
+			foreach ($espresso_db_update as $version => $times_activated) {
1676
+				if ((string)$version[0] === '3') {//if its NON EE4
1677
+					$db_update_sans_ee4[$version] = $times_activated;
1678
+				}
1679
+			}
1680
+			update_option('espresso_db_update', $db_update_sans_ee4);
1681
+		}
1682
+		$errors = '';
1683
+		if ( ! empty($undeleted_options)) {
1684
+			$errors .= sprintf(
1685
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1686
+				'<br/>',
1687
+				implode(',<br/>', $undeleted_options)
1688
+			);
1689
+		}
1690
+		if ( ! empty($errors)) {
1691
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1692
+		}
1693
+	}
1694
+
1695
+	/**
1696
+	 * Gets the mysql error code from the last used query by wpdb
1697
+	 *
1698
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1699
+	 */
1700
+	public static function last_wpdb_error_code()
1701
+	{
1702
+		global $wpdb;
1703
+		if ($wpdb->use_mysqli) {
1704
+			return mysqli_errno($wpdb->dbh);
1705
+		} else {
1706
+			return mysql_errno($wpdb->dbh);
1707
+		}
1708
+	}
1709
+
1710
+	/**
1711
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1712
+	 *
1713
+	 * @global wpdb  $wpdb
1714
+	 * @deprecated instead use TableAnalysis::tableExists()
1715
+	 * @param string $table_name with or without $wpdb->prefix
1716
+	 * @return boolean
1717
+	 */
1718
+	public static function table_exists($table_name)
1719
+	{
1720
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1721
+	}
1722
+
1723
+	/**
1724
+	 * Resets the cache on EEH_Activation
1725
+	 */
1726
+	public static function reset()
1727
+	{
1728
+		self::$_default_creator_id                             = null;
1729
+		self::$_initialized_db_content_already_in_this_request = false;
1730
+	}
1731 1731
 }
1732 1732
 // End of file EEH_Activation.helper.php
1733 1733
 // Location: /helpers/EEH_Activation.core.php
Please login to merge, or discard this patch.
core/exceptions/ExceptionStackTraceDisplay.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
 			// add generic non-identifying messages for non-privileged users
119 119
 			if ( ! WP_DEBUG ) {
120 120
 				$output .= '<span class="ee-error-user-msg-spn">'
121
-				           . trim( $msg )
122
-				           . '</span> &nbsp; <sup>'
123
-				           . $code
124
-				           . '</sup><br />';
121
+						   . trim( $msg )
122
+						   . '</span> &nbsp; <sup>'
123
+						   . $code
124
+						   . '</sup><br />';
125 125
 			} else {
126 126
 				// or helpful developer messages if debugging is on
127 127
 				$output .= '
@@ -130,39 +130,39 @@  discard block
 block discarded – undo
130 130
 				'
131 131
 				. sprintf(
132 132
 					__( '%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso' ),
133
-				    '<strong class="ee-error-dev-msg-str">',
133
+					'<strong class="ee-error-dev-msg-str">',
134 134
 					get_class( $exception ),
135 135
 					'</strong>  &nbsp; <span>',
136 136
 					$code . '</span>'
137 137
 				)
138 138
 				. '<br />
139 139
 				<span class="big-text">"'
140
-				           . trim( $msg )
141
-				           . '"</span><br/>
140
+						   . trim( $msg )
141
+						   . '"</span><br/>
142 142
 				<a id="display-ee-error-trace-1'
143
-				           . $time
144
-				           . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1'
145
-				           . $time
146
-				           . '">
143
+						   . $time
144
+						   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1'
145
+						   . $time
146
+						   . '">
147 147
 					'
148
-				           . __( 'click to view backtrace and class/method details', 'event_espresso' )
149
-				           . '
148
+						   . __( 'click to view backtrace and class/method details', 'event_espresso' )
149
+						   . '
150 150
 				</a><br />
151 151
 				'
152
-				           . $exception->getFile()
153
-				           . sprintf(
154
-					           __( '%1$s( line no: %2$s )%3$s', 'event_espresso' ),
155
-					           ' &nbsp; <span class="small-text lt-grey-text">',
156
-					           $exception->getLine(),
157
-					           '</span>'
158
-				           )
159
-				           . '
152
+						   . $exception->getFile()
153
+						   . sprintf(
154
+							   __( '%1$s( line no: %2$s )%3$s', 'event_espresso' ),
155
+							   ' &nbsp; <span class="small-text lt-grey-text">',
156
+							   $exception->getLine(),
157
+							   '</span>'
158
+						   )
159
+						   . '
160 160
 			</p>
161 161
 			<div id="ee-error-trace-1'
162
-				           . $time
163
-				           . '-dv" class="ee-error-trace-dv" style="display: none;">
162
+						   . $time
163
+						   . '-dv" class="ee-error-trace-dv" style="display: none;">
164 164
 				'
165
-				           . $trace_details;
165
+						   . $trace_details;
166 166
 				if ( ! empty( $class ) ) {
167 167
 					$output .= '
168 168
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;">
@@ -371,9 +371,9 @@  discard block
 block discarded – undo
371 371
 			if ( wp_script_is( 'ee_error_js', 'enqueued' ) ) {
372 372
 				return '';
373 373
 			} else if ( wp_script_is( 'ee_error_js', 'registered' ) ) {
374
-                wp_enqueue_style('espresso_default');
375
-                wp_enqueue_style('espresso_custom_css');
376
-                wp_enqueue_script( 'ee_error_js' );
374
+				wp_enqueue_style('espresso_default');
375
+				wp_enqueue_style('espresso_custom_css');
376
+				wp_enqueue_script( 'ee_error_js' );
377 377
 				wp_localize_script( 'ee_error_js', 'ee_settings', array( 'wp_debug' => WP_DEBUG ) );
378 378
 			}
379 379
 		} else {
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\exceptions;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * @param \Exception $exception
24 24
 	 */
25
-	public function __construct( \Exception $exception ) {
26
-		if ( WP_DEBUG ) {
27
-			$this->displayException( $exception );
25
+	public function __construct(\Exception $exception) {
26
+		if (WP_DEBUG) {
27
+			$this->displayException($exception);
28 28
 		}
29 29
 	}
30 30
 
@@ -34,27 +34,27 @@  discard block
 block discarded – undo
34 34
 	 * @access protected
35 35
 	 * @param \Exception $exception
36 36
 	 */
37
-	protected function displayException( \Exception $exception ) {
37
+	protected function displayException(\Exception $exception) {
38 38
 
39 39
 		$error_code = '';
40 40
 		$trace_details = '';
41 41
 		$time = time();
42 42
 		$trace = $exception->getTrace();
43 43
 		// get separate user and developer messages if they exist
44
-		$msg = explode( '||', $exception->getMessage() );
44
+		$msg = explode('||', $exception->getMessage());
45 45
 		$user_msg = $msg[0];
46
-		$dev_msg = isset( $msg[1] ) ? $msg[1] : $msg[0];
46
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
47 47
 		$msg = WP_DEBUG ? $dev_msg : $user_msg;
48 48
 		// start gathering output
49 49
 		$output = $this->exceptionStyles();
50 50
 		$output .= '
51 51
 <div id="ee-error-message" class="error">';
52
-		if ( ! WP_DEBUG ) {
52
+		if ( ! WP_DEBUG) {
53 53
 			$output .= '
54 54
 	<p>';
55 55
 		}
56 56
 			// process trace info
57
-			if ( empty( $trace ) ) {
57
+			if (empty($trace)) {
58 58
 				$trace_details .= __(
59 59
 					'Sorry, but no trace information was available for this exception.',
60 60
 					'event_espresso'
@@ -67,47 +67,47 @@  discard block
 block discarded – undo
67 67
 					<th scope="col" align="right" style="width:2.5%;">#</th>
68 68
 					<th scope="col" align="right" style="width:3.5%;">Line</th>
69 69
 					<th scope="col" align="left" style="width:40%;">File</th>
70
-					<th scope="col" align="left">' . __( 'Class', 'event_espresso' ) . '->' . __( 'Method( arguments )', 'event_espresso' ) . '</th>
70
+					<th scope="col" align="left">' . __('Class', 'event_espresso').'->'.__('Method( arguments )', 'event_espresso').'</th>
71 71
 				</tr>';
72
-				$last_on_stack = count( $trace ) - 1;
72
+				$last_on_stack = count($trace) - 1;
73 73
 				// reverse array so that stack is in proper chronological order
74
-				$sorted_trace = array_reverse( $trace );
75
-				foreach ( $sorted_trace as $nmbr => $trace ) {
76
-					$file = isset( $trace['file'] ) ? $trace['file'] : '';
77
-					$class = isset( $trace['class'] ) ? $trace['class'] : '';
78
-					$type = isset( $trace['type'] ) ? $trace['type'] : '';
79
-					$function = isset( $trace['function'] ) ? $trace['function'] : '';
80
-					$args = isset( $trace['args'] ) ? $this->_convert_args_to_string( $trace['args'] ) : '';
81
-					$args = isset( $trace['args'] ) && count( $trace['args'] ) > 4  ? ' <br />' . $args . '<br />' : $args;
82
-					$line = isset( $trace['line'] ) ? $trace['line'] : '';
74
+				$sorted_trace = array_reverse($trace);
75
+				foreach ($sorted_trace as $nmbr => $trace) {
76
+					$file = isset($trace['file']) ? $trace['file'] : '';
77
+					$class = isset($trace['class']) ? $trace['class'] : '';
78
+					$type = isset($trace['type']) ? $trace['type'] : '';
79
+					$function = isset($trace['function']) ? $trace['function'] : '';
80
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
81
+					$args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />'.$args.'<br />' : $args;
82
+					$line = isset($trace['line']) ? $trace['line'] : '';
83 83
 					$zebra = $nmbr % 2 !== 0 ? ' odd' : '';
84
-					if ( empty( $file ) && ! empty( $class ) ) {
85
-						$a = new \ReflectionClass( $class );
84
+					if (empty($file) && ! empty($class)) {
85
+						$a = new \ReflectionClass($class);
86 86
 						$file = $a->getFileName();
87
-						if ( empty( $line ) && ! empty( $function ) ) {
88
-							$b = new \ReflectionMethod( $class, $function );
87
+						if (empty($line) && ! empty($function)) {
88
+							$b = new \ReflectionMethod($class, $function);
89 89
 							$line = $b->getStartLine();
90 90
 						}
91 91
 					}
92
-					if ( $nmbr === $last_on_stack ) {
92
+					if ($nmbr === $last_on_stack) {
93 93
 						$file = $exception->getFile() !== '' ? $exception->getFile() : $file;
94 94
 						$line = $exception->getLine() !== '' ? $exception->getLine() : $line;
95
-						$error_code = $this->generate_error_code( $file, $trace['function'], $line );
95
+						$error_code = $this->generate_error_code($file, $trace['function'], $line);
96 96
 					}
97
-					$file = \EEH_File::standardise_directory_separators( $file );
98
-					$nmbr = ! empty( $nmbr ) ? $nmbr : '&nbsp;';
99
-					$line = ! empty( $line ) ? $line : '&nbsp;';
100
-					$file = ! empty( $file ) ? $file : '&nbsp;';
101
-					$class_display = ! empty( $class ) ? $class : '';
102
-					$type = ! empty( $type ) ? $type : '';
103
-					$function = ! empty( $function ) ? $function : '';
104
-					$args = ! empty( $args ) ? '( ' . $args . ' )' : '()';
97
+					$file = \EEH_File::standardise_directory_separators($file);
98
+					$nmbr = ! empty($nmbr) ? $nmbr : '&nbsp;';
99
+					$line = ! empty($line) ? $line : '&nbsp;';
100
+					$file = ! empty($file) ? $file : '&nbsp;';
101
+					$class_display = ! empty($class) ? $class : '';
102
+					$type = ! empty($type) ? $type : '';
103
+					$function = ! empty($function) ? $function : '';
104
+					$args = ! empty($args) ? '( '.$args.' )' : '()';
105 105
 					$trace_details .= '
106 106
 					<tr>
107
-						<td align="right" valign="top" class="' . $zebra . '">' . $nmbr . '</td>
108
-						<td align="right" valign="top" class="' . $zebra . '">' . $line . '</td>
109
-						<td align="left" valign="top" class="' . $zebra . '">' . $file . '</td>
110
-						<td align="left" valign="top" class="' . $zebra . '">' . $class_display . $type . $function . $args . '</td>
107
+						<td align="right" valign="top" class="' . $zebra.'">'.$nmbr.'</td>
108
+						<td align="right" valign="top" class="' . $zebra.'">'.$line.'</td>
109
+						<td align="left" valign="top" class="' . $zebra.'">'.$file.'</td>
110
+						<td align="left" valign="top" class="' . $zebra.'">'.$class_display.$type.$function.$args.'</td>
111 111
 					</tr>';
112 112
 				}
113 113
 				$trace_details .= '
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 			}
117 117
 			$code = $exception->getCode() ? $exception->getCode() : $error_code;
118 118
 			// add generic non-identifying messages for non-privileged users
119
-			if ( ! WP_DEBUG ) {
119
+			if ( ! WP_DEBUG) {
120 120
 				$output .= '<span class="ee-error-user-msg-spn">'
121
-				           . trim( $msg )
121
+				           . trim($msg)
122 122
 				           . '</span> &nbsp; <sup>'
123 123
 				           . $code
124 124
 				           . '</sup><br />';
@@ -129,15 +129,15 @@  discard block
 block discarded – undo
129 129
 			<p class="ee-error-dev-msg-pg">
130 130
 				'
131 131
 				. sprintf(
132
-					__( '%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso' ),
132
+					__('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'),
133 133
 				    '<strong class="ee-error-dev-msg-str">',
134
-					get_class( $exception ),
134
+					get_class($exception),
135 135
 					'</strong>  &nbsp; <span>',
136
-					$code . '</span>'
136
+					$code.'</span>'
137 137
 				)
138 138
 				. '<br />
139 139
 				<span class="big-text">"'
140
-				           . trim( $msg )
140
+				           . trim($msg)
141 141
 				           . '"</span><br/>
142 142
 				<a id="display-ee-error-trace-1'
143 143
 				           . $time
@@ -145,13 +145,13 @@  discard block
 block discarded – undo
145 145
 				           . $time
146 146
 				           . '">
147 147
 					'
148
-				           . __( 'click to view backtrace and class/method details', 'event_espresso' )
148
+				           . __('click to view backtrace and class/method details', 'event_espresso')
149 149
 				           . '
150 150
 				</a><br />
151 151
 				'
152 152
 				           . $exception->getFile()
153 153
 				           . sprintf(
154
-					           __( '%1$s( line no: %2$s )%3$s', 'event_espresso' ),
154
+					           __('%1$s( line no: %2$s )%3$s', 'event_espresso'),
155 155
 					           ' &nbsp; <span class="small-text lt-grey-text">',
156 156
 					           $exception->getLine(),
157 157
 					           '</span>'
@@ -163,14 +163,14 @@  discard block
 block discarded – undo
163 163
 				           . '-dv" class="ee-error-trace-dv" style="display: none;">
164 164
 				'
165 165
 				           . $trace_details;
166
-				if ( ! empty( $class ) ) {
166
+				if ( ! empty($class)) {
167 167
 					$output .= '
168 168
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;">
169 169
 					<div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;">
170
-						<h3>' . __( 'Class Details', 'event_espresso' ) . '</h3>';
171
-					$a = new \ReflectionClass( $class );
170
+						<h3>' . __('Class Details', 'event_espresso').'</h3>';
171
+					$a = new \ReflectionClass($class);
172 172
 					$output .= '
173
-						<pre>' . $a . '</pre>
173
+						<pre>' . $a.'</pre>
174 174
 					</div>
175 175
 				</div>';
176 176
 				}
@@ -180,16 +180,16 @@  discard block
 block discarded – undo
180 180
 		<br />';
181 181
 			}
182 182
 		// remove last linebreak
183
-		$output = substr( $output, 0, count( $output ) - 7 );
184
-		if ( ! WP_DEBUG ) {
183
+		$output = substr($output, 0, count($output) - 7);
184
+		if ( ! WP_DEBUG) {
185 185
 			$output .= '
186 186
 	</p>';
187 187
 		}
188 188
 		$output .= '
189 189
 </div>';
190
-		$output .= $this->printScripts( true );
191
-		if ( defined( 'DOING_AJAX' ) ) {
192
-			echo wp_json_encode( array( 'error' => $output ) );
190
+		$output .= $this->printScripts(true);
191
+		if (defined('DOING_AJAX')) {
192
+			echo wp_json_encode(array('error' => $output));
193 193
 			exit();
194 194
 		}
195 195
 		echo $output;
@@ -206,56 +206,56 @@  discard block
 block discarded – undo
206 206
 	 * @param bool  $array
207 207
 	 * @return string
208 208
 	 */
209
-	private function _convert_args_to_string( $arguments = array(), $indent = 0, $array = false ) {
209
+	private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false) {
210 210
 		$args = array();
211
-		$args_count = count( $arguments );
212
-		if ( $args_count > 2 ) {
211
+		$args_count = count($arguments);
212
+		if ($args_count > 2) {
213 213
 			$indent++;
214 214
 			$args[] = '<br />';
215 215
 		}
216 216
 		$x = 0;
217
-		foreach ( $arguments as $arg ) {
217
+		foreach ($arguments as $arg) {
218 218
 			$x++;
219
-			for( $i = 0; $i < $indent; $i++ ) {
219
+			for ($i = 0; $i < $indent; $i++) {
220 220
 				$args[] = ' &nbsp;&nbsp; ';
221 221
 			}
222
-			if ( is_string( $arg ) ) {
223
-				if ( ! $array && strlen( $arg ) > 75 ) {
222
+			if (is_string($arg)) {
223
+				if ( ! $array && strlen($arg) > 75) {
224 224
 					$args[] = "<br />";
225
-					for ( $i = 0; $i <= $indent; $i++ ) {
225
+					for ($i = 0; $i <= $indent; $i++) {
226 226
 						$args[] = ' &nbsp;&nbsp; ';
227 227
 					}
228
-					$args[] = "'" . $arg . "'<br />";
228
+					$args[] = "'".$arg."'<br />";
229 229
 				} else {
230
-					$args[] = " '" . $arg . "'";
230
+					$args[] = " '".$arg."'";
231 231
 				}
232
-			} elseif ( is_array( $arg ) ) {
233
-				$arg_count = count( $arg );
234
-				if ( $arg_count > 2 ) {
232
+			} elseif (is_array($arg)) {
233
+				$arg_count = count($arg);
234
+				if ($arg_count > 2) {
235 235
 					$indent++;
236
-					$args[] = " array(" . $this->_convert_args_to_string( $arg, $indent, true ) . ")";
236
+					$args[] = " array(".$this->_convert_args_to_string($arg, $indent, true).")";
237 237
 					$indent--;
238
-				} else if ( $arg_count === 0 ) {
238
+				} else if ($arg_count === 0) {
239 239
 					$args[] = " array()";
240 240
 				} else {
241
-					$args[] = " array( " . $this->_convert_args_to_string( $arg ) . " )";
241
+					$args[] = " array( ".$this->_convert_args_to_string($arg)." )";
242 242
 				}
243
-			} elseif ( $arg === null ) {
243
+			} elseif ($arg === null) {
244 244
 				$args[] = ' null';
245
-			} elseif ( is_bool( $arg ) ) {
245
+			} elseif (is_bool($arg)) {
246 246
 				$args[] = $arg ? ' true' : ' false';
247
-			} elseif ( is_object( $arg ) ) {
248
-				$args[] = get_class( $arg );
249
-			} elseif ( is_resource( $arg ) ) {
250
-				$args[] = get_resource_type( $arg );
247
+			} elseif (is_object($arg)) {
248
+				$args[] = get_class($arg);
249
+			} elseif (is_resource($arg)) {
250
+				$args[] = get_resource_type($arg);
251 251
 			} else {
252 252
 				$args[] = $arg;
253 253
 			}
254
-			if ( $x === $args_count ) {
255
-				if ( $args_count > 2 ) {
254
+			if ($x === $args_count) {
255
+				if ($args_count > 2) {
256 256
 					$args[] = "<br />";
257 257
 					$indent--;
258
-					for ( $i = 1; $i < $indent; $i++ ) {
258
+					for ($i = 1; $i < $indent; $i++) {
259 259
 						$args[] = ' &nbsp;&nbsp; ';
260 260
 					}
261 261
 				}
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 				$args[] = $args_count > 2 ? ",<br />" : ', ';
264 264
 			}
265 265
 		}
266
-		return implode( '', $args );
266
+		return implode('', $args);
267 267
 	}
268 268
 
269 269
 
@@ -278,11 +278,11 @@  discard block
 block discarded – undo
278 278
 	 * @param string $line
279 279
 	 * @return string
280 280
 	 */
281
-	protected function generate_error_code( $file = '', $func = '', $line = '' ) {
282
-		$file_bits = explode( '.', basename( $file ) );
283
-		$error_code = ! empty( $file_bits[0] ) ? $file_bits[0] : '';
284
-		$error_code .= ! empty( $func ) ? ' - ' . $func : '';
285
-		$error_code .= ! empty( $line ) ? ' - ' . $line : '';
281
+	protected function generate_error_code($file = '', $func = '', $line = '') {
282
+		$file_bits = explode('.', basename($file));
283
+		$error_code = ! empty($file_bits[0]) ? $file_bits[0] : '';
284
+		$error_code .= ! empty($func) ? ' - '.$func : '';
285
+		$error_code .= ! empty($line) ? ' - '.$line : '';
286 286
 		return $error_code;
287 287
 	}
288 288
 
@@ -366,26 +366,26 @@  discard block
 block discarded – undo
366 366
 	 * @param bool $force_print
367 367
 	 * @return string|void
368 368
 	 */
369
-	private function printScripts( $force_print = false ) {
370
-		if ( ! $force_print  && ( did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' ) ) ) {
371
-			if ( wp_script_is( 'ee_error_js', 'enqueued' ) ) {
369
+	private function printScripts($force_print = false) {
370
+		if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
371
+			if (wp_script_is('ee_error_js', 'enqueued')) {
372 372
 				return '';
373
-			} else if ( wp_script_is( 'ee_error_js', 'registered' ) ) {
373
+			} else if (wp_script_is('ee_error_js', 'registered')) {
374 374
                 wp_enqueue_style('espresso_default');
375 375
                 wp_enqueue_style('espresso_custom_css');
376
-                wp_enqueue_script( 'ee_error_js' );
377
-				wp_localize_script( 'ee_error_js', 'ee_settings', array( 'wp_debug' => WP_DEBUG ) );
376
+                wp_enqueue_script('ee_error_js');
377
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
378 378
 			}
379 379
 		} else {
380 380
 			return '
381 381
 <script>
382 382
 /* <![CDATA[ */
383
-var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
383
+var ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
384 384
 /* ]]> */
385 385
 </script>
386
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
387
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
388
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
386
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
387
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
388
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
389 389
 ';
390 390
 		}
391 391
 		return '';
Please login to merge, or discard this patch.
modules/events_archive_filters/EED_Events_Archive_Filters.module.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -589,9 +589,9 @@
 block discarded – undo
589 589
 	 */
590 590
 	private function _load_assests() {
591 591
 		do_action( 'AHEE__EED_Events_Archive_Filters__before_load_assests' );
592
-        wp_enqueue_style('espresso_default');
593
-        wp_enqueue_style('espresso_custom_css');
594
-        add_filter( 'FHEE_load_EE_Session', '__return_true' );
592
+		wp_enqueue_style('espresso_default');
593
+		wp_enqueue_style('espresso_custom_css');
594
+		add_filter( 'FHEE_load_EE_Session', '__return_true' );
595 595
 		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
596 596
 		if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) {
597 597
 			add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 );
Please login to merge, or discard this patch.
Spacing   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * @return EED_Events_Archive_Filters
30 30
 	 */
31 31
 	public static function instance() {
32
-		return parent::get_instance( __CLASS__ );
32
+		return parent::get_instance(__CLASS__);
33 33
 	}
34 34
 
35 35
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 *	@var 	$_types
72 72
 	 * 	@access 	protected
73 73
 	 */
74
-	protected static $_types = array( 'grid', 'text', 'dates' );
74
+	protected static $_types = array('grid', 'text', 'dates');
75 75
 
76 76
 
77 77
 //	public static $espresso_event_list_ID = 0;
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 	 *  @access 	public
126 126
 	 *  @return 	void
127 127
 	 */
128
-	public function run( $WP ) {
128
+	public function run($WP) {
129 129
 //		do_action( 'AHEE__EED_Events_Archive_Filters__before_run' );
130 130
 //		// set config
131 131
 //		if ( ! isset( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters ) || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters instanceof EE_Events_Archive_Config ) {
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
 	 */
171 171
 	private function _filter_query_parts() {
172 172
 		// build event list query
173
-		add_filter( 'posts_join', array( $this, 'posts_join' ), 1, 2 );
174
-		add_filter( 'posts_where', array( $this, 'posts_where' ), 1, 2 );
175
-		add_filter( 'posts_orderby', array( $this, 'posts_orderby' ), 1, 2 );
173
+		add_filter('posts_join', array($this, 'posts_join'), 1, 2);
174
+		add_filter('posts_where', array($this, 'posts_where'), 1, 2);
175
+		add_filter('posts_orderby', array($this, 'posts_orderby'), 1, 2);
176 176
 	}
177 177
 
178 178
 	/**
@@ -182,13 +182,13 @@  discard block
 block discarded – undo
182 182
 	 *  @return 	string
183 183
 	 */
184 184
 	public static function set_type() {
185
-		do_action( 'AHEE__EED_Events_Archive_Filters__before_set_type' );
186
-		EED_Events_Archive_Filters::$_types = apply_filters( 'EED_Events_Archive_Filters__set_type__types', EED_Events_Archive_Filters::$_types );
187
-		$view = isset( EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] ) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] : 'grid';
188
-		$elf_type = EE_Registry::instance()->REQ->is_set( 'elf_type' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_type' )) : '';
189
-		$view = ! empty( $elf_type ) ? $elf_type : $view;
190
-		$view = apply_filters( 'EED_Events_Archive_Filters__set_type__type', $view );
191
-		if ( ! empty( $view ) && in_array( $view, EED_Events_Archive_Filters::$_types )) {
185
+		do_action('AHEE__EED_Events_Archive_Filters__before_set_type');
186
+		EED_Events_Archive_Filters::$_types = apply_filters('EED_Events_Archive_Filters__set_type__types', EED_Events_Archive_Filters::$_types);
187
+		$view = isset(EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type']) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] : 'grid';
188
+		$elf_type = EE_Registry::instance()->REQ->is_set('elf_type') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_type')) : '';
189
+		$view = ! empty($elf_type) ? $elf_type : $view;
190
+		$view = apply_filters('EED_Events_Archive_Filters__set_type__type', $view);
191
+		if ( ! empty($view) && in_array($view, EED_Events_Archive_Filters::$_types)) {
192 192
 			self::$_type = $view;
193 193
 		}
194 194
 	}
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
 	 *  @param	boolean	$req_only if TRUE, then ignore defaults and only return $_POST value
201 201
 	 *  @return 	boolean
202 202
 	 */
203
-	private static function _show_expired( $req_only = FALSE ) {
203
+	private static function _show_expired($req_only = FALSE) {
204 204
 		// get default value for "display_expired_events" as set in the EE General Settings > Templates > Event Listings
205
-		$show_expired = ! $req_only && isset( EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] ) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] : FALSE;
205
+		$show_expired = ! $req_only && isset(EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events']) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] : FALSE;
206 206
 		// override default expired option if set via filter
207
-		$show_expired = EE_Registry::instance()->REQ->is_set( 'elf_expired_chk' ) ? absint( EE_Registry::instance()->REQ->get( 'elf_expired_chk' )) : $show_expired;
207
+		$show_expired = EE_Registry::instance()->REQ->is_set('elf_expired_chk') ? absint(EE_Registry::instance()->REQ->get('elf_expired_chk')) : $show_expired;
208 208
 		return $show_expired ? TRUE : FALSE;
209 209
 	}
210 210
 
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 *  @return 	string
216 216
 	 */
217 217
 	private static function _event_category_slug() {
218
-		return EE_Registry::instance()->REQ->is_set( 'elf_category_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_category_dd' )) : '';
218
+		return EE_Registry::instance()->REQ->is_set('elf_category_dd') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_category_dd')) : '';
219 219
 	}
220 220
 
221 221
 	/**
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 *  @return 	string
226 226
 	 */
227 227
 	private static function _display_month() {
228
-		return EE_Registry::instance()->REQ->is_set( 'elf_month_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_month_dd' )) : '';
228
+		return EE_Registry::instance()->REQ->is_set('elf_month_dd') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_month_dd')) : '';
229 229
 	}
230 230
 
231 231
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	public function get_post_data() {
240 240
 		$this->_elf_month = EED_Events_Archive_Filters::_display_month();
241 241
 		$this->_elf_category = EED_Events_Archive_Filters::_event_category_slug();
242
-		$this->_show_expired = EED_Events_Archive_Filters::_show_expired( TRUE );
242
+		$this->_show_expired = EED_Events_Archive_Filters::_show_expired(TRUE);
243 243
 //		EEH_Debug_Tools::printr( EE_Registry::instance()->REQ, 'EE_Registry::instance()->REQ  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
244 244
 //		echo '<h4>$this->_elf_month : ' . $this->_elf_month . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
245 245
 //		echo '<h4>$this->_elf_category : ' . $this->_elf_category . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
@@ -256,11 +256,11 @@  discard block
 block discarded – undo
256 256
 	 *  @access 	public
257 257
 	 *  @return 	void
258 258
 	 */
259
-	public function posts_join( $SQL, WP_Query $wp_query ) {
260
-		if ( isset( $wp_query->query ) && isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == 'espresso_events' ) {
259
+	public function posts_join($SQL, WP_Query $wp_query) {
260
+		if (isset($wp_query->query) && isset($wp_query->query['post_type']) && $wp_query->query['post_type'] == 'espresso_events') {
261 261
 			// Category
262 262
 //			$elf_category = EE_Registry::instance()->REQ->is_set( 'elf_category_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_category_dd' )) : '';
263
-			$SQL .= EED_Events_Archive_Filters::posts_join_sql_for_terms( EED_Events_Archive_Filters::_event_category_slug() );
263
+			$SQL .= EED_Events_Archive_Filters::posts_join_sql_for_terms(EED_Events_Archive_Filters::_event_category_slug());
264 264
 		}
265 265
 		return $SQL;
266 266
 	}
@@ -273,9 +273,9 @@  discard block
 block discarded – undo
273 273
 	 *  @param	mixed boolean|string	$join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get used for anything yet
274 274
 	 *  @return 	string
275 275
 	 */
276
-	public static function posts_join_sql_for_terms( $join_terms = NULL ) {
277
-		$SQL= '';
278
-		if ( ! empty( $join_terms )) {
276
+	public static function posts_join_sql_for_terms($join_terms = NULL) {
277
+		$SQL = '';
278
+		if ( ! empty($join_terms)) {
279 279
 			global $wpdb;
280 280
 			$SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
281 281
 			$SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
@@ -293,28 +293,28 @@  discard block
 block discarded – undo
293 293
 	 *  @param	array	$orderby_params
294 294
 	 *  @return 	string
295 295
 	 */
296
-	public static function posts_join_for_orderby( $orderby_params = array() ) {
296
+	public static function posts_join_for_orderby($orderby_params = array()) {
297 297
 		global $wpdb;
298
-		$SQL= '';
299
-		$orderby_params = is_array( $orderby_params ) ? $orderby_params : array( $orderby_params );
300
-		foreach( $orderby_params as $orderby ) {
301
-			switch ( $orderby ) {
298
+		$SQL = '';
299
+		$orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params);
300
+		foreach ($orderby_params as $orderby) {
301
+			switch ($orderby) {
302 302
 
303 303
 				case 'ticket_start' :
304 304
 				case 'ticket_end' :
305
-					$SQL .= ' LEFT JOIN ' . EEM_Datetime_Ticket::instance()->table() . ' ON (' . EEM_Datetime::instance()->table() . '.DTT_ID = ' . EEM_Datetime_Ticket::instance()->table() . '.DTT_ID )';
306
-					$SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table() . ' ON (' . EEM_Datetime_Ticket::instance()->table() . '.TKT_ID = ' . EEM_Ticket::instance()->table() . '.TKT_ID )';
305
+					$SQL .= ' LEFT JOIN '.EEM_Datetime_Ticket::instance()->table().' ON ('.EEM_Datetime::instance()->table().'.DTT_ID = '.EEM_Datetime_Ticket::instance()->table().'.DTT_ID )';
306
+					$SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table().' ON ('.EEM_Datetime_Ticket::instance()->table().'.TKT_ID = '.EEM_Ticket::instance()->table().'.TKT_ID )';
307 307
 					break;
308 308
 
309 309
 				case 'venue_title' :
310 310
 				case 'city' :
311
-					$SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->table() . ' ON (' . $wpdb->posts . '.ID = ' . EEM_Event_Venue::instance()->table() . '.EVT_ID )';
312
-					$SQL .= ' LEFT JOIN ' . EEM_Venue::instance()->table() . ' ON (' . EEM_Event_Venue::instance()->table() . '.VNU_ID = ' . EEM_Venue::instance()->table() . '.VNU_ID )';
311
+					$SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->table().' ON ('.$wpdb->posts.'.ID = '.EEM_Event_Venue::instance()->table().'.EVT_ID )';
312
+					$SQL .= ' LEFT JOIN '.EEM_Venue::instance()->table().' ON ('.EEM_Event_Venue::instance()->table().'.VNU_ID = '.EEM_Venue::instance()->table().'.VNU_ID )';
313 313
 					break;
314 314
 
315 315
 				case 'state' :
316
-					$SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->table() . ' ON (' . $wpdb->posts . '.ID = ' . EEM_Event_Venue::instance()->table() . '.EVT_ID )';
317
-					$SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->second_table() . ' ON (' . EEM_Event_Venue::instance()->table() . '.VNU_ID = ' . EEM_Event_Venue::instance()->second_table() . '.VNU_ID )';
316
+					$SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->table().' ON ('.$wpdb->posts.'.ID = '.EEM_Event_Venue::instance()->table().'.EVT_ID )';
317
+					$SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->second_table().' ON ('.EEM_Event_Venue::instance()->table().'.VNU_ID = '.EEM_Event_Venue::instance()->second_table().'.VNU_ID )';
318 318
 					break;
319 319
 
320 320
 				break;
@@ -331,16 +331,16 @@  discard block
 block discarded – undo
331 331
 	 *  @access 	public
332 332
 	 *  @return 	void
333 333
 	 */
334
-	public function posts_where( $SQL, WP_Query $wp_query ) {
335
-		if ( isset( $wp_query->query_vars ) && isset( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'espresso_events'  ) {
334
+	public function posts_where($SQL, WP_Query $wp_query) {
335
+		if (isset($wp_query->query_vars) && isset($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'espresso_events') {
336 336
 			// Show Expired ?
337
-			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_show_expired( EED_Events_Archive_Filters::_show_expired() );
337
+			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_show_expired(EED_Events_Archive_Filters::_show_expired());
338 338
 			// Category
339 339
 			//$elf_category = EED_Events_Archive_Filters::_event_category_slug();
340
-			$SQL .=  EED_Events_Archive_Filters::posts_where_sql_for_event_category_slug( EED_Events_Archive_Filters::_event_category_slug() );
340
+			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_category_slug(EED_Events_Archive_Filters::_event_category_slug());
341 341
 			// Start Date
342 342
 			//$elf_month = EED_Events_Archive_Filters::_display_month();
343
-			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_list_month( EED_Events_Archive_Filters::_display_month() );
343
+			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_list_month(EED_Events_Archive_Filters::_display_month());
344 344
 		}
345 345
 		return $SQL;
346 346
 	}
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
 	 *  @param	boolean	$show_expired if TRUE, then displayed past events
354 354
 	 *  @return 	string
355 355
 	 */
356
-	public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) {
357
-		return  ! $show_expired ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > "' . date('Y-m-d H:s:i') . '" ' : '';
356
+	public static function posts_where_sql_for_show_expired($show_expired = FALSE) {
357
+		return  ! $show_expired ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > "'.date('Y-m-d H:s:i').'" ' : '';
358 358
 	}
359 359
 
360 360
 
@@ -365,9 +365,9 @@  discard block
 block discarded – undo
365 365
 	 *  @param	boolean	$event_category_slug
366 366
 	 *  @return 	string
367 367
 	 */
368
-	public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) {
368
+	public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) {
369 369
 		global $wpdb;
370
-		return  ! empty( $event_category_slug ) ? ' AND ' . $wpdb->terms . '.slug = "' . $event_category_slug . '" ' : '';
370
+		return  ! empty($event_category_slug) ? ' AND '.$wpdb->terms.'.slug = "'.$event_category_slug.'" ' : '';
371 371
 	}
372 372
 
373 373
 	/**
@@ -377,15 +377,15 @@  discard block
 block discarded – undo
377 377
 	 *  @param	boolean	$month
378 378
 	 *  @return 	string
379 379
 	 */
380
-	public static function posts_where_sql_for_event_list_month( $month = NULL ) {
381
-		$SQL= '';
382
-		if ( ! empty( $month )) {
380
+	public static function posts_where_sql_for_event_list_month($month = NULL) {
381
+		$SQL = '';
382
+		if ( ! empty($month)) {
383 383
 			// event start date is LESS than the end of the month ( so nothing that doesn't start until next month )
384
-			$SQL = ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start';
385
-			$SQL .= ' <= "' . date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . '"';
384
+			$SQL = ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_start';
385
+			$SQL .= ' <= "'.date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)).'"';
386 386
 			// event end date is GREATER than the start of the month ( so nothing that ended before this month )
387
-			$SQL .= ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end';
388
-			$SQL .= ' >= "' . date('Y-m-d 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . '" ';
387
+			$SQL .= ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end';
388
+			$SQL .= ' >= "'.date('Y-m-d 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)).'" ';
389 389
 		}
390 390
 		return $SQL;
391 391
 	}
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
 	 *  @access 	public
398 398
 	 *  @return 	void
399 399
 	 */
400
-	public function posts_orderby( $SQL, WP_Query $wp_query ) {
401
-		if ( isset( $wp_query->query ) && isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == 'espresso_events' ) {
402
-			$SQL = EED_Events_Archive_Filters::posts_orderby_sql( array( 'start_date' ));
400
+	public function posts_orderby($SQL, WP_Query $wp_query) {
401
+		if (isset($wp_query->query) && isset($wp_query->query['post_type']) && $wp_query->query['post_type'] == 'espresso_events') {
402
+			$SQL = EED_Events_Archive_Filters::posts_orderby_sql(array('start_date'));
403 403
 		}
404 404
 		return $SQL;
405 405
 	}
@@ -428,54 +428,54 @@  discard block
 block discarded – undo
428 428
 	 *  @param	boolean	$orderby_params
429 429
 	 *  @return 	string
430 430
 	 */
431
-	public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) {
431
+	public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') {
432 432
 		global $wpdb;
433 433
 		$SQL = '';
434 434
 		$cntr = 1;
435
-		$orderby_params = is_array( $orderby_params ) ? $orderby_params : array( $orderby_params );
436
-		foreach( $orderby_params as $orderby ) {
437
-			$glue = $cntr == 1 || $cntr == count( $orderby_params ) ? ' ' : ', ';
438
-			switch ( $orderby ) {
435
+		$orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params);
436
+		foreach ($orderby_params as $orderby) {
437
+			$glue = $cntr == 1 || $cntr == count($orderby_params) ? ' ' : ', ';
438
+			switch ($orderby) {
439 439
 
440 440
 				case 'id' :
441 441
 				case 'ID' :
442
-					$SQL .= $glue . $wpdb->posts . '.ID ' . $sort;
442
+					$SQL .= $glue.$wpdb->posts.'.ID '.$sort;
443 443
 					break;
444 444
 
445 445
 				case 'start_date' :
446
-					$SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_start ' . $sort;
446
+					$SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_start '.$sort;
447 447
 					break;
448 448
 
449 449
 				case 'end_date' :
450
-					$SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort;
450
+					$SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort;
451 451
 					break;
452 452
 
453 453
 				case 'event_name' :
454
-					$SQL .= $glue . $wpdb->posts . '.post_title ' . $sort;
454
+					$SQL .= $glue.$wpdb->posts.'.post_title '.$sort;
455 455
 					break;
456 456
 
457 457
 				case 'category_slug' :
458
-					$SQL .= $glue . $wpdb->terms . '.slug ' . $sort;
458
+					$SQL .= $glue.$wpdb->terms.'.slug '.$sort;
459 459
 					break;
460 460
 
461 461
 				case 'ticket_start' :
462
-					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort;
462
+					$SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort;
463 463
 					break;
464 464
 
465 465
 				case 'ticket_end' :
466
-					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort;
466
+					$SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort;
467 467
 					break;
468 468
 
469 469
 				case 'venue_title' :
470
-					$SQL .= $glue . 'venue_title ' . $sort;
470
+					$SQL .= $glue.'venue_title '.$sort;
471 471
 					break;
472 472
 
473 473
 				case 'city' :
474
-					$SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort;
474
+					$SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort;
475 475
 				break;
476 476
 
477 477
 				case 'state' :
478
-					$SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort;
478
+					$SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort;
479 479
 				break;
480 480
 
481 481
 			}
@@ -495,26 +495,26 @@  discard block
 block discarded – undo
495 495
 	 */
496 496
 	public function template_redirect() {
497 497
 		// add event list filters
498
-		add_action( 'loop_start', array( $this, 'event_list_template_filters' ));
498
+		add_action('loop_start', array($this, 'event_list_template_filters'));
499 499
 		// and pagination
500
-		add_action( 'loop_start', array( $this, 'event_list_pagination' ));
501
-		add_action( 'loop_end', array( $this, 'event_list_pagination' ));
500
+		add_action('loop_start', array($this, 'event_list_pagination'));
501
+		add_action('loop_end', array($this, 'event_list_pagination'));
502 502
 		// if NOT a custom template
503
-		if ( EE_Registry::instance()->load_core( 'Front_Controller', array(), false, true )->get_selected_template() != 'archive-espresso_events.php' ) {
503
+		if (EE_Registry::instance()->load_core('Front_Controller', array(), false, true)->get_selected_template() != 'archive-espresso_events.php') {
504 504
 			// don't know if theme uses the_excerpt
505
-			add_filter( 'the_excerpt', array( $this, 'event_details' ), 100 );
506
-			add_filter( 'the_excerpt', array( $this, 'event_tickets' ), 110 );
507
-			add_filter( 'the_excerpt', array( $this, 'event_datetimes' ), 120 );
508
-			add_filter( 'the_excerpt', array( $this, 'event_venues' ), 130 );
505
+			add_filter('the_excerpt', array($this, 'event_details'), 100);
506
+			add_filter('the_excerpt', array($this, 'event_tickets'), 110);
507
+			add_filter('the_excerpt', array($this, 'event_datetimes'), 120);
508
+			add_filter('the_excerpt', array($this, 'event_venues'), 130);
509 509
 			// or the_content
510
-			add_filter( 'the_content', array( $this, 'event_details' ), 100 );
511
-			add_filter( 'the_content', array( $this, 'event_tickets' ), 110 );
512
-			add_filter( 'the_content', array( $this, 'event_datetimes' ), 120 );
513
-			add_filter( 'the_content', array( $this, 'event_venues' ), 130 );
510
+			add_filter('the_content', array($this, 'event_details'), 100);
511
+			add_filter('the_content', array($this, 'event_tickets'), 110);
512
+			add_filter('the_content', array($this, 'event_datetimes'), 120);
513
+			add_filter('the_content', array($this, 'event_venues'), 130);
514 514
 		} else {
515
-			remove_all_filters( 'excerpt_length' );
516
-			add_filter( 'excerpt_length', array( $this, 'excerpt_length' ), 10 );
517
-			add_filter( 'excerpt_more', array( $this, 'excerpt_more' ), 10 );
515
+			remove_all_filters('excerpt_length');
516
+			add_filter('excerpt_length', array($this, 'excerpt_length'), 10);
517
+			add_filter('excerpt_more', array($this, 'excerpt_more'), 10);
518 518
 		}
519 519
 	}
520 520
 
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
 	 *  	@return 		void
528 528
 	 */
529 529
 	public function event_list_pagination() {
530
-		echo '<div class="ee-pagination-dv clear">' . espresso_event_list_pagination() . '</div>';
530
+		echo '<div class="ee-pagination-dv clear">'.espresso_event_list_pagination().'</div>';
531 531
 	}
532 532
 
533 533
 
@@ -538,8 +538,8 @@  discard block
 block discarded – undo
538 538
 	 * 	@param		string 	$content
539 539
 	 *  	@return 		void
540 540
 	 */
541
-	public function event_details( $content ) {
542
-		return EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-details.php', array( 'the_content' => $content ), TRUE );
541
+	public function event_details($content) {
542
+		return EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-details.php', array('the_content' => $content), TRUE);
543 543
 	}
544 544
 
545 545
 
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
 	 * 	@param		string 	$content
551 551
 	 *  	@return 		void
552 552
 	 */
553
-	public function event_tickets( $content ) {
554
-		return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-tickets.php', array(), TRUE );
553
+	public function event_tickets($content) {
554
+		return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-tickets.php', array(), TRUE);
555 555
 	}
556 556
 
557 557
 	/**
@@ -561,8 +561,8 @@  discard block
 block discarded – undo
561 561
 	 * 	@param		string 	$content
562 562
 	 *  	@return 		void
563 563
 	 */
564
-	public function event_datetimes( $content ) {
565
-		return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-datetimes.php', array(), TRUE );
564
+	public function event_datetimes($content) {
565
+		return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-datetimes.php', array(), TRUE);
566 566
 	}
567 567
 
568 568
 	/**
@@ -572,8 +572,8 @@  discard block
 block discarded – undo
572 572
 	 * 	@param		string 	$content
573 573
 	 *  	@return 		void
574 574
 	 */
575
-	public function event_venues( $content ) {
576
-		return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-venues.php', array(), TRUE );
575
+	public function event_venues($content) {
576
+		return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-venues.php', array(), TRUE);
577 577
 	}
578 578
 
579 579
 
@@ -588,13 +588,13 @@  discard block
 block discarded – undo
588 588
 	 *  @return 	void
589 589
 	 */
590 590
 	private function _load_assests() {
591
-		do_action( 'AHEE__EED_Events_Archive_Filters__before_load_assests' );
591
+		do_action('AHEE__EED_Events_Archive_Filters__before_load_assests');
592 592
         wp_enqueue_style('espresso_default');
593 593
         wp_enqueue_style('espresso_custom_css');
594
-        add_filter( 'FHEE_load_EE_Session', '__return_true' );
595
-		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
596
-		if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) {
597
-			add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 );
594
+        add_filter('FHEE_load_EE_Session', '__return_true');
595
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
596
+		if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
597
+			add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
598 598
 		}
599 599
 		//add_filter( 'the_excerpt', array( $this, 'the_excerpt' ), 999 );
600 600
 	}
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
 	 *  @access 	private
610 610
 	 *  @return 	string
611 611
 	 */
612
-	private function _get_template( $which = 'part' ) {
613
-		return EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php';
612
+	private function _get_template($which = 'part') {
613
+		return EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php';
614 614
 	}
615 615
 
616 616
 
@@ -621,13 +621,13 @@  discard block
 block discarded – undo
621 621
 	 *  @access 	public
622 622
 	 *  @return 	void
623 623
 	 */
624
-	public function excerpt_length( $length ) {
624
+	public function excerpt_length($length) {
625 625
 
626
-		if ( self::$_type == 'grid' ) {
626
+		if (self::$_type == 'grid') {
627 627
 			return 36;
628 628
 		}
629 629
 
630
-		switch ( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size ) {
630
+		switch (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size) {
631 631
 			case 'tiny' :
632 632
 				return 12;
633 633
 				break;
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
 	 *  @access 	public
652 652
 	 *  @return 	void
653 653
 	 */
654
-	public function excerpt_more( $more ) {
654
+	public function excerpt_more($more) {
655 655
 		return '&hellip;';
656 656
 	}
657 657
 
@@ -681,22 +681,22 @@  discard block
 block discarded – undo
681 681
 	 */
682 682
 	public function wp_enqueue_scripts() {
683 683
 		// get some style
684
-		if ( apply_filters( 'FHEE_enable_default_espresso_css', FALSE ) ) {
684
+		if (apply_filters('FHEE_enable_default_espresso_css', FALSE)) {
685 685
 			// first check uploads folder
686
-			if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css' )) {
687
-				wp_register_style( 'archive-espresso_events', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css', array( 'dashicons', 'espresso_default' ));
686
+			if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'archive-espresso_events.css')) {
687
+				wp_register_style('archive-espresso_events', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'archive-espresso_events.css', array('dashicons', 'espresso_default'));
688 688
 			} else {
689
-				wp_register_style( 'archive-espresso_events', EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css', array( 'dashicons', 'espresso_default' ));
689
+				wp_register_style('archive-espresso_events', EE_TEMPLATES_URL.EE_Config::get_current_theme().DS.'archive-espresso_events.css', array('dashicons', 'espresso_default'));
690 690
 			}
691
-			if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.js' )) {
692
-				wp_register_script( 'archive-espresso_events', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.js', array( 'jquery-masonry' ), '1.0', TRUE  );
691
+			if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'archive-espresso_events.js')) {
692
+				wp_register_script('archive-espresso_events', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'archive-espresso_events.js', array('jquery-masonry'), '1.0', TRUE);
693 693
 			} else {
694
-				wp_register_script( 'archive-espresso_events', EVENTS_ARCHIVE_ASSETS_URL . 'archive-espresso_events.js', array( 'jquery-masonry' ), '1.0', TRUE );
694
+				wp_register_script('archive-espresso_events', EVENTS_ARCHIVE_ASSETS_URL.'archive-espresso_events.js', array('jquery-masonry'), '1.0', TRUE);
695 695
 			}
696
-			wp_enqueue_style( 'archive-espresso_events' );
697
-			wp_enqueue_script( 'jquery-masonry' );
698
-			wp_enqueue_script( 'archive-espresso_events' );
699
-			add_action( 'wp_footer', array( 'EED_Events_Archive_Filters', 'localize_grid_event_lists' ), 1 );
696
+			wp_enqueue_style('archive-espresso_events');
697
+			wp_enqueue_script('jquery-masonry');
698
+			wp_enqueue_script('archive-espresso_events');
699
+			add_action('wp_footer', array('EED_Events_Archive_Filters', 'localize_grid_event_lists'), 1);
700 700
 		}
701 701
 	}
702 702
 
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 	 *  @return 	void
712 712
 	 */
713 713
 	public static function localize_grid_event_lists() {
714
-		wp_localize_script( 'archive-espresso_events', 'espresso_grid_event_lists', EED_Events_Archive_Filters::$espresso_grid_event_lists );
714
+		wp_localize_script('archive-espresso_events', 'espresso_grid_event_lists', EED_Events_Archive_Filters::$espresso_grid_event_lists);
715 715
 	}
716 716
 
717 717
 
@@ -726,9 +726,9 @@  discard block
 block discarded – undo
726 726
 	 */
727 727
 	public static function template_settings_form() {
728 728
 		$EE = EE_Registry::instance();
729
-		$EE->CFG->template_settings->EED_Events_Archive_Filters = isset( $EE->CFG->template_settings->EED_Events_Archive_Filters ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters : new EE_Events_Archive_Config();
730
-		$EE->CFG->template_settings->EED_Events_Archive_Filters = apply_filters( 'FHEE__Event_List__template_settings_form__event_list_config', $EE->CFG->template_settings->EED_Events_Archive_Filters );
731
-		EEH_Template::display_template( EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $EE->CFG->template_settings->EED_Events_Archive_Filters );
729
+		$EE->CFG->template_settings->EED_Events_Archive_Filters = isset($EE->CFG->template_settings->EED_Events_Archive_Filters) ? $EE->CFG->template_settings->EED_Events_Archive_Filters : new EE_Events_Archive_Config();
730
+		$EE->CFG->template_settings->EED_Events_Archive_Filters = apply_filters('FHEE__Event_List__template_settings_form__event_list_config', $EE->CFG->template_settings->EED_Events_Archive_Filters);
731
+		EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', $EE->CFG->template_settings->EED_Events_Archive_Filters);
732 732
 	}
733 733
 
734 734
 
@@ -742,16 +742,16 @@  discard block
 block discarded – undo
742 742
 	 *  @static
743 743
 	 *  @return 	void
744 744
 	 */
745
-	public static function set_default_settings( $CFG ) {
745
+	public static function set_default_settings($CFG) {
746 746
 		//EEH_Debug_Tools::printr( $CFG, '$CFG  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
747
-		$CFG->display_description = isset( $CFG->display_description ) && ! empty( $CFG->display_description ) ? $CFG->display_description : 1;
748
-		$CFG->display_address = isset( $CFG->display_address ) && ! empty( $CFG->display_address ) ? $CFG->display_address : TRUE;
749
-		$CFG->display_venue_details = isset( $CFG->display_venue_details ) && ! empty( $CFG->display_venue_details ) ? $CFG->display_venue_details : TRUE;
750
-		$CFG->display_expired_events = isset( $CFG->display_expired_events ) && ! empty( $CFG->display_expired_events ) ? $CFG->display_expired_events : FALSE;
751
-		$CFG->default_type = isset( $CFG->default_type ) && ! empty( $CFG->default_type ) ? $CFG->default_type : 'grid';
752
-		$CFG->event_list_grid_size = isset( $CFG->event_list_grid_size ) && ! empty( $CFG->event_list_grid_size ) ? $CFG->event_list_grid_size : 'medium';
753
-		$CFG->templates['full'] = isset( $CFG->templates['full'] ) && ! empty( $CFG->templates['full'] ) ? $CFG->templates['full'] : EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php';
754
-		$CFG->templates['part'] = isset( $CFG->templates['part'] ) && ! empty( $CFG->templates['part'] ) ? $CFG->templates['part'] : EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-grid-view.php';
747
+		$CFG->display_description = isset($CFG->display_description) && ! empty($CFG->display_description) ? $CFG->display_description : 1;
748
+		$CFG->display_address = isset($CFG->display_address) && ! empty($CFG->display_address) ? $CFG->display_address : TRUE;
749
+		$CFG->display_venue_details = isset($CFG->display_venue_details) && ! empty($CFG->display_venue_details) ? $CFG->display_venue_details : TRUE;
750
+		$CFG->display_expired_events = isset($CFG->display_expired_events) && ! empty($CFG->display_expired_events) ? $CFG->display_expired_events : FALSE;
751
+		$CFG->default_type = isset($CFG->default_type) && ! empty($CFG->default_type) ? $CFG->default_type : 'grid';
752
+		$CFG->event_list_grid_size = isset($CFG->event_list_grid_size) && ! empty($CFG->event_list_grid_size) ? $CFG->event_list_grid_size : 'medium';
753
+		$CFG->templates['full'] = isset($CFG->templates['full']) && ! empty($CFG->templates['full']) ? $CFG->templates['full'] : EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php';
754
+		$CFG->templates['part'] = isset($CFG->templates['part']) && ! empty($CFG->templates['part']) ? $CFG->templates['part'] : EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-grid-view.php';
755 755
 		return $CFG;
756 756
 	}
757 757
 
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 	 *  @access 	public
764 764
 	 *  @return 	void
765 765
 	 */
766
-	public function filter_config( $CFG ) {
766
+	public function filter_config($CFG) {
767 767
 		return $CFG;
768 768
 	}
769 769
 
@@ -776,32 +776,32 @@  discard block
 block discarded – undo
776 776
 	 *  @access 	public
777 777
 	 *  @return 	void
778 778
 	 */
779
-	public static function update_template_settings( $CFG, $REQ ) {
779
+	public static function update_template_settings($CFG, $REQ) {
780 780
 //		EEH_Debug_Tools::printr( $REQ, '$REQ  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
781 781
 //		EEH_Debug_Tools::printr( $CFG, '$CFG  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
782 782
 		//$CFG->template_settings->EED_Events_Archive_Filters = new stdClass();
783
-		$CFG->EED_Events_Archive_Filters->display_description = isset( $REQ['display_description_in_event_list'] ) ? absint( $REQ['display_description_in_event_list'] ) : 1;
784
-		$CFG->EED_Events_Archive_Filters->display_address = isset( $REQ['display_address_in_event_list'] ) ? absint( $REQ['display_address_in_event_list'] ) : TRUE;
785
-		$CFG->EED_Events_Archive_Filters->display_venue_details = isset( $REQ['display_venue_details_in_event_list'] ) ? absint( $REQ['display_venue_details_in_event_list'] ) : TRUE;
786
-		$CFG->EED_Events_Archive_Filters->display_expired_events = isset( $REQ['display_expired_events'] ) ? absint( $REQ['display_expired_events'] ) : FALSE;
787
-		$CFG->EED_Events_Archive_Filters->default_type = isset( $REQ['default_type'] ) ? sanitize_text_field( $REQ['default_type'] ) : 'grid';
788
-		$CFG->EED_Events_Archive_Filters->event_list_grid_size = isset( $REQ['event_list_grid_size'] ) ? sanitize_text_field( $REQ['event_list_grid_size'] ) : 'medium';
783
+		$CFG->EED_Events_Archive_Filters->display_description = isset($REQ['display_description_in_event_list']) ? absint($REQ['display_description_in_event_list']) : 1;
784
+		$CFG->EED_Events_Archive_Filters->display_address = isset($REQ['display_address_in_event_list']) ? absint($REQ['display_address_in_event_list']) : TRUE;
785
+		$CFG->EED_Events_Archive_Filters->display_venue_details = isset($REQ['display_venue_details_in_event_list']) ? absint($REQ['display_venue_details_in_event_list']) : TRUE;
786
+		$CFG->EED_Events_Archive_Filters->display_expired_events = isset($REQ['display_expired_events']) ? absint($REQ['display_expired_events']) : FALSE;
787
+		$CFG->EED_Events_Archive_Filters->default_type = isset($REQ['default_type']) ? sanitize_text_field($REQ['default_type']) : 'grid';
788
+		$CFG->EED_Events_Archive_Filters->event_list_grid_size = isset($REQ['event_list_grid_size']) ? sanitize_text_field($REQ['event_list_grid_size']) : 'medium';
789 789
 		$CFG->EED_Events_Archive_Filters->templates = array(
790
-				'full'  => EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php'
790
+				'full'  => EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php'
791 791
 			);
792 792
 
793
-		switch ( $CFG->EED_Events_Archive_Filters->default_type ) {
793
+		switch ($CFG->EED_Events_Archive_Filters->default_type) {
794 794
 			case 'dates' :
795
-					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-dates-view.php';
795
+					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-dates-view.php';
796 796
 				break;
797 797
 			case 'text' :
798
-					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-text-view.php';
798
+					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-text-view.php';
799 799
 				break;
800 800
 			default :
801
-					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-grid-view.php';
801
+					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-grid-view.php';
802 802
 		}
803 803
 
804
-		$CFG->EED_Events_Archive_Filters = isset( $REQ['reset_event_list_settings'] ) && absint( $REQ['reset_event_list_settings'] ) == 1 ? new EE_Events_Archive_Config() : $CFG->EED_Events_Archive_Filters;
804
+		$CFG->EED_Events_Archive_Filters = isset($REQ['reset_event_list_settings']) && absint($REQ['reset_event_list_settings']) == 1 ? new EE_Events_Archive_Config() : $CFG->EED_Events_Archive_Filters;
805 805
 		return $CFG;
806 806
 	}
807 807
 
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
 	 *  @return 	void
817 817
 	 */
818 818
 	public static function get_template_part() {
819
-		switch ( self::$_type ) {
819
+		switch (self::$_type) {
820 820
 			case 'dates' :
821 821
 					return 'archive-espresso_events-dates-view.php';
822 822
 				break;
@@ -840,13 +840,13 @@  discard block
 block discarded – undo
840 840
 	 */
841 841
 	public function event_list_template_filters() {
842 842
 		$args = array(
843
-			'form_url' => get_post_type_archive_link( 'espresso_events' ), //add_query_arg( array( 'post_type' => 'espresso_events' ), home_url() ),
843
+			'form_url' => get_post_type_archive_link('espresso_events'), //add_query_arg( array( 'post_type' => 'espresso_events' ), home_url() ),
844 844
 			'elf_month' => EED_Events_Archive_Filters::_display_month(),
845 845
 			'elf_category' => EED_Events_Archive_Filters::_event_category_slug(),
846 846
 			'elf_show_expired' => EED_Events_Archive_Filters::_show_expired(),
847 847
 			'elf_type' => self::$_type
848 848
 		);
849
-		EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-filters.php', $args );
849
+		EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-filters.php', $args);
850 850
 	}
851 851
 
852 852
 
@@ -859,16 +859,16 @@  discard block
 block discarded – undo
859 859
 	 *  @access 	public
860 860
 	 *  @return 	void
861 861
 	 */
862
-	public static function event_list_css( $extra_class = '' ) {
862
+	public static function event_list_css($extra_class = '') {
863 863
 		$EE = EE_Registry::instance();
864
-		$event_list_css = ! empty( $extra_class ) ? array( $extra_class ) : array();
864
+		$event_list_css = ! empty($extra_class) ? array($extra_class) : array();
865 865
 		$event_list_css[] = 'espresso-event-list-event';
866
-		if ( self::$_type == 'grid' ) {
867
-			$event_list_grid_size = isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size : 'medium';
868
-			$event_list_css[] = $event_list_grid_size . '-event-list-grid';
866
+		if (self::$_type == 'grid') {
867
+			$event_list_grid_size = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size : 'medium';
868
+			$event_list_css[] = $event_list_grid_size.'-event-list-grid';
869 869
 		}
870
-		$event_list_css = apply_filters( 'EED_Events_Archive_Filters__event_list_css__event_list_css_array', $event_list_css );
871
-		return implode( ' ', $event_list_css );
870
+		$event_list_css = apply_filters('EED_Events_Archive_Filters__event_list_css__event_list_css_array', $event_list_css);
871
+		return implode(' ', $event_list_css);
872 872
 	}
873 873
 
874 874
 
@@ -894,9 +894,9 @@  discard block
 block discarded – undo
894 894
 	 *  @access 	public
895 895
 	 *  @return 	void
896 896
 	 */
897
-	public static function display_description( $value ) {
897
+	public static function display_description($value) {
898 898
 		$EE = EE_Registry::instance();
899
-		$display_description= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description : 1;
899
+		$display_description = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_description) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description : 1;
900 900
 		return $display_description === $value ? TRUE : FALSE;
901 901
 	}
902 902
 
@@ -910,9 +910,9 @@  discard block
 block discarded – undo
910 910
 	 */
911 911
 	public static function display_venue_details() {
912 912
 		$EE = EE_Registry::instance();
913
-		$display_venue_details= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details : TRUE;
913
+		$display_venue_details = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details : TRUE;
914 914
 		$venue_name = EEH_Venue_View::venue_name();
915
-		return $display_venue_details && ! empty( $venue_name ) ? TRUE : FALSE;
915
+		return $display_venue_details && ! empty($venue_name) ? TRUE : FALSE;
916 916
 	}
917 917
 
918 918
 
@@ -924,9 +924,9 @@  discard block
 block discarded – undo
924 924
 	 */
925 925
 	public static function display_address() {
926 926
 		$EE = EE_Registry::instance();
927
-		$display_address= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address : FALSE;
927
+		$display_address = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_address) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address : FALSE;
928 928
 		$venue_name = EEH_Venue_View::venue_name();
929
-		return $display_address && ! empty( $venue_name ) ? TRUE : FALSE;
929
+		return $display_address && ! empty($venue_name) ? TRUE : FALSE;
930 930
 	}
931 931
 
932 932
 
@@ -940,22 +940,22 @@  discard block
 block discarded – undo
940 940
 	public static function pagination() {
941 941
 		global $wp_query;
942 942
 		$big = 999999999; // need an unlikely integer
943
-		$pagination = paginate_links( array(
944
-			'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
943
+		$pagination = paginate_links(array(
944
+			'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
945 945
 			'format' => '?paged=%#%',
946
-			'current' => max( 1, get_query_var('paged') ),
946
+			'current' => max(1, get_query_var('paged')),
947 947
 			'total' => $wp_query->max_num_pages,
948 948
 			'show_all'     => TRUE,
949 949
 			'end_size'     => 10,
950 950
 			'mid_size'     => 6,
951 951
 			'prev_next'    => TRUE,
952
-			'prev_text'    => __( '&lsaquo; PREV', 'event_espresso' ),
953
-			'next_text'    => __( 'NEXT &rsaquo;', 'event_espresso' ),
952
+			'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
953
+			'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
954 954
 			'type'         => 'plain',
955 955
 			'add_args'     => FALSE,
956 956
 			'add_fragment' => ''
957 957
 		));
958
-		return ! empty( $pagination ) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : '';
958
+		return ! empty($pagination) ? '<div class="ee-pagination-dv clear">'.$pagination.'</div>' : '';
959 959
 	}
960 960
 
961 961
 
@@ -969,7 +969,7 @@  discard block
 block discarded – undo
969 969
 	 *  @return 	void
970 970
 	 */
971 971
 	public static function event_list_title() {
972
-		return apply_filters( 'EED_Events_Archive_Filters__event_list_title__event_list_title', __( 'Upcoming Events', 'event_espresso' ));
972
+		return apply_filters('EED_Events_Archive_Filters__event_list_title__event_list_title', __('Upcoming Events', 'event_espresso'));
973 973
 	}
974 974
 
975 975
 
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 1 patch
Indentation   +1221 added lines, -1221 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -16,1226 +16,1226 @@  discard block
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Extend_Events_Admin_Page constructor.
21
-     *
22
-     * @param bool $routing
23
-     */
24
-    public function __construct($routing = true)
25
-    {
26
-        parent::__construct($routing);
27
-        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
-        }
32
-    }
33
-
34
-
35
-
36
-    protected function _extend_page_config()
37
-    {
38
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
39
-        //is there a evt_id in the request?
40
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41
-            ? $this->_req_data['EVT_ID']
42
-            : 0;
43
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
44
-        //tkt_id?
45
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
46
-            ? $this->_req_data['TKT_ID']
47
-            : 0;
48
-        $new_page_routes = array(
49
-            'duplicate_event'          => array(
50
-                'func'       => '_duplicate_event',
51
-                'capability' => 'ee_edit_event',
52
-                'obj_id'     => $evt_id,
53
-                'noheader'   => true,
54
-            ),
55
-            'ticket_list_table'        => array(
56
-                'func'       => '_tickets_overview_list_table',
57
-                'capability' => 'ee_read_default_tickets',
58
-            ),
59
-            'trash_ticket'             => array(
60
-                'func'       => '_trash_or_restore_ticket',
61
-                'capability' => 'ee_delete_default_ticket',
62
-                'obj_id'     => $tkt_id,
63
-                'noheader'   => true,
64
-                'args'       => array('trash' => true),
65
-            ),
66
-            'trash_tickets'            => array(
67
-                'func'       => '_trash_or_restore_ticket',
68
-                'capability' => 'ee_delete_default_tickets',
69
-                'noheader'   => true,
70
-                'args'       => array('trash' => true),
71
-            ),
72
-            'restore_ticket'           => array(
73
-                'func'       => '_trash_or_restore_ticket',
74
-                'capability' => 'ee_delete_default_ticket',
75
-                'obj_id'     => $tkt_id,
76
-                'noheader'   => true,
77
-            ),
78
-            'restore_tickets'          => array(
79
-                'func'       => '_trash_or_restore_ticket',
80
-                'capability' => 'ee_delete_default_tickets',
81
-                'noheader'   => true,
82
-            ),
83
-            'delete_ticket'            => array(
84
-                'func'       => '_delete_ticket',
85
-                'capability' => 'ee_delete_default_ticket',
86
-                'obj_id'     => $tkt_id,
87
-                'noheader'   => true,
88
-            ),
89
-            'delete_tickets'           => array(
90
-                'func'       => '_delete_ticket',
91
-                'capability' => 'ee_delete_default_tickets',
92
-                'noheader'   => true,
93
-            ),
94
-            'import_page'              => array(
95
-                'func'       => '_import_page',
96
-                'capability' => 'import',
97
-            ),
98
-            'import'                   => array(
99
-                'func'       => '_import_events',
100
-                'capability' => 'import',
101
-                'noheader'   => true,
102
-            ),
103
-            'import_events'            => array(
104
-                'func'       => '_import_events',
105
-                'capability' => 'import',
106
-                'noheader'   => true,
107
-            ),
108
-            'export_events'            => array(
109
-                'func'       => '_events_export',
110
-                'capability' => 'export',
111
-                'noheader'   => true,
112
-            ),
113
-            'export_categories'        => array(
114
-                'func'       => '_categories_export',
115
-                'capability' => 'export',
116
-                'noheader'   => true,
117
-            ),
118
-            'sample_export_file'       => array(
119
-                'func'       => '_sample_export_file',
120
-                'capability' => 'export',
121
-                'noheader'   => true,
122
-            ),
123
-            'update_template_settings' => array(
124
-                'func'       => '_update_template_settings',
125
-                'capability' => 'manage_options',
126
-                'noheader'   => true,
127
-            ),
128
-        );
129
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
130
-        //partial route/config override
131
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
132
-        $this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
133
-        $this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
134
-        $this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
135
-        $this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
136
-        $this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
137
-        //add tickets tab but only if there are more than one default ticket!
138
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
139
-            array(array('TKT_is_default' => 1)),
140
-            'TKT_ID',
141
-            true
142
-        );
143
-        if ($tkt_count > 1) {
144
-            $new_page_config = array(
145
-                'ticket_list_table' => array(
146
-                    'nav'           => array(
147
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
148
-                        'order' => 60,
149
-                    ),
150
-                    'list_table'    => 'Tickets_List_Table',
151
-                    'require_nonce' => false,
152
-                ),
153
-            );
154
-        }
155
-        //template settings
156
-        $new_page_config['template_settings'] = array(
157
-            'nav'           => array(
158
-                'label' => esc_html__('Templates', 'event_espresso'),
159
-                'order' => 30,
160
-            ),
161
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
162
-            'help_tabs'     => array(
163
-                'general_settings_templates_help_tab' => array(
164
-                    'title'    => esc_html__('Templates', 'event_espresso'),
165
-                    'filename' => 'general_settings_templates',
166
-                ),
167
-            ),
168
-            'help_tour'     => array('Templates_Help_Tour'),
169
-            'require_nonce' => false,
170
-        );
171
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
172
-        //add filters and actions
173
-        //modifying _views
174
-        add_filter(
175
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
-            array($this, 'add_additional_datetime_button'),
177
-            10,
178
-            2
179
-        );
180
-        add_filter(
181
-            'FHEE_event_datetime_metabox_clone_button_template',
182
-            array($this, 'add_datetime_clone_button'),
183
-            10,
184
-            2
185
-        );
186
-        add_filter(
187
-            'FHEE_event_datetime_metabox_timezones_template',
188
-            array($this, 'datetime_timezones_template'),
189
-            10,
190
-            2
191
-        );
192
-        //filters for event list table
193
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
194
-        add_filter(
195
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
-            array($this, 'extra_list_table_actions'),
197
-            10,
198
-            2
199
-        );
200
-        //legend item
201
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
202
-        add_action('admin_init', array($this, 'admin_init'));
203
-        //heartbeat stuff
204
-        add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
205
-    }
206
-
207
-
208
-
209
-    /**
210
-     * admin_init
211
-     */
212
-    public function admin_init()
213
-    {
214
-        EE_Registry::$i18n_js_strings = array_merge(
215
-            EE_Registry::$i18n_js_strings,
216
-            array(
217
-                'image_confirm'          => esc_html__(
218
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
219
-                    'event_espresso'
220
-                ),
221
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
222
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
223
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
224
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
225
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
226
-            )
227
-        );
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
234
-     * accordingly.
235
-     *
236
-     * @param array $response The existing heartbeat response array.
237
-     * @param array $data     The incoming data package.
238
-     * @return array  possibly appended response.
239
-     */
240
-    public function heartbeat_response($response, $data)
241
-    {
242
-        /**
243
-         * check whether count of tickets is approaching the potential
244
-         * limits for the server.
245
-         */
246
-        if ( ! empty($data['input_count'])) {
247
-            $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
248
-                $data['input_count']
249
-            );
250
-        }
251
-        return $response;
252
-    }
253
-
254
-
255
-
256
-    protected function _add_screen_options_ticket_list_table()
257
-    {
258
-        $this->_per_page_screen_option();
259
-    }
260
-
261
-
262
-
263
-    /**
264
-     * @param string $return
265
-     * @param int    $id
266
-     * @param string $new_title
267
-     * @param string $new_slug
268
-     * @return string
269
-     */
270
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
271
-    {
272
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
273
-        //make sure this is only when editing
274
-        if ( ! empty($id)) {
275
-            $href  = EE_Admin_Page::add_query_args_and_nonce(
276
-                array('action' => 'duplicate_event', 'EVT_ID' => $id),
277
-                $this->_admin_base_url
278
-            );
279
-            $title = esc_attr__('Duplicate Event', 'event_espresso');
280
-            $return .= '<a href="'
281
-                       . $href
282
-                       . '" title="'
283
-                       . $title
284
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
285
-                       . $title
286
-                       . '</button>';
287
-        }
288
-        return $return;
289
-    }
290
-
291
-
292
-
293
-    public function _set_list_table_views_ticket_list_table()
294
-    {
295
-        $this->_views = array(
296
-            'all'     => array(
297
-                'slug'        => 'all',
298
-                'label'       => esc_html__('All', 'event_espresso'),
299
-                'count'       => 0,
300
-                'bulk_action' => array(
301
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
302
-                ),
303
-            ),
304
-            'trashed' => array(
305
-                'slug'        => 'trashed',
306
-                'label'       => esc_html__('Trash', 'event_espresso'),
307
-                'count'       => 0,
308
-                'bulk_action' => array(
309
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
310
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
311
-                ),
312
-            ),
313
-        );
314
-    }
315
-
316
-
317
-
318
-    public function load_scripts_styles_edit()
319
-    {
320
-        wp_register_script(
321
-            'ee-event-editor-heartbeat',
322
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
323
-            array('ee_admin_js', 'heartbeat'),
324
-            EVENT_ESPRESSO_VERSION,
325
-            true
326
-        );
327
-        wp_enqueue_script('ee-accounting');
328
-        //styles
329
-        wp_enqueue_style('espresso-ui-theme');
330
-        wp_enqueue_script('event_editor_js');
331
-        wp_enqueue_script('ee-event-editor-heartbeat');
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * @param $template
338
-     * @param $template_args
339
-     * @return mixed
340
-     */
341
-    public function add_additional_datetime_button($template, $template_args)
342
-    {
343
-        return EEH_Template::display_template(
344
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
345
-            $template_args,
346
-            true
347
-        );
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * @param $template
354
-     * @param $template_args
355
-     * @return mixed
356
-     */
357
-    public function add_datetime_clone_button($template, $template_args)
358
-    {
359
-        return EEH_Template::display_template(
360
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
361
-            $template_args,
362
-            true
363
-        );
364
-    }
365
-
366
-
367
-
368
-    /**
369
-     * @param $template
370
-     * @param $template_args
371
-     * @return mixed
372
-     */
373
-    public function datetime_timezones_template($template, $template_args)
374
-    {
375
-        return EEH_Template::display_template(
376
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
377
-            $template_args,
378
-            true
379
-        );
380
-    }
381
-
382
-
383
-
384
-    protected function _set_list_table_views_default()
385
-    {
386
-        parent::_set_list_table_views_default();
387
-        $new_views = array(
388
-            'today' => array(
389
-                'slug'        => 'today',
390
-                'label'       => esc_html__('Today', 'event_espresso'),
391
-                'count'       => $this->total_events_today(),
392
-                'bulk_action' => array(
393
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
394
-                ),
395
-            ),
396
-            'month' => array(
397
-                'slug'        => 'month',
398
-                'label'       => esc_html__('This Month', 'event_espresso'),
399
-                'count'       => $this->total_events_this_month(),
400
-                'bulk_action' => array(
401
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
402
-                ),
403
-            ),
404
-        );
405
-        $this->_views = array_merge($this->_views, $new_views);
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * @param array     $action_links
412
-     * @param \EE_Event $event
413
-     * @return array
414
-     */
415
-    public function extra_list_table_actions(array $action_links, \EE_Event $event)
416
-    {
417
-        if (
418
-        EE_Registry::instance()->CAP->current_user_can(
419
-            'ee_read_registrations',
420
-            'espresso_registrations_reports',
421
-            $event->ID()
422
-        )
423
-        ) {
424
-            $reports_query_args = array(
425
-                'action' => 'reports',
426
-                'EVT_ID' => $event->ID(),
427
-            );
428
-            $reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
429
-            $action_links[]     = '<a href="'
430
-                                  . $reports_link
431
-                                  . '" title="'
432
-                                  . esc_attr__('View Report', 'event_espresso')
433
-                                  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
434
-                                  . "\n\t";
435
-        }
436
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
437
-            EE_Registry::instance()->load_helper('MSG_Template');
438
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
439
-                'see_notifications_for',
440
-                null,
441
-                array('EVT_ID' => $event->ID())
442
-            );
443
-        }
444
-        return $action_links;
445
-    }
446
-
447
-
448
-
449
-    /**
450
-     * @param $items
451
-     * @return mixed
452
-     */
453
-    public function additional_legend_items($items)
454
-    {
455
-        if (
456
-        EE_Registry::instance()->CAP->current_user_can(
457
-            'ee_read_registrations',
458
-            'espresso_registrations_reports'
459
-        )
460
-        ) {
461
-            $items['reports'] = array(
462
-                'class' => 'dashicons dashicons-chart-bar',
463
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
464
-            );
465
-        }
466
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
467
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
468
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
469
-                $items['view_related_messages'] = array(
470
-                    'class' => $related_for_icon['css_class'],
471
-                    'desc'  => $related_for_icon['label'],
472
-                );
473
-            }
474
-        }
475
-        return $items;
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * This is the callback method for the duplicate event route
482
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
483
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
484
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
485
-     * After duplication the redirect is to the new event edit page.
486
-     *
487
-     * @return void
488
-     * @access protected
489
-     * @throws EE_Error If EE_Event is not available with given ID
490
-     */
491
-    protected function _duplicate_event()
492
-    {
493
-        // first make sure the ID for the event is in the request.
494
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
495
-        if ( ! isset($this->_req_data['EVT_ID'])) {
496
-            EE_Error::add_error(
497
-                esc_html__(
498
-                    'In order to duplicate an event an Event ID is required.  None was given.',
499
-                    'event_espresso'
500
-                ),
501
-                __FILE__,
502
-                __FUNCTION__,
503
-                __LINE__
504
-            );
505
-            $this->_redirect_after_action(false, '', '', array(), true);
506
-            return;
507
-        }
508
-        //k we've got EVT_ID so let's use that to get the event we'll duplicate
509
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
510
-        if ( ! $orig_event instanceof EE_Event) {
511
-            throw new EE_Error(
512
-                sprintf(
513
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
514
-                    $this->_req_data['EVT_ID']
515
-                )
516
-            );
517
-        }
518
-        //k now let's clone the $orig_event before getting relations
519
-        $new_event = clone $orig_event;
520
-        //original datetimes
521
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
522
-        //other original relations
523
-        $orig_ven = $orig_event->get_many_related('Venue');
524
-        //reset the ID and modify other details to make it clear this is a dupe
525
-        $new_event->set('EVT_ID', 0);
526
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
527
-        $new_event->set('EVT_name', $new_name);
528
-        $new_event->set(
529
-            'EVT_slug',
530
-            wp_unique_post_slug(
531
-                sanitize_title($orig_event->name()),
532
-                0,
533
-                'publish',
534
-                'espresso_events',
535
-                0
536
-            )
537
-        );
538
-        $new_event->set('status', 'draft');
539
-        //duplicate discussion settings
540
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
541
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
542
-        //save the new event
543
-        $new_event->save();
544
-        //venues
545
-        foreach ($orig_ven as $ven) {
546
-            $new_event->_add_relation_to($ven, 'Venue');
547
-        }
548
-        $new_event->save();
549
-        //now we need to get the question group relations and handle that
550
-        //first primary question groups
551
-        $orig_primary_qgs = $orig_event->get_many_related(
552
-            'Question_Group',
553
-            array(array('Event_Question_Group.EQG_primary' => 1))
554
-        );
555
-        if ( ! empty($orig_primary_qgs)) {
556
-            foreach ($orig_primary_qgs as $id => $obj) {
557
-                if ($obj instanceof EE_Question_Group) {
558
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
559
-                }
560
-            }
561
-        }
562
-        //next additional attendee question groups
563
-        $orig_additional_qgs = $orig_event->get_many_related(
564
-            'Question_Group',
565
-            array(array('Event_Question_Group.EQG_primary' => 0))
566
-        );
567
-        if ( ! empty($orig_additional_qgs)) {
568
-            foreach ($orig_additional_qgs as $id => $obj) {
569
-                if ($obj instanceof EE_Question_Group) {
570
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
571
-                }
572
-            }
573
-        }
574
-        //now save
575
-        $new_event->save();
576
-        //k now that we have the new event saved we can loop through the datetimes and start adding relations.
577
-        $cloned_tickets = array();
578
-        foreach ($orig_datetimes as $orig_dtt) {
579
-            if ( ! $orig_dtt instanceof EE_Datetime) {
580
-                continue;
581
-            }
582
-            $new_dtt   = clone $orig_dtt;
583
-            $orig_tkts = $orig_dtt->tickets();
584
-            //save new dtt then add to event
585
-            $new_dtt->set('DTT_ID', 0);
586
-            $new_dtt->set('DTT_sold', 0);
587
-            $new_dtt->save();
588
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
589
-            $new_event->save();
590
-            //now let's get the ticket relations setup.
591
-            foreach ((array)$orig_tkts as $orig_tkt) {
592
-                //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
593
-                if ( ! $orig_tkt instanceof EE_Ticket) {
594
-                    continue;
595
-                }
596
-                //is this ticket archived?  If it is then let's skip
597
-                if ($orig_tkt->get('TKT_deleted')) {
598
-                    continue;
599
-                }
600
-                // does this original ticket already exist in the clone_tickets cache?
601
-                //  If so we'll just use the new ticket from it.
602
-                if (isset($cloned_tickets[$orig_tkt->ID()])) {
603
-                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
604
-                } else {
605
-                    $new_tkt = clone $orig_tkt;
606
-                    //get relations on the $orig_tkt that we need to setup.
607
-                    $orig_prices = $orig_tkt->prices();
608
-                    $new_tkt->set('TKT_ID', 0);
609
-                    $new_tkt->set('TKT_sold', 0);
610
-                    $new_tkt->set('TKT_reserved', 0);
611
-                    $new_tkt->save(); //make sure new ticket has ID.
612
-                    //price relations on new ticket need to be setup.
613
-                    foreach ($orig_prices as $orig_price) {
614
-                        $new_price = clone $orig_price;
615
-                        $new_price->set('PRC_ID', 0);
616
-                        $new_price->save();
617
-                        $new_tkt->_add_relation_to($new_price, 'Price');
618
-                        $new_tkt->save();
619
-                    }
620
-                }
621
-                // k now we can add the new ticket as a relation to the new datetime
622
-                // and make sure its added to our cached $cloned_tickets array
623
-                // for use with later datetimes that have the same ticket.
624
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
625
-                $new_dtt->save();
626
-                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
627
-            }
628
-        }
629
-        //clone taxonomy information
630
-        $taxonomies_to_clone_with = apply_filters(
631
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
632
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
633
-        );
634
-        //get terms for original event (notice)
635
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
636
-        //loop through terms and add them to new event.
637
-        foreach ($orig_terms as $term) {
638
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
639
-        }
640
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
641
-        //now let's redirect to the edit page for this duplicated event if we have a new event id.
642
-        if ($new_event->ID()) {
643
-            $redirect_args = array(
644
-                'post'   => $new_event->ID(),
645
-                'action' => 'edit',
646
-            );
647
-            EE_Error::add_success(
648
-                esc_html__(
649
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
650
-                    'event_espresso'
651
-                )
652
-            );
653
-        } else {
654
-            $redirect_args = array(
655
-                'action' => 'default',
656
-            );
657
-            EE_Error::add_error(
658
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
659
-                __FILE__,
660
-                __FUNCTION__,
661
-                __LINE__
662
-            );
663
-        }
664
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
665
-    }
666
-
667
-
668
-    protected function _import_page()
669
-    {
670
-        $title                                      = esc_html__('Import', 'event_espresso');
671
-        $intro                                      = esc_html__(
672
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
673
-            'event_espresso'
674
-        );
675
-        $form_url                                   = EVENTS_ADMIN_URL;
676
-        $action                                     = 'import_events';
677
-        $type                                       = 'csv';
678
-        $this->_template_args['form']               = EE_Import::instance()->upload_form(
679
-            $title, $intro, $form_url, $action, $type
680
-        );
681
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
682
-            array('action' => 'sample_export_file'),
683
-            $this->_admin_base_url
684
-        );
685
-        $content                                    = EEH_Template::display_template(
686
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
687
-            $this->_template_args,
688
-            true
689
-        );
690
-        $this->_template_args['admin_page_content'] = $content;
691
-        $this->display_admin_page_with_sidebar();
692
-    }
693
-
694
-
695
-
696
-    /**
697
-     * _import_events
698
-     * This handles displaying the screen and running imports for importing events.
699
-     *
700
-     * @return void
701
-     */
702
-    protected function _import_events()
703
-    {
704
-        require_once(EE_CLASSES . 'EE_Import.class.php');
705
-        $success = EE_Import::instance()->import();
706
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * _events_export
713
-     * Will export all (or just the given event) to a Excel compatible file.
714
-     *
715
-     * @access protected
716
-     * @return void
717
-     */
718
-    protected function _events_export()
719
-    {
720
-        if (isset($this->_req_data['EVT_ID'])) {
721
-            $event_ids = $this->_req_data['EVT_ID'];
722
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
723
-            $event_ids = $this->_req_data['EVT_IDs'];
724
-        } else {
725
-            $event_ids = null;
726
-        }
727
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
728
-        $new_request_args = array(
729
-            'export' => 'report',
730
-            'action' => 'all_event_data',
731
-            'EVT_ID' => $event_ids,
732
-        );
733
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
734
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
735
-            require_once(EE_CLASSES . 'EE_Export.class.php');
736
-            $EE_Export = EE_Export::instance($this->_req_data);
737
-            $EE_Export->export();
738
-        }
739
-    }
740
-
741
-
742
-
743
-    /**
744
-     * handle category exports()
745
-     *
746
-     * @return void
747
-     */
748
-    protected function _categories_export()
749
-    {
750
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
751
-        $new_request_args = array(
752
-            'export'       => 'report',
753
-            'action'       => 'categories',
754
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
755
-        );
756
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
757
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
758
-            require_once(EE_CLASSES . 'EE_Export.class.php');
759
-            $EE_Export = EE_Export::instance($this->_req_data);
760
-            $EE_Export->export();
761
-        }
762
-    }
763
-
764
-
765
-
766
-    /**
767
-     * Creates a sample CSV file for importing
768
-     */
769
-    protected function _sample_export_file()
770
-    {
771
-        //		require_once(EE_CLASSES . 'EE_Export.class.php');
772
-        EE_Export::instance()->export_sample();
773
-    }
774
-
775
-
776
-
777
-    /*************        Template Settings        *************/
778
-    protected function _template_settings()
779
-    {
780
-        $this->_template_args['values'] = $this->_yes_no_values;
781
-        /**
782
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
783
-         * from General_Settings_Admin_Page to here.
784
-         */
785
-        $this->_template_args = apply_filters(
786
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
787
-            $this->_template_args
788
-        );
789
-        $this->_set_add_edit_form_tags('update_template_settings');
790
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
791
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
792
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
793
-            $this->_template_args,
794
-            true
795
-        );
796
-        $this->display_admin_page_with_sidebar();
797
-    }
798
-
799
-
800
-
801
-    protected function _update_template_settings()
802
-    {
803
-        /**
804
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
805
-         * from General_Settings_Admin_Page to here.
806
-         */
807
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
808
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
809
-            EE_Registry::instance()->CFG->template_settings,
810
-            $this->_req_data
811
-        );
812
-        //update custom post type slugs and detect if we need to flush rewrite rules
813
-        $old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
814
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
815
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
816
-            : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
817
-        $what                                              = 'Template Settings';
818
-        $success                                           = $this->_update_espresso_configuration(
819
-            $what,
820
-            EE_Registry::instance()->CFG->template_settings,
821
-            __FILE__,
822
-            __FUNCTION__,
823
-            __LINE__
824
-        );
825
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
826
-            update_option('ee_flush_rewrite_rules', true);
827
-        }
828
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
829
-    }
830
-
831
-
832
-
833
-    /**
834
-     * _premium_event_editor_meta_boxes
835
-     * add all metaboxes related to the event_editor
836
-     *
837
-     * @access protected
838
-     * @return void
839
-     */
840
-    protected function _premium_event_editor_meta_boxes()
841
-    {
842
-        $this->verify_cpt_object();
843
-        add_meta_box(
844
-            'espresso_event_editor_event_options',
845
-            esc_html__('Event Registration Options', 'event_espresso'),
846
-            array($this, 'registration_options_meta_box'),
847
-            $this->page_slug,
848
-            'side',
849
-            'core'
850
-        );
851
-    }
852
-
853
-
854
-
855
-    /**
856
-     * override caf metabox
857
-     *
858
-     * @return void
859
-     */
860
-    public function registration_options_meta_box()
861
-    {
862
-        $yes_no_values = array(
863
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
864
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
865
-        );
866
-        $default_reg_status_values = EEM_Registration::reg_status_array(
867
-            array(
868
-                EEM_Registration::status_id_cancelled,
869
-                EEM_Registration::status_id_declined,
870
-                EEM_Registration::status_id_incomplete,
871
-                EEM_Registration::status_id_wait_list,
872
-            ),
873
-            true
874
-        );
875
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
876
-        $template_args['_event']                          = $this->_cpt_model_obj;
877
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
878
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
879
-            'default_reg_status',
880
-            $default_reg_status_values,
881
-            $this->_cpt_model_obj->default_registration_status()
882
-        );
883
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
884
-            'display_desc',
885
-            $yes_no_values,
886
-            $this->_cpt_model_obj->display_description()
887
-        );
888
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
889
-            'display_ticket_selector',
890
-            $yes_no_values,
891
-            $this->_cpt_model_obj->display_ticket_selector(),
892
-            '',
893
-            '',
894
-            false
895
-        );
896
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
897
-            'EVT_default_registration_status',
898
-            $default_reg_status_values,
899
-            $this->_cpt_model_obj->default_registration_status()
900
-        );
901
-        $template_args['additional_registration_options'] = apply_filters(
902
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
903
-            '',
904
-            $template_args,
905
-            $yes_no_values,
906
-            $default_reg_status_values
907
-        );
908
-        EEH_Template::display_template(
909
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
910
-            $template_args
911
-        );
912
-    }
913
-
914
-
915
-
916
-    /**
917
-     * wp_list_table_mods for caf
918
-     * ============================
919
-     */
920
-    /**
921
-     * hook into list table filters and provide filters for caffeinated list table
922
-     *
923
-     * @param  array $old_filters    any existing filters present
924
-     * @param  array $list_table_obj the list table object
925
-     * @return array                  new filters
926
-     */
927
-    public function list_table_filters($old_filters, $list_table_obj)
928
-    {
929
-        $filters = array();
930
-        //first month/year filters
931
-        $filters[] = $this->espresso_event_months_dropdown();
932
-        $status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
933
-        //active status dropdown
934
-        if ($status !== 'draft') {
935
-            $filters[] = $this->active_status_dropdown(
936
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
937
-            );
938
-        }
939
-        //category filter
940
-        $filters[] = $this->category_dropdown();
941
-        return array_merge($old_filters, $filters);
942
-    }
943
-
944
-
945
-
946
-    /**
947
-     * espresso_event_months_dropdown
948
-     *
949
-     * @access public
950
-     * @return string                dropdown listing month/year selections for events.
951
-     */
952
-    public function espresso_event_months_dropdown()
953
-    {
954
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
955
-        // Note we need to include any other filters that are set!
956
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
957
-        //categories?
958
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
959
-            ? $this->_req_data['EVT_CAT']
960
-            : null;
961
-        //active status?
962
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
963
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
964
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
965
-    }
966
-
967
-
968
-
969
-    /**
970
-     * returns a list of "active" statuses on the event
971
-     *
972
-     * @param  string $current_value whatever the current active status is
973
-     * @return string
974
-     */
975
-    public function active_status_dropdown($current_value = '')
976
-    {
977
-        $select_name = 'active_status';
978
-        $values      = array(
979
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
980
-            'active'   => esc_html__('Active', 'event_espresso'),
981
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
982
-            'expired'  => esc_html__('Expired', 'event_espresso'),
983
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
984
-        );
985
-        $id          = 'id="espresso-active-status-dropdown-filter"';
986
-        $class       = 'wide';
987
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
988
-    }
989
-
990
-
991
-
992
-    /**
993
-     * output a dropdown of the categories for the category filter on the event admin list table
994
-     *
995
-     * @access  public
996
-     * @return string html
997
-     */
998
-    public function category_dropdown()
999
-    {
1000
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1001
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1002
-    }
1003
-
1004
-
1005
-
1006
-    /**
1007
-     * get total number of events today
1008
-     *
1009
-     * @access public
1010
-     * @return int
1011
-     */
1012
-    public function total_events_today()
1013
-    {
1014
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1015
-            'DTT_EVT_start',
1016
-            date('Y-m-d') . ' 00:00:00',
1017
-            'Y-m-d H:i:s',
1018
-            'UTC'
1019
-        );
1020
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1021
-            'DTT_EVT_start',
1022
-            date('Y-m-d') . ' 23:59:59',
1023
-            'Y-m-d H:i:s',
1024
-            'UTC'
1025
-        );
1026
-        $where = array(
1027
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1028
-        );
1029
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1030
-        return $count;
1031
-    }
1032
-
1033
-
1034
-
1035
-    /**
1036
-     * get total number of events this month
1037
-     *
1038
-     * @access public
1039
-     * @return int
1040
-     */
1041
-    public function total_events_this_month()
1042
-    {
1043
-        //Dates
1044
-        $this_year_r     = date('Y');
1045
-        $this_month_r    = date('m');
1046
-        $days_this_month = date('t');
1047
-        $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1048
-            'DTT_EVT_start',
1049
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1050
-            'Y-m-d H:i:s',
1051
-            'UTC'
1052
-        );
1053
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1054
-            'DTT_EVT_start',
1055
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1056
-            'Y-m-d H:i:s',
1057
-            'UTC'
1058
-        );
1059
-        $where = array(
1060
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1061
-        );
1062
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1063
-        return $count;
1064
-    }
1065
-
1066
-
1067
-
1068
-    /** DEFAULT TICKETS STUFF **/
1069
-    public function _tickets_overview_list_table()
1070
-    {
1071
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1072
-        $this->display_admin_list_table_page_with_no_sidebar();
1073
-    }
1074
-
1075
-
1076
-
1077
-    /**
1078
-     * @param int  $per_page
1079
-     * @param bool $count
1080
-     * @param bool $trashed
1081
-     * @return \EE_Soft_Delete_Base_Class[]|int
1082
-     */
1083
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1084
-    {
1085
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1086
-        $order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1087
-        switch ($orderby) {
1088
-            case 'TKT_name' :
1089
-                $orderby = array('TKT_name' => $order);
1090
-                break;
1091
-            case 'TKT_price' :
1092
-                $orderby = array('TKT_price' => $order);
1093
-                break;
1094
-            case 'TKT_uses' :
1095
-                $orderby = array('TKT_uses' => $order);
1096
-                break;
1097
-            case 'TKT_min' :
1098
-                $orderby = array('TKT_min' => $order);
1099
-                break;
1100
-            case 'TKT_max' :
1101
-                $orderby = array('TKT_max' => $order);
1102
-                break;
1103
-            case 'TKT_qty' :
1104
-                $orderby = array('TKT_qty' => $order);
1105
-                break;
1106
-        }
1107
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1108
-            ? $this->_req_data['paged']
1109
-            : 1;
1110
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1111
-            ? $this->_req_data['perpage']
1112
-            : $per_page;
1113
-        $_where       = array(
1114
-            'TKT_is_default' => 1,
1115
-            'TKT_deleted'    => $trashed,
1116
-        );
1117
-        $offset       = ($current_page - 1) * $per_page;
1118
-        $limit        = array($offset, $per_page);
1119
-        if (isset($this->_req_data['s'])) {
1120
-            $sstr         = '%' . $this->_req_data['s'] . '%';
1121
-            $_where['OR'] = array(
1122
-                'TKT_name'        => array('LIKE', $sstr),
1123
-                'TKT_description' => array('LIKE', $sstr),
1124
-            );
1125
-        }
1126
-        $query_params = array(
1127
-            $_where,
1128
-            'order_by' => $orderby,
1129
-            'limit'    => $limit,
1130
-            'group_by' => 'TKT_ID',
1131
-        );
1132
-        if ($count) {
1133
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1134
-        } else {
1135
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1136
-        }
1137
-    }
1138
-
1139
-
1140
-
1141
-    /**
1142
-     * @param bool $trash
1143
-     */
1144
-    protected function _trash_or_restore_ticket($trash = false)
1145
-    {
1146
-        $success = 1;
1147
-        $TKT = EEM_Ticket::instance();
1148
-        //checkboxes?
1149
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1150
-            //if array has more than one element then success message should be plural
1151
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1152
-            //cycle thru the boxes
1153
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1154
-                if ($trash) {
1155
-                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1156
-                        $success = 0;
1157
-                    }
1158
-                } else {
1159
-                    if ( ! $TKT->restore_by_ID($TKT_ID)) {
1160
-                        $success = 0;
1161
-                    }
1162
-                }
1163
-            }
1164
-        } else {
1165
-            //grab single id and trash
1166
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1167
-            if ($trash) {
1168
-                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1169
-                    $success = 0;
1170
-                }
1171
-            } else {
1172
-                if ( ! $TKT->restore_by_ID($TKT_ID)) {
1173
-                    $success = 0;
1174
-                }
1175
-            }
1176
-        }
1177
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1178
-        $query_args  = array(
1179
-            'action' => 'ticket_list_table',
1180
-            'status' => $trash ? '' : 'trashed',
1181
-        );
1182
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1183
-    }
1184
-
1185
-
1186
-
1187
-    protected function _delete_ticket()
1188
-    {
1189
-        $success = 1;
1190
-        //checkboxes?
1191
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1192
-            //if array has more than one element then success message should be plural
1193
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1194
-            //cycle thru the boxes
1195
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1196
-                //delete
1197
-                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1198
-                    $success = 0;
1199
-                }
1200
-            }
1201
-        } else {
1202
-            //grab single id and trash
1203
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1204
-            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1205
-                $success = 0;
1206
-            }
1207
-        }
1208
-        $action_desc = 'deleted';
1209
-        $query_args  = array(
1210
-            'action' => 'ticket_list_table',
1211
-            'status' => 'trashed',
1212
-        );
1213
-        //fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1214
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1215
-            array(array('TKT_is_default' => 1)),
1216
-            'TKT_ID',
1217
-            true
1218
-        )
1219
-        ) {
1220
-            $query_args = array();
1221
-        }
1222
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1223
-    }
1224
-
1225
-
1226
-
1227
-    /**
1228
-     * @param int $TKT_ID
1229
-     * @return bool|int
1230
-     */
1231
-    protected function _delete_the_ticket($TKT_ID)
1232
-    {
1233
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1234
-        $tkt->_remove_relations('Datetime');
1235
-        //delete all related prices first
1236
-        $tkt->delete_related_permanently('Price');
1237
-        return $tkt->delete_permanently();
1238
-    }
19
+	/**
20
+	 * Extend_Events_Admin_Page constructor.
21
+	 *
22
+	 * @param bool $routing
23
+	 */
24
+	public function __construct($routing = true)
25
+	{
26
+		parent::__construct($routing);
27
+		if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
+		}
32
+	}
33
+
34
+
35
+
36
+	protected function _extend_page_config()
37
+	{
38
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
39
+		//is there a evt_id in the request?
40
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41
+			? $this->_req_data['EVT_ID']
42
+			: 0;
43
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
44
+		//tkt_id?
45
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
46
+			? $this->_req_data['TKT_ID']
47
+			: 0;
48
+		$new_page_routes = array(
49
+			'duplicate_event'          => array(
50
+				'func'       => '_duplicate_event',
51
+				'capability' => 'ee_edit_event',
52
+				'obj_id'     => $evt_id,
53
+				'noheader'   => true,
54
+			),
55
+			'ticket_list_table'        => array(
56
+				'func'       => '_tickets_overview_list_table',
57
+				'capability' => 'ee_read_default_tickets',
58
+			),
59
+			'trash_ticket'             => array(
60
+				'func'       => '_trash_or_restore_ticket',
61
+				'capability' => 'ee_delete_default_ticket',
62
+				'obj_id'     => $tkt_id,
63
+				'noheader'   => true,
64
+				'args'       => array('trash' => true),
65
+			),
66
+			'trash_tickets'            => array(
67
+				'func'       => '_trash_or_restore_ticket',
68
+				'capability' => 'ee_delete_default_tickets',
69
+				'noheader'   => true,
70
+				'args'       => array('trash' => true),
71
+			),
72
+			'restore_ticket'           => array(
73
+				'func'       => '_trash_or_restore_ticket',
74
+				'capability' => 'ee_delete_default_ticket',
75
+				'obj_id'     => $tkt_id,
76
+				'noheader'   => true,
77
+			),
78
+			'restore_tickets'          => array(
79
+				'func'       => '_trash_or_restore_ticket',
80
+				'capability' => 'ee_delete_default_tickets',
81
+				'noheader'   => true,
82
+			),
83
+			'delete_ticket'            => array(
84
+				'func'       => '_delete_ticket',
85
+				'capability' => 'ee_delete_default_ticket',
86
+				'obj_id'     => $tkt_id,
87
+				'noheader'   => true,
88
+			),
89
+			'delete_tickets'           => array(
90
+				'func'       => '_delete_ticket',
91
+				'capability' => 'ee_delete_default_tickets',
92
+				'noheader'   => true,
93
+			),
94
+			'import_page'              => array(
95
+				'func'       => '_import_page',
96
+				'capability' => 'import',
97
+			),
98
+			'import'                   => array(
99
+				'func'       => '_import_events',
100
+				'capability' => 'import',
101
+				'noheader'   => true,
102
+			),
103
+			'import_events'            => array(
104
+				'func'       => '_import_events',
105
+				'capability' => 'import',
106
+				'noheader'   => true,
107
+			),
108
+			'export_events'            => array(
109
+				'func'       => '_events_export',
110
+				'capability' => 'export',
111
+				'noheader'   => true,
112
+			),
113
+			'export_categories'        => array(
114
+				'func'       => '_categories_export',
115
+				'capability' => 'export',
116
+				'noheader'   => true,
117
+			),
118
+			'sample_export_file'       => array(
119
+				'func'       => '_sample_export_file',
120
+				'capability' => 'export',
121
+				'noheader'   => true,
122
+			),
123
+			'update_template_settings' => array(
124
+				'func'       => '_update_template_settings',
125
+				'capability' => 'manage_options',
126
+				'noheader'   => true,
127
+			),
128
+		);
129
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
130
+		//partial route/config override
131
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
132
+		$this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
133
+		$this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
134
+		$this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
135
+		$this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
136
+		$this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
137
+		//add tickets tab but only if there are more than one default ticket!
138
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
139
+			array(array('TKT_is_default' => 1)),
140
+			'TKT_ID',
141
+			true
142
+		);
143
+		if ($tkt_count > 1) {
144
+			$new_page_config = array(
145
+				'ticket_list_table' => array(
146
+					'nav'           => array(
147
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
148
+						'order' => 60,
149
+					),
150
+					'list_table'    => 'Tickets_List_Table',
151
+					'require_nonce' => false,
152
+				),
153
+			);
154
+		}
155
+		//template settings
156
+		$new_page_config['template_settings'] = array(
157
+			'nav'           => array(
158
+				'label' => esc_html__('Templates', 'event_espresso'),
159
+				'order' => 30,
160
+			),
161
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
162
+			'help_tabs'     => array(
163
+				'general_settings_templates_help_tab' => array(
164
+					'title'    => esc_html__('Templates', 'event_espresso'),
165
+					'filename' => 'general_settings_templates',
166
+				),
167
+			),
168
+			'help_tour'     => array('Templates_Help_Tour'),
169
+			'require_nonce' => false,
170
+		);
171
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
172
+		//add filters and actions
173
+		//modifying _views
174
+		add_filter(
175
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
+			array($this, 'add_additional_datetime_button'),
177
+			10,
178
+			2
179
+		);
180
+		add_filter(
181
+			'FHEE_event_datetime_metabox_clone_button_template',
182
+			array($this, 'add_datetime_clone_button'),
183
+			10,
184
+			2
185
+		);
186
+		add_filter(
187
+			'FHEE_event_datetime_metabox_timezones_template',
188
+			array($this, 'datetime_timezones_template'),
189
+			10,
190
+			2
191
+		);
192
+		//filters for event list table
193
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
194
+		add_filter(
195
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
+			array($this, 'extra_list_table_actions'),
197
+			10,
198
+			2
199
+		);
200
+		//legend item
201
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
202
+		add_action('admin_init', array($this, 'admin_init'));
203
+		//heartbeat stuff
204
+		add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
205
+	}
206
+
207
+
208
+
209
+	/**
210
+	 * admin_init
211
+	 */
212
+	public function admin_init()
213
+	{
214
+		EE_Registry::$i18n_js_strings = array_merge(
215
+			EE_Registry::$i18n_js_strings,
216
+			array(
217
+				'image_confirm'          => esc_html__(
218
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
219
+					'event_espresso'
220
+				),
221
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
222
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
223
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
224
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
225
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
226
+			)
227
+		);
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
234
+	 * accordingly.
235
+	 *
236
+	 * @param array $response The existing heartbeat response array.
237
+	 * @param array $data     The incoming data package.
238
+	 * @return array  possibly appended response.
239
+	 */
240
+	public function heartbeat_response($response, $data)
241
+	{
242
+		/**
243
+		 * check whether count of tickets is approaching the potential
244
+		 * limits for the server.
245
+		 */
246
+		if ( ! empty($data['input_count'])) {
247
+			$response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
248
+				$data['input_count']
249
+			);
250
+		}
251
+		return $response;
252
+	}
253
+
254
+
255
+
256
+	protected function _add_screen_options_ticket_list_table()
257
+	{
258
+		$this->_per_page_screen_option();
259
+	}
260
+
261
+
262
+
263
+	/**
264
+	 * @param string $return
265
+	 * @param int    $id
266
+	 * @param string $new_title
267
+	 * @param string $new_slug
268
+	 * @return string
269
+	 */
270
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
271
+	{
272
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
273
+		//make sure this is only when editing
274
+		if ( ! empty($id)) {
275
+			$href  = EE_Admin_Page::add_query_args_and_nonce(
276
+				array('action' => 'duplicate_event', 'EVT_ID' => $id),
277
+				$this->_admin_base_url
278
+			);
279
+			$title = esc_attr__('Duplicate Event', 'event_espresso');
280
+			$return .= '<a href="'
281
+					   . $href
282
+					   . '" title="'
283
+					   . $title
284
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
285
+					   . $title
286
+					   . '</button>';
287
+		}
288
+		return $return;
289
+	}
290
+
291
+
292
+
293
+	public function _set_list_table_views_ticket_list_table()
294
+	{
295
+		$this->_views = array(
296
+			'all'     => array(
297
+				'slug'        => 'all',
298
+				'label'       => esc_html__('All', 'event_espresso'),
299
+				'count'       => 0,
300
+				'bulk_action' => array(
301
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
302
+				),
303
+			),
304
+			'trashed' => array(
305
+				'slug'        => 'trashed',
306
+				'label'       => esc_html__('Trash', 'event_espresso'),
307
+				'count'       => 0,
308
+				'bulk_action' => array(
309
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
310
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
311
+				),
312
+			),
313
+		);
314
+	}
315
+
316
+
317
+
318
+	public function load_scripts_styles_edit()
319
+	{
320
+		wp_register_script(
321
+			'ee-event-editor-heartbeat',
322
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
323
+			array('ee_admin_js', 'heartbeat'),
324
+			EVENT_ESPRESSO_VERSION,
325
+			true
326
+		);
327
+		wp_enqueue_script('ee-accounting');
328
+		//styles
329
+		wp_enqueue_style('espresso-ui-theme');
330
+		wp_enqueue_script('event_editor_js');
331
+		wp_enqueue_script('ee-event-editor-heartbeat');
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * @param $template
338
+	 * @param $template_args
339
+	 * @return mixed
340
+	 */
341
+	public function add_additional_datetime_button($template, $template_args)
342
+	{
343
+		return EEH_Template::display_template(
344
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
345
+			$template_args,
346
+			true
347
+		);
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * @param $template
354
+	 * @param $template_args
355
+	 * @return mixed
356
+	 */
357
+	public function add_datetime_clone_button($template, $template_args)
358
+	{
359
+		return EEH_Template::display_template(
360
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
361
+			$template_args,
362
+			true
363
+		);
364
+	}
365
+
366
+
367
+
368
+	/**
369
+	 * @param $template
370
+	 * @param $template_args
371
+	 * @return mixed
372
+	 */
373
+	public function datetime_timezones_template($template, $template_args)
374
+	{
375
+		return EEH_Template::display_template(
376
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
377
+			$template_args,
378
+			true
379
+		);
380
+	}
381
+
382
+
383
+
384
+	protected function _set_list_table_views_default()
385
+	{
386
+		parent::_set_list_table_views_default();
387
+		$new_views = array(
388
+			'today' => array(
389
+				'slug'        => 'today',
390
+				'label'       => esc_html__('Today', 'event_espresso'),
391
+				'count'       => $this->total_events_today(),
392
+				'bulk_action' => array(
393
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
394
+				),
395
+			),
396
+			'month' => array(
397
+				'slug'        => 'month',
398
+				'label'       => esc_html__('This Month', 'event_espresso'),
399
+				'count'       => $this->total_events_this_month(),
400
+				'bulk_action' => array(
401
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
402
+				),
403
+			),
404
+		);
405
+		$this->_views = array_merge($this->_views, $new_views);
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * @param array     $action_links
412
+	 * @param \EE_Event $event
413
+	 * @return array
414
+	 */
415
+	public function extra_list_table_actions(array $action_links, \EE_Event $event)
416
+	{
417
+		if (
418
+		EE_Registry::instance()->CAP->current_user_can(
419
+			'ee_read_registrations',
420
+			'espresso_registrations_reports',
421
+			$event->ID()
422
+		)
423
+		) {
424
+			$reports_query_args = array(
425
+				'action' => 'reports',
426
+				'EVT_ID' => $event->ID(),
427
+			);
428
+			$reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
429
+			$action_links[]     = '<a href="'
430
+								  . $reports_link
431
+								  . '" title="'
432
+								  . esc_attr__('View Report', 'event_espresso')
433
+								  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
434
+								  . "\n\t";
435
+		}
436
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
437
+			EE_Registry::instance()->load_helper('MSG_Template');
438
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
439
+				'see_notifications_for',
440
+				null,
441
+				array('EVT_ID' => $event->ID())
442
+			);
443
+		}
444
+		return $action_links;
445
+	}
446
+
447
+
448
+
449
+	/**
450
+	 * @param $items
451
+	 * @return mixed
452
+	 */
453
+	public function additional_legend_items($items)
454
+	{
455
+		if (
456
+		EE_Registry::instance()->CAP->current_user_can(
457
+			'ee_read_registrations',
458
+			'espresso_registrations_reports'
459
+		)
460
+		) {
461
+			$items['reports'] = array(
462
+				'class' => 'dashicons dashicons-chart-bar',
463
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
464
+			);
465
+		}
466
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
467
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
468
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
469
+				$items['view_related_messages'] = array(
470
+					'class' => $related_for_icon['css_class'],
471
+					'desc'  => $related_for_icon['label'],
472
+				);
473
+			}
474
+		}
475
+		return $items;
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * This is the callback method for the duplicate event route
482
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
483
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
484
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
485
+	 * After duplication the redirect is to the new event edit page.
486
+	 *
487
+	 * @return void
488
+	 * @access protected
489
+	 * @throws EE_Error If EE_Event is not available with given ID
490
+	 */
491
+	protected function _duplicate_event()
492
+	{
493
+		// first make sure the ID for the event is in the request.
494
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
495
+		if ( ! isset($this->_req_data['EVT_ID'])) {
496
+			EE_Error::add_error(
497
+				esc_html__(
498
+					'In order to duplicate an event an Event ID is required.  None was given.',
499
+					'event_espresso'
500
+				),
501
+				__FILE__,
502
+				__FUNCTION__,
503
+				__LINE__
504
+			);
505
+			$this->_redirect_after_action(false, '', '', array(), true);
506
+			return;
507
+		}
508
+		//k we've got EVT_ID so let's use that to get the event we'll duplicate
509
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
510
+		if ( ! $orig_event instanceof EE_Event) {
511
+			throw new EE_Error(
512
+				sprintf(
513
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
514
+					$this->_req_data['EVT_ID']
515
+				)
516
+			);
517
+		}
518
+		//k now let's clone the $orig_event before getting relations
519
+		$new_event = clone $orig_event;
520
+		//original datetimes
521
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
522
+		//other original relations
523
+		$orig_ven = $orig_event->get_many_related('Venue');
524
+		//reset the ID and modify other details to make it clear this is a dupe
525
+		$new_event->set('EVT_ID', 0);
526
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
527
+		$new_event->set('EVT_name', $new_name);
528
+		$new_event->set(
529
+			'EVT_slug',
530
+			wp_unique_post_slug(
531
+				sanitize_title($orig_event->name()),
532
+				0,
533
+				'publish',
534
+				'espresso_events',
535
+				0
536
+			)
537
+		);
538
+		$new_event->set('status', 'draft');
539
+		//duplicate discussion settings
540
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
541
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
542
+		//save the new event
543
+		$new_event->save();
544
+		//venues
545
+		foreach ($orig_ven as $ven) {
546
+			$new_event->_add_relation_to($ven, 'Venue');
547
+		}
548
+		$new_event->save();
549
+		//now we need to get the question group relations and handle that
550
+		//first primary question groups
551
+		$orig_primary_qgs = $orig_event->get_many_related(
552
+			'Question_Group',
553
+			array(array('Event_Question_Group.EQG_primary' => 1))
554
+		);
555
+		if ( ! empty($orig_primary_qgs)) {
556
+			foreach ($orig_primary_qgs as $id => $obj) {
557
+				if ($obj instanceof EE_Question_Group) {
558
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
559
+				}
560
+			}
561
+		}
562
+		//next additional attendee question groups
563
+		$orig_additional_qgs = $orig_event->get_many_related(
564
+			'Question_Group',
565
+			array(array('Event_Question_Group.EQG_primary' => 0))
566
+		);
567
+		if ( ! empty($orig_additional_qgs)) {
568
+			foreach ($orig_additional_qgs as $id => $obj) {
569
+				if ($obj instanceof EE_Question_Group) {
570
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
571
+				}
572
+			}
573
+		}
574
+		//now save
575
+		$new_event->save();
576
+		//k now that we have the new event saved we can loop through the datetimes and start adding relations.
577
+		$cloned_tickets = array();
578
+		foreach ($orig_datetimes as $orig_dtt) {
579
+			if ( ! $orig_dtt instanceof EE_Datetime) {
580
+				continue;
581
+			}
582
+			$new_dtt   = clone $orig_dtt;
583
+			$orig_tkts = $orig_dtt->tickets();
584
+			//save new dtt then add to event
585
+			$new_dtt->set('DTT_ID', 0);
586
+			$new_dtt->set('DTT_sold', 0);
587
+			$new_dtt->save();
588
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
589
+			$new_event->save();
590
+			//now let's get the ticket relations setup.
591
+			foreach ((array)$orig_tkts as $orig_tkt) {
592
+				//it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
593
+				if ( ! $orig_tkt instanceof EE_Ticket) {
594
+					continue;
595
+				}
596
+				//is this ticket archived?  If it is then let's skip
597
+				if ($orig_tkt->get('TKT_deleted')) {
598
+					continue;
599
+				}
600
+				// does this original ticket already exist in the clone_tickets cache?
601
+				//  If so we'll just use the new ticket from it.
602
+				if (isset($cloned_tickets[$orig_tkt->ID()])) {
603
+					$new_tkt = $cloned_tickets[$orig_tkt->ID()];
604
+				} else {
605
+					$new_tkt = clone $orig_tkt;
606
+					//get relations on the $orig_tkt that we need to setup.
607
+					$orig_prices = $orig_tkt->prices();
608
+					$new_tkt->set('TKT_ID', 0);
609
+					$new_tkt->set('TKT_sold', 0);
610
+					$new_tkt->set('TKT_reserved', 0);
611
+					$new_tkt->save(); //make sure new ticket has ID.
612
+					//price relations on new ticket need to be setup.
613
+					foreach ($orig_prices as $orig_price) {
614
+						$new_price = clone $orig_price;
615
+						$new_price->set('PRC_ID', 0);
616
+						$new_price->save();
617
+						$new_tkt->_add_relation_to($new_price, 'Price');
618
+						$new_tkt->save();
619
+					}
620
+				}
621
+				// k now we can add the new ticket as a relation to the new datetime
622
+				// and make sure its added to our cached $cloned_tickets array
623
+				// for use with later datetimes that have the same ticket.
624
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
625
+				$new_dtt->save();
626
+				$cloned_tickets[$orig_tkt->ID()] = $new_tkt;
627
+			}
628
+		}
629
+		//clone taxonomy information
630
+		$taxonomies_to_clone_with = apply_filters(
631
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
632
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
633
+		);
634
+		//get terms for original event (notice)
635
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
636
+		//loop through terms and add them to new event.
637
+		foreach ($orig_terms as $term) {
638
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
639
+		}
640
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
641
+		//now let's redirect to the edit page for this duplicated event if we have a new event id.
642
+		if ($new_event->ID()) {
643
+			$redirect_args = array(
644
+				'post'   => $new_event->ID(),
645
+				'action' => 'edit',
646
+			);
647
+			EE_Error::add_success(
648
+				esc_html__(
649
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
650
+					'event_espresso'
651
+				)
652
+			);
653
+		} else {
654
+			$redirect_args = array(
655
+				'action' => 'default',
656
+			);
657
+			EE_Error::add_error(
658
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
659
+				__FILE__,
660
+				__FUNCTION__,
661
+				__LINE__
662
+			);
663
+		}
664
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
665
+	}
666
+
667
+
668
+	protected function _import_page()
669
+	{
670
+		$title                                      = esc_html__('Import', 'event_espresso');
671
+		$intro                                      = esc_html__(
672
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
673
+			'event_espresso'
674
+		);
675
+		$form_url                                   = EVENTS_ADMIN_URL;
676
+		$action                                     = 'import_events';
677
+		$type                                       = 'csv';
678
+		$this->_template_args['form']               = EE_Import::instance()->upload_form(
679
+			$title, $intro, $form_url, $action, $type
680
+		);
681
+		$this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
682
+			array('action' => 'sample_export_file'),
683
+			$this->_admin_base_url
684
+		);
685
+		$content                                    = EEH_Template::display_template(
686
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
687
+			$this->_template_args,
688
+			true
689
+		);
690
+		$this->_template_args['admin_page_content'] = $content;
691
+		$this->display_admin_page_with_sidebar();
692
+	}
693
+
694
+
695
+
696
+	/**
697
+	 * _import_events
698
+	 * This handles displaying the screen and running imports for importing events.
699
+	 *
700
+	 * @return void
701
+	 */
702
+	protected function _import_events()
703
+	{
704
+		require_once(EE_CLASSES . 'EE_Import.class.php');
705
+		$success = EE_Import::instance()->import();
706
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * _events_export
713
+	 * Will export all (or just the given event) to a Excel compatible file.
714
+	 *
715
+	 * @access protected
716
+	 * @return void
717
+	 */
718
+	protected function _events_export()
719
+	{
720
+		if (isset($this->_req_data['EVT_ID'])) {
721
+			$event_ids = $this->_req_data['EVT_ID'];
722
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
723
+			$event_ids = $this->_req_data['EVT_IDs'];
724
+		} else {
725
+			$event_ids = null;
726
+		}
727
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
728
+		$new_request_args = array(
729
+			'export' => 'report',
730
+			'action' => 'all_event_data',
731
+			'EVT_ID' => $event_ids,
732
+		);
733
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
734
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
735
+			require_once(EE_CLASSES . 'EE_Export.class.php');
736
+			$EE_Export = EE_Export::instance($this->_req_data);
737
+			$EE_Export->export();
738
+		}
739
+	}
740
+
741
+
742
+
743
+	/**
744
+	 * handle category exports()
745
+	 *
746
+	 * @return void
747
+	 */
748
+	protected function _categories_export()
749
+	{
750
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
751
+		$new_request_args = array(
752
+			'export'       => 'report',
753
+			'action'       => 'categories',
754
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
755
+		);
756
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
757
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
758
+			require_once(EE_CLASSES . 'EE_Export.class.php');
759
+			$EE_Export = EE_Export::instance($this->_req_data);
760
+			$EE_Export->export();
761
+		}
762
+	}
763
+
764
+
765
+
766
+	/**
767
+	 * Creates a sample CSV file for importing
768
+	 */
769
+	protected function _sample_export_file()
770
+	{
771
+		//		require_once(EE_CLASSES . 'EE_Export.class.php');
772
+		EE_Export::instance()->export_sample();
773
+	}
774
+
775
+
776
+
777
+	/*************        Template Settings        *************/
778
+	protected function _template_settings()
779
+	{
780
+		$this->_template_args['values'] = $this->_yes_no_values;
781
+		/**
782
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
783
+		 * from General_Settings_Admin_Page to here.
784
+		 */
785
+		$this->_template_args = apply_filters(
786
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
787
+			$this->_template_args
788
+		);
789
+		$this->_set_add_edit_form_tags('update_template_settings');
790
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
791
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
792
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
793
+			$this->_template_args,
794
+			true
795
+		);
796
+		$this->display_admin_page_with_sidebar();
797
+	}
798
+
799
+
800
+
801
+	protected function _update_template_settings()
802
+	{
803
+		/**
804
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
805
+		 * from General_Settings_Admin_Page to here.
806
+		 */
807
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
808
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
809
+			EE_Registry::instance()->CFG->template_settings,
810
+			$this->_req_data
811
+		);
812
+		//update custom post type slugs and detect if we need to flush rewrite rules
813
+		$old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
814
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
815
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
816
+			: sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
817
+		$what                                              = 'Template Settings';
818
+		$success                                           = $this->_update_espresso_configuration(
819
+			$what,
820
+			EE_Registry::instance()->CFG->template_settings,
821
+			__FILE__,
822
+			__FUNCTION__,
823
+			__LINE__
824
+		);
825
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
826
+			update_option('ee_flush_rewrite_rules', true);
827
+		}
828
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
829
+	}
830
+
831
+
832
+
833
+	/**
834
+	 * _premium_event_editor_meta_boxes
835
+	 * add all metaboxes related to the event_editor
836
+	 *
837
+	 * @access protected
838
+	 * @return void
839
+	 */
840
+	protected function _premium_event_editor_meta_boxes()
841
+	{
842
+		$this->verify_cpt_object();
843
+		add_meta_box(
844
+			'espresso_event_editor_event_options',
845
+			esc_html__('Event Registration Options', 'event_espresso'),
846
+			array($this, 'registration_options_meta_box'),
847
+			$this->page_slug,
848
+			'side',
849
+			'core'
850
+		);
851
+	}
852
+
853
+
854
+
855
+	/**
856
+	 * override caf metabox
857
+	 *
858
+	 * @return void
859
+	 */
860
+	public function registration_options_meta_box()
861
+	{
862
+		$yes_no_values = array(
863
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
864
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
865
+		);
866
+		$default_reg_status_values = EEM_Registration::reg_status_array(
867
+			array(
868
+				EEM_Registration::status_id_cancelled,
869
+				EEM_Registration::status_id_declined,
870
+				EEM_Registration::status_id_incomplete,
871
+				EEM_Registration::status_id_wait_list,
872
+			),
873
+			true
874
+		);
875
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
876
+		$template_args['_event']                          = $this->_cpt_model_obj;
877
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
878
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
879
+			'default_reg_status',
880
+			$default_reg_status_values,
881
+			$this->_cpt_model_obj->default_registration_status()
882
+		);
883
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
884
+			'display_desc',
885
+			$yes_no_values,
886
+			$this->_cpt_model_obj->display_description()
887
+		);
888
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
889
+			'display_ticket_selector',
890
+			$yes_no_values,
891
+			$this->_cpt_model_obj->display_ticket_selector(),
892
+			'',
893
+			'',
894
+			false
895
+		);
896
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
897
+			'EVT_default_registration_status',
898
+			$default_reg_status_values,
899
+			$this->_cpt_model_obj->default_registration_status()
900
+		);
901
+		$template_args['additional_registration_options'] = apply_filters(
902
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
903
+			'',
904
+			$template_args,
905
+			$yes_no_values,
906
+			$default_reg_status_values
907
+		);
908
+		EEH_Template::display_template(
909
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
910
+			$template_args
911
+		);
912
+	}
913
+
914
+
915
+
916
+	/**
917
+	 * wp_list_table_mods for caf
918
+	 * ============================
919
+	 */
920
+	/**
921
+	 * hook into list table filters and provide filters for caffeinated list table
922
+	 *
923
+	 * @param  array $old_filters    any existing filters present
924
+	 * @param  array $list_table_obj the list table object
925
+	 * @return array                  new filters
926
+	 */
927
+	public function list_table_filters($old_filters, $list_table_obj)
928
+	{
929
+		$filters = array();
930
+		//first month/year filters
931
+		$filters[] = $this->espresso_event_months_dropdown();
932
+		$status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
933
+		//active status dropdown
934
+		if ($status !== 'draft') {
935
+			$filters[] = $this->active_status_dropdown(
936
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
937
+			);
938
+		}
939
+		//category filter
940
+		$filters[] = $this->category_dropdown();
941
+		return array_merge($old_filters, $filters);
942
+	}
943
+
944
+
945
+
946
+	/**
947
+	 * espresso_event_months_dropdown
948
+	 *
949
+	 * @access public
950
+	 * @return string                dropdown listing month/year selections for events.
951
+	 */
952
+	public function espresso_event_months_dropdown()
953
+	{
954
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
955
+		// Note we need to include any other filters that are set!
956
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
957
+		//categories?
958
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
959
+			? $this->_req_data['EVT_CAT']
960
+			: null;
961
+		//active status?
962
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
963
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
964
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
965
+	}
966
+
967
+
968
+
969
+	/**
970
+	 * returns a list of "active" statuses on the event
971
+	 *
972
+	 * @param  string $current_value whatever the current active status is
973
+	 * @return string
974
+	 */
975
+	public function active_status_dropdown($current_value = '')
976
+	{
977
+		$select_name = 'active_status';
978
+		$values      = array(
979
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
980
+			'active'   => esc_html__('Active', 'event_espresso'),
981
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
982
+			'expired'  => esc_html__('Expired', 'event_espresso'),
983
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
984
+		);
985
+		$id          = 'id="espresso-active-status-dropdown-filter"';
986
+		$class       = 'wide';
987
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
988
+	}
989
+
990
+
991
+
992
+	/**
993
+	 * output a dropdown of the categories for the category filter on the event admin list table
994
+	 *
995
+	 * @access  public
996
+	 * @return string html
997
+	 */
998
+	public function category_dropdown()
999
+	{
1000
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1001
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1002
+	}
1003
+
1004
+
1005
+
1006
+	/**
1007
+	 * get total number of events today
1008
+	 *
1009
+	 * @access public
1010
+	 * @return int
1011
+	 */
1012
+	public function total_events_today()
1013
+	{
1014
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1015
+			'DTT_EVT_start',
1016
+			date('Y-m-d') . ' 00:00:00',
1017
+			'Y-m-d H:i:s',
1018
+			'UTC'
1019
+		);
1020
+		$end   = EEM_Datetime::instance()->convert_datetime_for_query(
1021
+			'DTT_EVT_start',
1022
+			date('Y-m-d') . ' 23:59:59',
1023
+			'Y-m-d H:i:s',
1024
+			'UTC'
1025
+		);
1026
+		$where = array(
1027
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1028
+		);
1029
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1030
+		return $count;
1031
+	}
1032
+
1033
+
1034
+
1035
+	/**
1036
+	 * get total number of events this month
1037
+	 *
1038
+	 * @access public
1039
+	 * @return int
1040
+	 */
1041
+	public function total_events_this_month()
1042
+	{
1043
+		//Dates
1044
+		$this_year_r     = date('Y');
1045
+		$this_month_r    = date('m');
1046
+		$days_this_month = date('t');
1047
+		$start           = EEM_Datetime::instance()->convert_datetime_for_query(
1048
+			'DTT_EVT_start',
1049
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1050
+			'Y-m-d H:i:s',
1051
+			'UTC'
1052
+		);
1053
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1054
+			'DTT_EVT_start',
1055
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1056
+			'Y-m-d H:i:s',
1057
+			'UTC'
1058
+		);
1059
+		$where = array(
1060
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1061
+		);
1062
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1063
+		return $count;
1064
+	}
1065
+
1066
+
1067
+
1068
+	/** DEFAULT TICKETS STUFF **/
1069
+	public function _tickets_overview_list_table()
1070
+	{
1071
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1072
+		$this->display_admin_list_table_page_with_no_sidebar();
1073
+	}
1074
+
1075
+
1076
+
1077
+	/**
1078
+	 * @param int  $per_page
1079
+	 * @param bool $count
1080
+	 * @param bool $trashed
1081
+	 * @return \EE_Soft_Delete_Base_Class[]|int
1082
+	 */
1083
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1084
+	{
1085
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1086
+		$order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1087
+		switch ($orderby) {
1088
+			case 'TKT_name' :
1089
+				$orderby = array('TKT_name' => $order);
1090
+				break;
1091
+			case 'TKT_price' :
1092
+				$orderby = array('TKT_price' => $order);
1093
+				break;
1094
+			case 'TKT_uses' :
1095
+				$orderby = array('TKT_uses' => $order);
1096
+				break;
1097
+			case 'TKT_min' :
1098
+				$orderby = array('TKT_min' => $order);
1099
+				break;
1100
+			case 'TKT_max' :
1101
+				$orderby = array('TKT_max' => $order);
1102
+				break;
1103
+			case 'TKT_qty' :
1104
+				$orderby = array('TKT_qty' => $order);
1105
+				break;
1106
+		}
1107
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1108
+			? $this->_req_data['paged']
1109
+			: 1;
1110
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1111
+			? $this->_req_data['perpage']
1112
+			: $per_page;
1113
+		$_where       = array(
1114
+			'TKT_is_default' => 1,
1115
+			'TKT_deleted'    => $trashed,
1116
+		);
1117
+		$offset       = ($current_page - 1) * $per_page;
1118
+		$limit        = array($offset, $per_page);
1119
+		if (isset($this->_req_data['s'])) {
1120
+			$sstr         = '%' . $this->_req_data['s'] . '%';
1121
+			$_where['OR'] = array(
1122
+				'TKT_name'        => array('LIKE', $sstr),
1123
+				'TKT_description' => array('LIKE', $sstr),
1124
+			);
1125
+		}
1126
+		$query_params = array(
1127
+			$_where,
1128
+			'order_by' => $orderby,
1129
+			'limit'    => $limit,
1130
+			'group_by' => 'TKT_ID',
1131
+		);
1132
+		if ($count) {
1133
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1134
+		} else {
1135
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1136
+		}
1137
+	}
1138
+
1139
+
1140
+
1141
+	/**
1142
+	 * @param bool $trash
1143
+	 */
1144
+	protected function _trash_or_restore_ticket($trash = false)
1145
+	{
1146
+		$success = 1;
1147
+		$TKT = EEM_Ticket::instance();
1148
+		//checkboxes?
1149
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1150
+			//if array has more than one element then success message should be plural
1151
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1152
+			//cycle thru the boxes
1153
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1154
+				if ($trash) {
1155
+					if ( ! $TKT->delete_by_ID($TKT_ID)) {
1156
+						$success = 0;
1157
+					}
1158
+				} else {
1159
+					if ( ! $TKT->restore_by_ID($TKT_ID)) {
1160
+						$success = 0;
1161
+					}
1162
+				}
1163
+			}
1164
+		} else {
1165
+			//grab single id and trash
1166
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1167
+			if ($trash) {
1168
+				if ( ! $TKT->delete_by_ID($TKT_ID)) {
1169
+					$success = 0;
1170
+				}
1171
+			} else {
1172
+				if ( ! $TKT->restore_by_ID($TKT_ID)) {
1173
+					$success = 0;
1174
+				}
1175
+			}
1176
+		}
1177
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1178
+		$query_args  = array(
1179
+			'action' => 'ticket_list_table',
1180
+			'status' => $trash ? '' : 'trashed',
1181
+		);
1182
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1183
+	}
1184
+
1185
+
1186
+
1187
+	protected function _delete_ticket()
1188
+	{
1189
+		$success = 1;
1190
+		//checkboxes?
1191
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1192
+			//if array has more than one element then success message should be plural
1193
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1194
+			//cycle thru the boxes
1195
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1196
+				//delete
1197
+				if ( ! $this->_delete_the_ticket($TKT_ID)) {
1198
+					$success = 0;
1199
+				}
1200
+			}
1201
+		} else {
1202
+			//grab single id and trash
1203
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1204
+			if ( ! $this->_delete_the_ticket($TKT_ID)) {
1205
+				$success = 0;
1206
+			}
1207
+		}
1208
+		$action_desc = 'deleted';
1209
+		$query_args  = array(
1210
+			'action' => 'ticket_list_table',
1211
+			'status' => 'trashed',
1212
+		);
1213
+		//fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1214
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1215
+			array(array('TKT_is_default' => 1)),
1216
+			'TKT_ID',
1217
+			true
1218
+		)
1219
+		) {
1220
+			$query_args = array();
1221
+		}
1222
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1223
+	}
1224
+
1225
+
1226
+
1227
+	/**
1228
+	 * @param int $TKT_ID
1229
+	 * @return bool|int
1230
+	 */
1231
+	protected function _delete_the_ticket($TKT_ID)
1232
+	{
1233
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1234
+		$tkt->_remove_relations('Datetime');
1235
+		//delete all related prices first
1236
+		$tkt->delete_related_permanently('Price');
1237
+		return $tkt->delete_permanently();
1238
+	}
1239 1239
 
1240 1240
 
1241 1241
 
Please login to merge, or discard this patch.