@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Event Espresso |
4 | 6 | * |
@@ -513,7 +515,7 @@ discard block |
||
513 | 515 | |
514 | 516 | if($count){ |
515 | 517 | return EEM_Price::instance()->count_deleted_and_undeleted(array($_where)); |
516 | - }else{ |
|
518 | + } else{ |
|
517 | 519 | return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params); |
518 | 520 | } |
519 | 521 | } |
@@ -943,7 +945,7 @@ discard block |
||
943 | 945 | 'limit'=>$limit); |
944 | 946 | if($count){ |
945 | 947 | return EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params); |
946 | - }else{ |
|
948 | + } else{ |
|
947 | 949 | return EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params); |
948 | 950 | } |
949 | 951 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public static function instance() { |
37 | 37 | // check if class object is instantiated, and instantiated properly |
38 | - if ( ! self::$_instance instanceof EE_Payment_Method_Manager ) { |
|
38 | + if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
39 | 39 | self::$_instance = new self(); |
40 | 40 | } |
41 | 41 | EE_Registry::instance()->load_lib('PMT_Base'); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * Resets the instance and returns a new one |
47 | 47 | * @return EE_Payment_Method_Manager |
48 | 48 | */ |
49 | - public static function reset(){ |
|
49 | + public static function reset() { |
|
50 | 50 | self::$_instance = NULL; |
51 | 51 | return self::instance(); |
52 | 52 | } |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | * or just re-use the PMTs we found last time we checked during this request (if |
58 | 58 | * we have not yet checked during this request, then we need to check anyways) |
59 | 59 | */ |
60 | - public function maybe_register_payment_methods( $force_recheck = FALSE ){ |
|
61 | - if( ! $this->_payment_method_types || $force_recheck ){ |
|
60 | + public function maybe_register_payment_methods($force_recheck = FALSE) { |
|
61 | + if ( ! $this->_payment_method_types || $force_recheck) { |
|
62 | 62 | $this->_register_payment_methods(); |
63 | 63 | //if in admin lets ensure caps are set. |
64 | - if ( is_admin() ) { |
|
65 | - add_filter( 'FHEE__EE_Capabilities__init_caps_map__caps', array( $this, 'add_payment_method_caps' ) ); |
|
64 | + if (is_admin()) { |
|
65 | + add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps')); |
|
66 | 66 | EE_Registry::instance()->CAP->init_caps(); |
67 | 67 | } |
68 | 68 | } |
@@ -75,19 +75,19 @@ discard block |
||
75 | 75 | */ |
76 | 76 | protected function _register_payment_methods() { |
77 | 77 | // grab list of installed modules |
78 | - $pm_to_register = glob( EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR ); |
|
78 | + $pm_to_register = glob(EE_PAYMENT_METHODS.'*', GLOB_ONLYDIR); |
|
79 | 79 | // filter list of modules to register |
80 | - $pm_to_register = apply_filters( 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', $pm_to_register ); |
|
80 | + $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', $pm_to_register); |
|
81 | 81 | |
82 | 82 | // loop through folders |
83 | - foreach ( $pm_to_register as $pm_path ) { |
|
84 | - $this->register_payment_method( $pm_path ); |
|
83 | + foreach ($pm_to_register as $pm_path) { |
|
84 | + $this->register_payment_method($pm_path); |
|
85 | 85 | } |
86 | - do_action( 'FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods' ); |
|
86 | + do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
87 | 87 | // filter list of installed modules |
88 | 88 | //keep them organized alphabetically by the payment method type's name |
89 | - ksort( $this->_payment_method_types ); |
|
90 | - return apply_filters( 'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', $this->_payment_method_types ); |
|
89 | + ksort($this->_payment_method_types); |
|
90 | + return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', $this->_payment_method_types); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | |
@@ -99,35 +99,35 @@ discard block |
||
99 | 99 | * @param string $payment_method_path - full path up to and including payment method folder |
100 | 100 | * @return boolean |
101 | 101 | */ |
102 | - public function register_payment_method( $payment_method_path = '' ) { |
|
103 | - do_action( 'AHEE__EE_Payment_Method_Manager__register_payment_method__begin',$payment_method_path ); |
|
102 | + public function register_payment_method($payment_method_path = '') { |
|
103 | + do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
104 | 104 | $module_ext = '.pm.php'; |
105 | 105 | // make all separators match |
106 | - $payment_method_path = rtrim( str_replace( '/\\', DS, $payment_method_path ), DS ); |
|
106 | + $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
107 | 107 | // grab and sanitize module name |
108 | - $module_dir = basename( $payment_method_path ); |
|
108 | + $module_dir = basename($payment_method_path); |
|
109 | 109 | // create classname from module directory name |
110 | - $module = str_replace( ' ', '_', str_replace( '_', ' ', $module_dir )); |
|
110 | + $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
|
111 | 111 | // add class prefix |
112 | - $module_class = 'EE_PMT_' . $module; |
|
112 | + $module_class = 'EE_PMT_'.$module; |
|
113 | 113 | // does the module exist ? |
114 | - if ( ! is_readable( $payment_method_path . DS . $module_class . $module_ext )) { |
|
115 | - $msg = sprintf( __( 'The requested %s payment method file could not be found or is not readable due to file permissions.', 'event_espresso' ), $module ); |
|
116 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
114 | + if ( ! is_readable($payment_method_path.DS.$module_class.$module_ext)) { |
|
115 | + $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', 'event_espresso'), $module); |
|
116 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
117 | 117 | return FALSE; |
118 | 118 | } |
119 | - if ( WP_DEBUG === TRUE ) { EEH_Debug_Tools::instance()->start_timer(); } |
|
119 | + if (WP_DEBUG === TRUE) { EEH_Debug_Tools::instance()->start_timer(); } |
|
120 | 120 | // load the module class file |
121 | - require_once( $payment_method_path . DS . $module_class . $module_ext ); |
|
122 | - if ( WP_DEBUG === TRUE ) { EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); } |
|
121 | + require_once($payment_method_path.DS.$module_class.$module_ext); |
|
122 | + if (WP_DEBUG === TRUE) { EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); } |
|
123 | 123 | // verify that class exists |
124 | - if ( ! class_exists( $module_class )) { |
|
125 | - $msg = sprintf( __( 'The requested %s module class does not exist.', 'event_espresso' ), $module_class ); |
|
126 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
124 | + if ( ! class_exists($module_class)) { |
|
125 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
126 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
127 | 127 | return FALSE; |
128 | 128 | } |
129 | 129 | // add to array of registered modules |
130 | - $this->_payment_method_types[ $module ] = $payment_method_path . DS . $module_class . $module_ext; |
|
130 | + $this->_payment_method_types[$module] = $payment_method_path.DS.$module_class.$module_ext; |
|
131 | 131 | return TRUE; |
132 | 132 | } |
133 | 133 | /** |
@@ -136,15 +136,15 @@ discard block |
||
136 | 136 | * @param boolean $force_recheck whether to force re-checking for new payment method types |
137 | 137 | * @return boolean |
138 | 138 | */ |
139 | - public function payment_method_type_exists($payment_method_name, $force_recheck = FALSE){ |
|
140 | - if ( ! is_array( $this->_payment_method_types ) || ! isset( $this->_payment_method_types[$payment_method_name] ) |
|
141 | - || $force_recheck ) { |
|
139 | + public function payment_method_type_exists($payment_method_name, $force_recheck = FALSE) { |
|
140 | + if ( ! is_array($this->_payment_method_types) || ! isset($this->_payment_method_types[$payment_method_name]) |
|
141 | + || $force_recheck) { |
|
142 | 142 | $this->maybe_register_payment_methods($force_recheck); |
143 | 143 | } |
144 | - if(isset($this->_payment_method_types[$payment_method_name])){ |
|
144 | + if (isset($this->_payment_method_types[$payment_method_name])) { |
|
145 | 145 | require_once($this->_payment_method_types[$payment_method_name]); |
146 | 146 | return true; |
147 | - }else{ |
|
147 | + } else { |
|
148 | 148 | return false; |
149 | 149 | } |
150 | 150 | } |
@@ -155,16 +155,16 @@ discard block |
||
155 | 155 | * @param boolean $force_recheck whether to force re-checking for new payment method types |
156 | 156 | * @return array |
157 | 157 | */ |
158 | - public function payment_method_type_names($with_prefixes = FALSE, $force_recheck = FALSE ){ |
|
158 | + public function payment_method_type_names($with_prefixes = FALSE, $force_recheck = FALSE) { |
|
159 | 159 | $this->maybe_register_payment_methods($force_recheck); |
160 | - if($with_prefixes){ |
|
160 | + if ($with_prefixes) { |
|
161 | 161 | $classnames = array_keys($this->_payment_method_types); |
162 | 162 | $payment_methods = array(); |
163 | - foreach($classnames as $classname){ |
|
163 | + foreach ($classnames as $classname) { |
|
164 | 164 | $payment_methods[] = $this->payment_method_class_from_type($classname); |
165 | 165 | } |
166 | 166 | return $payment_methods; |
167 | - }else{ |
|
167 | + } else { |
|
168 | 168 | return array_keys($this->_payment_method_types); |
169 | 169 | } |
170 | 170 | } |
@@ -174,10 +174,10 @@ discard block |
||
174 | 174 | * @param boolean $force_recheck whether to force re-checking for new payment method types |
175 | 175 | * @return EE_PMT_Base[] |
176 | 176 | */ |
177 | - public function payment_method_types( $force_recheck = FALSE ){ |
|
177 | + public function payment_method_types($force_recheck = FALSE) { |
|
178 | 178 | $this->maybe_register_payment_methods($force_recheck); |
179 | 179 | $pmt_objs = array(); |
180 | - foreach($this->payment_method_type_names(true) as $classname){ |
|
180 | + foreach ($this->payment_method_type_names(true) as $classname) { |
|
181 | 181 | $pmt_objs[] = new $classname; |
182 | 182 | } |
183 | 183 | return $pmt_objs; |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | * @param string $classname |
190 | 190 | * @return string |
191 | 191 | */ |
192 | - public function payment_method_type_sans_class_prefix($classname){ |
|
193 | - $pmt_name = str_replace("EE_PMT_","",$classname); |
|
192 | + public function payment_method_type_sans_class_prefix($classname) { |
|
193 | + $pmt_name = str_replace("EE_PMT_", "", $classname); |
|
194 | 194 | return $pmt_name; |
195 | 195 | } |
196 | 196 | |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * @param string $type |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public function payment_method_class_from_type($type){ |
|
202 | + public function payment_method_class_from_type($type) { |
|
203 | 203 | $this->maybe_register_payment_methods(); |
204 | 204 | return "EE_PMT_".$type; |
205 | 205 | } |
@@ -213,38 +213,38 @@ discard block |
||
213 | 213 | * @return \EE_Payment_Method |
214 | 214 | * @throws \EE_Error |
215 | 215 | */ |
216 | - public function activate_a_payment_method_of_type( $payment_method_type ){ |
|
216 | + public function activate_a_payment_method_of_type($payment_method_type) { |
|
217 | 217 | $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
218 | - if( ! $payment_method instanceof EE_Payment_Method ){ |
|
218 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
219 | 219 | $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
220 | - if(class_exists($pm_type_class)){ |
|
220 | + if (class_exists($pm_type_class)) { |
|
221 | 221 | /** @var $pm_type_obj EE_PMT_Base */ |
222 | 222 | $pm_type_obj = new $pm_type_class; |
223 | 223 | $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
224 | - if( ! $payment_method){ |
|
225 | - $payment_method = $this->create_payment_method_of_type( $pm_type_obj ); |
|
224 | + if ( ! $payment_method) { |
|
225 | + $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
226 | 226 | } |
227 | - $payment_method->set_type( $payment_method_type ); |
|
228 | - $this->initialize_payment_method( $payment_method ); |
|
227 | + $payment_method->set_type($payment_method_type); |
|
228 | + $this->initialize_payment_method($payment_method); |
|
229 | 229 | } else { |
230 | 230 | throw new EE_Error( |
231 | 231 | sprintf( |
232 | - __( 'There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
232 | + __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
233 | 233 | $pm_type_class ) |
234 | 234 | ); |
235 | 235 | } |
236 | 236 | } |
237 | 237 | $payment_method->set_active(); |
238 | 238 | $payment_method->save(); |
239 | - $this->set_usable_currencies_on_payment_method( $payment_method ); |
|
240 | - if( $payment_method->type() == 'Invoice' ){ |
|
241 | - $messages = EE_Registry::instance()->load_lib( 'messages' ); |
|
242 | - $messages->ensure_message_type_is_active( 'invoice', 'html' ); |
|
243 | - $messages->ensure_messenger_is_active( 'pdf' ); |
|
239 | + $this->set_usable_currencies_on_payment_method($payment_method); |
|
240 | + if ($payment_method->type() == 'Invoice') { |
|
241 | + $messages = EE_Registry::instance()->load_lib('messages'); |
|
242 | + $messages->ensure_message_type_is_active('invoice', 'html'); |
|
243 | + $messages->ensure_messenger_is_active('pdf'); |
|
244 | 244 | EE_Error::add_attention( |
245 | 245 | sprintf( |
246 | - __( 'Note, when the invoice payment method is activated, the invoice message type, html messenger, and pdf messenger are activated as well for the %1$smessages system%2$s.', 'event_espresso' ), |
|
247 | - '<a href="' . admin_url( 'admin.php?page=espresso_messages') . '">', |
|
246 | + __('Note, when the invoice payment method is activated, the invoice message type, html messenger, and pdf messenger are activated as well for the %1$smessages system%2$s.', 'event_espresso'), |
|
247 | + '<a href="'.admin_url('admin.php?page=espresso_messages').'">', |
|
248 | 248 | '</a>' |
249 | 249 | ) |
250 | 250 | ); |
@@ -258,17 +258,17 @@ discard block |
||
258 | 258 | * @param EE_PMT_Base $pm_type_obj |
259 | 259 | * @return EE_Payment_Method |
260 | 260 | */ |
261 | - public function create_payment_method_of_type( $pm_type_obj ) { |
|
261 | + public function create_payment_method_of_type($pm_type_obj) { |
|
262 | 262 | global $current_user; |
263 | 263 | $payment_method = EE_Payment_Method::new_instance( |
264 | 264 | array( |
265 | 265 | 'PMD_type' => $pm_type_obj->system_name(), |
266 | 266 | 'PMD_name' => $pm_type_obj->pretty_name(), |
267 | 267 | 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
268 | - 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
268 | + 'PMD_slug' => $pm_type_obj->system_name(), //automatically converted to slug |
|
269 | 269 | 'PMD_wp_user' => $current_user->ID, |
270 | 270 | 'PMD_order' => EEM_Payment_Method::instance()->count( |
271 | - array( array( 'PMD_type' => array( '!=', 'Admin_Only' ))) |
|
271 | + array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
272 | 272 | ) * 10, |
273 | 273 | ) |
274 | 274 | ); |
@@ -280,16 +280,16 @@ discard block |
||
280 | 280 | * @param EE_Payment_Method $payment_method |
281 | 281 | * @return EE_Payment_Method |
282 | 282 | */ |
283 | - public function initialize_payment_method( $payment_method ) { |
|
283 | + public function initialize_payment_method($payment_method) { |
|
284 | 284 | $pm_type_obj = $payment_method->type_obj(); |
285 | - $payment_method->set_description( $pm_type_obj->default_description() ); |
|
286 | - if( ! $payment_method->button_url() ){ |
|
287 | - $payment_method->set_button_url( $pm_type_obj->default_button_url() ); |
|
285 | + $payment_method->set_description($pm_type_obj->default_description()); |
|
286 | + if ( ! $payment_method->button_url()) { |
|
287 | + $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
288 | 288 | } |
289 | 289 | //now add setup its default extra meta properties |
290 | 290 | $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
291 | - foreach( $extra_metas as $meta_name => $input ){ |
|
292 | - $payment_method->update_extra_meta($meta_name, $input->raw_value() ); |
|
291 | + foreach ($extra_metas as $meta_name => $input) { |
|
292 | + $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
293 | 293 | } |
294 | 294 | return $payment_method; |
295 | 295 | } |
@@ -299,8 +299,8 @@ discard block |
||
299 | 299 | * @param EE_Payment_Method $payment_method |
300 | 300 | * @return EE_Payment_Method |
301 | 301 | */ |
302 | - public function set_usable_currencies_on_payment_method( $payment_method ) { |
|
303 | - foreach($payment_method->get_all_usable_currencies() as $currency_obj){ |
|
302 | + public function set_usable_currencies_on_payment_method($payment_method) { |
|
303 | + foreach ($payment_method->get_all_usable_currencies() as $currency_obj) { |
|
304 | 304 | $payment_method->_add_relation_to($currency_obj, 'Currency'); |
305 | 305 | } |
306 | 306 | return $payment_method; |
@@ -318,8 +318,8 @@ discard block |
||
318 | 318 | * |
319 | 319 | * @return int count of rows updated. |
320 | 320 | */ |
321 | - public function deactivate_payment_method( $payment_method_slug ) { |
|
322 | - $count_updated = EEM_Payment_Method::instance()->update(array('PMD_scope'=>array()),array(array('PMD_slug'=>$payment_method_slug))); |
|
321 | + public function deactivate_payment_method($payment_method_slug) { |
|
322 | + $count_updated = EEM_Payment_Method::instance()->update(array('PMD_scope'=>array()), array(array('PMD_slug'=>$payment_method_slug))); |
|
323 | 323 | return $count_updated; |
324 | 324 | } |
325 | 325 | |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | * @param array $caps capabilities being filtered |
333 | 333 | * @return array |
334 | 334 | */ |
335 | - public function add_payment_method_caps( $caps ) { |
|
335 | + public function add_payment_method_caps($caps) { |
|
336 | 336 | /* add dynamic caps from payment methods |
337 | 337 | * at the time of writing, october 20 2014, these are the caps added: |
338 | 338 | * ee_payment_method_admin_only |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | * their related capability automatically added too, so long as they are |
348 | 348 | * registered properly using EE_Register_Payment_Method::register() |
349 | 349 | */ |
350 | - foreach( $this->payment_method_types() as $payment_method_type_obj ){ |
|
350 | + foreach ($this->payment_method_types() as $payment_method_type_obj) { |
|
351 | 351 | $caps['administrator'][] = $payment_method_type_obj->cap_name(); |
352 | 352 | } |
353 | 353 | return $caps; |
@@ -5,42 +5,42 @@ |
||
5 | 5 | <table class="admin-primary-mbox-tbl"> |
6 | 6 | <thead> |
7 | 7 | <tr> |
8 | - <th class="jst-left"><?php esc_html_e( 'Event Name', 'event_espresso' );?></th> |
|
9 | - <th class="jst-left"><?php esc_html_e( 'REG ID', 'event_espresso' );?></th> |
|
10 | - <th class="jst-left"><?php esc_html_e( 'TXN ID', 'event_espresso' );?></th> |
|
11 | - <th class="jst-left"><?php esc_html_e( 'Reg Code', 'event_espresso' );?></th> |
|
12 | - <th class="jst-rght"><?php esc_html_e( 'Ticket Price', 'event_espresso' );?></th> |
|
8 | + <th class="jst-left"><?php esc_html_e('Event Name', 'event_espresso'); ?></th> |
|
9 | + <th class="jst-left"><?php esc_html_e('REG ID', 'event_espresso'); ?></th> |
|
10 | + <th class="jst-left"><?php esc_html_e('TXN ID', 'event_espresso'); ?></th> |
|
11 | + <th class="jst-left"><?php esc_html_e('Reg Code', 'event_espresso'); ?></th> |
|
12 | + <th class="jst-rght"><?php esc_html_e('Ticket Price', 'event_espresso'); ?></th> |
|
13 | 13 | </tr> |
14 | 14 | </thead> |
15 | 15 | <tbody> |
16 | - <?php foreach( $registrations as $registration ) : ?> |
|
16 | + <?php foreach ($registrations as $registration) : ?> |
|
17 | 17 | <tr> |
18 | 18 | <td class="jst-left"> |
19 | 19 | <?php |
20 | - $event_url = add_query_arg( array( 'action' => 'edit', 'post' => $registration->event_ID() ), admin_url( 'admin.php?page=espresso_events' )); |
|
21 | - echo EE_Registry::instance()->CAP->current_user_can( 'ee_edit_event', 'espresso_events_edit', $registration->event_ID() ) ? '<a href="'. $event_url .'" title="'. esc_attr__( 'Edit Event', 'event_espresso' ) .'">' . $registration->event_name() . '</a>' : $registration->event_name(); |
|
20 | + $event_url = add_query_arg(array('action' => 'edit', 'post' => $registration->event_ID()), admin_url('admin.php?page=espresso_events')); |
|
21 | + echo EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $registration->event_ID()) ? '<a href="'.$event_url.'" title="'.esc_attr__('Edit Event', 'event_espresso').'">'.$registration->event_name().'</a>' : $registration->event_name(); |
|
22 | 22 | ?> |
23 | 23 | </td> |
24 | 24 | <td class="jst-left"> |
25 | 25 | <?php |
26 | - $reg_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action'=>'view_registration', '_REG_ID'=>$registration->ID() ), REG_ADMIN_URL ); |
|
27 | - echo EE_Registry::instance()->CAP->current_user_can( 'ee_read_registration', 'espresso_registrations_view_registration', $registration->ID() ) ? ' |
|
28 | - <a href="'.$reg_url.'" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">' . |
|
29 | - esc_html__( 'View Registration', 'event_espresso' ) . |
|
26 | + $reg_url = EE_Admin_Page::add_query_args_and_nonce(array('action'=>'view_registration', '_REG_ID'=>$registration->ID()), REG_ADMIN_URL); |
|
27 | + echo EE_Registry::instance()->CAP->current_user_can('ee_read_registration', 'espresso_registrations_view_registration', $registration->ID()) ? ' |
|
28 | + <a href="'.$reg_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">'. |
|
29 | + esc_html__('View Registration', 'event_espresso'). |
|
30 | 30 | '</a>' : $registration->ID(); |
31 | 31 | ?> |
32 | 32 | </td> |
33 | 33 | <td class="jst-left"> |
34 | 34 | <?php |
35 | - $txn_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action'=>'view_transaction', 'TXN_ID'=>$registration->transaction_ID() ), TXN_ADMIN_URL ); |
|
36 | - echo EE_Registry::instance()->CAP->current_user_can( 'ee_read_transaction', 'espresso_transactions_view_transaction' ) ? ' |
|
37 | - <a href="'.$txn_url.'" title="' . esc_attr__( 'View Transaction Details', 'event_espresso' ) . '">' . |
|
38 | - sprintf( esc_html__('View Transaction %d', 'event_espresso'), $registration->transaction_ID() ) . |
|
35 | + $txn_url = EE_Admin_Page::add_query_args_and_nonce(array('action'=>'view_transaction', 'TXN_ID'=>$registration->transaction_ID()), TXN_ADMIN_URL); |
|
36 | + echo EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction') ? ' |
|
37 | + <a href="'.$txn_url.'" title="'.esc_attr__('View Transaction Details', 'event_espresso').'">'. |
|
38 | + sprintf(esc_html__('View Transaction %d', 'event_espresso'), $registration->transaction_ID()). |
|
39 | 39 | '</a>' : $registration->transaction_ID(); |
40 | 40 | ?> |
41 | 41 | </td> |
42 | - <td class="jst-left"><?php echo $registration->reg_code();?></td> |
|
43 | - <td class="jst-rght"><?php echo EEH_Template::format_currency( $registration->final_price() );?></td> |
|
42 | + <td class="jst-left"><?php echo $registration->reg_code(); ?></td> |
|
43 | + <td class="jst-rght"><?php echo EEH_Template::format_currency($registration->final_price()); ?></td> |
|
44 | 44 | </tr> |
45 | 45 | <?php endforeach; ?> |
46 | 46 | </tbody> |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | * @param $table_name |
58 | 58 | * @return string |
59 | 59 | */ |
60 | - public static function ensure_table_name_has_prefix( $table_name ) { |
|
60 | + public static function ensure_table_name_has_prefix($table_name) { |
|
61 | 61 | global $wpdb; |
62 | - return strpos( $table_name, $wpdb->prefix ) === 0 ? $table_name : $wpdb->prefix . $table_name; |
|
62 | + return strpos($table_name, $wpdb->prefix) === 0 ? $table_name : $wpdb->prefix.$table_name; |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * be called on plugin activation and reactivation |
86 | 86 | * @return boolean success, whether the database and folders are setup properly |
87 | 87 | */ |
88 | - public static function initialize_db_and_folders(){ |
|
88 | + public static function initialize_db_and_folders() { |
|
89 | 89 | $good_filesystem = EEH_Activation::create_upload_directories(); |
90 | 90 | $good_db = EEH_Activation::create_database_tables(); |
91 | 91 | return $good_filesystem && $good_db; |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | * upon activation of a new plugin, reactivation, and at the end |
100 | 100 | * of running migration scripts |
101 | 101 | */ |
102 | - public static function initialize_db_content(){ |
|
102 | + public static function initialize_db_content() { |
|
103 | 103 | //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
104 | - if( EEH_Activation::$_initialized_db_content_already_in_this_request ) { |
|
104 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
105 | 105 | return; |
106 | 106 | } |
107 | 107 | EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | EEH_Activation::remove_cron_tasks(); |
119 | 119 | EEH_Activation::create_cron_tasks(); |
120 | 120 | //also, check for CAF default db content |
121 | - do_action( 'AHEE__EEH_Activation__initialize_db_content' ); |
|
121 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
122 | 122 | //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
123 | 123 | //which users really won't care about on initial activation |
124 | 124 | EE_Error::overwrite_success(); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @return array |
138 | 138 | * @throws \EE_Error |
139 | 139 | */ |
140 | - public static function get_cron_tasks( $which_to_include ) { |
|
140 | + public static function get_cron_tasks($which_to_include) { |
|
141 | 141 | $cron_tasks = apply_filters( |
142 | 142 | 'FHEE__EEH_Activation__get_cron_tasks', |
143 | 143 | array( |
@@ -146,17 +146,17 @@ discard block |
||
146 | 146 | 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, //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 |
147 | 147 | ) |
148 | 148 | ); |
149 | - if( $which_to_include === 'all' ) { |
|
149 | + if ($which_to_include === 'all') { |
|
150 | 150 | //leave as-is |
151 | - }elseif( $which_to_include === 'old' ) { |
|
152 | - $cron_tasks = array_filter( $cron_tasks, function ( $value ) { |
|
151 | + }elseif ($which_to_include === 'old') { |
|
152 | + $cron_tasks = array_filter($cron_tasks, function($value) { |
|
153 | 153 | return $value === EEH_Activation::cron_task_no_longer_in_use; |
154 | 154 | }); |
155 | - }elseif( $which_to_include === 'current' ) { |
|
156 | - $cron_tasks = array_filter( $cron_tasks ); |
|
157 | - }elseif( WP_DEBUG ) { |
|
158 | - throw new EE_Error( sprintf( __( 'Invalidate argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', 'event_espresso' ), $which_to_include ) ); |
|
159 | - }else{ |
|
155 | + }elseif ($which_to_include === 'current') { |
|
156 | + $cron_tasks = array_filter($cron_tasks); |
|
157 | + }elseif (WP_DEBUG) { |
|
158 | + throw new EE_Error(sprintf(__('Invalidate argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', 'event_espresso'), $which_to_include)); |
|
159 | + } else { |
|
160 | 160 | //leave as-is |
161 | 161 | } |
162 | 162 | return $cron_tasks; |
@@ -167,9 +167,9 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public static function create_cron_tasks() { |
169 | 169 | |
170 | - foreach( EEH_Activation::get_cron_tasks( 'current' ) as $hook_name => $frequency ) { |
|
171 | - if( ! wp_next_scheduled( $hook_name ) ) { |
|
172 | - wp_schedule_event( time(), $frequency, $hook_name ); |
|
170 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
171 | + if ( ! wp_next_scheduled($hook_name)) { |
|
172 | + wp_schedule_event(time(), $frequency, $hook_name); |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
@@ -179,10 +179,10 @@ discard block |
||
179 | 179 | * Remove the currently-existing and now-removed cron tasks. |
180 | 180 | * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
181 | 181 | */ |
182 | - public static function remove_cron_tasks( $remove_all = true ) { |
|
182 | + public static function remove_cron_tasks($remove_all = true) { |
|
183 | 183 | $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
184 | 184 | $crons = _get_cron_array(); |
185 | - $crons = is_array( $crons ) ? $crons : array(); |
|
185 | + $crons = is_array($crons) ? $crons : array(); |
|
186 | 186 | /* reminder that $crons looks like: top-level keys are timestamps, |
187 | 187 | * and their values are arrays. |
188 | 188 | * The 2nd level arrays have keys with each of the cron task hooknames to run at that time |
@@ -200,14 +200,14 @@ discard block |
||
200 | 200 | * ... |
201 | 201 | * ... |
202 | 202 | */ |
203 | - foreach( EEH_Activation::get_cron_tasks( $cron_tasks_to_remove ) as $hook_name => $frequency ) { |
|
204 | - foreach( $crons as $timestamp => $hooks_to_fire_at_time ) { |
|
205 | - if ( array_key_exists( $hook_name, $hooks_to_fire_at_time ) ) { |
|
206 | - unset( $crons[ $timestamp ][ $hook_name ] ); |
|
203 | + foreach (EEH_Activation::get_cron_tasks($cron_tasks_to_remove) as $hook_name => $frequency) { |
|
204 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
205 | + if (array_key_exists($hook_name, $hooks_to_fire_at_time)) { |
|
206 | + unset($crons[$timestamp][$hook_name]); |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 | } |
210 | - _set_cron_array( $crons ); |
|
210 | + _set_cron_array($crons); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | */ |
223 | 223 | public static function CPT_initialization() { |
224 | 224 | // register Custom Post Types |
225 | - EE_Registry::instance()->load_core( 'Register_CPTs' ); |
|
225 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
226 | 226 | flush_rewrite_rules(); |
227 | 227 | } |
228 | 228 | |
@@ -240,8 +240,8 @@ discard block |
||
240 | 240 | * @return void |
241 | 241 | */ |
242 | 242 | public static function reset_and_update_config() { |
243 | - do_action( 'AHEE__EE_Config___load_core_config__start', array( 'EEH_Activation', 'load_calendar_config' ) ); |
|
244 | - add_filter( 'FHEE__EE_Config___load_core_config__config_settings', array( 'EEH_Activation', 'migrate_old_config_data' ), 10, 3 ); |
|
243 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
244 | + add_filter('FHEE__EE_Config___load_core_config__config_settings', array('EEH_Activation', 'migrate_old_config_data'), 10, 3); |
|
245 | 245 | //EE_Config::reset(); |
246 | 246 | } |
247 | 247 | |
@@ -254,23 +254,23 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public static function load_calendar_config() { |
256 | 256 | // grab array of all plugin folders and loop thru it |
257 | - $plugins = glob( WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR ); |
|
258 | - if ( empty( $plugins ) ) { |
|
257 | + $plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR); |
|
258 | + if (empty($plugins)) { |
|
259 | 259 | return; |
260 | 260 | } |
261 | - foreach ( $plugins as $plugin_path ) { |
|
261 | + foreach ($plugins as $plugin_path) { |
|
262 | 262 | // grab plugin folder name from path |
263 | - $plugin = basename( $plugin_path ); |
|
263 | + $plugin = basename($plugin_path); |
|
264 | 264 | // drill down to Espresso plugins |
265 | - if ( strpos( $plugin, 'espresso' ) !== FALSE || strpos( $plugin, 'Espresso' ) !== FALSE || strpos( $plugin, 'ee4' ) !== FALSE || strpos( $plugin, 'EE4' ) !== FALSE ) { |
|
265 | + if (strpos($plugin, 'espresso') !== FALSE || strpos($plugin, 'Espresso') !== FALSE || strpos($plugin, 'ee4') !== FALSE || strpos($plugin, 'EE4') !== FALSE) { |
|
266 | 266 | // then to calendar related plugins |
267 | - if ( strpos( $plugin, 'calendar' ) !== FALSE ) { |
|
267 | + if (strpos($plugin, 'calendar') !== FALSE) { |
|
268 | 268 | // this is what we are looking for |
269 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
269 | + $calendar_config = $plugin_path.DS.'EE_Calendar_Config.php'; |
|
270 | 270 | // does it exist in this folder ? |
271 | - if ( is_readable( $calendar_config )) { |
|
271 | + if (is_readable($calendar_config)) { |
|
272 | 272 | // YEAH! let's load it |
273 | - require_once( $calendar_config ); |
|
273 | + require_once($calendar_config); |
|
274 | 274 | } |
275 | 275 | } |
276 | 276 | } |
@@ -287,21 +287,21 @@ discard block |
||
287 | 287 | * @param \EE_Config $EE_Config |
288 | 288 | * @return \stdClass |
289 | 289 | */ |
290 | - public static function migrate_old_config_data( $settings = array(), $config = '', EE_Config $EE_Config ) { |
|
291 | - $convert_from_array = array( 'addons' ); |
|
290 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) { |
|
291 | + $convert_from_array = array('addons'); |
|
292 | 292 | // in case old settings were saved as an array |
293 | - if ( is_array( $settings ) && in_array( $config, $convert_from_array )) { |
|
293 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
294 | 294 | // convert existing settings to an object |
295 | 295 | $config_array = $settings; |
296 | 296 | $settings = new stdClass(); |
297 | - foreach ( $config_array as $key => $value ){ |
|
298 | - if ( $key == 'calendar' && class_exists( 'EE_Calendar_Config' )) { |
|
299 | - $EE_Config->set_config( 'addons', 'EE_Calendar', 'EE_Calendar_Config', $value ); |
|
297 | + foreach ($config_array as $key => $value) { |
|
298 | + if ($key == 'calendar' && class_exists('EE_Calendar_Config')) { |
|
299 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
300 | 300 | } else { |
301 | 301 | $settings->$key = $value; |
302 | 302 | } |
303 | 303 | } |
304 | - add_filter( 'FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true' ); |
|
304 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
305 | 305 | } |
306 | 306 | return $settings; |
307 | 307 | } |
@@ -317,8 +317,8 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public static function deactivate_event_espresso() { |
319 | 319 | // check permissions |
320 | - if ( current_user_can( 'activate_plugins' )) { |
|
321 | - deactivate_plugins( EE_PLUGIN_BASENAME, TRUE ); |
|
320 | + if (current_user_can('activate_plugins')) { |
|
321 | + deactivate_plugins(EE_PLUGIN_BASENAME, TRUE); |
|
322 | 322 | } |
323 | 323 | } |
324 | 324 | |
@@ -340,79 +340,79 @@ discard block |
||
340 | 340 | $critical_pages = array( |
341 | 341 | array( |
342 | 342 | 'id' =>'reg_page_id', |
343 | - 'name' => __( 'Registration Checkout', 'event_espresso' ), |
|
343 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
344 | 344 | 'post' => NULL, |
345 | 345 | 'code' => 'ESPRESSO_CHECKOUT' |
346 | 346 | ), |
347 | 347 | array( |
348 | 348 | 'id' => 'txn_page_id', |
349 | - 'name' => __( 'Transactions', 'event_espresso' ), |
|
349 | + 'name' => __('Transactions', 'event_espresso'), |
|
350 | 350 | 'post' => NULL, |
351 | 351 | 'code' => 'ESPRESSO_TXN_PAGE' |
352 | 352 | ), |
353 | 353 | array( |
354 | 354 | 'id' => 'thank_you_page_id', |
355 | - 'name' => __( 'Thank You', 'event_espresso' ), |
|
355 | + 'name' => __('Thank You', 'event_espresso'), |
|
356 | 356 | 'post' => NULL, |
357 | 357 | 'code' => 'ESPRESSO_THANK_YOU' |
358 | 358 | ), |
359 | 359 | array( |
360 | 360 | 'id' => 'cancel_page_id', |
361 | - 'name' => __( 'Registration Cancelled', 'event_espresso' ), |
|
361 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
362 | 362 | 'post' => NULL, |
363 | 363 | 'code' => 'ESPRESSO_CANCELLED' |
364 | 364 | ), |
365 | 365 | ); |
366 | 366 | |
367 | - foreach ( $critical_pages as $critical_page ) { |
|
367 | + foreach ($critical_pages as $critical_page) { |
|
368 | 368 | // is critical page ID set in config ? |
369 | - if ( EE_Registry::instance()->CFG->core->$critical_page['id'] !== FALSE ) { |
|
369 | + if (EE_Registry::instance()->CFG->core->$critical_page['id'] !== FALSE) { |
|
370 | 370 | // attempt to find post by ID |
371 | - $critical_page['post'] = get_post( EE_Registry::instance()->CFG->core->$critical_page['id'] ); |
|
371 | + $critical_page['post'] = get_post(EE_Registry::instance()->CFG->core->$critical_page['id']); |
|
372 | 372 | } |
373 | 373 | // no dice? |
374 | - if ( $critical_page['post'] == NULL ) { |
|
374 | + if ($critical_page['post'] == NULL) { |
|
375 | 375 | // attempt to find post by title |
376 | - $critical_page['post'] = self::get_page_by_ee_shortcode( $critical_page['code'] ); |
|
376 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
377 | 377 | // still nothing? |
378 | - if ( $critical_page['post'] == NULL ) { |
|
379 | - $critical_page = EEH_Activation::create_critical_page( $critical_page ); |
|
378 | + if ($critical_page['post'] == NULL) { |
|
379 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
380 | 380 | // REALLY? Still nothing ??!?!? |
381 | - if ( $critical_page['post'] == NULL ) { |
|
382 | - $msg = __( 'The Event Espresso critical page configuration settings could not be updated.', 'event_espresso' ); |
|
383 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
381 | + if ($critical_page['post'] == NULL) { |
|
382 | + $msg = __('The Event Espresso critical page configuration settings could not be updated.', 'event_espresso'); |
|
383 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
384 | 384 | break; |
385 | 385 | } |
386 | 386 | } |
387 | 387 | } |
388 | 388 | // track post_shortcodes |
389 | - if ( $critical_page['post'] ) { |
|
390 | - EEH_Activation::_track_critical_page_post_shortcodes( $critical_page ); |
|
389 | + if ($critical_page['post']) { |
|
390 | + EEH_Activation::_track_critical_page_post_shortcodes($critical_page); |
|
391 | 391 | } |
392 | 392 | // check that Post ID matches critical page ID in config |
393 | - if ( isset( $critical_page['post']->ID ) && $critical_page['post']->ID != EE_Registry::instance()->CFG->core->$critical_page['id'] ) { |
|
393 | + if (isset($critical_page['post']->ID) && $critical_page['post']->ID != EE_Registry::instance()->CFG->core->$critical_page['id']) { |
|
394 | 394 | //update Config with post ID |
395 | 395 | EE_Registry::instance()->CFG->core->$critical_page['id'] = $critical_page['post']->ID; |
396 | - if ( ! EE_Config::instance()->update_espresso_config( FALSE, FALSE ) ) { |
|
397 | - $msg = __( 'The Event Espresso critical page configuration settings could not be updated.', 'event_espresso' ); |
|
398 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
396 | + if ( ! EE_Config::instance()->update_espresso_config(FALSE, FALSE)) { |
|
397 | + $msg = __('The Event Espresso critical page configuration settings could not be updated.', 'event_espresso'); |
|
398 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
399 | 399 | } |
400 | 400 | } |
401 | 401 | |
402 | - $critical_page_problem = ! isset( $critical_page['post']->post_status ) || $critical_page['post']->post_status != 'publish' || strpos( $critical_page['post']->post_content, $critical_page['code'] ) === FALSE ? TRUE : $critical_page_problem; |
|
402 | + $critical_page_problem = ! isset($critical_page['post']->post_status) || $critical_page['post']->post_status != 'publish' || strpos($critical_page['post']->post_content, $critical_page['code']) === FALSE ? TRUE : $critical_page_problem; |
|
403 | 403 | |
404 | 404 | } |
405 | 405 | |
406 | - if ( $critical_page_problem ) { |
|
406 | + if ($critical_page_problem) { |
|
407 | 407 | $msg = sprintf( |
408 | - __('A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', 'event_espresso' ), |
|
409 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' . __('Event Espresso Critical Pages Settings', 'event_espresso') . '</a>' |
|
408 | + __('A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', 'event_espresso'), |
|
409 | + '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">'.__('Event Espresso Critical Pages Settings', 'event_espresso').'</a>' |
|
410 | 410 | ); |
411 | - EE_Error::add_persistent_admin_notice( 'critical_page_problem', $msg ); |
|
411 | + EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
412 | 412 | } |
413 | 413 | |
414 | - if ( EE_Error::has_notices() ) { |
|
415 | - EE_Error::get_notices( FALSE, TRUE, TRUE ); |
|
414 | + if (EE_Error::has_notices()) { |
|
415 | + EE_Error::get_notices(FALSE, TRUE, TRUE); |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | } |
@@ -425,13 +425,13 @@ discard block |
||
425 | 425 | * parameter to the shortcode |
426 | 426 | * @return WP_Post or NULl |
427 | 427 | */ |
428 | - public static function get_page_by_ee_shortcode($ee_shortcode){ |
|
428 | + public static function get_page_by_ee_shortcode($ee_shortcode) { |
|
429 | 429 | global $wpdb; |
430 | 430 | $shortcode_and_opening_bracket = '['.$ee_shortcode; |
431 | 431 | $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
432 | - if($post_id){ |
|
432 | + if ($post_id) { |
|
433 | 433 | return get_post($post_id); |
434 | - }else{ |
|
434 | + } else { |
|
435 | 435 | return NULL; |
436 | 436 | } |
437 | 437 | |
@@ -448,32 +448,32 @@ discard block |
||
448 | 448 | * @param array $critical_page |
449 | 449 | * @return array |
450 | 450 | */ |
451 | - public static function create_critical_page( $critical_page ) { |
|
451 | + public static function create_critical_page($critical_page) { |
|
452 | 452 | |
453 | 453 | $post_args = array( |
454 | 454 | 'post_title' => $critical_page['name'], |
455 | 455 | 'post_status' => 'publish', |
456 | 456 | 'post_type' => 'page', |
457 | 457 | 'comment_status' => 'closed', |
458 | - 'post_content' => '[' . $critical_page['code'] . ']' |
|
458 | + 'post_content' => '['.$critical_page['code'].']' |
|
459 | 459 | ); |
460 | 460 | |
461 | - $post_id = wp_insert_post( $post_args ); |
|
462 | - if ( ! $post_id ) { |
|
461 | + $post_id = wp_insert_post($post_args); |
|
462 | + if ( ! $post_id) { |
|
463 | 463 | $msg = sprintf( |
464 | - __( 'The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso' ), |
|
464 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
465 | 465 | $critical_page['name'] |
466 | 466 | ); |
467 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
467 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
468 | 468 | return $critical_page; |
469 | 469 | } |
470 | 470 | // get newly created post's details |
471 | - if ( ! $critical_page['post'] = get_post( $post_id )) { |
|
471 | + if ( ! $critical_page['post'] = get_post($post_id)) { |
|
472 | 472 | $msg = sprintf( |
473 | - __( 'The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso' ), |
|
473 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
474 | 474 | $critical_page['name'] |
475 | 475 | ); |
476 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
476 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | return $critical_page; |
@@ -492,34 +492,34 @@ discard block |
||
492 | 492 | * @param array $critical_page |
493 | 493 | * @return void |
494 | 494 | */ |
495 | - private static function _track_critical_page_post_shortcodes( $critical_page = array() ) { |
|
495 | + private static function _track_critical_page_post_shortcodes($critical_page = array()) { |
|
496 | 496 | // check the goods |
497 | - if ( ! $critical_page['post'] instanceof WP_Post ) { |
|
497 | + if ( ! $critical_page['post'] instanceof WP_Post) { |
|
498 | 498 | $msg = sprintf( |
499 | - __( 'The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.', 'event_espresso' ), |
|
499 | + __('The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.', 'event_espresso'), |
|
500 | 500 | $critical_page['name'] |
501 | 501 | ); |
502 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
502 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
503 | 503 | return; |
504 | 504 | } |
505 | 505 | // map shortcode to post |
506 | - EE_Registry::instance()->CFG->core->post_shortcodes[ $critical_page['post']->post_name ][ $critical_page['code'] ] = $critical_page['post']->ID; |
|
506 | + EE_Registry::instance()->CFG->core->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID; |
|
507 | 507 | // and make sure it's NOT added to the WP "Posts Page" |
508 | 508 | // name of the WP Posts Page |
509 | 509 | $posts_page = EE_Registry::instance()->CFG->get_page_for_posts(); |
510 | - if ( isset( EE_Registry::instance()->CFG->core->post_shortcodes[ $posts_page ] )) { |
|
511 | - unset( EE_Registry::instance()->CFG->core->post_shortcodes[ $posts_page ][ $critical_page['code'] ] ); |
|
510 | + if (isset(EE_Registry::instance()->CFG->core->post_shortcodes[$posts_page])) { |
|
511 | + unset(EE_Registry::instance()->CFG->core->post_shortcodes[$posts_page][$critical_page['code']]); |
|
512 | 512 | } |
513 | - if ( $posts_page != 'posts' && isset( EE_Registry::instance()->CFG->core->post_shortcodes['posts'] )) { |
|
514 | - unset( EE_Registry::instance()->CFG->core->post_shortcodes['posts'][ $critical_page['code'] ] ); |
|
513 | + if ($posts_page != 'posts' && isset(EE_Registry::instance()->CFG->core->post_shortcodes['posts'])) { |
|
514 | + unset(EE_Registry::instance()->CFG->core->post_shortcodes['posts'][$critical_page['code']]); |
|
515 | 515 | } |
516 | 516 | // update post_shortcode CFG |
517 | - if ( ! EE_Config::instance()->update_espresso_config( FALSE, FALSE )) { |
|
517 | + if ( ! EE_Config::instance()->update_espresso_config(FALSE, FALSE)) { |
|
518 | 518 | $msg = sprintf( |
519 | - __( 'The Event Espresso critical page shortcode for the %s page could not be configured properly.', 'event_espresso' ), |
|
519 | + __('The Event Espresso critical page shortcode for the %s page could not be configured properly.', 'event_espresso'), |
|
520 | 520 | $critical_page['name'] |
521 | 521 | ); |
522 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
522 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
523 | 523 | } |
524 | 524 | } |
525 | 525 | |
@@ -537,24 +537,24 @@ discard block |
||
537 | 537 | public static function get_default_creator_id() { |
538 | 538 | global $wpdb; |
539 | 539 | |
540 | - if ( ! empty( self::$_default_creator_id ) ) { |
|
540 | + if ( ! empty(self::$_default_creator_id)) { |
|
541 | 541 | return self::$_default_creator_id; |
542 | 542 | }/**/ |
543 | 543 | |
544 | - $role_to_check = apply_filters( 'FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator' ); |
|
544 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
545 | 545 | |
546 | 546 | //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. |
547 | - $pre_filtered_id = apply_filters( 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', false, $role_to_check ); |
|
548 | - if ( $pre_filtered_id !== false ) { |
|
547 | + $pre_filtered_id = apply_filters('FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', false, $role_to_check); |
|
548 | + if ($pre_filtered_id !== false) { |
|
549 | 549 | return (int) $pre_filtered_id; |
550 | 550 | } |
551 | 551 | |
552 | - $capabilities_key = EEH_Activation::ensure_table_name_has_prefix( 'capabilities' ); |
|
553 | - $query = $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", '%' . $role_to_check . '%' ); |
|
554 | - $user_id = $wpdb->get_var( $query ); |
|
555 | - $user_id = apply_filters( 'FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id ); |
|
556 | - if ( $user_id && intval( $user_id ) ) { |
|
557 | - self::$_default_creator_id = intval( $user_id ); |
|
552 | + $capabilities_key = EEH_Activation::ensure_table_name_has_prefix('capabilities'); |
|
553 | + $query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", '%'.$role_to_check.'%'); |
|
554 | + $user_id = $wpdb->get_var($query); |
|
555 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
556 | + if ($user_id && intval($user_id)) { |
|
557 | + self::$_default_creator_id = intval($user_id); |
|
558 | 558 | return self::$_default_creator_id; |
559 | 559 | } else { |
560 | 560 | return NULL; |
@@ -581,29 +581,29 @@ discard block |
||
581 | 581 | * @return void |
582 | 582 | * @throws EE_Error if there are database errors |
583 | 583 | */ |
584 | - public static function create_table( $table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false ) { |
|
585 | - if( apply_filters( 'FHEE__EEH_Activation__create_table__short_circuit', FALSE, $table_name, $sql ) ){ |
|
584 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) { |
|
585 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', FALSE, $table_name, $sql)) { |
|
586 | 586 | return; |
587 | 587 | } |
588 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
589 | - if ( ! function_exists( 'dbDelta' )) { |
|
590 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
588 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
589 | + if ( ! function_exists('dbDelta')) { |
|
590 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
591 | 591 | } |
592 | 592 | /** @var WPDB $wpdb */ |
593 | 593 | global $wpdb; |
594 | - $wp_table_name = EEH_Activation::ensure_table_name_has_prefix( $table_name ); |
|
594 | + $wp_table_name = EEH_Activation::ensure_table_name_has_prefix($table_name); |
|
595 | 595 | // do we need to first delete an existing version of this table ? |
596 | - if ( $drop_pre_existing_table && EEH_Activation::table_exists( $wp_table_name ) ){ |
|
596 | + if ($drop_pre_existing_table && EEH_Activation::table_exists($wp_table_name)) { |
|
597 | 597 | // ok, delete the table... but ONLY if it's empty |
598 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty( $wp_table_name ); |
|
598 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
599 | 599 | // table is NOT empty, are you SURE you want to delete this table ??? |
600 | - if ( ! $deleted_safely && defined( 'EE_DROP_BAD_TABLES' ) && EE_DROP_BAD_TABLES ){ |
|
601 | - EEH_Activation::delete_unused_db_table( $wp_table_name ); |
|
602 | - } else if ( ! $deleted_safely ) { |
|
600 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
601 | + EEH_Activation::delete_unused_db_table($wp_table_name); |
|
602 | + } else if ( ! $deleted_safely) { |
|
603 | 603 | // so we should be more cautious rather than just dropping tables so easily |
604 | 604 | EE_Error::add_persistent_admin_notice( |
605 | - 'bad_table_' . $wp_table_name . '_detected', |
|
606 | - sprintf( __( 'Database table %1$s exists when it shouldn\'t, and may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend adding %2$s to your %3$s file then restore to that backup again. This will clear out the invalid data from %1$s. Afterwards you should undo that change from your %3$s file. %4$sIf you cannot edit %3$s, you should remove the data from %1$s manually then restore to the backup again.', 'event_espresso' ), |
|
605 | + 'bad_table_'.$wp_table_name.'_detected', |
|
606 | + sprintf(__('Database table %1$s exists when it shouldn\'t, and may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend adding %2$s to your %3$s file then restore to that backup again. This will clear out the invalid data from %1$s. Afterwards you should undo that change from your %3$s file. %4$sIf you cannot edit %3$s, you should remove the data from %1$s manually then restore to the backup again.', 'event_espresso'), |
|
607 | 607 | $wp_table_name, |
608 | 608 | "<pre>define( 'EE_DROP_BAD_TABLES', TRUE );</pre>", |
609 | 609 | '<b>wp-config.php</b>', |
@@ -612,25 +612,25 @@ discard block |
||
612 | 612 | } |
613 | 613 | } |
614 | 614 | // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns ) |
615 | - if ( preg_match( '((((.*?))(,\s))+)', $sql, $valid_column_data ) ) { |
|
615 | + if (preg_match('((((.*?))(,\s))+)', $sql, $valid_column_data)) { |
|
616 | 616 | $SQL = "CREATE TABLE $wp_table_name ( $sql ) $engine DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; |
617 | 617 | //get $wpdb to echo errors, but buffer them. This way at least WE know an error |
618 | 618 | //happened. And then we can choose to tell the end user |
619 | - $old_show_errors_policy = $wpdb->show_errors( TRUE ); |
|
620 | - $old_error_suppression_policy = $wpdb->suppress_errors( FALSE ); |
|
619 | + $old_show_errors_policy = $wpdb->show_errors(TRUE); |
|
620 | + $old_error_suppression_policy = $wpdb->suppress_errors(FALSE); |
|
621 | 621 | ob_start(); |
622 | - dbDelta( $SQL ); |
|
622 | + dbDelta($SQL); |
|
623 | 623 | $output = ob_get_contents(); |
624 | 624 | ob_end_clean(); |
625 | - $wpdb->show_errors( $old_show_errors_policy ); |
|
626 | - $wpdb->suppress_errors( $old_error_suppression_policy ); |
|
627 | - if( ! empty( $output ) ){ |
|
628 | - throw new EE_Error( $output ); |
|
625 | + $wpdb->show_errors($old_show_errors_policy); |
|
626 | + $wpdb->suppress_errors($old_error_suppression_policy); |
|
627 | + if ( ! empty($output)) { |
|
628 | + throw new EE_Error($output); |
|
629 | 629 | } |
630 | 630 | } else { |
631 | 631 | throw new EE_Error( |
632 | 632 | sprintf( |
633 | - __( 'The following table creation SQL does not contain valid information about the table columns: %1$s %2$s', 'event_espresso' ), |
|
633 | + __('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s', 'event_espresso'), |
|
634 | 634 | '<br />', |
635 | 635 | $sql |
636 | 636 | ) |
@@ -652,15 +652,15 @@ discard block |
||
652 | 652 | * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be 'VARCHAR(10)' |
653 | 653 | * @return bool|int |
654 | 654 | */ |
655 | - public static function add_column_if_it_doesnt_exist($table_name,$column_name,$column_info='INT UNSIGNED NOT NULL'){ |
|
656 | - if( apply_filters( 'FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', FALSE ) ){ |
|
655 | + public static function add_column_if_it_doesnt_exist($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL') { |
|
656 | + if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', FALSE)) { |
|
657 | 657 | return FALSE; |
658 | 658 | } |
659 | 659 | global $wpdb; |
660 | - $full_table_name= EEH_Activation::ensure_table_name_has_prefix( $table_name ); |
|
660 | + $full_table_name = EEH_Activation::ensure_table_name_has_prefix($table_name); |
|
661 | 661 | $fields = self::get_fields_on_table($table_name); |
662 | - if (!in_array($column_name, $fields)){ |
|
663 | - $alter_query="ALTER TABLE $full_table_name ADD $column_name $column_info"; |
|
662 | + if ( ! in_array($column_name, $fields)) { |
|
663 | + $alter_query = "ALTER TABLE $full_table_name ADD $column_name $column_info"; |
|
664 | 664 | //echo "alter query:$alter_query"; |
665 | 665 | return $wpdb->query($alter_query); |
666 | 666 | } |
@@ -679,15 +679,15 @@ discard block |
||
679 | 679 | * @param string $table_name, without prefixed $wpdb->prefix |
680 | 680 | * @return array of database column names |
681 | 681 | */ |
682 | - public static function get_fields_on_table( $table_name = NULL ) { |
|
682 | + public static function get_fields_on_table($table_name = NULL) { |
|
683 | 683 | global $wpdb; |
684 | - $table_name= EEH_Activation::ensure_table_name_has_prefix( $table_name ); |
|
685 | - if ( ! empty( $table_name )) { |
|
684 | + $table_name = EEH_Activation::ensure_table_name_has_prefix($table_name); |
|
685 | + if ( ! empty($table_name)) { |
|
686 | 686 | $columns = $wpdb->get_results("SHOW COLUMNS FROM $table_name "); |
687 | 687 | if ($columns !== FALSE) { |
688 | 688 | $field_array = array(); |
689 | - foreach($columns as $column ){ |
|
690 | - $field_array[] = $column->Field;; |
|
689 | + foreach ($columns as $column) { |
|
690 | + $field_array[] = $column->Field; ; |
|
691 | 691 | } |
692 | 692 | return $field_array; |
693 | 693 | } |
@@ -705,12 +705,12 @@ discard block |
||
705 | 705 | * @param string $table_name |
706 | 706 | * @return bool |
707 | 707 | */ |
708 | - public static function db_table_is_empty( $table_name ) { |
|
708 | + public static function db_table_is_empty($table_name) { |
|
709 | 709 | global $wpdb; |
710 | - $table_name = EEH_Activation::ensure_table_name_has_prefix( $table_name ); |
|
711 | - if ( EEH_Activation::table_exists( $table_name ) ) { |
|
712 | - $count = $wpdb->get_var( "SELECT COUNT(*) FROM $table_name" ); |
|
713 | - return absint( $count ) === 0 ? true : false; |
|
710 | + $table_name = EEH_Activation::ensure_table_name_has_prefix($table_name); |
|
711 | + if (EEH_Activation::table_exists($table_name)) { |
|
712 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM $table_name"); |
|
713 | + return absint($count) === 0 ? true : false; |
|
714 | 714 | } |
715 | 715 | return false; |
716 | 716 | } |
@@ -725,9 +725,9 @@ discard block |
||
725 | 725 | * @param string $table_name |
726 | 726 | * @return bool | int |
727 | 727 | */ |
728 | - public static function delete_db_table_if_empty( $table_name ) { |
|
729 | - if ( EEH_Activation::db_table_is_empty( $table_name ) ) { |
|
730 | - return EEH_Activation::delete_unused_db_table( $table_name ); |
|
728 | + public static function delete_db_table_if_empty($table_name) { |
|
729 | + if (EEH_Activation::db_table_is_empty($table_name)) { |
|
730 | + return EEH_Activation::delete_unused_db_table($table_name); |
|
731 | 731 | } |
732 | 732 | return false; |
733 | 733 | } |
@@ -742,11 +742,11 @@ discard block |
||
742 | 742 | * @param string $table_name |
743 | 743 | * @return bool | int |
744 | 744 | */ |
745 | - public static function delete_unused_db_table( $table_name ) { |
|
745 | + public static function delete_unused_db_table($table_name) { |
|
746 | 746 | global $wpdb; |
747 | - if ( EEH_Activation::table_exists( $table_name ) ) { |
|
748 | - $table_name = EEH_Activation::ensure_table_name_has_prefix( $table_name ); |
|
749 | - return $wpdb->query( "DROP TABLE IF EXISTS $table_name" ); |
|
747 | + if (EEH_Activation::table_exists($table_name)) { |
|
748 | + $table_name = EEH_Activation::ensure_table_name_has_prefix($table_name); |
|
749 | + return $wpdb->query("DROP TABLE IF EXISTS $table_name"); |
|
750 | 750 | } |
751 | 751 | return false; |
752 | 752 | } |
@@ -762,18 +762,18 @@ discard block |
||
762 | 762 | * @param string $index_name |
763 | 763 | * @return bool | int |
764 | 764 | */ |
765 | - public static function drop_index( $table_name, $index_name ) { |
|
766 | - if( apply_filters( 'FHEE__EEH_Activation__drop_index__short_circuit', FALSE ) ){ |
|
765 | + public static function drop_index($table_name, $index_name) { |
|
766 | + if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', FALSE)) { |
|
767 | 767 | return FALSE; |
768 | 768 | } |
769 | 769 | global $wpdb; |
770 | - $table_name = EEH_Activation::ensure_table_name_has_prefix( $table_name ); |
|
770 | + $table_name = EEH_Activation::ensure_table_name_has_prefix($table_name); |
|
771 | 771 | $index_exists_query = "SHOW INDEX FROM $table_name WHERE Key_name = '$index_name'"; |
772 | 772 | if ( |
773 | - $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) == $table_name |
|
774 | - && $wpdb->get_var( $index_exists_query ) == $table_name //using get_var with the $index_exists_query returns the table's name |
|
773 | + $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name |
|
774 | + && $wpdb->get_var($index_exists_query) == $table_name //using get_var with the $index_exists_query returns the table's name |
|
775 | 775 | ) { |
776 | - return $wpdb->query( "ALTER TABLE $table_name DROP INDEX $index_name" ); |
|
776 | + return $wpdb->query("ALTER TABLE $table_name DROP INDEX $index_name"); |
|
777 | 777 | } |
778 | 778 | return TRUE; |
779 | 779 | } |
@@ -789,27 +789,27 @@ discard block |
||
789 | 789 | * @return boolean success (whether database is setup properly or not) |
790 | 790 | */ |
791 | 791 | public static function create_database_tables() { |
792 | - EE_Registry::instance()->load_core( 'Data_Migration_Manager' ); |
|
792 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
793 | 793 | //find the migration script that sets the database to be compatible with the code |
794 | 794 | $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
795 | - if( $dms_name ){ |
|
796 | - $current_data_migration_script = EE_Registry::instance()->load_dms( $dms_name ); |
|
797 | - $current_data_migration_script->set_migrating( false ); |
|
795 | + if ($dms_name) { |
|
796 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
797 | + $current_data_migration_script->set_migrating(false); |
|
798 | 798 | $current_data_migration_script->schema_changes_before_migration(); |
799 | 799 | $current_data_migration_script->schema_changes_after_migration(); |
800 | - if( $current_data_migration_script->get_errors() ){ |
|
801 | - if( WP_DEBUG ){ |
|
802 | - foreach( $current_data_migration_script->get_errors() as $error ){ |
|
803 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__ ); |
|
800 | + if ($current_data_migration_script->get_errors()) { |
|
801 | + if (WP_DEBUG) { |
|
802 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
803 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
804 | 804 | } |
805 | - }else{ |
|
806 | - EE_Error::add_error( __( 'There were errors creating the Event Espresso database tables and Event Espresso has been deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', 'event_espresso' ) ); |
|
805 | + } else { |
|
806 | + EE_Error::add_error(__('There were errors creating the Event Espresso database tables and Event Espresso has been deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', 'event_espresso')); |
|
807 | 807 | } |
808 | 808 | return false; |
809 | 809 | } |
810 | 810 | EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
811 | - }else{ |
|
812 | - EE_Error::add_error( __( 'Could not determine most up-to-date data migration script from which to pull database schema structure. So database is probably not setup properly', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
811 | + } else { |
|
812 | + EE_Error::add_error(__('Could not determine most up-to-date data migration script from which to pull database schema structure. So database is probably not setup properly', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
813 | 813 | return false; |
814 | 814 | } |
815 | 815 | return true; |
@@ -829,27 +829,27 @@ discard block |
||
829 | 829 | public static function initialize_system_questions() { |
830 | 830 | // QUESTION GROUPS |
831 | 831 | global $wpdb; |
832 | - $table_name = EEH_Activation::ensure_table_name_has_prefix( 'esp_question_group' ); |
|
832 | + $table_name = EEH_Activation::ensure_table_name_has_prefix('esp_question_group'); |
|
833 | 833 | $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
834 | 834 | // what we have |
835 | - $question_groups = $wpdb->get_col( $SQL ); |
|
835 | + $question_groups = $wpdb->get_col($SQL); |
|
836 | 836 | // check the response |
837 | - $question_groups = is_array( $question_groups ) ? $question_groups : array(); |
|
837 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
838 | 838 | // what we should have |
839 | - $QSG_systems = array( 1, 2 ); |
|
839 | + $QSG_systems = array(1, 2); |
|
840 | 840 | // loop thru what we should have and compare to what we have |
841 | - foreach ( $QSG_systems as $QSG_system ) { |
|
841 | + foreach ($QSG_systems as $QSG_system) { |
|
842 | 842 | // reset values array |
843 | 843 | $QSG_values = array(); |
844 | 844 | // 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) |
845 | - if ( ! in_array( "$QSG_system", $question_groups )) { |
|
845 | + if ( ! in_array("$QSG_system", $question_groups)) { |
|
846 | 846 | // add it |
847 | - switch ( $QSG_system ) { |
|
847 | + switch ($QSG_system) { |
|
848 | 848 | |
849 | 849 | case 1: |
850 | 850 | $QSG_values = array( |
851 | - 'QSG_name' => __( 'Personal Information', 'event_espresso' ), |
|
852 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
851 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
852 | + 'QSG_identifier' => 'personal-information-'.time(), |
|
853 | 853 | 'QSG_desc' => '', |
854 | 854 | 'QSG_order' => 1, |
855 | 855 | 'QSG_show_group_name' => 1, |
@@ -861,8 +861,8 @@ discard block |
||
861 | 861 | |
862 | 862 | case 2: |
863 | 863 | $QSG_values = array( |
864 | - 'QSG_name' => __( 'Address Information','event_espresso' ), |
|
865 | - 'QSG_identifier' => 'address-information-' . time(), |
|
864 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
865 | + 'QSG_identifier' => 'address-information-'.time(), |
|
866 | 866 | 'QSG_desc' => '', |
867 | 867 | 'QSG_order' => 2, |
868 | 868 | 'QSG_show_group_name' => 1, |
@@ -874,14 +874,14 @@ discard block |
||
874 | 874 | |
875 | 875 | } |
876 | 876 | // make sure we have some values before inserting them |
877 | - if ( ! empty( $QSG_values )) { |
|
877 | + if ( ! empty($QSG_values)) { |
|
878 | 878 | // insert system question |
879 | 879 | $wpdb->insert( |
880 | 880 | $table_name, |
881 | 881 | $QSG_values, |
882 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d' ) |
|
882 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
883 | 883 | ); |
884 | - $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
884 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
885 | 885 | } |
886 | 886 | } |
887 | 887 | } |
@@ -890,10 +890,10 @@ discard block |
||
890 | 890 | |
891 | 891 | // QUESTIONS |
892 | 892 | global $wpdb; |
893 | - $table_name = EEH_Activation::ensure_table_name_has_prefix( 'esp_question' ); |
|
893 | + $table_name = EEH_Activation::ensure_table_name_has_prefix('esp_question'); |
|
894 | 894 | $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
895 | 895 | // what we have |
896 | - $questions = $wpdb->get_col( $SQL ); |
|
896 | + $questions = $wpdb->get_col($SQL); |
|
897 | 897 | // what we should have |
898 | 898 | $QST_systems = array( |
899 | 899 | 'fname', |
@@ -910,22 +910,22 @@ discard block |
||
910 | 910 | $order_for_group_1 = 1; |
911 | 911 | $order_for_group_2 = 1; |
912 | 912 | // loop thru what we should have and compare to what we have |
913 | - foreach ( $QST_systems as $QST_system ) { |
|
913 | + foreach ($QST_systems as $QST_system) { |
|
914 | 914 | // reset values array |
915 | 915 | $QST_values = array(); |
916 | 916 | // if we don't have what we should have |
917 | - if ( ! in_array( $QST_system, $questions )) { |
|
917 | + if ( ! in_array($QST_system, $questions)) { |
|
918 | 918 | // add it |
919 | - switch ( $QST_system ) { |
|
919 | + switch ($QST_system) { |
|
920 | 920 | |
921 | 921 | case 'fname': |
922 | 922 | $QST_values = array( |
923 | - 'QST_display_text' => __( 'First Name', 'event_espresso' ), |
|
924 | - 'QST_admin_label' => __( 'First Name - System Question', 'event_espresso' ), |
|
923 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
924 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
925 | 925 | 'QST_system' => 'fname', |
926 | 926 | 'QST_type' => 'TEXT', |
927 | 927 | 'QST_required' => 1, |
928 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
928 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
929 | 929 | 'QST_order' => 1, |
930 | 930 | 'QST_admin_only' => 0, |
931 | 931 | 'QST_wp_user' => self::get_default_creator_id(), |
@@ -935,12 +935,12 @@ discard block |
||
935 | 935 | |
936 | 936 | case 'lname': |
937 | 937 | $QST_values = array( |
938 | - 'QST_display_text' => __( 'Last Name', 'event_espresso' ), |
|
939 | - 'QST_admin_label' => __( 'Last Name - System Question', 'event_espresso' ), |
|
938 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
939 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
940 | 940 | 'QST_system' => 'lname', |
941 | 941 | 'QST_type' => 'TEXT', |
942 | 942 | 'QST_required' => 1, |
943 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
943 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
944 | 944 | 'QST_order' => 2, |
945 | 945 | 'QST_admin_only' => 0, |
946 | 946 | 'QST_wp_user' => self::get_default_creator_id(), |
@@ -950,12 +950,12 @@ discard block |
||
950 | 950 | |
951 | 951 | case 'email': |
952 | 952 | $QST_values = array( |
953 | - 'QST_display_text' => __( 'Email Address', 'event_espresso' ), |
|
954 | - 'QST_admin_label' => __( 'Email Address - System Question', 'event_espresso' ), |
|
953 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
954 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
955 | 955 | 'QST_system' => 'email', |
956 | 956 | 'QST_type' => 'TEXT', |
957 | 957 | 'QST_required' => 1, |
958 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
958 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
959 | 959 | 'QST_order' => 3, |
960 | 960 | 'QST_admin_only' => 0, |
961 | 961 | 'QST_wp_user' => self::get_default_creator_id(), |
@@ -965,12 +965,12 @@ discard block |
||
965 | 965 | |
966 | 966 | case 'address': |
967 | 967 | $QST_values = array( |
968 | - 'QST_display_text' => __( 'Address', 'event_espresso' ), |
|
969 | - 'QST_admin_label' => __( 'Address - System Question', 'event_espresso' ), |
|
968 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
969 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
970 | 970 | 'QST_system' => 'address', |
971 | 971 | 'QST_type' => 'TEXT', |
972 | 972 | 'QST_required' => 0, |
973 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
973 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
974 | 974 | 'QST_order' => 4, |
975 | 975 | 'QST_admin_only' => 0, |
976 | 976 | 'QST_wp_user' => self::get_default_creator_id(), |
@@ -980,12 +980,12 @@ discard block |
||
980 | 980 | |
981 | 981 | case 'address2': |
982 | 982 | $QST_values = array( |
983 | - 'QST_display_text' => __( 'Address2', 'event_espresso' ), |
|
984 | - 'QST_admin_label' => __( 'Address2 - System Question', 'event_espresso' ), |
|
983 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
984 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
985 | 985 | 'QST_system' => 'address2', |
986 | 986 | 'QST_type' => 'TEXT', |
987 | 987 | 'QST_required' => 0, |
988 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
988 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
989 | 989 | 'QST_order' => 5, |
990 | 990 | 'QST_admin_only' => 0, |
991 | 991 | 'QST_wp_user' => self::get_default_creator_id(), |
@@ -995,12 +995,12 @@ discard block |
||
995 | 995 | |
996 | 996 | case 'city': |
997 | 997 | $QST_values = array( |
998 | - 'QST_display_text' => __( 'City', 'event_espresso' ), |
|
999 | - 'QST_admin_label' => __( 'City - System Question', 'event_espresso' ), |
|
998 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
999 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1000 | 1000 | 'QST_system' => 'city', |
1001 | 1001 | 'QST_type' => 'TEXT', |
1002 | 1002 | 'QST_required' => 0, |
1003 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
1003 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1004 | 1004 | 'QST_order' => 6, |
1005 | 1005 | 'QST_admin_only' => 0, |
1006 | 1006 | 'QST_wp_user' => self::get_default_creator_id(), |
@@ -1010,12 +1010,12 @@ discard block |
||
1010 | 1010 | |
1011 | 1011 | case 'state': |
1012 | 1012 | $QST_values = array( |
1013 | - 'QST_display_text' => __( 'State/Province', 'event_espresso' ), |
|
1014 | - 'QST_admin_label' => __( 'State/Province - System Question', 'event_espresso' ), |
|
1013 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1014 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1015 | 1015 | 'QST_system' => 'state', |
1016 | 1016 | 'QST_type' => 'STATE', |
1017 | 1017 | 'QST_required' => 0, |
1018 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
1018 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1019 | 1019 | 'QST_order' => 7, |
1020 | 1020 | 'QST_admin_only' => 0, |
1021 | 1021 | 'QST_wp_user' => self::get_default_creator_id(), |
@@ -1025,12 +1025,12 @@ discard block |
||
1025 | 1025 | |
1026 | 1026 | case 'country' : |
1027 | 1027 | $QST_values = array( |
1028 | - 'QST_display_text' => __( 'Country', 'event_espresso' ), |
|
1029 | - 'QST_admin_label' => __( 'Country - System Question', 'event_espresso' ), |
|
1028 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
1029 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1030 | 1030 | 'QST_system' => 'country', |
1031 | 1031 | 'QST_type' => 'COUNTRY', |
1032 | 1032 | 'QST_required' => 0, |
1033 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
1033 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1034 | 1034 | 'QST_order' => 8, |
1035 | 1035 | 'QST_admin_only' => 0, |
1036 | 1036 | 'QST_wp_user' => self::get_default_creator_id(), |
@@ -1040,12 +1040,12 @@ discard block |
||
1040 | 1040 | |
1041 | 1041 | case 'zip': |
1042 | 1042 | $QST_values = array( |
1043 | - 'QST_display_text' => __( 'Zip/Postal Code', 'event_espresso' ), |
|
1044 | - 'QST_admin_label' => __( 'Zip/Postal Code - System Question', 'event_espresso' ), |
|
1043 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1044 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1045 | 1045 | 'QST_system' => 'zip', |
1046 | 1046 | 'QST_type' => 'TEXT', |
1047 | 1047 | 'QST_required' => 0, |
1048 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
1048 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1049 | 1049 | 'QST_order' => 9, |
1050 | 1050 | 'QST_admin_only' => 0, |
1051 | 1051 | 'QST_wp_user' => self::get_default_creator_id(), |
@@ -1055,12 +1055,12 @@ discard block |
||
1055 | 1055 | |
1056 | 1056 | case 'phone': |
1057 | 1057 | $QST_values = array( |
1058 | - 'QST_display_text' => __( 'Phone Number', 'event_espresso' ), |
|
1059 | - 'QST_admin_label' => __( 'Phone Number - System Question', 'event_espresso' ), |
|
1058 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1059 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1060 | 1060 | 'QST_system' => 'phone', |
1061 | 1061 | 'QST_type' => 'TEXT', |
1062 | 1062 | 'QST_required' => 0, |
1063 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
1063 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1064 | 1064 | 'QST_order' => 10, |
1065 | 1065 | 'QST_admin_only' => 0, |
1066 | 1066 | 'QST_wp_user' => self::get_default_creator_id(), |
@@ -1069,34 +1069,34 @@ discard block |
||
1069 | 1069 | break; |
1070 | 1070 | |
1071 | 1071 | } |
1072 | - if ( ! empty( $QST_values )) { |
|
1072 | + if ( ! empty($QST_values)) { |
|
1073 | 1073 | // insert system question |
1074 | 1074 | $wpdb->insert( |
1075 | 1075 | $table_name, |
1076 | 1076 | $QST_values, |
1077 | - array( '%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d' ) |
|
1077 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1078 | 1078 | ); |
1079 | 1079 | $QST_ID = $wpdb->insert_id; |
1080 | 1080 | |
1081 | 1081 | // QUESTION GROUP QUESTIONS |
1082 | - if( in_array( $QST_system, array( 'fname', 'lname', 'email' ) ) ) { |
|
1082 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
1083 | 1083 | $system_question_we_want = EEM_Question_Group::system_personal; |
1084 | 1084 | } else { |
1085 | 1085 | $system_question_we_want = EEM_Question_Group::system_address; |
1086 | 1086 | } |
1087 | - if( isset( $QSG_IDs[ $system_question_we_want ] ) ) { |
|
1088 | - $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
1087 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
1088 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
1089 | 1089 | } else { |
1090 | - $id_col = EEM_Question_Group::instance()->get_col( array( array( 'QSG_system' => $system_question_we_want ) ) ); |
|
1091 | - if( is_array( $id_col ) ) { |
|
1092 | - $QSG_ID = reset( $id_col ); |
|
1090 | + $id_col = EEM_Question_Group::instance()->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1091 | + if (is_array($id_col)) { |
|
1092 | + $QSG_ID = reset($id_col); |
|
1093 | 1093 | } else { |
1094 | 1094 | //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 |
1095 | 1095 | EE_Log::instance()->log( |
1096 | 1096 | __FILE__, |
1097 | 1097 | __FUNCTION__, |
1098 | 1098 | sprintf( |
1099 | - __( 'Could not associate question %1$s to a question group because no system question group existed', 'event_espresso'), |
|
1099 | + __('Could not associate question %1$s to a question group because no system question group existed', 'event_espresso'), |
|
1100 | 1100 | $QST_ID ), |
1101 | 1101 | 'error' ); |
1102 | 1102 | continue; |
@@ -1105,9 +1105,9 @@ discard block |
||
1105 | 1105 | |
1106 | 1106 | // add system questions to groups |
1107 | 1107 | $wpdb->insert( |
1108 | - EEH_Activation::ensure_table_name_has_prefix( 'esp_question_group_question' ), |
|
1109 | - array( 'QSG_ID' => $QSG_ID , 'QST_ID' => $QST_ID, 'QGQ_order'=>($QSG_ID==1)? $order_for_group_1++ : $order_for_group_2++ ), |
|
1110 | - array( '%d', '%d','%d' ) |
|
1108 | + EEH_Activation::ensure_table_name_has_prefix('esp_question_group_question'), |
|
1109 | + array('QSG_ID' => $QSG_ID, 'QST_ID' => $QST_ID, 'QGQ_order'=>($QSG_ID == 1) ? $order_for_group_1++ : $order_for_group_2++), |
|
1110 | + array('%d', '%d', '%d') |
|
1111 | 1111 | ); |
1112 | 1112 | } |
1113 | 1113 | } |
@@ -1119,11 +1119,11 @@ discard block |
||
1119 | 1119 | * Makes sure the default payment method (Invoice) is active. |
1120 | 1120 | * This used to be done automatically as part of constructing the old gateways config |
1121 | 1121 | */ |
1122 | - public static function insert_default_payment_methods(){ |
|
1123 | - if( ! EEM_Payment_Method::instance()->count_active( EEM_Payment_Method::scope_cart ) ){ |
|
1124 | - EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
|
1125 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type( 'Invoice' ); |
|
1126 | - }else{ |
|
1122 | + public static function insert_default_payment_methods() { |
|
1123 | + if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1124 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1125 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1126 | + } else { |
|
1127 | 1127 | EEM_Payment_Method::instance()->verify_button_urls(); |
1128 | 1128 | } |
1129 | 1129 | } |
@@ -1139,7 +1139,7 @@ discard block |
||
1139 | 1139 | |
1140 | 1140 | global $wpdb; |
1141 | 1141 | |
1142 | - if ( EEH_Activation::table_exists( EEM_Status::instance()->table() ) ) { |
|
1142 | + if (EEH_Activation::table_exists(EEM_Status::instance()->table())) { |
|
1143 | 1143 | |
1144 | 1144 | $table_name = EEM_Status::instance()->table(); |
1145 | 1145 | |
@@ -1205,38 +1205,38 @@ discard block |
||
1205 | 1205 | * @return boolean success of verifying upload directories exist |
1206 | 1206 | */ |
1207 | 1207 | public static function create_upload_directories() { |
1208 | - EE_Registry::instance()->load_helper( 'File' ); |
|
1208 | + EE_Registry::instance()->load_helper('File'); |
|
1209 | 1209 | // Create the required folders |
1210 | 1210 | $folders = array( |
1211 | 1211 | EVENT_ESPRESSO_TEMPLATE_DIR, |
1212 | 1212 | EVENT_ESPRESSO_GATEWAY_DIR, |
1213 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
1214 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
1215 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/' |
|
1213 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/', |
|
1214 | + EVENT_ESPRESSO_UPLOAD_DIR.'css/', |
|
1215 | + EVENT_ESPRESSO_UPLOAD_DIR.'tickets/' |
|
1216 | 1216 | ); |
1217 | - foreach ( $folders as $folder ) { |
|
1217 | + foreach ($folders as $folder) { |
|
1218 | 1218 | try { |
1219 | - EEH_File::ensure_folder_exists_and_is_writable( $folder ); |
|
1220 | - @ chmod( $folder, 0755 ); |
|
1221 | - } catch( EE_Error $e ){ |
|
1219 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
1220 | + @ chmod($folder, 0755); |
|
1221 | + } catch (EE_Error $e) { |
|
1222 | 1222 | EE_Error::add_error( |
1223 | 1223 | sprintf( |
1224 | - __( 'Could not create the folder at "%1$s" because: %2$s', 'event_espresso' ), |
|
1224 | + __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
1225 | 1225 | $folder, |
1226 | - '<br />' . $e->getMessage() |
|
1226 | + '<br />'.$e->getMessage() |
|
1227 | 1227 | ), |
1228 | 1228 | __FILE__, __FUNCTION__, __LINE__ |
1229 | 1229 | ); |
1230 | 1230 | //indicate we'll need to fix this later |
1231 | - update_option( EEH_Activation::upload_directories_incomplete_option_name, true ); |
|
1231 | + update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
1232 | 1232 | return FALSE; |
1233 | 1233 | } |
1234 | 1234 | } |
1235 | 1235 | //just add the .htaccess file to the logs directory to begin with. Even if logging |
1236 | 1236 | //is disabled, there might be activation errors recorded in there |
1237 | - EEH_File::add_htaccess_deny_from_all( EVENT_ESPRESSO_UPLOAD_DIR . 'logs/' ); |
|
1237 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs/'); |
|
1238 | 1238 | //remember EE's folders are all good |
1239 | - delete_option( EEH_Activation::upload_directories_incomplete_option_name ); |
|
1239 | + delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
1240 | 1240 | return TRUE; |
1241 | 1241 | } |
1242 | 1242 | |
@@ -1249,7 +1249,7 @@ discard block |
||
1249 | 1249 | * @return boolean |
1250 | 1250 | */ |
1251 | 1251 | public static function upload_directories_incomplete() { |
1252 | - return get_option( EEH_Activation::upload_directories_incomplete_option_name, false ); |
|
1252 | + return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
1253 | 1253 | } |
1254 | 1254 | |
1255 | 1255 | |
@@ -1268,16 +1268,16 @@ discard block |
||
1268 | 1268 | $installed_messengers = $default_messengers = array(); |
1269 | 1269 | |
1270 | 1270 | //include our helper |
1271 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
1271 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
1272 | 1272 | |
1273 | 1273 | //get all installed messenger objects |
1274 | 1274 | $installed = EEH_MSG_Template::get_installed_message_objects(); |
1275 | 1275 | |
1276 | 1276 | //let's setup the $installed messengers in an array AND the messengers that are set to be activated on install. |
1277 | - foreach ( $installed['messengers'] as $msgr ) { |
|
1278 | - if ( $msgr instanceof EE_messenger ) { |
|
1277 | + foreach ($installed['messengers'] as $msgr) { |
|
1278 | + if ($msgr instanceof EE_messenger) { |
|
1279 | 1279 | $installed_messengers[$msgr->name] = $msgr; |
1280 | - if ( $msgr->activate_on_install ) { |
|
1280 | + if ($msgr->activate_on_install) { |
|
1281 | 1281 | $default_messengers[] = $msgr->name; |
1282 | 1282 | } |
1283 | 1283 | } |
@@ -1287,36 +1287,36 @@ discard block |
||
1287 | 1287 | $active_messengers = EEH_MSG_Template::get_active_messengers_in_db(); |
1288 | 1288 | |
1289 | 1289 | //things that have already been activated before |
1290 | - $has_activated = get_option( 'ee_has_activated_messenger' ); |
|
1290 | + $has_activated = get_option('ee_has_activated_messenger'); |
|
1291 | 1291 | |
1292 | 1292 | //do an initial loop to determine if we need to continue |
1293 | 1293 | $def_ms = array(); |
1294 | - foreach ( $default_messengers as $msgr ) { |
|
1295 | - if ( isset($active_messengers[$msgr] ) || isset( $has_activated[$msgr] ) ) continue; |
|
1294 | + foreach ($default_messengers as $msgr) { |
|
1295 | + if (isset($active_messengers[$msgr]) || isset($has_activated[$msgr])) continue; |
|
1296 | 1296 | $def_ms[] = $msgr; |
1297 | 1297 | } |
1298 | 1298 | |
1299 | 1299 | //setup the $installed_mts in an array |
1300 | - foreach ( $installed['message_types'] as $imt ) { |
|
1301 | - if ( $imt instanceof EE_message_type ) { |
|
1300 | + foreach ($installed['message_types'] as $imt) { |
|
1301 | + if ($imt instanceof EE_message_type) { |
|
1302 | 1302 | $installed_mts[$imt->name] = $imt; |
1303 | 1303 | } |
1304 | 1304 | } |
1305 | 1305 | |
1306 | 1306 | //loop through default array for default messengers (if present) |
1307 | - if ( ! empty( $def_ms ) ) { |
|
1308 | - foreach ( $def_ms as $messenger ) { |
|
1307 | + if ( ! empty($def_ms)) { |
|
1308 | + foreach ($def_ms as $messenger) { |
|
1309 | 1309 | //all is good so let's setup the default stuff. We need to use the given messenger object (if exists) to get the default message type for the messenger. |
1310 | - if ( ! isset( $installed_messengers[$messenger] )) { |
|
1310 | + if ( ! isset($installed_messengers[$messenger])) { |
|
1311 | 1311 | continue; |
1312 | 1312 | } |
1313 | 1313 | /** @var EE_messenger[] $installed_messengers */ |
1314 | 1314 | $default_mts = $installed_messengers[$messenger]->get_default_message_types(); |
1315 | 1315 | $active_messengers[$messenger]['obj'] = $installed_messengers[$messenger]; |
1316 | - foreach ( $default_mts as $index => $mt ) { |
|
1316 | + foreach ($default_mts as $index => $mt) { |
|
1317 | 1317 | //is there an installed_mt matching the default string? If not then nothing to do here. |
1318 | - if ( ! isset( $installed_mts[$mt] ) ) { |
|
1319 | - unset( $default_mts[$index] ); |
|
1318 | + if ( ! isset($installed_mts[$mt])) { |
|
1319 | + unset($default_mts[$index]); |
|
1320 | 1320 | continue; |
1321 | 1321 | } |
1322 | 1322 | |
@@ -1325,41 +1325,41 @@ discard block |
||
1325 | 1325 | /** @var EE_message_type[] $installed_mts */ |
1326 | 1326 | $settings_fields = $installed_mts[$mt]->get_admin_settings_fields(); |
1327 | 1327 | $settings = array(); |
1328 | - if ( is_array( $settings_fields ) ) { |
|
1329 | - foreach ( $settings_fields as $field => $values ) { |
|
1330 | - if ( isset( $values['default'] ) ) { |
|
1328 | + if (is_array($settings_fields)) { |
|
1329 | + foreach ($settings_fields as $field => $values) { |
|
1330 | + if (isset($values['default'])) { |
|
1331 | 1331 | $settings[$field] = $values['default']; |
1332 | 1332 | } |
1333 | 1333 | } |
1334 | 1334 | } |
1335 | 1335 | |
1336 | - $active_messengers[$messenger]['settings'][$messenger . '-message_types'][$mt]['settings'] = $settings; |
|
1336 | + $active_messengers[$messenger]['settings'][$messenger.'-message_types'][$mt]['settings'] = $settings; |
|
1337 | 1337 | $has_activated[$messenger][] = $mt; |
1338 | 1338 | } |
1339 | 1339 | |
1340 | 1340 | //setup any initial settings for the messenger |
1341 | 1341 | $msgr_settings = $installed_messengers[$messenger]->get_admin_settings_fields(); |
1342 | 1342 | |
1343 | - if ( !empty( $msgr_settings ) ) { |
|
1344 | - foreach ( $msgr_settings as $field => $value ) { |
|
1343 | + if ( ! empty($msgr_settings)) { |
|
1344 | + foreach ($msgr_settings as $field => $value) { |
|
1345 | 1345 | $active_messengers[$messenger]['settings'][$field] = $value; |
1346 | 1346 | } |
1347 | 1347 | } |
1348 | 1348 | |
1349 | 1349 | //now let's save the settings for this messenger! Must do now because the validator checks the db for active messengers to validate. |
1350 | - EEH_MSG_Template::update_active_messengers_in_db( $active_messengers ); |
|
1350 | + EEH_MSG_Template::update_active_messengers_in_db($active_messengers); |
|
1351 | 1351 | |
1352 | 1352 | //let's generate all the templates but only if the messenger has default_mts (otherwise its just activated). |
1353 | - if ( !empty( $default_mts ) ) { |
|
1354 | - $success = EEH_MSG_Template::generate_new_templates( $messenger, $default_mts, '', TRUE ); |
|
1353 | + if ( ! empty($default_mts)) { |
|
1354 | + $success = EEH_MSG_Template::generate_new_templates($messenger, $default_mts, '', TRUE); |
|
1355 | 1355 | } |
1356 | 1356 | } |
1357 | 1357 | } //end check for empty( $def_ms ) |
1358 | 1358 | |
1359 | 1359 | //still need to see if there are any message types to activate for active messengers |
1360 | - foreach ( $active_messengers as $messenger => $settings ) { |
|
1360 | + foreach ($active_messengers as $messenger => $settings) { |
|
1361 | 1361 | $msg_obj = $settings['obj']; |
1362 | - if ( ! $msg_obj instanceof EE_messenger ) { |
|
1362 | + if ( ! $msg_obj instanceof EE_messenger) { |
|
1363 | 1363 | continue; |
1364 | 1364 | } |
1365 | 1365 | |
@@ -1367,45 +1367,45 @@ discard block |
||
1367 | 1367 | $new_default_mts = array(); |
1368 | 1368 | |
1369 | 1369 | //loop through each default mt reported by the messenger and make sure its set in its active db entry. |
1370 | - foreach( $all_default_mts as $index => $mt ) { |
|
1370 | + foreach ($all_default_mts as $index => $mt) { |
|
1371 | 1371 | //already active? already has generated templates? || has already been activated before (we dont' want to reactivate things users intentionally deactivated). |
1372 | - if ( ( isset( $has_activated[$messenger] ) && in_array($mt, $has_activated[$messenger]) ) || isset( $active_messengers[$messenger]['settings'][$messenger . '-message_types'][$mt] ) || EEH_MSG_Template::already_generated( $messenger, $mt, 0, FALSE ) ) { |
|
1372 | + if ((isset($has_activated[$messenger]) && in_array($mt, $has_activated[$messenger])) || isset($active_messengers[$messenger]['settings'][$messenger.'-message_types'][$mt]) || EEH_MSG_Template::already_generated($messenger, $mt, 0, FALSE)) { |
|
1373 | 1373 | continue; |
1374 | 1374 | } |
1375 | 1375 | |
1376 | 1376 | //is there an installed_mt matching the default string? If not then nothing to do here. |
1377 | - if ( ! isset( $installed_mts[$mt] ) ) { |
|
1378 | - unset( $all_default_mts[$mt] ); |
|
1377 | + if ( ! isset($installed_mts[$mt])) { |
|
1378 | + unset($all_default_mts[$mt]); |
|
1379 | 1379 | continue; |
1380 | 1380 | } |
1381 | 1381 | |
1382 | 1382 | $settings_fields = $installed_mts[$mt]->get_admin_settings_fields(); |
1383 | 1383 | $settings = array(); |
1384 | - if ( is_array( $settings_fields ) ) { |
|
1385 | - foreach ( $settings_fields as $field => $values ) { |
|
1386 | - if ( isset( $values['default'] ) ) { |
|
1384 | + if (is_array($settings_fields)) { |
|
1385 | + foreach ($settings_fields as $field => $values) { |
|
1386 | + if (isset($values['default'])) { |
|
1387 | 1387 | $settings[$field] = $values['default']; |
1388 | 1388 | } |
1389 | 1389 | } |
1390 | 1390 | } |
1391 | 1391 | |
1392 | - $active_messengers[$messenger]['settings'][$messenger . '-message_types'][$mt]['settings'] = $settings; |
|
1392 | + $active_messengers[$messenger]['settings'][$messenger.'-message_types'][$mt]['settings'] = $settings; |
|
1393 | 1393 | $new_default_mts[] = $mt; |
1394 | 1394 | $has_activated[$messenger][] = $mt; |
1395 | 1395 | } |
1396 | 1396 | |
1397 | 1397 | |
1398 | - if ( ! empty( $new_default_mts ) ) { |
|
1399 | - $success = EEH_MSG_Template::generate_new_templates( $messenger, $new_default_mts, '', TRUE ); |
|
1398 | + if ( ! empty($new_default_mts)) { |
|
1399 | + $success = EEH_MSG_Template::generate_new_templates($messenger, $new_default_mts, '', TRUE); |
|
1400 | 1400 | } |
1401 | 1401 | |
1402 | 1402 | } |
1403 | 1403 | |
1404 | 1404 | //now let's save the settings for this messenger! |
1405 | - EEH_MSG_Template::update_active_messengers_in_db( $active_messengers ); |
|
1405 | + EEH_MSG_Template::update_active_messengers_in_db($active_messengers); |
|
1406 | 1406 | |
1407 | 1407 | //update $has_activated record |
1408 | - update_option( 'ee_has_activated_messenger', $has_activated ); |
|
1408 | + update_option('ee_has_activated_messenger', $has_activated); |
|
1409 | 1409 | |
1410 | 1410 | //that's it! |
1411 | 1411 | return $success; |
@@ -1425,47 +1425,47 @@ discard block |
||
1425 | 1425 | */ |
1426 | 1426 | public static function validate_messages_system() { |
1427 | 1427 | //include our helper |
1428 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
1428 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
1429 | 1429 | |
1430 | 1430 | //get active and installed messengers/message types. |
1431 | 1431 | $active_messengers = EEH_MSG_Template::get_active_messengers_in_db(); |
1432 | 1432 | $installed = EEH_MSG_Template::get_installed_message_objects(); |
1433 | 1433 | $installed_messengers = $installed_mts = array(); |
1434 | 1434 | //set up the arrays so they can be handled easier. |
1435 | - foreach( $installed['messengers'] as $im ) { |
|
1436 | - if ( $im instanceof EE_messenger ) { |
|
1435 | + foreach ($installed['messengers'] as $im) { |
|
1436 | + if ($im instanceof EE_messenger) { |
|
1437 | 1437 | $installed_messengers[$im->name] = $im; |
1438 | 1438 | } |
1439 | 1439 | } |
1440 | - foreach( $installed['message_types'] as $imt ) { |
|
1441 | - if ( $imt instanceof EE_message_type ) { |
|
1440 | + foreach ($installed['message_types'] as $imt) { |
|
1441 | + if ($imt instanceof EE_message_type) { |
|
1442 | 1442 | $installed_mts[$imt->name] = $imt; |
1443 | 1443 | } |
1444 | 1444 | } |
1445 | 1445 | |
1446 | 1446 | //now let's loop through the active array and validate |
1447 | - foreach( $active_messengers as $messenger => $active_details ) { |
|
1447 | + foreach ($active_messengers as $messenger => $active_details) { |
|
1448 | 1448 | //first let's see if this messenger is installed. |
1449 | - if ( ! isset( $installed_messengers[$messenger] ) ) { |
|
1449 | + if ( ! isset($installed_messengers[$messenger])) { |
|
1450 | 1450 | //not set so let's just remove from actives and make sure templates are inactive. |
1451 | - unset( $active_messengers[$messenger] ); |
|
1452 | - EEH_MSG_Template::update_to_inactive( $messenger ); |
|
1451 | + unset($active_messengers[$messenger]); |
|
1452 | + EEH_MSG_Template::update_to_inactive($messenger); |
|
1453 | 1453 | continue; |
1454 | 1454 | } |
1455 | 1455 | |
1456 | 1456 | //messenger is active, so let's just make sure that any active message types not installed are deactivated. |
1457 | - $mts = ! empty( $active_details['settings'][$messenger . '-message_types'] ) ? $active_details['settings'][$messenger . '-message_types'] : array(); |
|
1458 | - foreach ( $mts as $mt_name => $mt ) { |
|
1459 | - if ( ! isset( $installed_mts[$mt_name] ) ) { |
|
1460 | - unset( $active_messengers[$messenger]['settings'][$messenger . '-message_types'][$mt_name] ); |
|
1461 | - EEH_MSG_Template::update_to_inactive( $messenger, $mt_name ); |
|
1457 | + $mts = ! empty($active_details['settings'][$messenger.'-message_types']) ? $active_details['settings'][$messenger.'-message_types'] : array(); |
|
1458 | + foreach ($mts as $mt_name => $mt) { |
|
1459 | + if ( ! isset($installed_mts[$mt_name])) { |
|
1460 | + unset($active_messengers[$messenger]['settings'][$messenger.'-message_types'][$mt_name]); |
|
1461 | + EEH_MSG_Template::update_to_inactive($messenger, $mt_name); |
|
1462 | 1462 | } |
1463 | 1463 | } |
1464 | 1464 | } |
1465 | 1465 | |
1466 | 1466 | //all done! let's update the active_messengers. |
1467 | - EEH_MSG_Template::update_active_messengers_in_db( $active_messengers ); |
|
1468 | - do_action( 'AHEE__EEH_Activation__validate_messages_system' ); |
|
1467 | + EEH_MSG_Template::update_active_messengers_in_db($active_messengers); |
|
1468 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1469 | 1469 | return; |
1470 | 1470 | } |
1471 | 1471 | |
@@ -1479,12 +1479,12 @@ discard block |
||
1479 | 1479 | * @static |
1480 | 1480 | * @return void |
1481 | 1481 | */ |
1482 | - public static function create_no_ticket_prices_array(){ |
|
1482 | + public static function create_no_ticket_prices_array() { |
|
1483 | 1483 | // this creates an array for tracking events that have no active ticket prices created |
1484 | 1484 | // this allows us to warn admins of the situation so that it can be corrected |
1485 | - $espresso_no_ticket_prices = get_option( 'ee_no_ticket_prices', FALSE ); |
|
1486 | - if ( ! $espresso_no_ticket_prices ) { |
|
1487 | - add_option( 'ee_no_ticket_prices', array(), '', FALSE ); |
|
1485 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', FALSE); |
|
1486 | + if ( ! $espresso_no_ticket_prices) { |
|
1487 | + add_option('ee_no_ticket_prices', array(), '', FALSE); |
|
1488 | 1488 | } |
1489 | 1489 | } |
1490 | 1490 | |
@@ -1506,24 +1506,24 @@ discard block |
||
1506 | 1506 | * Finds all our EE4 custom post types, and deletes them and their associated data (like post meta or term relations)/ |
1507 | 1507 | * @global wpdb $wpdb |
1508 | 1508 | */ |
1509 | - public static function delete_all_espresso_cpt_data(){ |
|
1509 | + public static function delete_all_espresso_cpt_data() { |
|
1510 | 1510 | global $wpdb; |
1511 | 1511 | //get all the CPT post_types |
1512 | 1512 | $ee_post_types = array(); |
1513 | - foreach(EE_Registry::instance()->non_abstract_db_models as $model_name){ |
|
1514 | - if ( method_exists( $model_name, 'instance' )) { |
|
1515 | - $model_obj = call_user_func( array( $model_name, 'instance' )); |
|
1516 | - if ( $model_obj instanceof EEM_CPT_Base ) { |
|
1517 | - $ee_post_types[] = $wpdb->prepare("%s",$model_obj->post_type()); |
|
1513 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1514 | + if (method_exists($model_name, 'instance')) { |
|
1515 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1516 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
1517 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1518 | 1518 | } |
1519 | 1519 | } |
1520 | 1520 | } |
1521 | 1521 | //get all our CPTs |
1522 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",",$ee_post_types).")"; |
|
1522 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")"; |
|
1523 | 1523 | $cpt_ids = $wpdb->get_col($query); |
1524 | 1524 | //delete each post meta and term relations too |
1525 | - foreach($cpt_ids as $post_id){ |
|
1526 | - wp_delete_post($post_id,true); |
|
1525 | + foreach ($cpt_ids as $post_id) { |
|
1526 | + wp_delete_post($post_id, true); |
|
1527 | 1527 | } |
1528 | 1528 | } |
1529 | 1529 | |
@@ -1537,18 +1537,18 @@ discard block |
||
1537 | 1537 | * @param bool $remove_all |
1538 | 1538 | * @return void |
1539 | 1539 | */ |
1540 | - public static function delete_all_espresso_tables_and_data( $remove_all = true ) { |
|
1540 | + public static function delete_all_espresso_tables_and_data($remove_all = true) { |
|
1541 | 1541 | global $wpdb; |
1542 | 1542 | $undeleted_tables = array(); |
1543 | 1543 | |
1544 | 1544 | // load registry |
1545 | - foreach( EE_Registry::instance()->non_abstract_db_models as $model_name ){ |
|
1546 | - if ( method_exists( $model_name, 'instance' )) { |
|
1547 | - $model_obj = call_user_func( array( $model_name, 'instance' )); |
|
1548 | - if ( $model_obj instanceof EEM_Base ) { |
|
1549 | - foreach ( $model_obj->get_tables() as $table ) { |
|
1550 | - if ( strpos( $table->get_table_name(), 'esp_' )) { |
|
1551 | - switch ( EEH_Activation::delete_unused_db_table( $table->get_table_name() )) { |
|
1545 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1546 | + if (method_exists($model_name, 'instance')) { |
|
1547 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1548 | + if ($model_obj instanceof EEM_Base) { |
|
1549 | + foreach ($model_obj->get_tables() as $table) { |
|
1550 | + if (strpos($table->get_table_name(), 'esp_')) { |
|
1551 | + switch (EEH_Activation::delete_unused_db_table($table->get_table_name())) { |
|
1552 | 1552 | case false : |
1553 | 1553 | $undeleted_tables[] = $table->get_table_name(); |
1554 | 1554 | break; |
@@ -1573,8 +1573,8 @@ discard block |
||
1573 | 1573 | 'esp_promotion_rule', |
1574 | 1574 | 'esp_rule' |
1575 | 1575 | ); |
1576 | - foreach( $tables_without_models as $table ){ |
|
1577 | - EEH_Activation::delete_db_table_if_empty( $table ); |
|
1576 | + foreach ($tables_without_models as $table) { |
|
1577 | + EEH_Activation::delete_db_table_if_empty($table); |
|
1578 | 1578 | } |
1579 | 1579 | |
1580 | 1580 | |
@@ -1611,58 +1611,58 @@ discard block |
||
1611 | 1611 | 'ee_pers_admin_notices' => true, |
1612 | 1612 | 'ee_upload_directories_incomplete' => true, |
1613 | 1613 | ); |
1614 | - if( is_main_site() ) { |
|
1615 | - $wp_options_to_delete[ 'ee_network_config' ] = true; |
|
1614 | + if (is_main_site()) { |
|
1615 | + $wp_options_to_delete['ee_network_config'] = true; |
|
1616 | 1616 | } |
1617 | 1617 | |
1618 | 1618 | $undeleted_options = array(); |
1619 | - foreach ( $wp_options_to_delete as $option_name => $no_wildcard ) { |
|
1619 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1620 | 1620 | |
1621 | - if( $no_wildcard ){ |
|
1622 | - if( ! delete_option( $option_name ) ){ |
|
1621 | + if ($no_wildcard) { |
|
1622 | + if ( ! delete_option($option_name)) { |
|
1623 | 1623 | $undeleted_options[] = $option_name; |
1624 | 1624 | } |
1625 | - }else{ |
|
1626 | - $option_names_to_delete_from_wildcard = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'" ); |
|
1627 | - foreach($option_names_to_delete_from_wildcard as $option_name_from_wildcard ){ |
|
1628 | - if( ! delete_option( $option_name_from_wildcard ) ){ |
|
1625 | + } else { |
|
1626 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1627 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1628 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
1629 | 1629 | $undeleted_options[] = $option_name_from_wildcard; |
1630 | 1630 | } |
1631 | 1631 | } |
1632 | 1632 | } |
1633 | 1633 | } |
1634 | 1634 | //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
1635 | - remove_action( 'shutdown', array( EE_Config::instance(), 'shutdown' ), 10 ); |
|
1635 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1636 | 1636 | |
1637 | - if ( $remove_all && $espresso_db_update = get_option( 'espresso_db_update' )) { |
|
1637 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1638 | 1638 | $db_update_sans_ee4 = array(); |
1639 | - foreach($espresso_db_update as $version => $times_activated){ |
|
1640 | - if( $version[0] =='3'){//if its NON EE4 |
|
1639 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
1640 | + if ($version[0] == '3') {//if its NON EE4 |
|
1641 | 1641 | $db_update_sans_ee4[$version] = $times_activated; |
1642 | 1642 | } |
1643 | 1643 | } |
1644 | - update_option( 'espresso_db_update', $db_update_sans_ee4 ); |
|
1644 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
1645 | 1645 | } |
1646 | 1646 | |
1647 | 1647 | $errors = ''; |
1648 | - if ( ! empty( $undeleted_tables )) { |
|
1648 | + if ( ! empty($undeleted_tables)) { |
|
1649 | 1649 | $errors .= sprintf( |
1650 | - __( 'The following tables could not be deleted: %s%s', 'event_espresso' ), |
|
1650 | + __('The following tables could not be deleted: %s%s', 'event_espresso'), |
|
1651 | 1651 | '<br/>', |
1652 | - implode( ',<br/>', $undeleted_tables ) |
|
1652 | + implode(',<br/>', $undeleted_tables) |
|
1653 | 1653 | ); |
1654 | 1654 | } |
1655 | - if ( ! empty( $undeleted_options )) { |
|
1656 | - $errors .= ! empty( $undeleted_tables ) ? '<br/>' : ''; |
|
1655 | + if ( ! empty($undeleted_options)) { |
|
1656 | + $errors .= ! empty($undeleted_tables) ? '<br/>' : ''; |
|
1657 | 1657 | $errors .= sprintf( |
1658 | - __( 'The following wp-options could not be deleted: %s%s', 'event_espresso' ), |
|
1658 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1659 | 1659 | '<br/>', |
1660 | - implode( ',<br/>', $undeleted_options ) |
|
1660 | + implode(',<br/>', $undeleted_options) |
|
1661 | 1661 | ); |
1662 | 1662 | |
1663 | 1663 | } |
1664 | - if ( $errors != '' ) { |
|
1665 | - EE_Error::add_attention( $errors, __FILE__, __FUNCTION__, __LINE__ ); |
|
1664 | + if ($errors != '') { |
|
1665 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1666 | 1666 | } |
1667 | 1667 | } |
1668 | 1668 | |
@@ -1672,23 +1672,23 @@ discard block |
||
1672 | 1672 | * @param string $table_name with or without $wpdb->prefix |
1673 | 1673 | * @return boolean |
1674 | 1674 | */ |
1675 | - public static function table_exists( $table_name ){ |
|
1675 | + public static function table_exists($table_name) { |
|
1676 | 1676 | global $wpdb, $EZSQL_ERROR; |
1677 | - $table_name = EEH_Activation::ensure_table_name_has_prefix( $table_name ); |
|
1677 | + $table_name = EEH_Activation::ensure_table_name_has_prefix($table_name); |
|
1678 | 1678 | //ignore if this causes an sql error |
1679 | 1679 | $old_error = $wpdb->last_error; |
1680 | 1680 | $old_suppress_errors = $wpdb->suppress_errors(); |
1681 | - $old_show_errors_value = $wpdb->show_errors( FALSE ); |
|
1681 | + $old_show_errors_value = $wpdb->show_errors(FALSE); |
|
1682 | 1682 | $ezsql_error_cache = $EZSQL_ERROR; |
1683 | - $wpdb->get_results( "SELECT * from $table_name LIMIT 1"); |
|
1684 | - $wpdb->show_errors( $old_show_errors_value ); |
|
1685 | - $wpdb->suppress_errors( $old_suppress_errors ); |
|
1683 | + $wpdb->get_results("SELECT * from $table_name LIMIT 1"); |
|
1684 | + $wpdb->show_errors($old_show_errors_value); |
|
1685 | + $wpdb->suppress_errors($old_suppress_errors); |
|
1686 | 1686 | $new_error = $wpdb->last_error; |
1687 | 1687 | $wpdb->last_error = $old_error; |
1688 | 1688 | $EZSQL_ERROR = $ezsql_error_cache; |
1689 | - if( empty( $new_error ) ){ |
|
1689 | + if (empty($new_error)) { |
|
1690 | 1690 | return TRUE; |
1691 | - }else{ |
|
1691 | + } else { |
|
1692 | 1692 | return FALSE; |
1693 | 1693 | } |
1694 | 1694 | } |
@@ -1696,7 +1696,7 @@ discard block |
||
1696 | 1696 | /** |
1697 | 1697 | * Resets the cache on EEH_Activation |
1698 | 1698 | */ |
1699 | - public static function reset(){ |
|
1699 | + public static function reset() { |
|
1700 | 1700 | self::$_default_creator_id = NULL; |
1701 | 1701 | self::$_initialized_db_content_already_in_this_request = false; |
1702 | 1702 | } |
@@ -32,7 +32,6 @@ |
||
32 | 32 | /** |
33 | 33 | * |
34 | 34 | * @param string $model_name |
35 | - * @param string $comparison_model_name |
|
36 | 35 | * @param string $id_or_name_field should be the string 'ID' or 'name' only |
37 | 36 | * @return EE_Model_Field_Base |
38 | 37 | */ |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Joins any two models together via a has-and-belongs-to-many relation, using |
4 | 4 | * the esp_extra_join table. |
5 | 5 | */ |
6 | -class EE_HABTM_Any_Relation extends EE_HABTM_Relation{ |
|
6 | +class EE_HABTM_Any_Relation extends EE_HABTM_Relation { |
|
7 | 7 | /** |
8 | 8 | * |
9 | 9 | * @var string |
@@ -17,16 +17,16 @@ discard block |
||
17 | 17 | * @param boolean $block_deletes for this type of relation, we block by default for now. if there are related models across this relation, block (prevent and add an error) the deletion of this model |
18 | 18 | * @param type $blocking_delete_error_message a customized error message on blocking deletes instead of the default |
19 | 19 | */ |
20 | - function __construct( $block_deletes = true, $blocking_delete_error_message =''){ |
|
21 | - parent::__construct( 'Extra_Join', $block_deletes, $blocking_delete_error_message); |
|
20 | + function __construct($block_deletes = true, $blocking_delete_error_message = '') { |
|
21 | + parent::__construct('Extra_Join', $block_deletes, $blocking_delete_error_message); |
|
22 | 22 | } |
23 | - function _construct_finalize_set_models($this_model_name, $other_model_name){ |
|
24 | - if( $this_model_name < $other_model_name ) { |
|
23 | + function _construct_finalize_set_models($this_model_name, $other_model_name) { |
|
24 | + if ($this_model_name < $other_model_name) { |
|
25 | 25 | $this->_alphabetically_first_model_name = $this_model_name; |
26 | - } else{ |
|
26 | + } else { |
|
27 | 27 | $this->_alphabetically_first_model_name = $other_model_name; |
28 | 28 | } |
29 | - return parent::_construct_finalize_set_models( $this_model_name, $other_model_name ); |
|
29 | + return parent::_construct_finalize_set_models($this_model_name, $other_model_name); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -36,21 +36,21 @@ discard block |
||
36 | 36 | * @param string $id_or_name_field should be the string 'ID' or 'name' only |
37 | 37 | * @return EE_Model_Field_Base |
38 | 38 | */ |
39 | - function get_join_table_fk_field_to( $model_name, $id_or_name_field ) { |
|
39 | + function get_join_table_fk_field_to($model_name, $id_or_name_field) { |
|
40 | 40 | $order = null; |
41 | - if( $model_name === $this->_alphabetically_first_model_name ) { |
|
41 | + if ($model_name === $this->_alphabetically_first_model_name) { |
|
42 | 42 | $order = 'first'; |
43 | 43 | } else { |
44 | 44 | $order = 'second'; |
45 | 45 | } |
46 | - return $this->get_join_model()->field_settings_for( 'EXJ_' . $order . '_model_' . $id_or_name_field ); |
|
46 | + return $this->get_join_model()->field_settings_for('EXJ_'.$order.'_model_'.$id_or_name_field); |
|
47 | 47 | } |
48 | 48 | /** |
49 | 49 | * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table" |
50 | 50 | * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
51 | 51 | * @return string of SQL |
52 | 52 | */ |
53 | - function get_join_to_intermediate_model_statement($model_relation_chain){ |
|
53 | + function get_join_to_intermediate_model_statement($model_relation_chain) { |
|
54 | 54 | //create sql like |
55 | 55 | //LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
56 | 56 | //LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | $field_with_model_name = $this->get_join_table_fk_field_to( |
65 | 65 | $this->get_this_model()->get_this_model_name(), |
66 | 66 | 'name' ); |
67 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
68 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
67 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()).$this_table_pk_field->get_table_alias(); |
|
68 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias(); |
|
69 | 69 | $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
70 | 70 | //phew! ok, we have all the info we need, now we can create the SQL join string |
71 | 71 | $SQL = $this->_left_join( |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $join_table_fk_field_to_this_table->get_table_column(), |
75 | 75 | $this_table_alias, |
76 | 76 | $this_table_pk_field->get_table_column(), |
77 | - $field_with_model_name->get_qualified_column()."='".$this->get_this_model()->get_this_model_name()."'" ) . |
|
77 | + $field_with_model_name->get_qualified_column()."='".$this->get_this_model()->get_this_model_name()."'" ). |
|
78 | 78 | $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
79 | 79 | |
80 | 80 | return $SQL; |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
88 | 88 | * @return string of SQL |
89 | 89 | */ |
90 | - function get_join_statement($model_relation_chain){ |
|
91 | - if( $this->_model_relation_chain_to_join_model === NULL ){ |
|
92 | - throw new EE_Error( sprintf( __( 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', 'event_espresso' ))); |
|
90 | + function get_join_statement($model_relation_chain) { |
|
91 | + if ($this->_model_relation_chain_to_join_model === NULL) { |
|
92 | + throw new EE_Error(sprintf(__('When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', 'event_espresso'))); |
|
93 | 93 | } |
94 | 94 | $join_table_fk_field_to_this_table = $this->get_join_table_fk_field_to( |
95 | 95 | $this->get_this_model()->get_this_model_name(), |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | $this->get_other_model()->get_this_model_name(), |
102 | 102 | 'name' ); |
103 | 103 | |
104 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model, $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
104 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model, $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias(); |
|
105 | 105 | |
106 | 106 | $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
107 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias(); |
|
107 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()).$other_table_pk_field->get_table_alias(); |
|
108 | 108 | $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
109 | 109 | |
110 | 110 | $SQL = $this->_left_join( |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $join_table_alias, |
115 | 115 | $join_table_fk_field_to_other_table->get_table_column(), |
116 | 116 | $field_with_other_model_name->get_qualified_column()."='".$this->get_other_model()->get_this_model_name()."'" |
117 | - ) . |
|
117 | + ). |
|
118 | 118 | $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
119 | 119 | return $SQL; |
120 | 120 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param array $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for checking existing values and for setting new rows if no exact matches. |
127 | 127 | * @return EE_Base_Class |
128 | 128 | */ |
129 | - function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array() ){ |
|
129 | + function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) { |
|
130 | 130 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
131 | 131 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
132 | 132 | //check if such a relationship already exists |
@@ -143,31 +143,31 @@ discard block |
||
143 | 143 | $this->get_other_model()->get_this_model_name(), |
144 | 144 | 'name' ); |
145 | 145 | |
146 | - $cols_n_values = array( |
|
146 | + $cols_n_values = array( |
|
147 | 147 | $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
148 | 148 | $join_model_name_field_to_this_model->get_name() => $this_model_obj->get_model()->get_this_model_name(), |
149 | 149 | $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
150 | 150 | $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name() ); |
151 | 151 | |
152 | 152 | //if $where_query exists lets add them to the query_params. |
153 | - if ( !empty( $extra_join_model_fields_n_values ) ) { |
|
153 | + if ( ! empty($extra_join_model_fields_n_values)) { |
|
154 | 154 | //make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
155 | 155 | //make sure we strip THIS models name from the query param |
156 | - foreach ( $extra_join_model_fields_n_values as $query_param => $val ) { |
|
157 | - $query_param = str_replace($this->get_join_model()->get_this_model_name().".","", $query_param); |
|
156 | + foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
157 | + $query_param = str_replace($this->get_join_model()->get_this_model_name().".", "", $query_param); |
|
158 | 158 | $parsed_query[$query_param] = $val; |
159 | 159 | } |
160 | - $cols_n_values = array_merge( $cols_n_values, $parsed_query ); |
|
160 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
161 | 161 | } |
162 | 162 | |
163 | - $query_params = array( $cols_n_values ); |
|
163 | + $query_params = array($cols_n_values); |
|
164 | 164 | |
165 | 165 | |
166 | 166 | $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params); |
167 | 167 | //if there is already an entry in the join table, indicating a relationship, we're done |
168 | 168 | //again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
169 | 169 | //the other tables, use the joining model directly! |
170 | - if( ! $existing_entry_in_join_table ){ |
|
170 | + if ( ! $existing_entry_in_join_table) { |
|
171 | 171 | $this->get_join_model()->insert($cols_n_values); |
172 | 172 | } |
173 | 173 | return $other_model_obj; |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * * @param array $where_query col=>val pairs that are used as extra conditions for checking existing values and for removing existing rows if exact matches exist. |
180 | 180 | * @return EE_Base_Class |
181 | 181 | */ |
182 | - function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array() ){ |
|
182 | + function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) { |
|
183 | 183 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
184 | 184 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
185 | 185 | //check if such a relationship already exists |
@@ -196,24 +196,24 @@ discard block |
||
196 | 196 | $this->get_other_model()->get_this_model_name(), |
197 | 197 | 'name' ); |
198 | 198 | |
199 | - $cols_n_values = array( |
|
199 | + $cols_n_values = array( |
|
200 | 200 | $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
201 | 201 | $join_model_name_field_to_this_model->get_name() => $this_model_obj->get_model()->get_this_model_name(), |
202 | 202 | $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
203 | 203 | $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name() ); |
204 | 204 | |
205 | 205 | //if $where_query exists lets add them to the query_params. |
206 | - if ( !empty( $where_query ) ) { |
|
206 | + if ( ! empty($where_query)) { |
|
207 | 207 | //make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
208 | 208 | //make sure we strip THIS models name from the query param |
209 | - foreach ( $where_query as $query_param => $val ) { |
|
210 | - $query_param = str_replace($this->get_join_model()->get_this_model_name().".","", $query_param); |
|
209 | + foreach ($where_query as $query_param => $val) { |
|
210 | + $query_param = str_replace($this->get_join_model()->get_this_model_name().".", "", $query_param); |
|
211 | 211 | $parsed_query[$query_param] = $val; |
212 | 212 | } |
213 | - $cols_n_values = array_merge( $cols_n_values, $parsed_query ); |
|
213 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
214 | 214 | } |
215 | 215 | |
216 | - $existing_entry_in_join_table = $this->get_join_model()->delete( array($cols_n_values) ); |
|
216 | + $existing_entry_in_join_table = $this->get_join_model()->delete(array($cols_n_values)); |
|
217 | 217 | return $other_model_obj; |
218 | 218 | } |
219 | 219 | } |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
2 | 2 | /** |
3 | - * Contains definition for EE_Extra_Join model object |
|
4 | - * @package Event Espresso |
|
5 | - * @subpackage models |
|
6 | - * @since $VID$ |
|
7 | - */ |
|
3 | + * Contains definition for EE_Extra_Join model object |
|
4 | + * @package Event Espresso |
|
5 | + * @subpackage models |
|
6 | + * @since $VID$ |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * EE_Extra_Join |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | * @param null $timezone |
23 | 23 | * @return EE_Event_Message_Template|mixed |
24 | 24 | */ |
25 | - public static function new_instance( $props_n_values = array(), $timezone = NULL ) { |
|
26 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone ); |
|
27 | - return $has_object ? $has_object : new self( $props_n_values, FALSE, $timezone ); |
|
25 | + public static function new_instance($props_n_values = array(), $timezone = NULL) { |
|
26 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
27 | + return $has_object ? $has_object : new self($props_n_values, FALSE, $timezone); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | * @param null $timezone |
35 | 35 | * @return EE_Event_Message_Template |
36 | 36 | */ |
37 | - public static function new_instance_from_db ( $props_n_values = array(), $timezone = NULL ) { |
|
38 | - return new self( $props_n_values, TRUE, $timezone ); |
|
37 | + public static function new_instance_from_db($props_n_values = array(), $timezone = NULL) { |
|
38 | + return new self($props_n_values, TRUE, $timezone); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | } |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | * @ version 4.0 |
13 | 13 | * |
14 | 14 | */ |
15 | -require_once( EE_HELPERS . 'EEH_Base.helper.php' ); |
|
16 | -require_once( EE_INTERFACES . 'EEI_Interfaces.php' ); |
|
15 | +require_once(EE_HELPERS.'EEH_Base.helper.php'); |
|
16 | +require_once(EE_INTERFACES.'EEI_Interfaces.php'); |
|
17 | 17 | /** |
18 | 18 | * |
19 | 19 | * Class EEH_File |
@@ -42,30 +42,30 @@ discard block |
||
42 | 42 | * @throws EE_Error |
43 | 43 | * @return WP_Filesystem_Base |
44 | 44 | */ |
45 | - private static function _get_wp_filesystem( $filepath = null) { |
|
46 | - if( apply_filters( |
|
45 | + private static function _get_wp_filesystem($filepath = null) { |
|
46 | + if (apply_filters( |
|
47 | 47 | 'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', |
48 | - $filepath && EEH_File::is_in_uploads_folder( $filepath ), |
|
49 | - $filepath ) ) { |
|
50 | - if( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct ) { |
|
51 | - require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); |
|
48 | + $filepath && EEH_File::is_in_uploads_folder($filepath), |
|
49 | + $filepath )) { |
|
50 | + if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
51 | + require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php'); |
|
52 | 52 | $method = 'direct'; |
53 | - $wp_filesystem_direct_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method ); |
|
53 | + $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method); |
|
54 | 54 | //check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem() |
55 | - if ( ! defined('FS_CHMOD_DIR') ) { |
|
56 | - define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) ); |
|
55 | + if ( ! defined('FS_CHMOD_DIR')) { |
|
56 | + define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755)); |
|
57 | 57 | } |
58 | - if ( ! defined('FS_CHMOD_FILE') ) { |
|
59 | - define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) ); |
|
58 | + if ( ! defined('FS_CHMOD_FILE')) { |
|
59 | + define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644)); |
|
60 | 60 | } |
61 | - require_once( $wp_filesystem_direct_file ); |
|
62 | - EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct( array() ); |
|
61 | + require_once($wp_filesystem_direct_file); |
|
62 | + EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array()); |
|
63 | 63 | } |
64 | 64 | return EEH_File::$_wp_filesystem_direct; |
65 | 65 | } |
66 | 66 | global $wp_filesystem; |
67 | 67 | // no filesystem setup ??? |
68 | - if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) { |
|
68 | + if ( ! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
69 | 69 | // if some eager beaver's just trying to get in there too early... |
70 | 70 | // let them do it, because we are one of those eager beavers! :P |
71 | 71 | /** |
@@ -78,34 +78,34 @@ discard block |
||
78 | 78 | * and there may be troubles if the WP files are owned by a different user |
79 | 79 | * than the server user. But both of these issues should exist in 4.4 and earlier too |
80 | 80 | */ |
81 | - if ( FALSE && ! did_action( 'wp_loaded' )) { |
|
81 | + if (FALSE && ! did_action('wp_loaded')) { |
|
82 | 82 | $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'); |
83 | - if ( WP_DEBUG ) { |
|
84 | - $msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
83 | + if (WP_DEBUG) { |
|
84 | + $msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
85 | 85 | } |
86 | - throw new EE_Error( $msg ); |
|
86 | + throw new EE_Error($msg); |
|
87 | 87 | } else { |
88 | 88 | // should be loaded if we are past the wp_loaded hook... |
89 | - if ( ! function_exists( 'WP_Filesystem' )) { |
|
90 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
91 | - require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
|
89 | + if ( ! function_exists('WP_Filesystem')) { |
|
90 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
91 | + require_once(ABSPATH.'wp-admin/includes/template.php'); |
|
92 | 92 | } |
93 | 93 | // turn on output buffering so that we can capture the credentials form |
94 | 94 | ob_start(); |
95 | - $credentials = request_filesystem_credentials( '' ); |
|
95 | + $credentials = request_filesystem_credentials(''); |
|
96 | 96 | // store credentials form for the time being |
97 | 97 | EEH_File::$_credentials_form = ob_get_clean(); |
98 | 98 | // basically check for direct or previously configured access |
99 | - if ( ! WP_Filesystem( $credentials ) ) { |
|
99 | + if ( ! WP_Filesystem($credentials)) { |
|
100 | 100 | // if credentials do NOT exist |
101 | - if ( $credentials === FALSE ) { |
|
102 | - add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 ); |
|
103 | - throw new EE_Error( __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
|
104 | - } elseif( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
105 | - add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 ); |
|
101 | + if ($credentials === FALSE) { |
|
102 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
103 | + throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
|
104 | + } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
|
105 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
106 | 106 | throw new EE_Error( |
107 | 107 | sprintf( |
108 | - __( 'WP Filesystem Error: $1%s', 'event_espresso' ), |
|
108 | + __('WP Filesystem Error: $1%s', 'event_espresso'), |
|
109 | 109 | $wp_filesystem->errors->get_error_message() ) ); |
110 | 110 | } |
111 | 111 | } |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | * display_request_filesystem_credentials_form |
119 | 119 | */ |
120 | 120 | public static function display_request_filesystem_credentials_form() { |
121 | - if ( ! empty( EEH_File::$_credentials_form )) { |
|
122 | - echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>'; |
|
121 | + if ( ! empty(EEH_File::$_credentials_form)) { |
|
122 | + echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>'; |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
@@ -137,29 +137,29 @@ discard block |
||
137 | 137 | * @throws EE_Error |
138 | 138 | * @return bool |
139 | 139 | */ |
140 | - public static function verify_filepath_and_permissions( $full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '' ) { |
|
140 | + public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') { |
|
141 | 141 | // load WP_Filesystem and set file permissions |
142 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
143 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
144 | - if ( ! $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) )) { |
|
145 | - $file_name = ! empty( $type_of_file ) ? $file_name . ' ' . $type_of_file : $file_name; |
|
146 | - $file_name .= ! empty( $file_ext ) ? ' file' : ' folder'; |
|
142 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
143 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
144 | + if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
145 | + $file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name; |
|
146 | + $file_name .= ! empty($file_ext) ? ' file' : ' folder'; |
|
147 | 147 | $msg = sprintf( |
148 | - __( 'The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso' ), |
|
148 | + __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'), |
|
149 | 149 | $file_name, |
150 | 150 | '<br />' |
151 | 151 | ); |
152 | - if ( EEH_File::exists( $full_file_path )) { |
|
153 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, $type_of_file ); |
|
152 | + if (EEH_File::exists($full_file_path)) { |
|
153 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file); |
|
154 | 154 | } else { |
155 | 155 | // no file permissions means the file was not found |
156 | 156 | $msg .= sprintf( |
157 | - __( 'Please ensure the following path is correct: "%s".', 'event_espresso' ), |
|
157 | + __('Please ensure the following path is correct: "%s".', 'event_espresso'), |
|
158 | 158 | $full_file_path |
159 | 159 | ); |
160 | 160 | } |
161 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
162 | - throw new EE_Error( $msg . '||' . $msg ); |
|
161 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
162 | + throw new EE_Error($msg.'||'.$msg); |
|
163 | 163 | } |
164 | 164 | return FALSE; |
165 | 165 | } |
@@ -176,24 +176,24 @@ discard block |
||
176 | 176 | * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages |
177 | 177 | * @return string |
178 | 178 | */ |
179 | - private static function _permissions_error_for_unreadable_filepath( $full_file_path = '', $type_of_file = '' ){ |
|
179 | + private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') { |
|
180 | 180 | // load WP_Filesystem and set file permissions |
181 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
181 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
182 | 182 | // check file permissions |
183 | - $perms = $wp_filesystem->getchmod( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ); |
|
184 | - if ( $perms ) { |
|
183 | + $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
184 | + if ($perms) { |
|
185 | 185 | // file permissions exist, but way be set incorrectly |
186 | - $type_of_file = ! empty( $type_of_file ) ? $type_of_file . ' ' : ''; |
|
187 | - $type_of_file .= ! empty( $type_of_file ) ? 'file' : 'folder'; |
|
186 | + $type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : ''; |
|
187 | + $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder'; |
|
188 | 188 | return sprintf( |
189 | - __( 'File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso' ), |
|
189 | + __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'), |
|
190 | 190 | $type_of_file, |
191 | 191 | $perms |
192 | 192 | ); |
193 | 193 | } else { |
194 | 194 | // file exists but file permissions could not be read ?!?! |
195 | 195 | return sprintf( |
196 | - __( 'Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso' ), |
|
196 | + __('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'), |
|
197 | 197 | $full_file_path |
198 | 198 | ); |
199 | 199 | } |
@@ -211,35 +211,35 @@ discard block |
||
211 | 211 | * can't write to it |
212 | 212 | * @return bool false if folder isn't writable; true if it exists and is writeable, |
213 | 213 | */ |
214 | - public static function ensure_folder_exists_and_is_writable( $folder = '' ){ |
|
215 | - if ( empty( $folder )) { |
|
214 | + public static function ensure_folder_exists_and_is_writable($folder = '') { |
|
215 | + if (empty($folder)) { |
|
216 | 216 | return false; |
217 | 217 | } |
218 | 218 | // remove ending DS |
219 | - $folder = EEH_File::standardise_directory_separators( rtrim( $folder, '/\\' )); |
|
220 | - $parent_folder = EEH_File::get_parent_folder( $folder ); |
|
219 | + $folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\')); |
|
220 | + $parent_folder = EEH_File::get_parent_folder($folder); |
|
221 | 221 | // add DS to folder |
222 | - $folder = EEH_File::end_with_directory_separator( $folder ); |
|
223 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $folder ); |
|
224 | - if ( ! $wp_filesystem->is_dir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) { |
|
222 | + $folder = EEH_File::end_with_directory_separator($folder); |
|
223 | + $wp_filesystem = EEH_File::_get_wp_filesystem($folder); |
|
224 | + if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
225 | 225 | //ok so it doesn't exist. Does its parent? Can we write to it? |
226 | - if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) { |
|
226 | + if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
227 | 227 | return false; |
228 | 228 | } |
229 | - if ( ! EEH_File::verify_is_writable( $parent_folder, 'folder' )) { |
|
229 | + if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
230 | 230 | return false; |
231 | 231 | } else { |
232 | - if ( ! $wp_filesystem->mkdir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) { |
|
233 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
234 | - $msg = sprintf( __( '"%s" could not be created.', 'event_espresso' ), $folder ); |
|
235 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $folder ); |
|
236 | - throw new EE_Error( $msg ); |
|
232 | + if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
233 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
234 | + $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder); |
|
235 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder); |
|
236 | + throw new EE_Error($msg); |
|
237 | 237 | } |
238 | 238 | return false; |
239 | 239 | } |
240 | - EEH_File::add_index_file( $folder ); |
|
240 | + EEH_File::add_index_file($folder); |
|
241 | 241 | } |
242 | - } elseif ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
242 | + } elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
243 | 243 | return false; |
244 | 244 | } |
245 | 245 | return true; |
@@ -254,15 +254,15 @@ discard block |
||
254 | 254 | * @throws EE_Error |
255 | 255 | * @return bool |
256 | 256 | */ |
257 | - public static function verify_is_writable( $full_path = '', $file_or_folder = 'folder' ){ |
|
257 | + public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') { |
|
258 | 258 | // load WP_Filesystem and set file permissions |
259 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_path ); |
|
260 | - $full_path = EEH_File::standardise_directory_separators( $full_path ); |
|
261 | - if ( ! $wp_filesystem->is_writable( EEH_File::convert_local_filepath_to_remote_filepath( $full_path ) ) ) { |
|
262 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
263 | - $msg = sprintf( __( 'The "%1$s" %2$s is not writable.', 'event_espresso' ), $full_path, $file_or_folder ); |
|
264 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_path ); |
|
265 | - throw new EE_Error( $msg ); |
|
259 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_path); |
|
260 | + $full_path = EEH_File::standardise_directory_separators($full_path); |
|
261 | + if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
262 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
263 | + $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder); |
|
264 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path); |
|
265 | + throw new EE_Error($msg); |
|
266 | 266 | } |
267 | 267 | return FALSE; |
268 | 268 | } |
@@ -279,25 +279,25 @@ discard block |
||
279 | 279 | * @throws EE_Error |
280 | 280 | * @return bool |
281 | 281 | */ |
282 | - public static function ensure_file_exists_and_is_writable( $full_file_path = '' ) { |
|
282 | + public static function ensure_file_exists_and_is_writable($full_file_path = '') { |
|
283 | 283 | // load WP_Filesystem and set file permissions |
284 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
285 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
286 | - $parent_folder = EEH_File::get_parent_folder( $full_file_path ); |
|
287 | - if ( ! EEH_File::exists( $full_file_path )) { |
|
288 | - if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) { |
|
284 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
285 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
286 | + $parent_folder = EEH_File::get_parent_folder($full_file_path); |
|
287 | + if ( ! EEH_File::exists($full_file_path)) { |
|
288 | + if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
289 | 289 | return false; |
290 | 290 | } |
291 | - if ( ! $wp_filesystem->touch( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) { |
|
292 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
293 | - $msg = sprintf( __( 'The "%s" file could not be created.', 'event_espresso' ), $full_file_path ); |
|
294 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path ); |
|
295 | - throw new EE_Error( $msg ); |
|
291 | + if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
292 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
293 | + $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path); |
|
294 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
295 | + throw new EE_Error($msg); |
|
296 | 296 | } |
297 | 297 | return false; |
298 | 298 | } |
299 | 299 | } |
300 | - if ( ! EEH_File::verify_is_writable( $full_file_path, 'file' )) { |
|
300 | + if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
301 | 301 | return false; |
302 | 302 | } |
303 | 303 | return true; |
@@ -309,15 +309,15 @@ discard block |
||
309 | 309 | * @param string $file_or_folder_path |
310 | 310 | * @return string parent folder, ENDING with a directory separator |
311 | 311 | */ |
312 | - public static function get_parent_folder( $file_or_folder_path ) { |
|
312 | + public static function get_parent_folder($file_or_folder_path) { |
|
313 | 313 | //find the last DS, ignoring a DS on the very end |
314 | 314 | //eg if given "/var/something/somewhere/", we want to get "somewhere"'s |
315 | 315 | //parent folder, "/var/something/" |
316 | - $ds = strrpos( $file_or_folder_path, DS, -2 ); |
|
317 | - return substr( $file_or_folder_path, 0, $ds + 1 ); |
|
316 | + $ds = strrpos($file_or_folder_path, DS, -2); |
|
317 | + return substr($file_or_folder_path, 0, $ds + 1); |
|
318 | 318 | } |
319 | 319 | |
320 | - public static function ensure_folder_exists_recursively( $folder ) { |
|
320 | + public static function ensure_folder_exists_recursively($folder) { |
|
321 | 321 | |
322 | 322 | } |
323 | 323 | |
@@ -328,12 +328,12 @@ discard block |
||
328 | 328 | * @param string $full_file_path |
329 | 329 | * @return string |
330 | 330 | */ |
331 | - public static function get_file_contents( $full_file_path = '' ){ |
|
332 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
333 | - if ( EEH_File::verify_filepath_and_permissions( $full_file_path, EEH_File::get_filename_from_filepath( $full_file_path ) , EEH_File::get_file_extension( $full_file_path ))) { |
|
331 | + public static function get_file_contents($full_file_path = '') { |
|
332 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
333 | + if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) { |
|
334 | 334 | // load WP_Filesystem and set file permissions |
335 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
336 | - return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ); |
|
335 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
336 | + return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
337 | 337 | } |
338 | 338 | return ''; |
339 | 339 | } |
@@ -348,26 +348,26 @@ discard block |
||
348 | 348 | * @throws EE_Error |
349 | 349 | * @return bool |
350 | 350 | */ |
351 | - public static function write_to_file( $full_file_path = '', $file_contents = '', $file_type = '' ){ |
|
352 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
353 | - $file_type = ! empty( $file_type ) ? rtrim( $file_type, ' ' ) . ' ' : ''; |
|
354 | - $folder = EEH_File::remove_filename_from_filepath( $full_file_path ); |
|
355 | - if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
356 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
357 | - $msg = sprintf( __( 'The %1$sfile located at "%2$s" is not writable.', 'event_espresso' ), $file_type, $full_file_path ); |
|
358 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path ); |
|
359 | - throw new EE_Error( $msg ); |
|
351 | + public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') { |
|
352 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
353 | + $file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : ''; |
|
354 | + $folder = EEH_File::remove_filename_from_filepath($full_file_path); |
|
355 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
356 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
357 | + $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path); |
|
358 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
359 | + throw new EE_Error($msg); |
|
360 | 360 | } |
361 | 361 | return FALSE; |
362 | 362 | } |
363 | 363 | // load WP_Filesystem and set file permissions |
364 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
364 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
365 | 365 | // write the file |
366 | - if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ), $file_contents )) { |
|
367 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
368 | - $msg = sprintf( __( 'The %1$sfile located at "%2$s" could not be written to.', 'event_espresso' ), $file_type, $full_file_path ); |
|
369 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, 'f' ); |
|
370 | - throw new EE_Error( $msg ); |
|
366 | + if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
367 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
368 | + $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path); |
|
369 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f'); |
|
370 | + throw new EE_Error($msg); |
|
371 | 371 | } |
372 | 372 | return FALSE; |
373 | 373 | } |
@@ -382,9 +382,9 @@ discard block |
||
382 | 382 | * @param boolean|string $type 'd' for directory, 'f' for file |
383 | 383 | * @return boolean |
384 | 384 | */ |
385 | - public static function delete( $filepath, $recursive = false, $type = false ) { |
|
385 | + public static function delete($filepath, $recursive = false, $type = false) { |
|
386 | 386 | $wp_filesystem = EEH_File::_get_wp_filesystem(); |
387 | - return $wp_filesystem->delete( $filepath, $recursive, $type ) ? TRUE : FALSE; |
|
387 | + return $wp_filesystem->delete($filepath, $recursive, $type) ? TRUE : FALSE; |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | |
@@ -396,9 +396,9 @@ discard block |
||
396 | 396 | * @param string $full_file_path |
397 | 397 | * @return bool |
398 | 398 | */ |
399 | - public static function exists( $full_file_path = '' ) { |
|
400 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
401 | - return $wp_filesystem->exists( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ? TRUE : FALSE; |
|
399 | + public static function exists($full_file_path = '') { |
|
400 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
401 | + return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? TRUE : FALSE; |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | |
@@ -410,9 +410,9 @@ discard block |
||
410 | 410 | * @param string $full_file_path |
411 | 411 | * @return bool |
412 | 412 | */ |
413 | - public static function is_readable( $full_file_path = '' ) { |
|
414 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
415 | - if( $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) { |
|
413 | + public static function is_readable($full_file_path = '') { |
|
414 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
415 | + if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
416 | 416 | return true; |
417 | 417 | } else { |
418 | 418 | return false; |
@@ -428,8 +428,8 @@ discard block |
||
428 | 428 | * @param string $full_file_path |
429 | 429 | * @return string |
430 | 430 | */ |
431 | - public static function remove_filename_from_filepath( $full_file_path = '' ) { |
|
432 | - return pathinfo( $full_file_path, PATHINFO_DIRNAME ); |
|
431 | + public static function remove_filename_from_filepath($full_file_path = '') { |
|
432 | + return pathinfo($full_file_path, PATHINFO_DIRNAME); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | |
@@ -439,8 +439,8 @@ discard block |
||
439 | 439 | * @param string $full_file_path |
440 | 440 | * @return string |
441 | 441 | */ |
442 | - public static function get_filename_from_filepath( $full_file_path = '' ) { |
|
443 | - return pathinfo( $full_file_path, PATHINFO_BASENAME ); |
|
442 | + public static function get_filename_from_filepath($full_file_path = '') { |
|
443 | + return pathinfo($full_file_path, PATHINFO_BASENAME); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | |
@@ -450,8 +450,8 @@ discard block |
||
450 | 450 | * @param string $full_file_path |
451 | 451 | * @return string |
452 | 452 | */ |
453 | - public static function get_file_extension( $full_file_path = '' ) { |
|
454 | - return pathinfo( $full_file_path, PATHINFO_EXTENSION ); |
|
453 | + public static function get_file_extension($full_file_path = '') { |
|
454 | + return pathinfo($full_file_path, PATHINFO_EXTENSION); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | |
@@ -461,10 +461,10 @@ discard block |
||
461 | 461 | * @param string $folder |
462 | 462 | * @return bool |
463 | 463 | */ |
464 | - public static function add_htaccess_deny_from_all( $folder = '' ) { |
|
465 | - $folder = EEH_File::standardise_and_end_with_directory_separator( $folder ); |
|
466 | - if ( ! EEH_File::exists( $folder . '.htaccess' ) ) { |
|
467 | - if ( ! EEH_File::write_to_file( $folder . '.htaccess', 'deny from all', '.htaccess' )) { |
|
464 | + public static function add_htaccess_deny_from_all($folder = '') { |
|
465 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
466 | + if ( ! EEH_File::exists($folder.'.htaccess')) { |
|
467 | + if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) { |
|
468 | 468 | return FALSE; |
469 | 469 | } |
470 | 470 | } |
@@ -477,10 +477,10 @@ discard block |
||
477 | 477 | * @param string $folder |
478 | 478 | * @return boolean |
479 | 479 | */ |
480 | - public static function add_index_file( $folder ) { |
|
481 | - $folder = EEH_File::standardise_and_end_with_directory_separator( $folder ); |
|
482 | - if ( ! EEH_File::exists( $folder . 'index.php' ) ) { |
|
483 | - if ( ! EEH_File::write_to_file( $folder . 'index.php', 'You are not permitted to read from this folder', '.php' )) { |
|
480 | + public static function add_index_file($folder) { |
|
481 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
482 | + if ( ! EEH_File::exists($folder.'index.php')) { |
|
483 | + if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
484 | 484 | return false; |
485 | 485 | } |
486 | 486 | } |
@@ -495,11 +495,11 @@ discard block |
||
495 | 495 | * @param string $file_path |
496 | 496 | * @return string |
497 | 497 | */ |
498 | - public static function get_classname_from_filepath_with_standard_filename( $file_path ){ |
|
498 | + public static function get_classname_from_filepath_with_standard_filename($file_path) { |
|
499 | 499 | //extract file from path |
500 | - $filename = basename( $file_path ); |
|
500 | + $filename = basename($file_path); |
|
501 | 501 | //now remove the first period and everything after |
502 | - $pos_of_first_period = strpos( $filename,'.' ); |
|
502 | + $pos_of_first_period = strpos($filename, '.'); |
|
503 | 503 | return substr($filename, 0, $pos_of_first_period); |
504 | 504 | } |
505 | 505 | |
@@ -511,8 +511,8 @@ discard block |
||
511 | 511 | * @param string $file_path |
512 | 512 | * @return string |
513 | 513 | */ |
514 | - public static function standardise_directory_separators( $file_path ){ |
|
515 | - return str_replace( array( '\\', '/' ), DS, $file_path ); |
|
514 | + public static function standardise_directory_separators($file_path) { |
|
515 | + return str_replace(array('\\', '/'), DS, $file_path); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | |
@@ -523,8 +523,8 @@ discard block |
||
523 | 523 | * @param string $file_path |
524 | 524 | * @return string |
525 | 525 | */ |
526 | - public static function end_with_directory_separator( $file_path ){ |
|
527 | - return rtrim( $file_path, '/\\' ) . DS; |
|
526 | + public static function end_with_directory_separator($file_path) { |
|
527 | + return rtrim($file_path, '/\\').DS; |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | |
@@ -534,8 +534,8 @@ discard block |
||
534 | 534 | * @param $file_path |
535 | 535 | * @return string |
536 | 536 | */ |
537 | - public static function standardise_and_end_with_directory_separator( $file_path ){ |
|
538 | - return self::end_with_directory_separator( self::standardise_directory_separators( $file_path )); |
|
537 | + public static function standardise_and_end_with_directory_separator($file_path) { |
|
538 | + return self::end_with_directory_separator(self::standardise_directory_separators($file_path)); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | |
@@ -552,21 +552,21 @@ discard block |
||
552 | 552 | * if $index_numerically == FALSE (Default) keys are what the class names SHOULD be; |
553 | 553 | * and values are their filepaths |
554 | 554 | */ |
555 | - public static function get_contents_of_folders( $folder_paths = array(), $index_numerically = FALSE ){ |
|
555 | + public static function get_contents_of_folders($folder_paths = array(), $index_numerically = FALSE) { |
|
556 | 556 | $class_to_folder_path = array(); |
557 | - foreach( $folder_paths as $folder_path ){ |
|
558 | - $folder_path = self::standardise_and_end_with_directory_separator( $folder_path ); |
|
557 | + foreach ($folder_paths as $folder_path) { |
|
558 | + $folder_path = self::standardise_and_end_with_directory_separator($folder_path); |
|
559 | 559 | // load WP_Filesystem and set file permissions |
560 | - $files_in_folder = glob( $folder_path . '*' ); |
|
560 | + $files_in_folder = glob($folder_path.'*'); |
|
561 | 561 | $class_to_folder_path = array(); |
562 | - if ( $files_in_folder ) { |
|
563 | - foreach( $files_in_folder as $file_path ){ |
|
562 | + if ($files_in_folder) { |
|
563 | + foreach ($files_in_folder as $file_path) { |
|
564 | 564 | //only add files, not folders |
565 | - if ( ! is_dir( $file_path )) { |
|
566 | - if ( $index_numerically ) { |
|
565 | + if ( ! is_dir($file_path)) { |
|
566 | + if ($index_numerically) { |
|
567 | 567 | $class_to_folder_path[] = $file_path; |
568 | 568 | } else { |
569 | - $classname = self::get_classname_from_filepath_with_standard_filename( $file_path ); |
|
569 | + $classname = self::get_classname_from_filepath_with_standard_filename($file_path); |
|
570 | 570 | $class_to_folder_path[$classname] = $file_path; |
571 | 571 | } |
572 | 572 | } |
@@ -586,39 +586,39 @@ discard block |
||
586 | 586 | * @return boolean success |
587 | 587 | * @throws EE_Error |
588 | 588 | */ |
589 | - public static function copy( $source_file, $destination_file, $overwrite = FALSE ){ |
|
590 | - $full_source_path = EEH_File::standardise_directory_separators( $source_file ); |
|
591 | - if( ! EEH_File::exists( $full_source_path ) ){ |
|
592 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
593 | - $msg = sprintf( __( 'The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso' ), $full_source_path ); |
|
594 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path ); |
|
595 | - throw new EE_Error( $msg ); |
|
589 | + public static function copy($source_file, $destination_file, $overwrite = FALSE) { |
|
590 | + $full_source_path = EEH_File::standardise_directory_separators($source_file); |
|
591 | + if ( ! EEH_File::exists($full_source_path)) { |
|
592 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
593 | + $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path); |
|
594 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path); |
|
595 | + throw new EE_Error($msg); |
|
596 | 596 | } |
597 | 597 | return FALSE; |
598 | 598 | } |
599 | 599 | |
600 | - $full_dest_path = EEH_File::standardise_directory_separators( $destination_file ); |
|
601 | - $folder = EEH_File::remove_filename_from_filepath( $full_dest_path ); |
|
602 | - if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
603 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
604 | - $msg = sprintf( __( 'The file located at "%2$s" is not writable.', 'event_espresso' ), $full_dest_path ); |
|
605 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_dest_path ); |
|
606 | - throw new EE_Error( $msg ); |
|
600 | + $full_dest_path = EEH_File::standardise_directory_separators($destination_file); |
|
601 | + $folder = EEH_File::remove_filename_from_filepath($full_dest_path); |
|
602 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
603 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
604 | + $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path); |
|
605 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path); |
|
606 | + throw new EE_Error($msg); |
|
607 | 607 | } |
608 | 608 | return FALSE; |
609 | 609 | } |
610 | 610 | |
611 | 611 | // load WP_Filesystem and set file permissions |
612 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $destination_file ); |
|
612 | + $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file); |
|
613 | 613 | // write the file |
614 | 614 | if ( ! $wp_filesystem->copy( |
615 | - EEH_File::convert_local_filepath_to_remote_filepath( $full_source_path ), |
|
616 | - EEH_File::convert_local_filepath_to_remote_filepath( $full_dest_path ), |
|
615 | + EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), |
|
616 | + EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), |
|
617 | 617 | $overwrite )) { |
618 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
619 | - $msg = sprintf( __( 'Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso' ), $full_source_path ); |
|
620 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path, 'f' ); |
|
621 | - throw new EE_Error( $msg ); |
|
618 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
619 | + $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path); |
|
620 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f'); |
|
621 | + throw new EE_Error($msg); |
|
622 | 622 | } |
623 | 623 | return FALSE; |
624 | 624 | } |
@@ -630,9 +630,9 @@ discard block |
||
630 | 630 | * @param string $filepath |
631 | 631 | * @return boolean |
632 | 632 | */ |
633 | - public static function is_in_uploads_folder( $filepath ) { |
|
633 | + public static function is_in_uploads_folder($filepath) { |
|
634 | 634 | $uploads = wp_upload_dir(); |
635 | - return strpos( $filepath, $uploads[ 'basedir' ] ) === 0 ? true : false; |
|
635 | + return strpos($filepath, $uploads['basedir']) === 0 ? true : false; |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | /** |
@@ -646,9 +646,9 @@ discard block |
||
646 | 646 | * @return string the remote filepath (eg the filepath the filesystem method, eg |
647 | 647 | * ftp or ssh, will use to access the folder |
648 | 648 | */ |
649 | - public static function convert_local_filepath_to_remote_filepath( $local_filepath ) { |
|
650 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $local_filepath ); |
|
651 | - return str_replace( WP_CONTENT_DIR . DS, $wp_filesystem->wp_content_dir(), $local_filepath ); |
|
649 | + public static function convert_local_filepath_to_remote_filepath($local_filepath) { |
|
650 | + $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath); |
|
651 | + return str_replace(WP_CONTENT_DIR.DS, $wp_filesystem->wp_content_dir(), $local_filepath); |
|
652 | 652 | } |
653 | 653 | } |
654 | 654 | // End of file EEH_File.helper.php |
@@ -21,26 +21,26 @@ |
||
21 | 21 | * @since $VID:$ |
22 | 22 | * |
23 | 23 | */ |
24 | -if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
24 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
25 | 25 | exit('No direct script access allowed'); |
26 | 26 | } |
27 | 27 | |
28 | -class EEM_Extra_Join extends EEM_Base{ |
|
28 | +class EEM_Extra_Join extends EEM_Base { |
|
29 | 29 | // private instance of the Extra Join object |
30 | 30 | protected static $_instance = NULL; |
31 | 31 | |
32 | 32 | public function __construct($timezone = NULL) { |
33 | - $models_this_can_join = array_keys( EE_Registry::instance()->non_abstract_db_models ); |
|
33 | + $models_this_can_join = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
34 | 34 | $this->_tables = array( |
35 | - 'Extra_Join' => new EE_Primary_Table( 'esp_extra_join', 'EXJ_ID' ), |
|
35 | + 'Extra_Join' => new EE_Primary_Table('esp_extra_join', 'EXJ_ID'), |
|
36 | 36 | ); |
37 | 37 | $this->_fields = array( |
38 | 38 | 'Extra_Join' => array( |
39 | - 'EXJ_ID' => new EE_Primary_Key_Int_Field( 'EXJ_ID', __( 'Extra Join ID', 'event_espresso' ) ), |
|
40 | - 'EXJ_first_model_ID' => new EE_Foreign_Key_String_Field( 'EXJ_first_model_ID', __( 'First Model ID', 'event_espresso' ), true, 0, $models_this_can_join ), |
|
41 | - 'EXJ_first_model_name' => new EE_Any_Foreign_Model_Name_Field( 'EXJ_first_model_name', __( 'First Model Name', 'event_espresso'), true, '', $models_this_can_join ), |
|
42 | - 'EXJ_second_model_ID' => new EE_Foreign_Key_String_Field( 'EXJ_second_model_ID', __( 'Second Model ID', 'event_espresso' ), true, 0, $models_this_can_join ), |
|
43 | - 'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field( 'EXJ_second_model_name', __( 'Second Model Name', 'event_espresso'), true, '', $models_this_can_join ), |
|
39 | + 'EXJ_ID' => new EE_Primary_Key_Int_Field('EXJ_ID', __('Extra Join ID', 'event_espresso')), |
|
40 | + 'EXJ_first_model_ID' => new EE_Foreign_Key_String_Field('EXJ_first_model_ID', __('First Model ID', 'event_espresso'), true, 0, $models_this_can_join), |
|
41 | + 'EXJ_first_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_first_model_name', __('First Model Name', 'event_espresso'), true, '', $models_this_can_join), |
|
42 | + 'EXJ_second_model_ID' => new EE_Foreign_Key_String_Field('EXJ_second_model_ID', __('Second Model ID', 'event_espresso'), true, 0, $models_this_can_join), |
|
43 | + 'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_second_model_name', __('Second Model Name', 'event_espresso'), true, '', $models_this_can_join), |
|
44 | 44 | |
45 | 45 | ) |
46 | 46 | ); |