@@ -5,51 +5,51 @@ |
||
5 | 5 | * it does not override any existing definition of the function in WP. |
6 | 6 | */ |
7 | 7 | if ( ! function_exists( 'get_preview_post_link' ) ) { |
8 | - /** |
|
9 | - * Function was added in WordPress 4.4.0 |
|
10 | - * @param null $post |
|
11 | - * @param array $query_args |
|
12 | - * @param string $preview_link |
|
13 | - * @return mixed |
|
14 | - */ |
|
15 | - function get_preview_post_link($post = null, $query_args = array(), $preview_link = '') |
|
16 | - { |
|
17 | - $post = get_post($post); |
|
18 | - if (! $post) { |
|
19 | - return ''; |
|
20 | - } |
|
8 | + /** |
|
9 | + * Function was added in WordPress 4.4.0 |
|
10 | + * @param null $post |
|
11 | + * @param array $query_args |
|
12 | + * @param string $preview_link |
|
13 | + * @return mixed |
|
14 | + */ |
|
15 | + function get_preview_post_link($post = null, $query_args = array(), $preview_link = '') |
|
16 | + { |
|
17 | + $post = get_post($post); |
|
18 | + if (! $post) { |
|
19 | + return ''; |
|
20 | + } |
|
21 | 21 | |
22 | - $post_type_object = get_post_type_object($post->post_type); |
|
23 | - if (is_post_type_viewable($post_type_object)) { |
|
24 | - if (! $preview_link) { |
|
25 | - $preview_link = set_url_scheme(get_permalink($post)); |
|
26 | - } |
|
22 | + $post_type_object = get_post_type_object($post->post_type); |
|
23 | + if (is_post_type_viewable($post_type_object)) { |
|
24 | + if (! $preview_link) { |
|
25 | + $preview_link = set_url_scheme(get_permalink($post)); |
|
26 | + } |
|
27 | 27 | |
28 | - $query_args['preview'] = 'true'; |
|
29 | - $preview_link = add_query_arg($query_args, $preview_link); |
|
30 | - } |
|
28 | + $query_args['preview'] = 'true'; |
|
29 | + $preview_link = add_query_arg($query_args, $preview_link); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Filters the URL used for a post preview. |
|
34 | - * |
|
35 | - * @since 2.0.5 |
|
36 | - * @since 4.0.0 Added the `$post` parameter. |
|
37 | - * @param string $preview_link URL used for the post preview. |
|
38 | - * @param WP_Post $post Post object. |
|
39 | - */ |
|
40 | - return apply_filters('preview_post_link', $preview_link, $post); |
|
41 | - } |
|
32 | + /** |
|
33 | + * Filters the URL used for a post preview. |
|
34 | + * |
|
35 | + * @since 2.0.5 |
|
36 | + * @since 4.0.0 Added the `$post` parameter. |
|
37 | + * @param string $preview_link URL used for the post preview. |
|
38 | + * @param WP_Post $post Post object. |
|
39 | + */ |
|
40 | + return apply_filters('preview_post_link', $preview_link, $post); |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | if ( ! function_exists( 'is_post_type_viewable' ) ) { |
45 | - function is_post_type_viewable( $post_type ) { |
|
46 | - if ( is_scalar( $post_type ) ) { |
|
47 | - $post_type = get_post_type_object( $post_type ); |
|
48 | - if ( ! $post_type ) { |
|
49 | - return false; |
|
50 | - } |
|
51 | - } |
|
45 | + function is_post_type_viewable( $post_type ) { |
|
46 | + if ( is_scalar( $post_type ) ) { |
|
47 | + $post_type = get_post_type_object( $post_type ); |
|
48 | + if ( ! $post_type ) { |
|
49 | + return false; |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | - return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public ); |
|
54 | - } |
|
53 | + return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public ); |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | \ No newline at end of file |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * Note: this file should only be required right before calling the function the shim is for. This is to ensure that |
5 | 5 | * it does not override any existing definition of the function in WP. |
6 | 6 | */ |
7 | -if ( ! function_exists( 'get_preview_post_link' ) ) { |
|
7 | +if ( ! function_exists('get_preview_post_link')) { |
|
8 | 8 | /** |
9 | 9 | * Function was added in WordPress 4.4.0 |
10 | 10 | * @param null $post |
@@ -15,13 +15,13 @@ discard block |
||
15 | 15 | function get_preview_post_link($post = null, $query_args = array(), $preview_link = '') |
16 | 16 | { |
17 | 17 | $post = get_post($post); |
18 | - if (! $post) { |
|
18 | + if ( ! $post) { |
|
19 | 19 | return ''; |
20 | 20 | } |
21 | 21 | |
22 | 22 | $post_type_object = get_post_type_object($post->post_type); |
23 | 23 | if (is_post_type_viewable($post_type_object)) { |
24 | - if (! $preview_link) { |
|
24 | + if ( ! $preview_link) { |
|
25 | 25 | $preview_link = set_url_scheme(get_permalink($post)); |
26 | 26 | } |
27 | 27 | |
@@ -41,15 +41,15 @@ discard block |
||
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | -if ( ! function_exists( 'is_post_type_viewable' ) ) { |
|
45 | - function is_post_type_viewable( $post_type ) { |
|
46 | - if ( is_scalar( $post_type ) ) { |
|
47 | - $post_type = get_post_type_object( $post_type ); |
|
48 | - if ( ! $post_type ) { |
|
44 | +if ( ! function_exists('is_post_type_viewable')) { |
|
45 | + function is_post_type_viewable($post_type) { |
|
46 | + if (is_scalar($post_type)) { |
|
47 | + $post_type = get_post_type_object($post_type); |
|
48 | + if ( ! $post_type) { |
|
49 | 49 | return false; |
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | - return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public ); |
|
53 | + return $post_type->publicly_queryable || ($post_type->_builtin && $post_type->public); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | \ No newline at end of file |
@@ -1,16 +1,16 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2 | 2 | /** |
3 | - * |
|
4 | - * Class EE_SPCO_Reg_Step_Attendee_Information |
|
5 | - * |
|
6 | - * Description |
|
7 | - * |
|
8 | - * @package Event Espresso |
|
9 | - * @subpackage core |
|
10 | - * @author Brent Christensen |
|
11 | - * @since 4.5.0 |
|
12 | - * |
|
13 | - */ |
|
3 | + * |
|
4 | + * Class EE_SPCO_Reg_Step_Attendee_Information |
|
5 | + * |
|
6 | + * Description |
|
7 | + * |
|
8 | + * @package Event Espresso |
|
9 | + * @subpackage core |
|
10 | + * @author Brent Christensen |
|
11 | + * @since 4.5.0 |
|
12 | + * |
|
13 | + */ |
|
14 | 14 | class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step { |
15 | 15 | |
16 | 16 | /** |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | // generate hidden input |
170 | 170 | if ( |
171 | 171 | isset( $subsections[ $primary_registrant ] ) |
172 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
172 | + && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
173 | 173 | ) { |
174 | 174 | $subsections[ $primary_registrant ]->add_subsections( $copy_options, 'primary_registrant', false ); |
175 | 175 | } |
@@ -904,7 +904,7 @@ discard block |
||
904 | 904 | if ( isset( $valid_data[ $reg_url_link ] ) ) { |
905 | 905 | // do we need to copy basic info from primary attendee ? |
906 | 906 | $copy_primary = isset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) |
907 | - && absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0 |
|
907 | + && absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0 |
|
908 | 908 | ? true |
909 | 909 | : false; |
910 | 910 | // filter form input data for this registration |
@@ -1079,7 +1079,7 @@ discard block |
||
1079 | 1079 | ? $form_input |
1080 | 1080 | : $form_input . '-' . $registration->reg_url_link(); |
1081 | 1081 | $answer_is_obj = isset( $this->_registration_answers[ $answer_cache_id ] ) |
1082 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
1082 | + && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
1083 | 1083 | ? true |
1084 | 1084 | : false; |
1085 | 1085 | //rename form_inputs if they are EE_Attendee properties |
@@ -1199,7 +1199,7 @@ discard block |
||
1199 | 1199 | // then attempt to copy them from the primary attendee |
1200 | 1200 | if ( |
1201 | 1201 | $this->checkout->primary_attendee_obj instanceof EE_Attendee |
1202 | - && ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] ) |
|
1202 | + && ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] ) |
|
1203 | 1203 | ) { |
1204 | 1204 | return $this->checkout->primary_attendee_obj; |
1205 | 1205 | } |
@@ -1317,7 +1317,7 @@ discard block |
||
1317 | 1317 | } |
1318 | 1318 | foreach ( $critical_attendee_details as $critical_attendee_detail ) { |
1319 | 1319 | if ( ! isset( $attendee_data[ $critical_attendee_detail ] ) |
1320 | - || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
1320 | + || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
1321 | 1321 | ) { |
1322 | 1322 | $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
1323 | 1323 | $critical_attendee_detail |
@@ -41,21 +41,21 @@ discard block |
||
41 | 41 | * @access public |
42 | 42 | * @param EE_Checkout $checkout |
43 | 43 | */ |
44 | - public function __construct( EE_Checkout $checkout ) { |
|
44 | + public function __construct(EE_Checkout $checkout) { |
|
45 | 45 | $this->_slug = 'attendee_information'; |
46 | 46 | $this->_name = __('Attendee Information', 'event_espresso'); |
47 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
47 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'attendee_info_main.template.php'; |
|
48 | 48 | $this->checkout = $checkout; |
49 | 49 | $this->_reset_success_message(); |
50 | 50 | $this->set_instructions( |
51 | - __( 'Please answer the following registration questions before proceeding.', 'event_espresso' ) |
|
51 | + __('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
52 | 52 | ); |
53 | 53 | } |
54 | 54 | |
55 | 55 | |
56 | 56 | |
57 | 57 | public function translate_js_strings() { |
58 | - EE_Registry::$i18n_js_strings['required_field'] = __( ' is a required question.', 'event_espresso' ); |
|
58 | + EE_Registry::$i18n_js_strings['required_field'] = __(' is a required question.', 'event_espresso'); |
|
59 | 59 | EE_Registry::$i18n_js_strings['required_multi_field'] = __( |
60 | 60 | ' is a required question. Please enter a value for at least one of the options.', |
61 | 61 | 'event_espresso' |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | // calculate taxes |
116 | 116 | $Line_Item_Display->display_line_item( |
117 | 117 | $this->checkout->cart->get_grand_total(), |
118 | - array( 'set_tax_rate' => true ) |
|
118 | + array('set_tax_rate' => true) |
|
119 | 119 | ); |
120 | 120 | /** @var $subsections EE_Form_Section_Proper[] */ |
121 | 121 | $subsections = array( |
@@ -127,51 +127,51 @@ discard block |
||
127 | 127 | 'ticket_count' => array() |
128 | 128 | ); |
129 | 129 | // grab the saved registrations from the transaction |
130 | - $registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ); |
|
131 | - if ( $registrations ) { |
|
132 | - foreach ( $registrations as $registration ) { |
|
130 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
131 | + if ($registrations) { |
|
132 | + foreach ($registrations as $registration) { |
|
133 | 133 | // can this registration be processed during this visit ? |
134 | 134 | if ( |
135 | 135 | $registration instanceof EE_Registration |
136 | - && $this->checkout->visit_allows_processing_of_this_registration( $registration ) |
|
136 | + && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
137 | 137 | ) { |
138 | - $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form( $registration ); |
|
139 | - if ( ! $this->checkout->admin_request ) { |
|
140 | - $template_args['registrations'][ $registration->reg_url_link() ] = $registration; |
|
141 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
142 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
138 | + $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
|
139 | + if ( ! $this->checkout->admin_request) { |
|
140 | + $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
141 | + $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
142 | + $template_args['ticket_count'][$registration->ticket()->ID()] |
|
143 | 143 | ) |
144 | - ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
144 | + ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
145 | 145 | : 1; |
146 | 146 | $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
147 | 147 | $this->checkout->cart->get_grand_total(), |
148 | 148 | 'Ticket', |
149 | - array( $registration->ticket()->ID() ) |
|
149 | + array($registration->ticket()->ID()) |
|
150 | 150 | ); |
151 | - $ticket_line_item = is_array( $ticket_line_item ) |
|
152 | - ? reset( $ticket_line_item ) |
|
151 | + $ticket_line_item = is_array($ticket_line_item) |
|
152 | + ? reset($ticket_line_item) |
|
153 | 153 | : $ticket_line_item; |
154 | - $template_args['ticket_line_item'][ $registration->ticket()->ID() ] = $Line_Item_Display->display_line_item( |
|
154 | + $template_args['ticket_line_item'][$registration->ticket()->ID()] = $Line_Item_Display->display_line_item( |
|
155 | 155 | $ticket_line_item |
156 | 156 | ); |
157 | 157 | } |
158 | - if ( $registration->is_primary_registrant() ) { |
|
158 | + if ($registration->is_primary_registrant()) { |
|
159 | 159 | $primary_registrant = $registration->reg_url_link(); |
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
163 | 163 | // print_copy_info ? |
164 | - if ( $primary_registrant && ! $this->checkout->admin_request && count( $registrations ) > 1 ) { |
|
164 | + if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) { |
|
165 | 165 | // TODO: add admin option for toggling copy attendee info, then use that value to change $this->_print_copy_info |
166 | 166 | $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
167 | 167 | ? $this->_copy_attendee_info_form() |
168 | 168 | : $this->_auto_copy_attendee_info(); |
169 | 169 | // generate hidden input |
170 | 170 | if ( |
171 | - isset( $subsections[ $primary_registrant ] ) |
|
172 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
171 | + isset($subsections[$primary_registrant]) |
|
172 | + && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
173 | 173 | ) { |
174 | - $subsections[ $primary_registrant ]->add_subsections( $copy_options, 'primary_registrant', false ); |
|
174 | + $subsections[$primary_registrant]->add_subsections($copy_options, 'primary_registrant', false); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
@@ -183,8 +183,7 @@ discard block |
||
183 | 183 | 'html_id' => $this->reg_form_name(), |
184 | 184 | 'subsections' => $subsections, |
185 | 185 | 'layout_strategy' => $this->checkout->admin_request ? |
186 | - new EE_Div_Per_Section_Layout() : |
|
187 | - new EE_Template_Layout( |
|
186 | + new EE_Div_Per_Section_Layout() : new EE_Template_Layout( |
|
188 | 187 | array( |
189 | 188 | 'layout_template_file' => $this->_template, // layout_template |
190 | 189 | 'template_args' => $template_args |
@@ -202,11 +201,11 @@ discard block |
||
202 | 201 | * @return EE_Form_Section_Proper |
203 | 202 | * @throws \EE_Error |
204 | 203 | */ |
205 | - private function _registrations_reg_form( EE_Registration $registration ) { |
|
204 | + private function _registrations_reg_form(EE_Registration $registration) { |
|
206 | 205 | static $attendee_nmbr = 1; |
207 | 206 | // array of params to pass to parent constructor |
208 | 207 | $form_args = array( |
209 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
208 | + 'html_id' => 'ee-registration-'.$registration->reg_url_link(), |
|
210 | 209 | 'html_class' => 'ee-reg-form-attendee-dv', |
211 | 210 | 'html_style' => $this->checkout->admin_request |
212 | 211 | ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
@@ -215,24 +214,24 @@ discard block |
||
215 | 214 | 'layout_strategy' => new EE_Fieldset_Section_Layout( |
216 | 215 | array( |
217 | 216 | 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
218 | - 'legend_text' => sprintf( __( 'Attendee %d', 'event_espresso' ), $attendee_nmbr ) |
|
217 | + 'legend_text' => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr) |
|
219 | 218 | ) |
220 | 219 | ) |
221 | 220 | ); |
222 | 221 | // verify that registration has valid event |
223 | - if ( $registration->event() instanceof EE_Event ) { |
|
222 | + if ($registration->event() instanceof EE_Event) { |
|
224 | 223 | $query_params = array( |
225 | 224 | array( |
226 | 225 | 'Event.EVT_ID' => $registration->event()->ID(), |
227 | 226 | 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false |
228 | 227 | ), |
229 | - 'order_by'=>array( 'QSG_order'=>'ASC' ) |
|
228 | + 'order_by'=>array('QSG_order'=>'ASC') |
|
230 | 229 | ); |
231 | - $question_groups = $registration->event()->question_groups( $query_params ); |
|
232 | - if ( $question_groups ) { |
|
233 | - foreach ( $question_groups as $question_group ) { |
|
234 | - if ( $question_group instanceof EE_Question_Group ) { |
|
235 | - $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
230 | + $question_groups = $registration->event()->question_groups($query_params); |
|
231 | + if ($question_groups) { |
|
232 | + foreach ($question_groups as $question_group) { |
|
233 | + if ($question_group instanceof EE_Question_Group) { |
|
234 | + $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form( |
|
236 | 235 | $registration, |
237 | 236 | $question_group |
238 | 237 | ); |
@@ -245,10 +244,10 @@ discard block |
||
245 | 244 | // if we have question groups for additional attendees, then display the copy options |
246 | 245 | $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info; |
247 | 246 | } else { |
248 | - $form_args['subsections'][ 'attendee_info_not_required_' . $registration->reg_url_link( |
|
249 | - ) ] = new EE_Form_Section_HTML( |
|
247 | + $form_args['subsections']['attendee_info_not_required_'.$registration->reg_url_link( |
|
248 | + )] = new EE_Form_Section_HTML( |
|
250 | 249 | EEH_Template::locate_template( |
251 | - SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_not_required.template.php', |
|
250 | + SPCO_REG_STEPS_PATH.$this->_slug.DS.'attendee_info_not_required.template.php', |
|
252 | 251 | apply_filters( |
253 | 252 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__attendee_info_not_required_template_args', |
254 | 253 | array() |
@@ -267,12 +266,12 @@ discard block |
||
267 | 266 | |
268 | 267 | } |
269 | 268 | } |
270 | - if ( $registration->is_primary_registrant() ) { |
|
269 | + if ($registration->is_primary_registrant()) { |
|
271 | 270 | // generate hidden input |
272 | - $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( $registration ); |
|
271 | + $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs($registration); |
|
273 | 272 | } |
274 | 273 | $attendee_nmbr++; |
275 | - return new EE_Form_Section_Proper( $form_args ); |
|
274 | + return new EE_Form_Section_Proper($form_args); |
|
276 | 275 | } |
277 | 276 | |
278 | 277 | |
@@ -293,7 +292,7 @@ discard block |
||
293 | 292 | // generate hidden input |
294 | 293 | return new EE_Hidden_Input( |
295 | 294 | array( |
296 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
295 | + 'html_id' => 'additional-attendee-reg-info-'.$registration->reg_url_link(), |
|
297 | 296 | 'default' => $additional_attendee_reg_info |
298 | 297 | ) |
299 | 298 | ); |
@@ -307,26 +306,26 @@ discard block |
||
307 | 306 | * @return EE_Form_Section_Proper |
308 | 307 | * @throws \EE_Error |
309 | 308 | */ |
310 | - private function _question_group_reg_form( EE_Registration $registration, EE_Question_Group $question_group ){ |
|
309 | + private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) { |
|
311 | 310 | // array of params to pass to parent constructor |
312 | 311 | $form_args = array( |
313 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier(), |
|
312 | + 'html_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier(), |
|
314 | 313 | 'html_class' => $this->checkout->admin_request |
315 | 314 | ? 'form-table ee-reg-form-qstn-grp-dv' |
316 | 315 | : 'ee-reg-form-qstn-grp-dv', |
317 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-lbl', |
|
316 | + 'html_label_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-lbl', |
|
318 | 317 | 'subsections' => array( |
319 | - 'reg_form_qstn_grp_hdr' => $this->_question_group_header( $question_group ) |
|
318 | + 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group) |
|
320 | 319 | ), |
321 | 320 | 'layout_strategy' => $this->checkout->admin_request |
322 | 321 | ? new EE_Admin_Two_Column_Layout() |
323 | 322 | : new EE_Div_Per_Section_Layout() |
324 | 323 | ); |
325 | 324 | // where params |
326 | - $query_params = array( 'QST_deleted' => 0 ); |
|
325 | + $query_params = array('QST_deleted' => 0); |
|
327 | 326 | // don't load admin only questions on the frontend |
328 | - if ( ! $this->checkout->admin_request ) { |
|
329 | - $query_params['QST_admin_only'] = array( '!=', true ); |
|
327 | + if ( ! $this->checkout->admin_request) { |
|
328 | + $query_params['QST_admin_only'] = array('!=', true); |
|
330 | 329 | } |
331 | 330 | $questions = $question_group->get_many_related( |
332 | 331 | 'Question', |
@@ -348,10 +347,10 @@ discard block |
||
348 | 347 | ) |
349 | 348 | ); |
350 | 349 | // loop thru questions |
351 | - foreach ( $questions as $question ) { |
|
352 | - if( $question instanceof EE_Question ){ |
|
350 | + foreach ($questions as $question) { |
|
351 | + if ($question instanceof EE_Question) { |
|
353 | 352 | $identifier = $question->is_system_question() ? $question->system_ID() : $question->ID(); |
354 | - $form_args['subsections'][ $identifier ] = $this->reg_form_question( $registration, $question ); |
|
353 | + $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question); |
|
355 | 354 | } |
356 | 355 | } |
357 | 356 | $form_args['subsections'] = apply_filters( |
@@ -372,7 +371,7 @@ discard block |
||
372 | 371 | ) |
373 | 372 | ); |
374 | 373 | // d( $form_args ); |
375 | - $question_group_reg_form = new EE_Form_Section_Proper( $form_args ); |
|
374 | + $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
376 | 375 | return apply_filters( |
377 | 376 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
378 | 377 | $question_group_reg_form, |
@@ -389,11 +388,11 @@ discard block |
||
389 | 388 | * @param EE_Question_Group $question_group |
390 | 389 | * @return EE_Form_Section_HTML |
391 | 390 | */ |
392 | - private function _question_group_header( EE_Question_Group $question_group ){ |
|
391 | + private function _question_group_header(EE_Question_Group $question_group) { |
|
393 | 392 | $html = ''; |
394 | 393 | // group_name |
395 | - if ( $question_group->show_group_name() && $question_group->name() !== '' ) { |
|
396 | - if ( $this->checkout->admin_request ) { |
|
394 | + if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
395 | + if ($this->checkout->admin_request) { |
|
397 | 396 | $html .= EEH_HTML::br(); |
398 | 397 | $html .= EEH_HTML::h3( |
399 | 398 | $question_group->name(), |
@@ -407,7 +406,7 @@ discard block |
||
407 | 406 | } |
408 | 407 | } |
409 | 408 | // group_desc |
410 | - if ( $question_group->show_group_desc() && $question_group->desc() !== '' ) { |
|
409 | + if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
411 | 410 | $html .= EEH_HTML::p( |
412 | 411 | $question_group->desc(), |
413 | 412 | '', |
@@ -417,7 +416,7 @@ discard block |
||
417 | 416 | ); |
418 | 417 | |
419 | 418 | } |
420 | - return new EE_Form_Section_HTML( $html ); |
|
419 | + return new EE_Form_Section_HTML($html); |
|
421 | 420 | } |
422 | 421 | |
423 | 422 | |
@@ -427,7 +426,7 @@ discard block |
||
427 | 426 | * @return EE_Form_Section_Proper |
428 | 427 | * @throws \EE_Error |
429 | 428 | */ |
430 | - private function _copy_attendee_info_form(){ |
|
429 | + private function _copy_attendee_info_form() { |
|
431 | 430 | // array of params to pass to parent constructor |
432 | 431 | return new EE_Form_Section_Proper( |
433 | 432 | array( |
@@ -456,7 +455,7 @@ discard block |
||
456 | 455 | private function _auto_copy_attendee_info() { |
457 | 456 | return new EE_Form_Section_HTML( |
458 | 457 | EEH_Template::locate_template( |
459 | - SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
458 | + SPCO_REG_STEPS_PATH.$this->_slug.DS.'_auto_copy_attendee_info.template.php', |
|
460 | 459 | apply_filters( |
461 | 460 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
462 | 461 | array() |
@@ -480,32 +479,32 @@ discard block |
||
480 | 479 | $copy_attendee_info_inputs = array(); |
481 | 480 | $prev_ticket = NULL; |
482 | 481 | // grab the saved registrations from the transaction |
483 | - $registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ); |
|
484 | - foreach ( $registrations as $registration ) { |
|
482 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
483 | + foreach ($registrations as $registration) { |
|
485 | 484 | // for all attendees other than the primary attendee |
486 | - if ( $registration instanceof EE_Registration && ! $registration->is_primary_registrant() ) { |
|
485 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
487 | 486 | // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
488 | - if ( $registration->ticket()->ID() !== $prev_ticket ) { |
|
487 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
489 | 488 | $item_name = $registration->ticket()->name(); |
490 | 489 | $item_name .= $registration->ticket()->description() !== '' |
491 | - ? ' - ' . $registration->ticket()->description() |
|
490 | + ? ' - '.$registration->ticket()->description() |
|
492 | 491 | : ''; |
493 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] = new EE_Form_Section_HTML( |
|
494 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
492 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID().']'] = new EE_Form_Section_HTML( |
|
493 | + '<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>' |
|
495 | 494 | ); |
496 | 495 | $prev_ticket = $registration->ticket()->ID(); |
497 | 496 | } |
498 | 497 | |
499 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = new |
|
498 | + $copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] = new |
|
500 | 499 | EE_Checkbox_Multi_Input( |
501 | 500 | array( |
502 | 501 | $registration->ID() => sprintf( |
503 | - __( 'Attendee #%s', 'event_espresso' ), |
|
502 | + __('Attendee #%s', 'event_espresso'), |
|
504 | 503 | $registration->count() |
505 | 504 | ) |
506 | 505 | ), |
507 | 506 | array( |
508 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
507 | + 'html_id' => 'spco-copy-attendee-chk-'.$registration->reg_url_link(), |
|
509 | 508 | 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
510 | 509 | 'display_html_label_text' => false |
511 | 510 | ) |
@@ -525,7 +524,7 @@ discard block |
||
525 | 524 | * @return EE_Form_Input_Base |
526 | 525 | * @throws \EE_Error |
527 | 526 | */ |
528 | - private function _additional_primary_registrant_inputs( EE_Registration $registration ){ |
|
527 | + private function _additional_primary_registrant_inputs(EE_Registration $registration) { |
|
529 | 528 | // generate hidden input |
530 | 529 | return new EE_Hidden_Input( |
531 | 530 | array( |
@@ -544,7 +543,7 @@ discard block |
||
544 | 543 | * @return EE_Form_Input_Base |
545 | 544 | * @throws \EE_Error |
546 | 545 | */ |
547 | - public function reg_form_question( EE_Registration $registration, EE_Question $question ){ |
|
546 | + public function reg_form_question(EE_Registration $registration, EE_Question $question) { |
|
548 | 547 | |
549 | 548 | // if this question was for an attendee detail, then check for that answer |
550 | 549 | $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
@@ -553,32 +552,32 @@ discard block |
||
553 | 552 | ); |
554 | 553 | $answer = $answer_value === null |
555 | 554 | ? EEM_Answer::instance()->get_one( |
556 | - array( array( 'QST_ID' => $question->ID(), 'REG_ID' => $registration->ID() ) ) |
|
555 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
557 | 556 | ) |
558 | 557 | : null; |
559 | 558 | // if NOT returning to edit an existing registration |
560 | 559 | // OR if this question is for an attendee property |
561 | 560 | // OR we still don't have an EE_Answer object |
562 | - if( $answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link() ) { |
|
561 | + if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
563 | 562 | // create an EE_Answer object for storing everything in |
564 | - $answer = EE_Answer::new_instance ( array( |
|
563 | + $answer = EE_Answer::new_instance(array( |
|
565 | 564 | 'QST_ID'=> $question->ID(), |
566 | 565 | 'REG_ID'=> $registration->ID() |
567 | 566 | )); |
568 | 567 | } |
569 | 568 | // verify instance |
570 | - if( $answer instanceof EE_Answer ){ |
|
571 | - if ( ! empty( $answer_value )) { |
|
572 | - $answer->set( 'ANS_value', $answer_value ); |
|
569 | + if ($answer instanceof EE_Answer) { |
|
570 | + if ( ! empty($answer_value)) { |
|
571 | + $answer->set('ANS_value', $answer_value); |
|
573 | 572 | } |
574 | - $answer->cache( 'Question', $question ); |
|
573 | + $answer->cache('Question', $question); |
|
575 | 574 | //remember system ID had a bug where sometimes it could be null |
576 | - $answer_cache_id =$question->is_system_question() |
|
577 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
578 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
579 | - $registration->cache( 'Answer', $answer, $answer_cache_id ); |
|
575 | + $answer_cache_id = $question->is_system_question() |
|
576 | + ? $question->system_ID().'-'.$registration->reg_url_link() |
|
577 | + : $question->ID().'-'.$registration->reg_url_link(); |
|
578 | + $registration->cache('Answer', $answer, $answer_cache_id); |
|
580 | 579 | } |
581 | - return $this->_generate_question_input( $registration, $question, $answer ); |
|
580 | + return $this->_generate_question_input($registration, $question, $answer); |
|
582 | 581 | |
583 | 582 | } |
584 | 583 | |
@@ -591,46 +590,46 @@ discard block |
||
591 | 590 | * @return EE_Form_Input_Base |
592 | 591 | * @throws \EE_Error |
593 | 592 | */ |
594 | - private function _generate_question_input( EE_Registration $registration, EE_Question $question, $answer ){ |
|
593 | + private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) { |
|
595 | 594 | $identifier = $question->is_system_question() ? $question->system_ID() : $question->ID(); |
596 | - $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
595 | + $this->_required_questions[$identifier] = $question->required() ? true : false; |
|
597 | 596 | add_filter( |
598 | 597 | 'FHEE__EE_Question__generate_form_input__country_options', |
599 | - array( $this, 'use_cached_countries_for_form_input' ), |
|
598 | + array($this, 'use_cached_countries_for_form_input'), |
|
600 | 599 | 10, |
601 | 600 | 4 |
602 | 601 | ); |
603 | 602 | add_filter( |
604 | 603 | 'FHEE__EE_Question__generate_form_input__state_options', |
605 | - array( $this, 'use_cached_states_for_form_input' ), |
|
604 | + array($this, 'use_cached_states_for_form_input'), |
|
606 | 605 | 10, |
607 | 606 | 4 |
608 | 607 | ); |
609 | 608 | $input_constructor_args = array( |
610 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
611 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
612 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
613 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
609 | + 'html_name' => 'ee_reg_qstn['.$registration->ID().']['.$identifier.']', |
|
610 | + 'html_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
611 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-'.$identifier, |
|
612 | + 'html_label_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
614 | 613 | 'html_label_class' => 'ee-reg-qstn', |
615 | 614 | ); |
616 | - $input_constructor_args['html_label_id'] .= '-lbl'; |
|
617 | - if ( $answer instanceof EE_Answer && $answer->ID() ) { |
|
618 | - $input_constructor_args[ 'html_name' ] .= '[' . $answer->ID() . ']'; |
|
619 | - $input_constructor_args[ 'html_id' ] .= '-' . $answer->ID(); |
|
620 | - $input_constructor_args[ 'html_label_id' ] .= '-' . $answer->ID(); |
|
615 | + $input_constructor_args['html_label_id'] .= '-lbl'; |
|
616 | + if ($answer instanceof EE_Answer && $answer->ID()) { |
|
617 | + $input_constructor_args['html_name'] .= '['.$answer->ID().']'; |
|
618 | + $input_constructor_args['html_id'] .= '-'.$answer->ID(); |
|
619 | + $input_constructor_args['html_label_id'] .= '-'.$answer->ID(); |
|
621 | 620 | } |
622 | - $form_input = $question->generate_form_input( |
|
621 | + $form_input = $question->generate_form_input( |
|
623 | 622 | $registration, |
624 | 623 | $answer, |
625 | 624 | $input_constructor_args |
626 | 625 | ); |
627 | 626 | remove_filter( |
628 | 627 | 'FHEE__EE_Question__generate_form_input__country_options', |
629 | - array( $this, 'use_cached_countries_for_form_input' ) |
|
628 | + array($this, 'use_cached_countries_for_form_input') |
|
630 | 629 | ); |
631 | 630 | remove_filter( |
632 | 631 | 'FHEE__EE_Question__generate_form_input__state_options', |
633 | - array( $this, 'use_cached_states_for_form_input' ) |
|
632 | + array($this, 'use_cached_states_for_form_input') |
|
634 | 633 | ); |
635 | 634 | return $form_input; |
636 | 635 | } |
@@ -652,22 +651,22 @@ discard block |
||
652 | 651 | \EE_Registration $registration = null, |
653 | 652 | \EE_Answer $answer = null |
654 | 653 | ) { |
655 | - $country_options = array( '' => '' ); |
|
654 | + $country_options = array('' => ''); |
|
656 | 655 | // get possibly cached list of countries |
657 | 656 | $countries = $this->checkout->action === 'process_reg_step' |
658 | 657 | ? EEM_Country::instance()->get_all_countries() |
659 | 658 | : EEM_Country::instance()->get_all_active_countries(); |
660 | - if ( ! empty( $countries )) { |
|
661 | - foreach( $countries as $country ){ |
|
662 | - if ( $country instanceof EE_Country ) { |
|
663 | - $country_options[ $country->ID() ] = $country->name(); |
|
659 | + if ( ! empty($countries)) { |
|
660 | + foreach ($countries as $country) { |
|
661 | + if ($country instanceof EE_Country) { |
|
662 | + $country_options[$country->ID()] = $country->name(); |
|
664 | 663 | } |
665 | 664 | } |
666 | 665 | } |
667 | - if( $question instanceof EE_Question |
|
668 | - && $registration instanceof EE_Registration ) { |
|
666 | + if ($question instanceof EE_Question |
|
667 | + && $registration instanceof EE_Registration) { |
|
669 | 668 | $answer = EEM_Answer::instance()->get_one( |
670 | - array( array( 'QST_ID' => $question->ID(), 'REG_ID' => $registration->ID() ) ) |
|
669 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
671 | 670 | ); |
672 | 671 | } else { |
673 | 672 | $answer = EE_Answer::new_instance(); |
@@ -700,14 +699,14 @@ discard block |
||
700 | 699 | \EE_Registration $registration = null, |
701 | 700 | \EE_Answer $answer = null |
702 | 701 | ) { |
703 | - $state_options = array( '' => array( '' => '')); |
|
702 | + $state_options = array('' => array('' => '')); |
|
704 | 703 | $states = $this->checkout->action === 'process_reg_step' |
705 | 704 | ? EEM_State::instance()->get_all_states() |
706 | 705 | : EEM_State::instance()->get_all_active_states(); |
707 | - if ( ! empty( $states )) { |
|
708 | - foreach( $states as $state ){ |
|
709 | - if ( $state instanceof EE_State ) { |
|
710 | - $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
706 | + if ( ! empty($states)) { |
|
707 | + foreach ($states as $state) { |
|
708 | + if ($state instanceof EE_State) { |
|
709 | + $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
|
711 | 710 | } |
712 | 711 | } |
713 | 712 | } |
@@ -735,24 +734,24 @@ discard block |
||
735 | 734 | * @throws \EE_Error |
736 | 735 | */ |
737 | 736 | public function process_reg_step() { |
738 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
737 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
739 | 738 | // grab validated data from form |
740 | 739 | $valid_data = $this->checkout->current_step->valid_data(); |
741 | 740 | // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
742 | 741 | // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
743 | 742 | // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
744 | - if ( empty( $valid_data )) { |
|
743 | + if (empty($valid_data)) { |
|
745 | 744 | EE_Error::add_error( |
746 | - __( 'No valid question responses were received.', 'event_espresso' ), |
|
745 | + __('No valid question responses were received.', 'event_espresso'), |
|
747 | 746 | __FILE__, |
748 | 747 | __FUNCTION__, |
749 | 748 | __LINE__ |
750 | 749 | ); |
751 | 750 | return false; |
752 | 751 | } |
753 | - if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg ) { |
|
752 | + if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
754 | 753 | EE_Error::add_error( |
755 | - __( 'A valid transaction could not be initiated for processing your registrations.', 'event_espresso' ), |
|
754 | + __('A valid transaction could not be initiated for processing your registrations.', 'event_espresso'), |
|
756 | 755 | __FILE__, |
757 | 756 | __FUNCTION__, |
758 | 757 | __LINE__ |
@@ -760,11 +759,11 @@ discard block |
||
760 | 759 | return false; |
761 | 760 | } |
762 | 761 | // get cached registrations |
763 | - $registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ); |
|
762 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
764 | 763 | // verify we got the goods |
765 | - if ( empty( $registrations )) { |
|
764 | + if (empty($registrations)) { |
|
766 | 765 | EE_Error::add_error( |
767 | - __( 'Your form data could not be applied to any valid registrations.', 'event_espresso' ), |
|
766 | + __('Your form data could not be applied to any valid registrations.', 'event_espresso'), |
|
768 | 767 | __FILE__, |
769 | 768 | __FUNCTION__, |
770 | 769 | __LINE__ |
@@ -772,15 +771,15 @@ discard block |
||
772 | 771 | return false; |
773 | 772 | } |
774 | 773 | // extract attendee info from form data and save to model objects |
775 | - $registrations_processed = $this->_process_registrations( $registrations, $valid_data ); |
|
774 | + $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
776 | 775 | // if first pass thru SPCO, |
777 | 776 | // then let's check processed registrations against the total number of tickets in the cart |
778 | - if ( $registrations_processed === false ) { |
|
777 | + if ($registrations_processed === false) { |
|
779 | 778 | // but return immediately if the previous step exited early due to errors |
780 | 779 | return false; |
781 | - } else if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count ) { |
|
780 | + } else if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
782 | 781 | // generate a correctly translated string for all possible singular/plural combinations |
783 | - if ( $this->checkout->total_ticket_count === 1 && $registrations_processed !== 1 ) { |
|
782 | + if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
784 | 783 | $error_msg = sprintf( |
785 | 784 | __( |
786 | 785 | 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
@@ -789,7 +788,7 @@ discard block |
||
789 | 788 | $this->checkout->total_ticket_count, |
790 | 789 | $registrations_processed |
791 | 790 | ); |
792 | - } else if ( $this->checkout->total_ticket_count !== 1 && $registrations_processed === 1 ) { |
|
791 | + } else if ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
793 | 792 | $error_msg = sprintf( |
794 | 793 | __( |
795 | 794 | 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
@@ -808,17 +807,17 @@ discard block |
||
808 | 807 | $registrations_processed |
809 | 808 | ); |
810 | 809 | } |
811 | - EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
810 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
812 | 811 | return false; |
813 | 812 | } |
814 | 813 | // mark this reg step as completed |
815 | 814 | $this->set_completed(); |
816 | 815 | $this->_set_success_message( |
817 | - __( 'The Attendee Information Step has been successfully completed.', 'event_espresso' ) |
|
816 | + __('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
818 | 817 | ); |
819 | 818 | //do action in case a plugin wants to do something with the data submitted in step 1. |
820 | 819 | //passes EE_Single_Page_Checkout, and it's posted data |
821 | - do_action( 'AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data ); |
|
820 | + do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
822 | 821 | return true; |
823 | 822 | } |
824 | 823 | |
@@ -832,9 +831,9 @@ discard block |
||
832 | 831 | * @return boolean | int |
833 | 832 | * @throws \EE_Error |
834 | 833 | */ |
835 | - private function _process_registrations( $registrations = array(), $valid_data = array() ) { |
|
834 | + private function _process_registrations($registrations = array(), $valid_data = array()) { |
|
836 | 835 | // load resources and set some defaults |
837 | - EE_Registry::instance()->load_model( 'Attendee' ); |
|
836 | + EE_Registry::instance()->load_model('Attendee'); |
|
838 | 837 | // holder for primary registrant attendee object |
839 | 838 | $this->checkout->primary_attendee_obj = NULL; |
840 | 839 | // array for tracking reg form data for the primary registrant |
@@ -851,9 +850,9 @@ discard block |
||
851 | 850 | // attendee counter |
852 | 851 | $att_nmbr = 0; |
853 | 852 | // grab the saved registrations from the transaction |
854 | - foreach ( $registrations as $registration ) { |
|
853 | + foreach ($registrations as $registration) { |
|
855 | 854 | // verify EE_Registration object |
856 | - if ( ! $registration instanceof EE_Registration ) { |
|
855 | + if ( ! $registration instanceof EE_Registration) { |
|
857 | 856 | EE_Error::add_error( |
858 | 857 | __( |
859 | 858 | 'An invalid Registration object was discovered when attempting to process your registration information.', |
@@ -868,12 +867,12 @@ discard block |
||
868 | 867 | /** @var string $reg_url_link */ |
869 | 868 | $reg_url_link = $registration->reg_url_link(); |
870 | 869 | // reg_url_link exists ? |
871 | - if ( ! empty( $reg_url_link ) ) { |
|
870 | + if ( ! empty($reg_url_link)) { |
|
872 | 871 | // should this registration be processed during this visit ? |
873 | - if ( $this->checkout->visit_allows_processing_of_this_registration( $registration ) ) { |
|
872 | + if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
874 | 873 | // if NOT revisiting, then let's save the registration now, |
875 | 874 | // so that we have a REG_ID to use when generating other objects |
876 | - if ( ! $this->checkout->revisit ) { |
|
875 | + if ( ! $this->checkout->revisit) { |
|
877 | 876 | $registration->save(); |
878 | 877 | } |
879 | 878 | /** |
@@ -883,7 +882,7 @@ discard block |
||
883 | 882 | * @var bool if true is returned by the plugin then the |
884 | 883 | * registration processing is halted. |
885 | 884 | */ |
886 | - if ( apply_filters( |
|
885 | + if (apply_filters( |
|
887 | 886 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
888 | 887 | false, |
889 | 888 | $att_nmbr, |
@@ -891,38 +890,38 @@ discard block |
||
891 | 890 | $registrations, |
892 | 891 | $valid_data, |
893 | 892 | $this |
894 | - ) ) { |
|
893 | + )) { |
|
895 | 894 | return false; |
896 | 895 | } |
897 | 896 | |
898 | 897 | // Houston, we have a registration! |
899 | 898 | $att_nmbr++; |
900 | - $this->_attendee_data[ $reg_url_link ] = array(); |
|
899 | + $this->_attendee_data[$reg_url_link] = array(); |
|
901 | 900 | // grab any existing related answer objects |
902 | 901 | $this->_registration_answers = $registration->answers(); |
903 | 902 | // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
904 | - if ( isset( $valid_data[ $reg_url_link ] ) ) { |
|
903 | + if (isset($valid_data[$reg_url_link])) { |
|
905 | 904 | // do we need to copy basic info from primary attendee ? |
906 | - $copy_primary = isset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) |
|
907 | - && absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0 |
|
905 | + $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info']) |
|
906 | + && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0 |
|
908 | 907 | ? true |
909 | 908 | : false; |
910 | 909 | // filter form input data for this registration |
911 | - $valid_data[ $reg_url_link ] = (array)apply_filters( |
|
910 | + $valid_data[$reg_url_link] = (array) apply_filters( |
|
912 | 911 | 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
913 | - $valid_data[ $reg_url_link ] |
|
912 | + $valid_data[$reg_url_link] |
|
914 | 913 | ); |
915 | 914 | // EEH_Debug_Tools::printr( $valid_data[ $reg_url_link ], '$valid_data[ $reg_url_link ]', __FILE__, __LINE__ ); |
916 | - if ( isset( $valid_data['primary_attendee'] )) { |
|
917 | - $primary_registrant['line_item_id'] = ! empty( $valid_data['primary_attendee'] ) |
|
915 | + if (isset($valid_data['primary_attendee'])) { |
|
916 | + $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
918 | 917 | ? $valid_data['primary_attendee'] |
919 | 918 | : false; |
920 | - unset( $valid_data['primary_attendee'] ); |
|
919 | + unset($valid_data['primary_attendee']); |
|
921 | 920 | } |
922 | 921 | // now loop through our array of valid post data && process attendee reg forms |
923 | - foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) { |
|
924 | - if ( ! in_array( $form_section, $non_input_form_sections )) { |
|
925 | - foreach ( $form_inputs as $form_input => $input_value ) { |
|
922 | + foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
|
923 | + if ( ! in_array($form_section, $non_input_form_sections)) { |
|
924 | + foreach ($form_inputs as $form_input => $input_value) { |
|
926 | 925 | // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
927 | 926 | // check for critical inputs |
928 | 927 | if ( |
@@ -936,16 +935,16 @@ discard block |
||
936 | 935 | // store a bit of data about the primary attendee |
937 | 936 | if ( |
938 | 937 | $att_nmbr === 1 |
939 | - && ! empty( $input_value ) |
|
938 | + && ! empty($input_value) |
|
940 | 939 | && $reg_url_link === $primary_registrant['line_item_id'] |
941 | 940 | ) { |
942 | - $primary_registrant[ $form_input ] = $input_value; |
|
941 | + $primary_registrant[$form_input] = $input_value; |
|
943 | 942 | } else if ( |
944 | 943 | $copy_primary |
945 | 944 | && $input_value === null |
946 | - && isset( $primary_registrant[ $form_input ] ) |
|
945 | + && isset($primary_registrant[$form_input]) |
|
947 | 946 | ) { |
948 | - $input_value = $primary_registrant[ $form_input ]; |
|
947 | + $input_value = $primary_registrant[$form_input]; |
|
949 | 948 | } |
950 | 949 | // now attempt to save the input data |
951 | 950 | if ( |
@@ -987,55 +986,55 @@ discard block |
||
987 | 986 | // have we met before? |
988 | 987 | $attendee = $this->_find_existing_attendee( |
989 | 988 | $registration, |
990 | - $this->_attendee_data[ $reg_url_link ] |
|
989 | + $this->_attendee_data[$reg_url_link] |
|
991 | 990 | ); |
992 | 991 | // did we find an already existing record for this attendee ? |
993 | - if ( $attendee instanceof EE_Attendee ) { |
|
992 | + if ($attendee instanceof EE_Attendee) { |
|
994 | 993 | $attendee = $this->_update_existing_attendee_data( |
995 | 994 | $attendee, |
996 | - $this->_attendee_data[ $reg_url_link ] |
|
995 | + $this->_attendee_data[$reg_url_link] |
|
997 | 996 | ); |
998 | 997 | } else { |
999 | 998 | // ensure critical details are set for additional attendees |
1000 | - $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
999 | + $this->_attendee_data[$reg_url_link] = $att_nmbr > 1 |
|
1001 | 1000 | ? $this->_copy_critical_attendee_details_from_primary_registrant( |
1002 | - $this->_attendee_data[ $reg_url_link ] |
|
1001 | + $this->_attendee_data[$reg_url_link] |
|
1003 | 1002 | ) |
1004 | - : $this->_attendee_data[ $reg_url_link ]; |
|
1003 | + : $this->_attendee_data[$reg_url_link]; |
|
1005 | 1004 | $attendee = $this->_create_new_attendee( |
1006 | 1005 | $registration, |
1007 | - $this->_attendee_data[ $reg_url_link ] |
|
1006 | + $this->_attendee_data[$reg_url_link] |
|
1008 | 1007 | ); |
1009 | 1008 | } |
1010 | 1009 | // who's #1 ? |
1011 | - if ( $att_nmbr === 1 ) { |
|
1010 | + if ($att_nmbr === 1) { |
|
1012 | 1011 | $this->checkout->primary_attendee_obj = $attendee; |
1013 | 1012 | } |
1014 | 1013 | } |
1015 | 1014 | // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
1016 | 1015 | // add relation to registration, set attendee ID, and cache attendee |
1017 | - $this->_associate_attendee_with_registration( $registration, $attendee ); |
|
1016 | + $this->_associate_attendee_with_registration($registration, $attendee); |
|
1018 | 1017 | // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
1019 | - if ( ! $registration->attendee() instanceof EE_Attendee ) { |
|
1020 | - EE_Error::add_error( sprintf( __( 'Registration %s has an invalid or missing Attendee object.', 'event_espresso' ), $reg_url_link ), __FILE__, __FUNCTION__, __LINE__ ); |
|
1018 | + if ( ! $registration->attendee() instanceof EE_Attendee) { |
|
1019 | + EE_Error::add_error(sprintf(__('Registration %s has an invalid or missing Attendee object.', 'event_espresso'), $reg_url_link), __FILE__, __FUNCTION__, __LINE__); |
|
1021 | 1020 | return false; |
1022 | 1021 | } |
1023 | 1022 | /** @type EE_Registration_Processor $registration_processor */ |
1024 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
1023 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1025 | 1024 | // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
1026 | - $registration_processor->toggle_incomplete_registration_status_to_default( $registration, false ); |
|
1025 | + $registration_processor->toggle_incomplete_registration_status_to_default($registration, false); |
|
1027 | 1026 | // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
1028 | 1027 | $this->checkout->transaction->toggle_failed_transaction_status(); |
1029 | 1028 | // if we've gotten this far, then let's save what we have |
1030 | 1029 | $registration->save(); |
1031 | 1030 | // add relation between TXN and registration |
1032 | - $this->_associate_registration_with_transaction( $registration ); |
|
1031 | + $this->_associate_registration_with_transaction($registration); |
|
1033 | 1032 | } // end of if ( ! $this->checkout->revisit || $this->checkout->primary_revisit || ( $this->checkout->revisit && $this->checkout->reg_url_link == $reg_url_link )) { |
1034 | 1033 | |
1035 | - } else { |
|
1036 | - EE_Error::add_error( __( 'An invalid or missing line item ID was encountered while attempting to process the registration form.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
1034 | + } else { |
|
1035 | + EE_Error::add_error(__('An invalid or missing line item ID was encountered while attempting to process the registration form.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1037 | 1036 | // remove malformed data |
1038 | - unset( $valid_data[ $reg_url_link ] ); |
|
1037 | + unset($valid_data[$reg_url_link]); |
|
1039 | 1038 | return false; |
1040 | 1039 | } |
1041 | 1040 | |
@@ -1064,26 +1063,26 @@ discard block |
||
1064 | 1063 | // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
1065 | 1064 | // allow for plugins to hook in and do their own processing of the form input. |
1066 | 1065 | // For plugins to bypass normal processing here, they just need to return a boolean value. |
1067 | - if ( apply_filters( |
|
1066 | + if (apply_filters( |
|
1068 | 1067 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
1069 | 1068 | false, |
1070 | 1069 | $registration, |
1071 | 1070 | $form_input, |
1072 | 1071 | $input_value, |
1073 | 1072 | $this |
1074 | - ) ) { |
|
1073 | + )) { |
|
1075 | 1074 | return true; |
1076 | 1075 | } |
1077 | 1076 | // $answer_cache_id is the key used to find the EE_Answer we want |
1078 | 1077 | $answer_cache_id = $this->checkout->reg_url_link |
1079 | 1078 | ? $form_input |
1080 | - : $form_input . '-' . $registration->reg_url_link(); |
|
1081 | - $answer_is_obj = isset( $this->_registration_answers[ $answer_cache_id ] ) |
|
1082 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
1079 | + : $form_input.'-'.$registration->reg_url_link(); |
|
1080 | + $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
|
1081 | + && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer |
|
1083 | 1082 | ? true |
1084 | 1083 | : false; |
1085 | 1084 | //rename form_inputs if they are EE_Attendee properties |
1086 | - switch( (string)$form_input ) { |
|
1085 | + switch ((string) $form_input) { |
|
1087 | 1086 | |
1088 | 1087 | case 'state' : |
1089 | 1088 | case 'STA_ID' : |
@@ -1098,32 +1097,32 @@ discard block |
||
1098 | 1097 | break; |
1099 | 1098 | |
1100 | 1099 | default : |
1101 | - $ATT_input = 'ATT_' . $form_input; |
|
1100 | + $ATT_input = 'ATT_'.$form_input; |
|
1102 | 1101 | //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
1103 | - $attendee_property = EEM_Attendee::instance()->has_field( $ATT_input ) ? true : false; |
|
1104 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1102 | + $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
1103 | + $form_input = $attendee_property ? 'ATT_'.$form_input : $form_input; |
|
1105 | 1104 | } |
1106 | 1105 | // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
1107 | 1106 | // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
1108 | 1107 | // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
1109 | 1108 | // if this form input has a corresponding attendee property |
1110 | - if ( $attendee_property ) { |
|
1111 | - $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
1112 | - if ( $answer_is_obj ) { |
|
1109 | + if ($attendee_property) { |
|
1110 | + $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value; |
|
1111 | + if ($answer_is_obj) { |
|
1113 | 1112 | // and delete the corresponding answer since we won't be storing this data in that object |
1114 | - $registration->_remove_relation_to( $this->_registration_answers[ $answer_cache_id ], 'Answer' ); |
|
1115 | - $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
1113 | + $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer'); |
|
1114 | + $this->_registration_answers[$answer_cache_id]->delete_permanently(); |
|
1116 | 1115 | } |
1117 | 1116 | return true; |
1118 | - } elseif ( $answer_is_obj ) { |
|
1117 | + } elseif ($answer_is_obj) { |
|
1119 | 1118 | // save this data to the answer object |
1120 | - $this->_registration_answers[ $answer_cache_id ]->set_value( $input_value ); |
|
1121 | - $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
1119 | + $this->_registration_answers[$answer_cache_id]->set_value($input_value); |
|
1120 | + $result = $this->_registration_answers[$answer_cache_id]->save(); |
|
1122 | 1121 | return $result !== false ? true : false; |
1123 | 1122 | } else { |
1124 | - foreach ( $this->_registration_answers as $answer ) { |
|
1125 | - if ( $answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id ) { |
|
1126 | - $answer->set_value( $input_value ); |
|
1123 | + foreach ($this->_registration_answers as $answer) { |
|
1124 | + if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
1125 | + $answer->set_value($input_value); |
|
1127 | 1126 | $result = $answer->save(); |
1128 | 1127 | return $result !== false ? true : false; |
1129 | 1128 | } |
@@ -1145,15 +1144,15 @@ discard block |
||
1145 | 1144 | $form_input = '', |
1146 | 1145 | $input_value = '' |
1147 | 1146 | ) { |
1148 | - if ( empty( $input_value ) ) { |
|
1147 | + if (empty($input_value)) { |
|
1149 | 1148 | // if the form input isn't marked as being required, then just return |
1150 | - if ( ! isset( $this->_required_questions[ $form_input ] ) || ! $this->_required_questions[ $form_input ] ) { |
|
1149 | + if ( ! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
1151 | 1150 | return true; |
1152 | 1151 | } |
1153 | - switch ( $form_input ) { |
|
1152 | + switch ($form_input) { |
|
1154 | 1153 | case 'fname' : |
1155 | 1154 | EE_Error::add_error( |
1156 | - __( 'First Name is a required value.', 'event_espresso' ), |
|
1155 | + __('First Name is a required value.', 'event_espresso'), |
|
1157 | 1156 | __FILE__, |
1158 | 1157 | __FUNCTION__, |
1159 | 1158 | __LINE__ |
@@ -1162,7 +1161,7 @@ discard block |
||
1162 | 1161 | break; |
1163 | 1162 | case 'lname' : |
1164 | 1163 | EE_Error::add_error( |
1165 | - __( 'Last Name is a required value.', 'event_espresso' ), |
|
1164 | + __('Last Name is a required value.', 'event_espresso'), |
|
1166 | 1165 | __FILE__, |
1167 | 1166 | __FUNCTION__, |
1168 | 1167 | __LINE__ |
@@ -1171,7 +1170,7 @@ discard block |
||
1171 | 1170 | break; |
1172 | 1171 | case 'email' : |
1173 | 1172 | EE_Error::add_error( |
1174 | - __( 'Please enter a valid email address.', 'event_espresso' ), |
|
1173 | + __('Please enter a valid email address.', 'event_espresso'), |
|
1175 | 1174 | __FILE__, |
1176 | 1175 | __FUNCTION__, |
1177 | 1176 | __LINE__ |
@@ -1193,30 +1192,30 @@ discard block |
||
1193 | 1192 | * @return boolean|EE_Attendee |
1194 | 1193 | * @throws \EE_Error |
1195 | 1194 | */ |
1196 | - private function _find_existing_attendee( EE_Registration $registration, $attendee_data = array() ) { |
|
1195 | + private function _find_existing_attendee(EE_Registration $registration, $attendee_data = array()) { |
|
1197 | 1196 | $existing_attendee = null; |
1198 | 1197 | // if none of the critical properties are set in the incoming attendee data... |
1199 | 1198 | // then attempt to copy them from the primary attendee |
1200 | 1199 | if ( |
1201 | 1200 | $this->checkout->primary_attendee_obj instanceof EE_Attendee |
1202 | - && ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] ) |
|
1201 | + && ! isset($attendee_data['ATT_fname'], $attendee_data['ATT_email']) |
|
1203 | 1202 | ) { |
1204 | 1203 | return $this->checkout->primary_attendee_obj; |
1205 | 1204 | } |
1206 | 1205 | // does this attendee already exist in the db ? |
1207 | 1206 | // we're searching using a combination of first name, last name, AND email address |
1208 | - $ATT_fname = isset( $attendee_data['ATT_fname'] ) && ! empty( $attendee_data['ATT_fname'] ) |
|
1207 | + $ATT_fname = isset($attendee_data['ATT_fname']) && ! empty($attendee_data['ATT_fname']) |
|
1209 | 1208 | ? $attendee_data['ATT_fname'] |
1210 | 1209 | : ''; |
1211 | - $ATT_lname = isset( $attendee_data['ATT_lname'] ) && ! empty( $attendee_data['ATT_lname'] ) |
|
1210 | + $ATT_lname = isset($attendee_data['ATT_lname']) && ! empty($attendee_data['ATT_lname']) |
|
1212 | 1211 | ? $attendee_data['ATT_lname'] |
1213 | 1212 | : ''; |
1214 | - $ATT_email = isset( $attendee_data['ATT_email'] ) && ! empty( $attendee_data['ATT_email'] ) |
|
1213 | + $ATT_email = isset($attendee_data['ATT_email']) && ! empty($attendee_data['ATT_email']) |
|
1215 | 1214 | ? $attendee_data['ATT_email'] |
1216 | 1215 | : ''; |
1217 | 1216 | // but only if those have values |
1218 | - if ( $ATT_fname && $ATT_lname && $ATT_email ) { |
|
1219 | - $existing_attendee = EEM_Attendee::instance()->find_existing_attendee( array( |
|
1217 | + if ($ATT_fname && $ATT_lname && $ATT_email) { |
|
1218 | + $existing_attendee = EEM_Attendee::instance()->find_existing_attendee(array( |
|
1220 | 1219 | 'ATT_fname' => $ATT_fname, |
1221 | 1220 | 'ATT_lname' => $ATT_lname, |
1222 | 1221 | 'ATT_email' => $ATT_email |
@@ -1240,13 +1239,13 @@ discard block |
||
1240 | 1239 | * @return \EE_Attendee |
1241 | 1240 | * @throws \EE_Error |
1242 | 1241 | */ |
1243 | - private function _update_existing_attendee_data( EE_Attendee $existing_attendee, $attendee_data = array() ) { |
|
1242 | + private function _update_existing_attendee_data(EE_Attendee $existing_attendee, $attendee_data = array()) { |
|
1244 | 1243 | // first remove fname, lname, and email from attendee data |
1245 | - $dont_set = array( 'ATT_fname', 'ATT_lname', 'ATT_email' ); |
|
1244 | + $dont_set = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1246 | 1245 | // now loop thru what's left and add to attendee CPT |
1247 | - foreach ( $attendee_data as $property_name => $property_value ) { |
|
1248 | - if ( ! in_array( $property_name, $dont_set ) && EEM_Attendee::instance()->has_field( $property_name )) { |
|
1249 | - $existing_attendee->set( $property_name, $property_value ); |
|
1246 | + foreach ($attendee_data as $property_name => $property_value) { |
|
1247 | + if ( ! in_array($property_name, $dont_set) && EEM_Attendee::instance()->has_field($property_name)) { |
|
1248 | + $existing_attendee->set($property_name, $property_value); |
|
1250 | 1249 | } |
1251 | 1250 | } |
1252 | 1251 | // better save that now |
@@ -1264,11 +1263,11 @@ discard block |
||
1264 | 1263 | * @return void |
1265 | 1264 | * @throws \EE_Error |
1266 | 1265 | */ |
1267 | - private function _associate_attendee_with_registration( EE_Registration $registration, EE_Attendee $attendee ) { |
|
1266 | + private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) { |
|
1268 | 1267 | // add relation to attendee |
1269 | - $registration->_add_relation_to( $attendee, 'Attendee' ); |
|
1270 | - $registration->set_attendee_id( $attendee->ID() ); |
|
1271 | - $registration->update_cache_after_object_save( 'Attendee', $attendee ); |
|
1268 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
1269 | + $registration->set_attendee_id($attendee->ID()); |
|
1270 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1272 | 1271 | } |
1273 | 1272 | |
1274 | 1273 | |
@@ -1280,10 +1279,10 @@ discard block |
||
1280 | 1279 | * @return void |
1281 | 1280 | * @throws \EE_Error |
1282 | 1281 | */ |
1283 | - private function _associate_registration_with_transaction( EE_Registration $registration ) { |
|
1282 | + private function _associate_registration_with_transaction(EE_Registration $registration) { |
|
1284 | 1283 | // add relation to attendee |
1285 | - $this->checkout->transaction->_add_relation_to( $registration, 'Registration' ); |
|
1286 | - $this->checkout->transaction->update_cache_after_object_save( 'Registration', $registration ); |
|
1284 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
1285 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
1287 | 1286 | } |
1288 | 1287 | |
1289 | 1288 | |
@@ -1296,14 +1295,14 @@ discard block |
||
1296 | 1295 | * @return array |
1297 | 1296 | * @throws \EE_Error |
1298 | 1297 | */ |
1299 | - private function _copy_critical_attendee_details_from_primary_registrant( $attendee_data = array() ) { |
|
1298 | + private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) { |
|
1300 | 1299 | // bare minimum critical details include first name, last name, email address |
1301 | - $critical_attendee_details = array( 'ATT_fname', 'ATT_lname', 'ATT_email' ); |
|
1300 | + $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1302 | 1301 | // add address info to critical details? |
1303 | - if ( apply_filters( |
|
1302 | + if (apply_filters( |
|
1304 | 1303 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
1305 | 1304 | false |
1306 | - ) ) { |
|
1305 | + )) { |
|
1307 | 1306 | $address_details = array( |
1308 | 1307 | 'ATT_address', |
1309 | 1308 | 'ATT_address2', |
@@ -1313,13 +1312,13 @@ discard block |
||
1313 | 1312 | 'ATT_zip', |
1314 | 1313 | 'ATT_phone' |
1315 | 1314 | ); |
1316 | - $critical_attendee_details = array_merge( $critical_attendee_details, $address_details ); |
|
1315 | + $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
1317 | 1316 | } |
1318 | - foreach ( $critical_attendee_details as $critical_attendee_detail ) { |
|
1319 | - if ( ! isset( $attendee_data[ $critical_attendee_detail ] ) |
|
1320 | - || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
1317 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
1318 | + if ( ! isset($attendee_data[$critical_attendee_detail]) |
|
1319 | + || empty($attendee_data[$critical_attendee_detail]) |
|
1321 | 1320 | ) { |
1322 | - $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
1321 | + $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
|
1323 | 1322 | $critical_attendee_detail |
1324 | 1323 | ); |
1325 | 1324 | } |
@@ -1337,11 +1336,11 @@ discard block |
||
1337 | 1336 | * @return \EE_Attendee |
1338 | 1337 | * @throws \EE_Error |
1339 | 1338 | */ |
1340 | - private function _create_new_attendee( EE_Registration $registration, $attendee_data = array() ) { |
|
1339 | + private function _create_new_attendee(EE_Registration $registration, $attendee_data = array()) { |
|
1341 | 1340 | // create new attendee object |
1342 | - $new_attendee = EE_Attendee::new_instance( $attendee_data ); |
|
1341 | + $new_attendee = EE_Attendee::new_instance($attendee_data); |
|
1343 | 1342 | // set author to event creator |
1344 | - $new_attendee->set( 'ATT_author', $registration->event()->wp_user() ); |
|
1343 | + $new_attendee->set('ATT_author', $registration->event()->wp_user()); |
|
1345 | 1344 | $new_attendee->save(); |
1346 | 1345 | return $new_attendee; |
1347 | 1346 | } |
@@ -1358,7 +1357,7 @@ discard block |
||
1358 | 1357 | */ |
1359 | 1358 | public function update_reg_step() { |
1360 | 1359 | // save everything |
1361 | - if ( $this->process_reg_step() ) { |
|
1360 | + if ($this->process_reg_step()) { |
|
1362 | 1361 | $this->checkout->redirect = true; |
1363 | 1362 | $this->checkout->redirect_url = add_query_arg( |
1364 | 1363 | array( |
@@ -1367,7 +1366,7 @@ discard block |
||
1367 | 1366 | ), |
1368 | 1367 | $this->checkout->thank_you_page_url |
1369 | 1368 | ); |
1370 | - $this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url ); |
|
1369 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1371 | 1370 | return true; |
1372 | 1371 | } |
1373 | 1372 | return false; |
@@ -16,219 +16,219 @@ |
||
16 | 16 | class Registry |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $jsdata = array(); |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * Registry constructor. |
|
28 | - * Hooking into WP actions for script registry. |
|
29 | - */ |
|
30 | - public function __construct() |
|
31 | - { |
|
32 | - add_action('wp_enqueue_scripts', array($this, 'scripts'), 100); |
|
33 | - add_action('admin_enqueue_scripts', array($this, 'scripts'), 100); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * Callback for the WP script actions. |
|
39 | - * Used to register globally accessible core scripts. |
|
40 | - * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
41 | - */ |
|
42 | - public function scripts() |
|
43 | - { |
|
44 | - wp_register_script( |
|
45 | - 'eejs-core', |
|
46 | - EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
47 | - array(), |
|
48 | - espresso_version(), |
|
49 | - true |
|
50 | - ); |
|
51 | - |
|
52 | - //js.api |
|
53 | - wp_register_script( |
|
54 | - 'eejs-api', |
|
55 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
56 | - array('underscore','eejs-core'), |
|
57 | - espresso_version(), |
|
58 | - true |
|
59 | - ); |
|
60 | - $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
61 | - |
|
62 | - wp_localize_script('eejs-core', 'eejs', array('data'=>$this->jsdata)); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * Used to add data to eejs.data object. |
|
68 | - * |
|
69 | - * Note: Overriding existing data is not allowed. |
|
70 | - * |
|
71 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
72 | - * If the data you add is something like this: |
|
73 | - * |
|
74 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
75 | - * |
|
76 | - * It will be exposed in the page source as: |
|
77 | - * |
|
78 | - * eejs.data.my_plugin_data.foo == gar |
|
79 | - * |
|
80 | - * @param string $key Key used to access your data |
|
81 | - * @param string|array $value Value to attach to key |
|
82 | - * @throws \InvalidArgumentException |
|
83 | - */ |
|
84 | - public function addData($key, $value) |
|
85 | - { |
|
86 | - if ($this->verifyDataNotExisting($key)) { |
|
87 | - $this->jsdata[$key] = $value; |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
94 | - * elements in an array. |
|
95 | - * |
|
96 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
97 | - * |
|
98 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript object |
|
99 | - * like this, |
|
100 | - * |
|
101 | - * eejs.data.test = [ |
|
102 | - * my_data, |
|
103 | - * ] |
|
104 | - * |
|
105 | - * If there has already been a scalar value attached to the data object given key, then |
|
106 | - * this will throw an exception. |
|
107 | - * |
|
108 | - * @param string $key Key to attach data to. |
|
109 | - * @param string|array $value Value being registered. |
|
110 | - * @throws InvalidArgumentException |
|
111 | - */ |
|
112 | - public function pushData($key, $value) |
|
113 | - { |
|
114 | - if (isset($this->jsdata[$key]) |
|
115 | - && ! is_array($this->jsdata[$key]) |
|
116 | - ) { |
|
117 | - throw new invalidArgumentException( |
|
118 | - sprintf( |
|
119 | - __( |
|
120 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
19 | + /** |
|
20 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $jsdata = array(); |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * Registry constructor. |
|
28 | + * Hooking into WP actions for script registry. |
|
29 | + */ |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + add_action('wp_enqueue_scripts', array($this, 'scripts'), 100); |
|
33 | + add_action('admin_enqueue_scripts', array($this, 'scripts'), 100); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * Callback for the WP script actions. |
|
39 | + * Used to register globally accessible core scripts. |
|
40 | + * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
41 | + */ |
|
42 | + public function scripts() |
|
43 | + { |
|
44 | + wp_register_script( |
|
45 | + 'eejs-core', |
|
46 | + EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
47 | + array(), |
|
48 | + espresso_version(), |
|
49 | + true |
|
50 | + ); |
|
51 | + |
|
52 | + //js.api |
|
53 | + wp_register_script( |
|
54 | + 'eejs-api', |
|
55 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
56 | + array('underscore','eejs-core'), |
|
57 | + espresso_version(), |
|
58 | + true |
|
59 | + ); |
|
60 | + $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
61 | + |
|
62 | + wp_localize_script('eejs-core', 'eejs', array('data'=>$this->jsdata)); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * Used to add data to eejs.data object. |
|
68 | + * |
|
69 | + * Note: Overriding existing data is not allowed. |
|
70 | + * |
|
71 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
72 | + * If the data you add is something like this: |
|
73 | + * |
|
74 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
75 | + * |
|
76 | + * It will be exposed in the page source as: |
|
77 | + * |
|
78 | + * eejs.data.my_plugin_data.foo == gar |
|
79 | + * |
|
80 | + * @param string $key Key used to access your data |
|
81 | + * @param string|array $value Value to attach to key |
|
82 | + * @throws \InvalidArgumentException |
|
83 | + */ |
|
84 | + public function addData($key, $value) |
|
85 | + { |
|
86 | + if ($this->verifyDataNotExisting($key)) { |
|
87 | + $this->jsdata[$key] = $value; |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
94 | + * elements in an array. |
|
95 | + * |
|
96 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
97 | + * |
|
98 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript object |
|
99 | + * like this, |
|
100 | + * |
|
101 | + * eejs.data.test = [ |
|
102 | + * my_data, |
|
103 | + * ] |
|
104 | + * |
|
105 | + * If there has already been a scalar value attached to the data object given key, then |
|
106 | + * this will throw an exception. |
|
107 | + * |
|
108 | + * @param string $key Key to attach data to. |
|
109 | + * @param string|array $value Value being registered. |
|
110 | + * @throws InvalidArgumentException |
|
111 | + */ |
|
112 | + public function pushData($key, $value) |
|
113 | + { |
|
114 | + if (isset($this->jsdata[$key]) |
|
115 | + && ! is_array($this->jsdata[$key]) |
|
116 | + ) { |
|
117 | + throw new invalidArgumentException( |
|
118 | + sprintf( |
|
119 | + __( |
|
120 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
121 | 121 | push values to this data element when it is an array.', |
122 | - 'event_espresso' |
|
123 | - ), |
|
124 | - $key, |
|
125 | - __METHOD__ |
|
126 | - ) |
|
127 | - ); |
|
128 | - } |
|
129 | - |
|
130 | - $this->jsdata[$key][] = $value; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * Used to set content used by javascript for a template. |
|
136 | - * |
|
137 | - * Note: Overrides of existing registered templates are not allowed. |
|
138 | - * |
|
139 | - * @param string $template_reference |
|
140 | - * @param string $template_content |
|
141 | - */ |
|
142 | - public function addTemplate($template_reference, $template_content) |
|
143 | - { |
|
144 | - if (! isset($this->jsdata['templates'])) { |
|
145 | - $this->jsdata['templates'] = array(); |
|
146 | - } |
|
147 | - |
|
148 | - //no overrides allowed. |
|
149 | - if (isset($this->jsdata['templates'][$template_reference])) { |
|
150 | - throw new invalidArgumentException( |
|
151 | - sprintf( |
|
152 | - __( |
|
153 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
154 | - 'event_espresso' |
|
155 | - ), |
|
156 | - $template_reference |
|
157 | - ) |
|
158 | - ); |
|
159 | - } else { |
|
160 | - $this->jsdata['templates'][$template_reference] = $template_content; |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Retrieve the template content already registered for the given reference. |
|
167 | - * @param string $template_reference |
|
168 | - * @return '' |
|
169 | - */ |
|
170 | - public function getTemplate($template_reference) |
|
171 | - { |
|
172 | - return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
173 | - ? $this->jsdata['templates'][$template_reference] |
|
174 | - : ''; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * Retrieve registered data. |
|
180 | - * |
|
181 | - * @param string $key Name of key to attach data to. |
|
182 | - * @return mixed If there is no for the given key, then false is returned. |
|
183 | - */ |
|
184 | - public function getData($key) |
|
185 | - { |
|
186 | - return isset($this->jsdata[$key]) |
|
187 | - ? $this->jsdata[$key] |
|
188 | - : false; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * Verifies whether the given data exists already on the jsdata array. |
|
196 | - * |
|
197 | - * Overriding data is not allowed. |
|
198 | - * |
|
199 | - * @param string $key Index for data. |
|
200 | - * @return bool If valid then return true. |
|
201 | - * @throws InvalidArgumentException if data already exists. |
|
202 | - */ |
|
203 | - protected function verifyDataNotExisting($key) |
|
204 | - { |
|
205 | - if (isset($this->jsdata[$key])) { |
|
206 | - if (is_array($this->jsdata[$key])) { |
|
207 | - throw new InvalidArgumentException( |
|
208 | - sprintf( |
|
209 | - __( |
|
210 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
122 | + 'event_espresso' |
|
123 | + ), |
|
124 | + $key, |
|
125 | + __METHOD__ |
|
126 | + ) |
|
127 | + ); |
|
128 | + } |
|
129 | + |
|
130 | + $this->jsdata[$key][] = $value; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * Used to set content used by javascript for a template. |
|
136 | + * |
|
137 | + * Note: Overrides of existing registered templates are not allowed. |
|
138 | + * |
|
139 | + * @param string $template_reference |
|
140 | + * @param string $template_content |
|
141 | + */ |
|
142 | + public function addTemplate($template_reference, $template_content) |
|
143 | + { |
|
144 | + if (! isset($this->jsdata['templates'])) { |
|
145 | + $this->jsdata['templates'] = array(); |
|
146 | + } |
|
147 | + |
|
148 | + //no overrides allowed. |
|
149 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
150 | + throw new invalidArgumentException( |
|
151 | + sprintf( |
|
152 | + __( |
|
153 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
154 | + 'event_espresso' |
|
155 | + ), |
|
156 | + $template_reference |
|
157 | + ) |
|
158 | + ); |
|
159 | + } else { |
|
160 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Retrieve the template content already registered for the given reference. |
|
167 | + * @param string $template_reference |
|
168 | + * @return '' |
|
169 | + */ |
|
170 | + public function getTemplate($template_reference) |
|
171 | + { |
|
172 | + return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
173 | + ? $this->jsdata['templates'][$template_reference] |
|
174 | + : ''; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * Retrieve registered data. |
|
180 | + * |
|
181 | + * @param string $key Name of key to attach data to. |
|
182 | + * @return mixed If there is no for the given key, then false is returned. |
|
183 | + */ |
|
184 | + public function getData($key) |
|
185 | + { |
|
186 | + return isset($this->jsdata[$key]) |
|
187 | + ? $this->jsdata[$key] |
|
188 | + : false; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * Verifies whether the given data exists already on the jsdata array. |
|
196 | + * |
|
197 | + * Overriding data is not allowed. |
|
198 | + * |
|
199 | + * @param string $key Index for data. |
|
200 | + * @return bool If valid then return true. |
|
201 | + * @throws InvalidArgumentException if data already exists. |
|
202 | + */ |
|
203 | + protected function verifyDataNotExisting($key) |
|
204 | + { |
|
205 | + if (isset($this->jsdata[$key])) { |
|
206 | + if (is_array($this->jsdata[$key])) { |
|
207 | + throw new InvalidArgumentException( |
|
208 | + sprintf( |
|
209 | + __( |
|
210 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
211 | 211 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
212 | 212 | %2$s method to push your value to the array.', |
213 | - 'event_espresso' |
|
214 | - ), |
|
215 | - $key, |
|
216 | - 'pushData()' |
|
217 | - ) |
|
218 | - ); |
|
219 | - } else { |
|
220 | - throw new InvalidArgumentException( |
|
221 | - sprintf( |
|
222 | - __( |
|
223 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
213 | + 'event_espresso' |
|
214 | + ), |
|
215 | + $key, |
|
216 | + 'pushData()' |
|
217 | + ) |
|
218 | + ); |
|
219 | + } else { |
|
220 | + throw new InvalidArgumentException( |
|
221 | + sprintf( |
|
222 | + __( |
|
223 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
224 | 224 | allowed. Consider attaching your value to a different key', |
225 | - 'event_espresso' |
|
226 | - ), |
|
227 | - $key |
|
228 | - ) |
|
229 | - ); |
|
230 | - } |
|
231 | - } |
|
232 | - return true; |
|
233 | - } |
|
225 | + 'event_espresso' |
|
226 | + ), |
|
227 | + $key |
|
228 | + ) |
|
229 | + ); |
|
230 | + } |
|
231 | + } |
|
232 | + return true; |
|
233 | + } |
|
234 | 234 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | { |
44 | 44 | wp_register_script( |
45 | 45 | 'eejs-core', |
46 | - EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
46 | + EE_PLUGIN_DIR_URL.'core/services/assets/core_assets/eejs-core.js', |
|
47 | 47 | array(), |
48 | 48 | espresso_version(), |
49 | 49 | true |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | //js.api |
53 | 53 | wp_register_script( |
54 | 54 | 'eejs-api', |
55 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
56 | - array('underscore','eejs-core'), |
|
55 | + EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js', |
|
56 | + array('underscore', 'eejs-core'), |
|
57 | 57 | espresso_version(), |
58 | 58 | true |
59 | 59 | ); |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function addTemplate($template_reference, $template_content) |
143 | 143 | { |
144 | - if (! isset($this->jsdata['templates'])) { |
|
144 | + if ( ! isset($this->jsdata['templates'])) { |
|
145 | 145 | $this->jsdata['templates'] = array(); |
146 | 146 | } |
147 | 147 |
@@ -16,1372 +16,1372 @@ |
||
16 | 16 | class EE_Registry |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * EE_Registry Object |
|
21 | - * |
|
22 | - * @var EE_Registry $_instance |
|
23 | - * @access private |
|
24 | - */ |
|
25 | - private static $_instance = null; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var EE_Dependency_Map $_dependency_map |
|
29 | - * @access protected |
|
30 | - */ |
|
31 | - protected $_dependency_map = null; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var array $_class_abbreviations |
|
35 | - * @access protected |
|
36 | - */ |
|
37 | - protected $_class_abbreviations = array(); |
|
38 | - |
|
39 | - /** |
|
40 | - * @access public |
|
41 | - * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
42 | - */ |
|
43 | - public $BUS; |
|
44 | - |
|
45 | - /** |
|
46 | - * EE_Cart Object |
|
47 | - * |
|
48 | - * @access public |
|
49 | - * @var EE_Cart $CART |
|
50 | - */ |
|
51 | - public $CART = null; |
|
52 | - |
|
53 | - /** |
|
54 | - * EE_Config Object |
|
55 | - * |
|
56 | - * @access public |
|
57 | - * @var EE_Config $CFG |
|
58 | - */ |
|
59 | - public $CFG = null; |
|
60 | - |
|
61 | - /** |
|
62 | - * EE_Network_Config Object |
|
63 | - * |
|
64 | - * @access public |
|
65 | - * @var EE_Network_Config $NET_CFG |
|
66 | - */ |
|
67 | - public $NET_CFG = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * StdClass object for storing library classes in |
|
71 | - * |
|
72 | - * @public LIB |
|
73 | - * @var StdClass $LIB |
|
74 | - */ |
|
75 | - public $LIB = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * EE_Request_Handler Object |
|
79 | - * |
|
80 | - * @access public |
|
81 | - * @var EE_Request_Handler $REQ |
|
82 | - */ |
|
83 | - public $REQ = null; |
|
84 | - |
|
85 | - /** |
|
86 | - * EE_Session Object |
|
87 | - * |
|
88 | - * @access public |
|
89 | - * @var EE_Session $SSN |
|
90 | - */ |
|
91 | - public $SSN = null; |
|
92 | - |
|
93 | - /** |
|
94 | - * holds the ee capabilities object. |
|
95 | - * |
|
96 | - * @since 4.5.0 |
|
97 | - * @var EE_Capabilities |
|
98 | - */ |
|
99 | - public $CAP = null; |
|
100 | - |
|
101 | - /** |
|
102 | - * holds the EE_Message_Resource_Manager object. |
|
103 | - * |
|
104 | - * @since 4.9.0 |
|
105 | - * @var EE_Message_Resource_Manager |
|
106 | - */ |
|
107 | - public $MRM = null; |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Holds the Assets Registry instance |
|
112 | - * @var Registry |
|
113 | - */ |
|
114 | - public $AssetsRegistry = null; |
|
115 | - |
|
116 | - /** |
|
117 | - * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * @var EE_Addon[] |
|
121 | - */ |
|
122 | - public $addons = null; |
|
123 | - |
|
124 | - /** |
|
125 | - * $models |
|
126 | - * @access public |
|
127 | - * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
128 | - */ |
|
129 | - public $models = array(); |
|
130 | - |
|
131 | - /** |
|
132 | - * $modules |
|
133 | - * @access public |
|
134 | - * @var EED_Module[] $modules |
|
135 | - */ |
|
136 | - public $modules = null; |
|
137 | - |
|
138 | - /** |
|
139 | - * $shortcodes |
|
140 | - * @access public |
|
141 | - * @var EES_Shortcode[] $shortcodes |
|
142 | - */ |
|
143 | - public $shortcodes = null; |
|
144 | - |
|
145 | - /** |
|
146 | - * $widgets |
|
147 | - * @access public |
|
148 | - * @var WP_Widget[] $widgets |
|
149 | - */ |
|
150 | - public $widgets = null; |
|
151 | - |
|
152 | - /** |
|
153 | - * $non_abstract_db_models |
|
154 | - * @access public |
|
155 | - * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
156 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
157 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
158 | - * classnames (eg "EEM_Event") |
|
159 | - */ |
|
160 | - public $non_abstract_db_models = array(); |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * $i18n_js_strings - internationalization for JS strings |
|
165 | - * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
166 | - * in js file: var translatedString = eei18n.string_key; |
|
167 | - * |
|
168 | - * @access public |
|
169 | - * @var array |
|
170 | - */ |
|
171 | - public static $i18n_js_strings = array(); |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * $main_file - path to espresso.php |
|
176 | - * |
|
177 | - * @access public |
|
178 | - * @var array |
|
179 | - */ |
|
180 | - public $main_file; |
|
181 | - |
|
182 | - /** |
|
183 | - * array of ReflectionClass objects where the key is the class name |
|
184 | - * |
|
185 | - * @access public |
|
186 | - * @var ReflectionClass[] |
|
187 | - */ |
|
188 | - public $_reflectors; |
|
189 | - |
|
190 | - /** |
|
191 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
192 | - * |
|
193 | - * @access protected |
|
194 | - * @var boolean $_cache_on |
|
195 | - */ |
|
196 | - protected $_cache_on = true; |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @singleton method used to instantiate class object |
|
202 | - * @access public |
|
203 | - * @param \EE_Dependency_Map $dependency_map |
|
204 | - * @return \EE_Registry instance |
|
205 | - */ |
|
206 | - public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
207 | - { |
|
208 | - // check if class object is instantiated |
|
209 | - if ( ! self::$_instance instanceof EE_Registry) { |
|
210 | - self::$_instance = new EE_Registry($dependency_map); |
|
211 | - } |
|
212 | - return self::$_instance; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - *protected constructor to prevent direct creation |
|
219 | - * |
|
220 | - * @Constructor |
|
221 | - * @access protected |
|
222 | - * @param \EE_Dependency_Map $dependency_map |
|
223 | - * @return \EE_Registry |
|
224 | - */ |
|
225 | - protected function __construct(\EE_Dependency_Map $dependency_map) |
|
226 | - { |
|
227 | - $this->_dependency_map = $dependency_map; |
|
228 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * initialize |
|
235 | - */ |
|
236 | - public function initialize() |
|
237 | - { |
|
238 | - $this->_class_abbreviations = apply_filters( |
|
239 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
240 | - array( |
|
241 | - 'EE_Config' => 'CFG', |
|
242 | - 'EE_Session' => 'SSN', |
|
243 | - 'EE_Capabilities' => 'CAP', |
|
244 | - 'EE_Cart' => 'CART', |
|
245 | - 'EE_Network_Config' => 'NET_CFG', |
|
246 | - 'EE_Request_Handler' => 'REQ', |
|
247 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
248 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
249 | - ) |
|
250 | - ); |
|
251 | - // class library |
|
252 | - $this->LIB = new stdClass(); |
|
253 | - $this->addons = new stdClass(); |
|
254 | - $this->modules = new stdClass(); |
|
255 | - $this->shortcodes = new stdClass(); |
|
256 | - $this->widgets = new stdClass(); |
|
257 | - $this->load_core('Base', array(), true); |
|
258 | - // add our request and response objects to the cache |
|
259 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
260 | - $this->_set_cached_class( |
|
261 | - $request_loader(), |
|
262 | - 'EE_Request' |
|
263 | - ); |
|
264 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
265 | - $this->_set_cached_class( |
|
266 | - $response_loader(), |
|
267 | - 'EE_Response' |
|
268 | - ); |
|
269 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * init |
|
276 | - * |
|
277 | - * @access public |
|
278 | - * @return void |
|
279 | - */ |
|
280 | - public function init() |
|
281 | - { |
|
282 | - $this->AssetsRegistry = new Registry(); |
|
283 | - // Get current page protocol |
|
284 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
285 | - // Output admin-ajax.php URL with same protocol as current page |
|
286 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
287 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * localize_i18n_js_strings |
|
294 | - * |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public static function localize_i18n_js_strings() |
|
298 | - { |
|
299 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
300 | - foreach ($i18n_js_strings as $key => $value) { |
|
301 | - if (is_scalar($value)) { |
|
302 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
303 | - } |
|
304 | - } |
|
305 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * @param mixed string | EED_Module $module |
|
312 | - */ |
|
313 | - public function add_module($module) |
|
314 | - { |
|
315 | - if ($module instanceof EED_Module) { |
|
316 | - $module_class = get_class($module); |
|
317 | - $this->modules->{$module_class} = $module; |
|
318 | - } else { |
|
319 | - if ( ! class_exists('EE_Module_Request_Router')) { |
|
320 | - $this->load_core('Module_Request_Router'); |
|
321 | - } |
|
322 | - $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
323 | - } |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * @param string $module_name |
|
330 | - * @return mixed EED_Module | NULL |
|
331 | - */ |
|
332 | - public function get_module($module_name = '') |
|
333 | - { |
|
334 | - return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * loads core classes - must be singletons |
|
341 | - * |
|
342 | - * @access public |
|
343 | - * @param string $class_name - simple class name ie: session |
|
344 | - * @param mixed $arguments |
|
345 | - * @param bool $load_only |
|
346 | - * @return mixed |
|
347 | - */ |
|
348 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
349 | - { |
|
350 | - $core_paths = apply_filters( |
|
351 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
352 | - array( |
|
353 | - EE_CORE, |
|
354 | - EE_ADMIN, |
|
355 | - EE_CPTS, |
|
356 | - EE_CORE . 'data_migration_scripts' . DS, |
|
357 | - EE_CORE . 'request_stack' . DS, |
|
358 | - EE_CORE . 'middleware' . DS, |
|
359 | - ) |
|
360 | - ); |
|
361 | - // retrieve instantiated class |
|
362 | - return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * loads service classes |
|
369 | - * |
|
370 | - * @access public |
|
371 | - * @param string $class_name - simple class name ie: session |
|
372 | - * @param mixed $arguments |
|
373 | - * @param bool $load_only |
|
374 | - * @return mixed |
|
375 | - */ |
|
376 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
377 | - { |
|
378 | - $service_paths = apply_filters( |
|
379 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
380 | - array( |
|
381 | - EE_CORE . 'services' . DS, |
|
382 | - ) |
|
383 | - ); |
|
384 | - // retrieve instantiated class |
|
385 | - return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * loads data_migration_scripts |
|
392 | - * |
|
393 | - * @access public |
|
394 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
395 | - * @param mixed $arguments |
|
396 | - * @return EE_Data_Migration_Script_Base|mixed |
|
397 | - */ |
|
398 | - public function load_dms($class_name, $arguments = array()) |
|
399 | - { |
|
400 | - // retrieve instantiated class |
|
401 | - return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * loads object creating classes - must be singletons |
|
408 | - * |
|
409 | - * @param string $class_name - simple class name ie: attendee |
|
410 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
411 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
412 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
413 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
414 | - * @return EE_Base_Class | bool |
|
415 | - */ |
|
416 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
417 | - { |
|
418 | - $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
419 | - EE_CORE, |
|
420 | - EE_CLASSES, |
|
421 | - EE_BUSINESS, |
|
422 | - )); |
|
423 | - // retrieve instantiated class |
|
424 | - return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * loads helper classes - must be singletons |
|
431 | - * |
|
432 | - * @param string $class_name - simple class name ie: price |
|
433 | - * @param mixed $arguments |
|
434 | - * @param bool $load_only |
|
435 | - * @return EEH_Base | bool |
|
436 | - */ |
|
437 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
438 | - { |
|
439 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
440 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
441 | - // retrieve instantiated class |
|
442 | - return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * loads core classes - must be singletons |
|
449 | - * |
|
450 | - * @access public |
|
451 | - * @param string $class_name - simple class name ie: session |
|
452 | - * @param mixed $arguments |
|
453 | - * @param bool $load_only |
|
454 | - * @param bool $cache whether to cache the object or not. |
|
455 | - * @return mixed |
|
456 | - */ |
|
457 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
458 | - { |
|
459 | - $paths = array( |
|
460 | - EE_LIBRARIES, |
|
461 | - EE_LIBRARIES . 'messages' . DS, |
|
462 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
463 | - EE_LIBRARIES . 'qtips' . DS, |
|
464 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
465 | - ); |
|
466 | - // retrieve instantiated class |
|
467 | - return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * loads model classes - must be singletons |
|
474 | - * |
|
475 | - * @param string $class_name - simple class name ie: price |
|
476 | - * @param mixed $arguments |
|
477 | - * @param bool $load_only |
|
478 | - * @return EEM_Base | bool |
|
479 | - */ |
|
480 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
481 | - { |
|
482 | - $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
483 | - EE_MODELS, |
|
484 | - EE_CORE, |
|
485 | - )); |
|
486 | - // retrieve instantiated class |
|
487 | - return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * loads model classes - must be singletons |
|
494 | - * |
|
495 | - * @param string $class_name - simple class name ie: price |
|
496 | - * @param mixed $arguments |
|
497 | - * @param bool $load_only |
|
498 | - * @return mixed | bool |
|
499 | - */ |
|
500 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
501 | - { |
|
502 | - $paths = array( |
|
503 | - EE_MODELS . 'fields' . DS, |
|
504 | - EE_MODELS . 'helpers' . DS, |
|
505 | - EE_MODELS . 'relations' . DS, |
|
506 | - EE_MODELS . 'strategies' . DS, |
|
507 | - ); |
|
508 | - // retrieve instantiated class |
|
509 | - return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * Determines if $model_name is the name of an actual EE model. |
|
516 | - * |
|
517 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
518 | - * @return boolean |
|
519 | - */ |
|
520 | - public function is_model_name($model_name) |
|
521 | - { |
|
522 | - return isset($this->models[$model_name]) ? true : false; |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * generic class loader |
|
529 | - * |
|
530 | - * @param string $path_to_file - directory path to file location, not including filename |
|
531 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
532 | - * @param string $type - file type - core? class? helper? model? |
|
533 | - * @param mixed $arguments |
|
534 | - * @param bool $load_only |
|
535 | - * @return mixed |
|
536 | - */ |
|
537 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
538 | - { |
|
539 | - // retrieve instantiated class |
|
540 | - return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
541 | - } |
|
542 | - |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * load_addon |
|
547 | - * |
|
548 | - * @param string $path_to_file - directory path to file location, not including filename |
|
549 | - * @param string $class_name - full class name ie: My_Class |
|
550 | - * @param string $type - file type - core? class? helper? model? |
|
551 | - * @param mixed $arguments |
|
552 | - * @param bool $load_only |
|
553 | - * @return EE_Addon |
|
554 | - */ |
|
555 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
556 | - { |
|
557 | - // retrieve instantiated class |
|
558 | - return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * instantiates, caches, and automatically resolves dependencies |
|
565 | - * for classes that use a Fully Qualified Class Name. |
|
566 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
567 | - * then you need to use one of the existing load_*() methods |
|
568 | - * which can resolve the classname and filepath from the passed arguments |
|
569 | - * |
|
570 | - * @param bool|string $class_name Fully Qualified Class Name |
|
571 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
572 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
573 | - * @param bool $from_db some classes are instantiated from the db |
|
574 | - * and thus call a different method to instantiate |
|
575 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
576 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
577 | - * @return mixed null = failure to load or instantiate class object. |
|
578 | - * object = class loaded and instantiated successfully. |
|
579 | - * bool = fail or success when $load_only is true |
|
580 | - */ |
|
581 | - public function create( |
|
582 | - $class_name = false, |
|
583 | - $arguments = array(), |
|
584 | - $cache = false, |
|
585 | - $from_db = false, |
|
586 | - $load_only = false, |
|
587 | - $addon = false |
|
588 | - ) { |
|
589 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
590 | - if ( ! class_exists($class_name)) { |
|
591 | - // maybe the class is registered with a preceding \ |
|
592 | - $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
593 | - // still doesn't exist ? |
|
594 | - if ( ! class_exists($class_name)) { |
|
595 | - return null; |
|
596 | - } |
|
597 | - } |
|
598 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
599 | - if ($load_only) { |
|
600 | - return true; |
|
601 | - } |
|
602 | - $addon = $addon ? 'addon' : ''; |
|
603 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
604 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
605 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
606 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
607 | - // return object if it's already cached |
|
608 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
609 | - if ($cached_class !== null) { |
|
610 | - return $cached_class; |
|
611 | - } |
|
612 | - } |
|
613 | - // instantiate the requested object |
|
614 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
615 | - if ($this->_cache_on && $cache) { |
|
616 | - // save it for later... kinda like gum { : $ |
|
617 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
618 | - } |
|
619 | - $this->_cache_on = true; |
|
620 | - return $class_obj; |
|
621 | - } |
|
622 | - |
|
623 | - |
|
624 | - |
|
625 | - /** |
|
626 | - * instantiates, caches, and injects dependencies for classes |
|
627 | - * |
|
628 | - * @param array $file_paths an array of paths to folders to look in |
|
629 | - * @param string $class_prefix EE or EEM or... ??? |
|
630 | - * @param bool|string $class_name $class name |
|
631 | - * @param string $type file type - core? class? helper? model? |
|
632 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
633 | - * @param bool $from_db some classes are instantiated from the db |
|
634 | - * and thus call a different method to instantiate |
|
635 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
636 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
637 | - * @return null|object|bool null = failure to load or instantiate class object. |
|
638 | - * object = class loaded and instantiated successfully. |
|
639 | - * bool = fail or success when $load_only is true |
|
640 | - */ |
|
641 | - protected function _load( |
|
642 | - $file_paths = array(), |
|
643 | - $class_prefix = 'EE_', |
|
644 | - $class_name = false, |
|
645 | - $type = 'class', |
|
646 | - $arguments = array(), |
|
647 | - $from_db = false, |
|
648 | - $cache = true, |
|
649 | - $load_only = false |
|
650 | - ) { |
|
651 | - // strip php file extension |
|
652 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
653 | - // does the class have a prefix ? |
|
654 | - if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
655 | - // make sure $class_prefix is uppercase |
|
656 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
657 | - // add class prefix ONCE!!! |
|
658 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
659 | - } |
|
660 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
661 | - $class_exists = class_exists($class_name); |
|
662 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
663 | - if ($load_only && $class_exists) { |
|
664 | - return true; |
|
665 | - } |
|
666 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
667 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
668 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
669 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
670 | - // return object if it's already cached |
|
671 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
672 | - if ($cached_class !== null) { |
|
673 | - return $cached_class; |
|
674 | - } |
|
675 | - } |
|
676 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
677 | - if ( ! $class_exists) { |
|
678 | - // get full path to file |
|
679 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
680 | - // load the file |
|
681 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
682 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
683 | - if ( ! $loaded || $load_only) { |
|
684 | - // return boolean if only loading, or null if an object was expected |
|
685 | - return $load_only ? $loaded : null; |
|
686 | - } |
|
687 | - } |
|
688 | - // instantiate the requested object |
|
689 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
690 | - if ($this->_cache_on && $cache) { |
|
691 | - // save it for later... kinda like gum { : $ |
|
692 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
693 | - } |
|
694 | - $this->_cache_on = true; |
|
695 | - return $class_obj; |
|
696 | - } |
|
697 | - |
|
698 | - |
|
699 | - |
|
700 | - /** |
|
701 | - * _get_cached_class |
|
702 | - * attempts to find a cached version of the requested class |
|
703 | - * by looking in the following places: |
|
704 | - * $this->{$class_abbreviation} ie: $this->CART |
|
705 | - * $this->{$class_name} ie: $this->Some_Class |
|
706 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
707 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
708 | - * |
|
709 | - * @access protected |
|
710 | - * @param string $class_name |
|
711 | - * @param string $class_prefix |
|
712 | - * @return mixed |
|
713 | - */ |
|
714 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
715 | - { |
|
716 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
717 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
718 | - } else { |
|
719 | - // have to specify something, but not anything that will conflict |
|
720 | - $class_abbreviation = 'FANCY_BATMAN_PANTS'; |
|
721 | - } |
|
722 | - // check if class has already been loaded, and return it if it has been |
|
723 | - if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
724 | - return $this->{$class_abbreviation}; |
|
725 | - } else if (isset ($this->{$class_name})) { |
|
726 | - return $this->{$class_name}; |
|
727 | - } else if (isset ($this->LIB->{$class_name})) { |
|
728 | - return $this->LIB->{$class_name}; |
|
729 | - } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) { |
|
730 | - return $this->addons->{$class_name}; |
|
731 | - } |
|
732 | - return null; |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - |
|
737 | - /** |
|
738 | - * _resolve_path |
|
739 | - * attempts to find a full valid filepath for the requested class. |
|
740 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
741 | - * then returns that path if the target file has been found and is readable |
|
742 | - * |
|
743 | - * @access protected |
|
744 | - * @param string $class_name |
|
745 | - * @param string $type |
|
746 | - * @param array $file_paths |
|
747 | - * @return string | bool |
|
748 | - */ |
|
749 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
750 | - { |
|
751 | - // make sure $file_paths is an array |
|
752 | - $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
753 | - // cycle thru paths |
|
754 | - foreach ($file_paths as $key => $file_path) { |
|
755 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
756 | - $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
757 | - // prep file type |
|
758 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
759 | - // build full file path |
|
760 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
761 | - //does the file exist and can be read ? |
|
762 | - if (is_readable($file_paths[$key])) { |
|
763 | - return $file_paths[$key]; |
|
764 | - } |
|
765 | - } |
|
766 | - return false; |
|
767 | - } |
|
768 | - |
|
769 | - |
|
770 | - |
|
771 | - /** |
|
772 | - * _require_file |
|
773 | - * basically just performs a require_once() |
|
774 | - * but with some error handling |
|
775 | - * |
|
776 | - * @access protected |
|
777 | - * @param string $path |
|
778 | - * @param string $class_name |
|
779 | - * @param string $type |
|
780 | - * @param array $file_paths |
|
781 | - * @return boolean |
|
782 | - * @throws \EE_Error |
|
783 | - */ |
|
784 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
785 | - { |
|
786 | - // don't give up! you gotta... |
|
787 | - try { |
|
788 | - //does the file exist and can it be read ? |
|
789 | - if ( ! $path) { |
|
790 | - // so sorry, can't find the file |
|
791 | - throw new EE_Error ( |
|
792 | - sprintf( |
|
793 | - __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
794 | - trim($type, '.'), |
|
795 | - $class_name, |
|
796 | - '<br />' . implode(',<br />', $file_paths) |
|
797 | - ) |
|
798 | - ); |
|
799 | - } |
|
800 | - // get the file |
|
801 | - require_once($path); |
|
802 | - // if the class isn't already declared somewhere |
|
803 | - if (class_exists($class_name, false) === false) { |
|
804 | - // so sorry, not a class |
|
805 | - throw new EE_Error( |
|
806 | - sprintf( |
|
807 | - __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
808 | - $type, |
|
809 | - $path, |
|
810 | - $class_name |
|
811 | - ) |
|
812 | - ); |
|
813 | - } |
|
814 | - } catch (EE_Error $e) { |
|
815 | - $e->get_error(); |
|
816 | - return false; |
|
817 | - } |
|
818 | - return true; |
|
819 | - } |
|
820 | - |
|
821 | - |
|
822 | - |
|
823 | - /** |
|
824 | - * _create_object |
|
825 | - * Attempts to instantiate the requested class via any of the |
|
826 | - * commonly used instantiation methods employed throughout EE. |
|
827 | - * The priority for instantiation is as follows: |
|
828 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
829 | - * - model objects via their 'new_instance_from_db' method |
|
830 | - * - model objects via their 'new_instance' method |
|
831 | - * - "singleton" classes" via their 'instance' method |
|
832 | - * - standard instantiable classes via their __constructor |
|
833 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
834 | - * then the constructor for the requested class will be examined to determine |
|
835 | - * if any dependencies exist, and if they can be injected. |
|
836 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
837 | - * |
|
838 | - * @access protected |
|
839 | - * @param string $class_name |
|
840 | - * @param array $arguments |
|
841 | - * @param string $type |
|
842 | - * @param bool $from_db |
|
843 | - * @return null | object |
|
844 | - * @throws \EE_Error |
|
845 | - */ |
|
846 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
847 | - { |
|
848 | - $class_obj = null; |
|
849 | - $instantiation_mode = '0) none'; |
|
850 | - // don't give up! you gotta... |
|
851 | - try { |
|
852 | - // create reflection |
|
853 | - $reflector = $this->get_ReflectionClass($class_name); |
|
854 | - // make sure arguments are an array |
|
855 | - $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
856 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
857 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
858 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
859 | - ? $arguments |
|
860 | - : array($arguments); |
|
861 | - // attempt to inject dependencies ? |
|
862 | - if ($this->_dependency_map->has($class_name)) { |
|
863 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
864 | - } |
|
865 | - // instantiate the class if possible |
|
866 | - if ($reflector->isAbstract()) { |
|
867 | - // nothing to instantiate, loading file was enough |
|
868 | - // does not throw an exception so $instantiation_mode is unused |
|
869 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
870 | - $class_obj = true; |
|
871 | - } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
872 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
873 | - $instantiation_mode = "2) no constructor but instantiable"; |
|
874 | - $class_obj = $reflector->newInstance(); |
|
875 | - } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
876 | - $instantiation_mode = "3) new_instance_from_db()"; |
|
877 | - $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
878 | - } else if (method_exists($class_name, 'new_instance')) { |
|
879 | - $instantiation_mode = "4) new_instance()"; |
|
880 | - $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
881 | - } else if (method_exists($class_name, 'instance')) { |
|
882 | - $instantiation_mode = "5) instance()"; |
|
883 | - $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
884 | - } else if ($reflector->isInstantiable()) { |
|
885 | - $instantiation_mode = "6) constructor"; |
|
886 | - $class_obj = $reflector->newInstanceArgs($arguments); |
|
887 | - } else { |
|
888 | - // heh ? something's not right ! |
|
889 | - throw new EE_Error( |
|
890 | - sprintf( |
|
891 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
892 | - $type, |
|
893 | - $class_name |
|
894 | - ) |
|
895 | - ); |
|
896 | - } |
|
897 | - } catch (Exception $e) { |
|
898 | - if ( ! $e instanceof EE_Error) { |
|
899 | - $e = new EE_Error( |
|
900 | - sprintf( |
|
901 | - __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
902 | - $class_name, |
|
903 | - '<br />', |
|
904 | - $e->getMessage(), |
|
905 | - $instantiation_mode |
|
906 | - ) |
|
907 | - ); |
|
908 | - } |
|
909 | - $e->get_error(); |
|
910 | - } |
|
911 | - return $class_obj; |
|
912 | - } |
|
913 | - |
|
914 | - |
|
915 | - |
|
916 | - /** |
|
917 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
918 | - * @param array $array |
|
919 | - * @return bool |
|
920 | - */ |
|
921 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
922 | - { |
|
923 | - return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
924 | - } |
|
925 | - |
|
926 | - |
|
927 | - |
|
928 | - /** |
|
929 | - * getReflectionClass |
|
930 | - * checks if a ReflectionClass object has already been generated for a class |
|
931 | - * and returns that instead of creating a new one |
|
932 | - * |
|
933 | - * @access public |
|
934 | - * @param string $class_name |
|
935 | - * @return ReflectionClass |
|
936 | - */ |
|
937 | - public function get_ReflectionClass($class_name) |
|
938 | - { |
|
939 | - if ( |
|
940 | - ! isset($this->_reflectors[$class_name]) |
|
941 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
942 | - ) { |
|
943 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
944 | - } |
|
945 | - return $this->_reflectors[$class_name]; |
|
946 | - } |
|
947 | - |
|
948 | - |
|
949 | - |
|
950 | - /** |
|
951 | - * _resolve_dependencies |
|
952 | - * examines the constructor for the requested class to determine |
|
953 | - * if any dependencies exist, and if they can be injected. |
|
954 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
955 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
956 | - * For example: |
|
957 | - * if attempting to load a class "Foo" with the following constructor: |
|
958 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
959 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
960 | - * but only IF they are NOT already present in the incoming arguments array, |
|
961 | - * and the correct classes can be loaded |
|
962 | - * |
|
963 | - * @access protected |
|
964 | - * @param ReflectionClass $reflector |
|
965 | - * @param string $class_name |
|
966 | - * @param array $arguments |
|
967 | - * @return array |
|
968 | - * @throws \ReflectionException |
|
969 | - */ |
|
970 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
971 | - { |
|
972 | - // let's examine the constructor |
|
973 | - $constructor = $reflector->getConstructor(); |
|
974 | - // whu? huh? nothing? |
|
975 | - if ( ! $constructor) { |
|
976 | - return $arguments; |
|
977 | - } |
|
978 | - // get constructor parameters |
|
979 | - $params = $constructor->getParameters(); |
|
980 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
981 | - $argument_keys = array_keys($arguments); |
|
982 | - // now loop thru all of the constructors expected parameters |
|
983 | - foreach ($params as $index => $param) { |
|
984 | - // is this a dependency for a specific class ? |
|
985 | - $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
986 | - if ( |
|
987 | - // param is not even a class |
|
988 | - empty($param_class) |
|
989 | - // and something already exists in the incoming arguments for this param |
|
990 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
991 | - ) { |
|
992 | - // so let's skip this argument and move on to the next |
|
993 | - continue; |
|
994 | - } else if ( |
|
995 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
996 | - ! empty($param_class) |
|
997 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
998 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
999 | - ) { |
|
1000 | - // skip this argument and move on to the next |
|
1001 | - continue; |
|
1002 | - } else if ( |
|
1003 | - // parameter is type hinted as a class, and should be injected |
|
1004 | - ! empty($param_class) |
|
1005 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1006 | - ) { |
|
1007 | - $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1008 | - } else { |
|
1009 | - try { |
|
1010 | - $arguments[$index] = $param->getDefaultValue(); |
|
1011 | - } catch (ReflectionException $e) { |
|
1012 | - throw new ReflectionException( |
|
1013 | - sprintf( |
|
1014 | - __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1015 | - $e->getMessage(), |
|
1016 | - $param->getName() |
|
1017 | - ) |
|
1018 | - ); |
|
1019 | - } |
|
1020 | - } |
|
1021 | - } |
|
1022 | - return $arguments; |
|
1023 | - } |
|
1024 | - |
|
1025 | - |
|
1026 | - |
|
1027 | - /** |
|
1028 | - * @access protected |
|
1029 | - * @param string $class_name |
|
1030 | - * @param string $param_class |
|
1031 | - * @param array $arguments |
|
1032 | - * @param mixed $index |
|
1033 | - * @return array |
|
1034 | - */ |
|
1035 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1036 | - { |
|
1037 | - $dependency = null; |
|
1038 | - // should dependency be loaded from cache ? |
|
1039 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1040 | - !== EE_Dependency_Map::load_new_object |
|
1041 | - ? true |
|
1042 | - : false; |
|
1043 | - // we might have a dependency... |
|
1044 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
1045 | - $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1046 | - // and grab it if it exists |
|
1047 | - if ($cached_class instanceof $param_class) { |
|
1048 | - $dependency = $cached_class; |
|
1049 | - } else if ($param_class != $class_name) { |
|
1050 | - // obtain the loader method from the dependency map |
|
1051 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
1052 | - // is loader a custom closure ? |
|
1053 | - if ($loader instanceof Closure) { |
|
1054 | - $dependency = $loader(); |
|
1055 | - } else { |
|
1056 | - // set the cache on property for the recursive loading call |
|
1057 | - $this->_cache_on = $cache_on; |
|
1058 | - // if not, then let's try and load it via the registry |
|
1059 | - if (method_exists($this, $loader)) { |
|
1060 | - $dependency = $this->{$loader}($param_class); |
|
1061 | - } else { |
|
1062 | - $dependency = $this->create($param_class, array(), $cache_on); |
|
1063 | - } |
|
1064 | - } |
|
1065 | - } |
|
1066 | - // did we successfully find the correct dependency ? |
|
1067 | - if ($dependency instanceof $param_class) { |
|
1068 | - // then let's inject it into the incoming array of arguments at the correct location |
|
1069 | - if (isset($argument_keys[$index])) { |
|
1070 | - $arguments[$argument_keys[$index]] = $dependency; |
|
1071 | - } else { |
|
1072 | - $arguments[$index] = $dependency; |
|
1073 | - } |
|
1074 | - } |
|
1075 | - return $arguments; |
|
1076 | - } |
|
1077 | - |
|
1078 | - |
|
1079 | - |
|
1080 | - /** |
|
1081 | - * _set_cached_class |
|
1082 | - * attempts to cache the instantiated class locally |
|
1083 | - * in one of the following places, in the following order: |
|
1084 | - * $this->{class_abbreviation} ie: $this->CART |
|
1085 | - * $this->{$class_name} ie: $this->Some_Class |
|
1086 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1087 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1088 | - * |
|
1089 | - * @access protected |
|
1090 | - * @param object $class_obj |
|
1091 | - * @param string $class_name |
|
1092 | - * @param string $class_prefix |
|
1093 | - * @param bool $from_db |
|
1094 | - * @return void |
|
1095 | - */ |
|
1096 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1097 | - { |
|
1098 | - if (empty($class_obj)) { |
|
1099 | - return; |
|
1100 | - } |
|
1101 | - // return newly instantiated class |
|
1102 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
1103 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1104 | - $this->{$class_abbreviation} = $class_obj; |
|
1105 | - } else if (property_exists($this, $class_name)) { |
|
1106 | - $this->{$class_name} = $class_obj; |
|
1107 | - } else if ($class_prefix == 'addon') { |
|
1108 | - $this->addons->{$class_name} = $class_obj; |
|
1109 | - } else if ( ! $from_db) { |
|
1110 | - $this->LIB->{$class_name} = $class_obj; |
|
1111 | - } |
|
1112 | - } |
|
1113 | - |
|
1114 | - |
|
1115 | - |
|
1116 | - /** |
|
1117 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1118 | - * |
|
1119 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1120 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
1121 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1122 | - * @param array $arguments |
|
1123 | - * @return object |
|
1124 | - */ |
|
1125 | - public static function factory($classname, $arguments = array()) |
|
1126 | - { |
|
1127 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1128 | - if ($loader instanceof Closure) { |
|
1129 | - return $loader($arguments); |
|
1130 | - } else if (method_exists(EE_Registry::instance(), $loader)) { |
|
1131 | - return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1132 | - } |
|
1133 | - return null; |
|
1134 | - } |
|
1135 | - |
|
1136 | - |
|
1137 | - |
|
1138 | - /** |
|
1139 | - * Gets the addon by its name/slug (not classname. For that, just |
|
1140 | - * use the classname as the property name on EE_Config::instance()->addons) |
|
1141 | - * |
|
1142 | - * @param string $name |
|
1143 | - * @return EE_Addon |
|
1144 | - */ |
|
1145 | - public function get_addon_by_name($name) |
|
1146 | - { |
|
1147 | - foreach ($this->addons as $addon) { |
|
1148 | - if ($addon->name() == $name) { |
|
1149 | - return $addon; |
|
1150 | - } |
|
1151 | - } |
|
1152 | - return null; |
|
1153 | - } |
|
1154 | - |
|
1155 | - |
|
1156 | - |
|
1157 | - /** |
|
1158 | - * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
1159 | - * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1160 | - * |
|
1161 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
1162 | - */ |
|
1163 | - public function get_addons_by_name() |
|
1164 | - { |
|
1165 | - $addons = array(); |
|
1166 | - foreach ($this->addons as $addon) { |
|
1167 | - $addons[$addon->name()] = $addon; |
|
1168 | - } |
|
1169 | - return $addons; |
|
1170 | - } |
|
1171 | - |
|
1172 | - |
|
1173 | - |
|
1174 | - /** |
|
1175 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1176 | - * a stale copy of it around |
|
1177 | - * |
|
1178 | - * @param string $model_name |
|
1179 | - * @return \EEM_Base |
|
1180 | - * @throws \EE_Error |
|
1181 | - */ |
|
1182 | - public function reset_model($model_name) |
|
1183 | - { |
|
1184 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1185 | - if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1186 | - return null; |
|
1187 | - } |
|
1188 | - //get that model reset it and make sure we nuke the old reference to it |
|
1189 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1190 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1191 | - } else { |
|
1192 | - throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1193 | - } |
|
1194 | - return $this->LIB->{$model_class_name}; |
|
1195 | - } |
|
1196 | - |
|
1197 | - |
|
1198 | - |
|
1199 | - /** |
|
1200 | - * Resets the registry. |
|
1201 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1202 | - * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1203 | - * - $_dependency_map |
|
1204 | - * - $_class_abbreviations |
|
1205 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1206 | - * - $REQ: Still on the same request so no need to change. |
|
1207 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
1208 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1209 | - * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1210 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1211 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1212 | - * switch or on the restore. |
|
1213 | - * - $modules |
|
1214 | - * - $shortcodes |
|
1215 | - * - $widgets |
|
1216 | - * |
|
1217 | - * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1218 | - * the Registry to its state at the beginning of the request |
|
1219 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1220 | - * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1221 | - * currently reinstantiate the singletons at the moment) |
|
1222 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1223 | - * code instead can just change the model context to a different blog id if necessary |
|
1224 | - * @return EE_Registry |
|
1225 | - */ |
|
1226 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1227 | - { |
|
1228 | - $instance = self::instance(); |
|
1229 | - EEH_Activation::reset(); |
|
1230 | - //properties that get reset |
|
1231 | - $instance->_cache_on = true; |
|
1232 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1233 | - $instance->CART = null; |
|
1234 | - $instance->MRM = null; |
|
1235 | - $instance->AssetsRegistry = new Registry(); |
|
1236 | - //messages reset |
|
1237 | - EED_Messages::reset(); |
|
1238 | - if ($reset_models) { |
|
1239 | - foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1240 | - $instance->reset_model($model_name); |
|
1241 | - } |
|
1242 | - } |
|
1243 | - $instance->LIB = new stdClass(); |
|
1244 | - return $instance; |
|
1245 | - } |
|
1246 | - |
|
1247 | - |
|
1248 | - |
|
1249 | - /** |
|
1250 | - * @override magic methods |
|
1251 | - * @return void |
|
1252 | - */ |
|
1253 | - final function __destruct() |
|
1254 | - { |
|
1255 | - } |
|
1256 | - |
|
1257 | - |
|
1258 | - |
|
1259 | - /** |
|
1260 | - * @param $a |
|
1261 | - * @param $b |
|
1262 | - */ |
|
1263 | - final function __call($a, $b) |
|
1264 | - { |
|
1265 | - } |
|
1266 | - |
|
1267 | - |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * @param $a |
|
1271 | - */ |
|
1272 | - final function __get($a) |
|
1273 | - { |
|
1274 | - } |
|
1275 | - |
|
1276 | - |
|
1277 | - |
|
1278 | - /** |
|
1279 | - * @param $a |
|
1280 | - * @param $b |
|
1281 | - */ |
|
1282 | - final function __set($a, $b) |
|
1283 | - { |
|
1284 | - } |
|
1285 | - |
|
1286 | - |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * @param $a |
|
1290 | - */ |
|
1291 | - final function __isset($a) |
|
1292 | - { |
|
1293 | - } |
|
19 | + /** |
|
20 | + * EE_Registry Object |
|
21 | + * |
|
22 | + * @var EE_Registry $_instance |
|
23 | + * @access private |
|
24 | + */ |
|
25 | + private static $_instance = null; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var EE_Dependency_Map $_dependency_map |
|
29 | + * @access protected |
|
30 | + */ |
|
31 | + protected $_dependency_map = null; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var array $_class_abbreviations |
|
35 | + * @access protected |
|
36 | + */ |
|
37 | + protected $_class_abbreviations = array(); |
|
38 | + |
|
39 | + /** |
|
40 | + * @access public |
|
41 | + * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
42 | + */ |
|
43 | + public $BUS; |
|
44 | + |
|
45 | + /** |
|
46 | + * EE_Cart Object |
|
47 | + * |
|
48 | + * @access public |
|
49 | + * @var EE_Cart $CART |
|
50 | + */ |
|
51 | + public $CART = null; |
|
52 | + |
|
53 | + /** |
|
54 | + * EE_Config Object |
|
55 | + * |
|
56 | + * @access public |
|
57 | + * @var EE_Config $CFG |
|
58 | + */ |
|
59 | + public $CFG = null; |
|
60 | + |
|
61 | + /** |
|
62 | + * EE_Network_Config Object |
|
63 | + * |
|
64 | + * @access public |
|
65 | + * @var EE_Network_Config $NET_CFG |
|
66 | + */ |
|
67 | + public $NET_CFG = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * StdClass object for storing library classes in |
|
71 | + * |
|
72 | + * @public LIB |
|
73 | + * @var StdClass $LIB |
|
74 | + */ |
|
75 | + public $LIB = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * EE_Request_Handler Object |
|
79 | + * |
|
80 | + * @access public |
|
81 | + * @var EE_Request_Handler $REQ |
|
82 | + */ |
|
83 | + public $REQ = null; |
|
84 | + |
|
85 | + /** |
|
86 | + * EE_Session Object |
|
87 | + * |
|
88 | + * @access public |
|
89 | + * @var EE_Session $SSN |
|
90 | + */ |
|
91 | + public $SSN = null; |
|
92 | + |
|
93 | + /** |
|
94 | + * holds the ee capabilities object. |
|
95 | + * |
|
96 | + * @since 4.5.0 |
|
97 | + * @var EE_Capabilities |
|
98 | + */ |
|
99 | + public $CAP = null; |
|
100 | + |
|
101 | + /** |
|
102 | + * holds the EE_Message_Resource_Manager object. |
|
103 | + * |
|
104 | + * @since 4.9.0 |
|
105 | + * @var EE_Message_Resource_Manager |
|
106 | + */ |
|
107 | + public $MRM = null; |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Holds the Assets Registry instance |
|
112 | + * @var Registry |
|
113 | + */ |
|
114 | + public $AssetsRegistry = null; |
|
115 | + |
|
116 | + /** |
|
117 | + * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * @var EE_Addon[] |
|
121 | + */ |
|
122 | + public $addons = null; |
|
123 | + |
|
124 | + /** |
|
125 | + * $models |
|
126 | + * @access public |
|
127 | + * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
128 | + */ |
|
129 | + public $models = array(); |
|
130 | + |
|
131 | + /** |
|
132 | + * $modules |
|
133 | + * @access public |
|
134 | + * @var EED_Module[] $modules |
|
135 | + */ |
|
136 | + public $modules = null; |
|
137 | + |
|
138 | + /** |
|
139 | + * $shortcodes |
|
140 | + * @access public |
|
141 | + * @var EES_Shortcode[] $shortcodes |
|
142 | + */ |
|
143 | + public $shortcodes = null; |
|
144 | + |
|
145 | + /** |
|
146 | + * $widgets |
|
147 | + * @access public |
|
148 | + * @var WP_Widget[] $widgets |
|
149 | + */ |
|
150 | + public $widgets = null; |
|
151 | + |
|
152 | + /** |
|
153 | + * $non_abstract_db_models |
|
154 | + * @access public |
|
155 | + * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
156 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
157 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
158 | + * classnames (eg "EEM_Event") |
|
159 | + */ |
|
160 | + public $non_abstract_db_models = array(); |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * $i18n_js_strings - internationalization for JS strings |
|
165 | + * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
166 | + * in js file: var translatedString = eei18n.string_key; |
|
167 | + * |
|
168 | + * @access public |
|
169 | + * @var array |
|
170 | + */ |
|
171 | + public static $i18n_js_strings = array(); |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * $main_file - path to espresso.php |
|
176 | + * |
|
177 | + * @access public |
|
178 | + * @var array |
|
179 | + */ |
|
180 | + public $main_file; |
|
181 | + |
|
182 | + /** |
|
183 | + * array of ReflectionClass objects where the key is the class name |
|
184 | + * |
|
185 | + * @access public |
|
186 | + * @var ReflectionClass[] |
|
187 | + */ |
|
188 | + public $_reflectors; |
|
189 | + |
|
190 | + /** |
|
191 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
192 | + * |
|
193 | + * @access protected |
|
194 | + * @var boolean $_cache_on |
|
195 | + */ |
|
196 | + protected $_cache_on = true; |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @singleton method used to instantiate class object |
|
202 | + * @access public |
|
203 | + * @param \EE_Dependency_Map $dependency_map |
|
204 | + * @return \EE_Registry instance |
|
205 | + */ |
|
206 | + public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
207 | + { |
|
208 | + // check if class object is instantiated |
|
209 | + if ( ! self::$_instance instanceof EE_Registry) { |
|
210 | + self::$_instance = new EE_Registry($dependency_map); |
|
211 | + } |
|
212 | + return self::$_instance; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + *protected constructor to prevent direct creation |
|
219 | + * |
|
220 | + * @Constructor |
|
221 | + * @access protected |
|
222 | + * @param \EE_Dependency_Map $dependency_map |
|
223 | + * @return \EE_Registry |
|
224 | + */ |
|
225 | + protected function __construct(\EE_Dependency_Map $dependency_map) |
|
226 | + { |
|
227 | + $this->_dependency_map = $dependency_map; |
|
228 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * initialize |
|
235 | + */ |
|
236 | + public function initialize() |
|
237 | + { |
|
238 | + $this->_class_abbreviations = apply_filters( |
|
239 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
240 | + array( |
|
241 | + 'EE_Config' => 'CFG', |
|
242 | + 'EE_Session' => 'SSN', |
|
243 | + 'EE_Capabilities' => 'CAP', |
|
244 | + 'EE_Cart' => 'CART', |
|
245 | + 'EE_Network_Config' => 'NET_CFG', |
|
246 | + 'EE_Request_Handler' => 'REQ', |
|
247 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
248 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
249 | + ) |
|
250 | + ); |
|
251 | + // class library |
|
252 | + $this->LIB = new stdClass(); |
|
253 | + $this->addons = new stdClass(); |
|
254 | + $this->modules = new stdClass(); |
|
255 | + $this->shortcodes = new stdClass(); |
|
256 | + $this->widgets = new stdClass(); |
|
257 | + $this->load_core('Base', array(), true); |
|
258 | + // add our request and response objects to the cache |
|
259 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
260 | + $this->_set_cached_class( |
|
261 | + $request_loader(), |
|
262 | + 'EE_Request' |
|
263 | + ); |
|
264 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
265 | + $this->_set_cached_class( |
|
266 | + $response_loader(), |
|
267 | + 'EE_Response' |
|
268 | + ); |
|
269 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * init |
|
276 | + * |
|
277 | + * @access public |
|
278 | + * @return void |
|
279 | + */ |
|
280 | + public function init() |
|
281 | + { |
|
282 | + $this->AssetsRegistry = new Registry(); |
|
283 | + // Get current page protocol |
|
284 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
285 | + // Output admin-ajax.php URL with same protocol as current page |
|
286 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
287 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * localize_i18n_js_strings |
|
294 | + * |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public static function localize_i18n_js_strings() |
|
298 | + { |
|
299 | + $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
300 | + foreach ($i18n_js_strings as $key => $value) { |
|
301 | + if (is_scalar($value)) { |
|
302 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
303 | + } |
|
304 | + } |
|
305 | + return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * @param mixed string | EED_Module $module |
|
312 | + */ |
|
313 | + public function add_module($module) |
|
314 | + { |
|
315 | + if ($module instanceof EED_Module) { |
|
316 | + $module_class = get_class($module); |
|
317 | + $this->modules->{$module_class} = $module; |
|
318 | + } else { |
|
319 | + if ( ! class_exists('EE_Module_Request_Router')) { |
|
320 | + $this->load_core('Module_Request_Router'); |
|
321 | + } |
|
322 | + $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
323 | + } |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * @param string $module_name |
|
330 | + * @return mixed EED_Module | NULL |
|
331 | + */ |
|
332 | + public function get_module($module_name = '') |
|
333 | + { |
|
334 | + return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * loads core classes - must be singletons |
|
341 | + * |
|
342 | + * @access public |
|
343 | + * @param string $class_name - simple class name ie: session |
|
344 | + * @param mixed $arguments |
|
345 | + * @param bool $load_only |
|
346 | + * @return mixed |
|
347 | + */ |
|
348 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
349 | + { |
|
350 | + $core_paths = apply_filters( |
|
351 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
352 | + array( |
|
353 | + EE_CORE, |
|
354 | + EE_ADMIN, |
|
355 | + EE_CPTS, |
|
356 | + EE_CORE . 'data_migration_scripts' . DS, |
|
357 | + EE_CORE . 'request_stack' . DS, |
|
358 | + EE_CORE . 'middleware' . DS, |
|
359 | + ) |
|
360 | + ); |
|
361 | + // retrieve instantiated class |
|
362 | + return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * loads service classes |
|
369 | + * |
|
370 | + * @access public |
|
371 | + * @param string $class_name - simple class name ie: session |
|
372 | + * @param mixed $arguments |
|
373 | + * @param bool $load_only |
|
374 | + * @return mixed |
|
375 | + */ |
|
376 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
377 | + { |
|
378 | + $service_paths = apply_filters( |
|
379 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
380 | + array( |
|
381 | + EE_CORE . 'services' . DS, |
|
382 | + ) |
|
383 | + ); |
|
384 | + // retrieve instantiated class |
|
385 | + return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * loads data_migration_scripts |
|
392 | + * |
|
393 | + * @access public |
|
394 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
395 | + * @param mixed $arguments |
|
396 | + * @return EE_Data_Migration_Script_Base|mixed |
|
397 | + */ |
|
398 | + public function load_dms($class_name, $arguments = array()) |
|
399 | + { |
|
400 | + // retrieve instantiated class |
|
401 | + return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * loads object creating classes - must be singletons |
|
408 | + * |
|
409 | + * @param string $class_name - simple class name ie: attendee |
|
410 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
411 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
412 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
413 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
414 | + * @return EE_Base_Class | bool |
|
415 | + */ |
|
416 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
417 | + { |
|
418 | + $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
419 | + EE_CORE, |
|
420 | + EE_CLASSES, |
|
421 | + EE_BUSINESS, |
|
422 | + )); |
|
423 | + // retrieve instantiated class |
|
424 | + return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * loads helper classes - must be singletons |
|
431 | + * |
|
432 | + * @param string $class_name - simple class name ie: price |
|
433 | + * @param mixed $arguments |
|
434 | + * @param bool $load_only |
|
435 | + * @return EEH_Base | bool |
|
436 | + */ |
|
437 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
438 | + { |
|
439 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
440 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
441 | + // retrieve instantiated class |
|
442 | + return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * loads core classes - must be singletons |
|
449 | + * |
|
450 | + * @access public |
|
451 | + * @param string $class_name - simple class name ie: session |
|
452 | + * @param mixed $arguments |
|
453 | + * @param bool $load_only |
|
454 | + * @param bool $cache whether to cache the object or not. |
|
455 | + * @return mixed |
|
456 | + */ |
|
457 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
458 | + { |
|
459 | + $paths = array( |
|
460 | + EE_LIBRARIES, |
|
461 | + EE_LIBRARIES . 'messages' . DS, |
|
462 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
463 | + EE_LIBRARIES . 'qtips' . DS, |
|
464 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
465 | + ); |
|
466 | + // retrieve instantiated class |
|
467 | + return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * loads model classes - must be singletons |
|
474 | + * |
|
475 | + * @param string $class_name - simple class name ie: price |
|
476 | + * @param mixed $arguments |
|
477 | + * @param bool $load_only |
|
478 | + * @return EEM_Base | bool |
|
479 | + */ |
|
480 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
481 | + { |
|
482 | + $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
483 | + EE_MODELS, |
|
484 | + EE_CORE, |
|
485 | + )); |
|
486 | + // retrieve instantiated class |
|
487 | + return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * loads model classes - must be singletons |
|
494 | + * |
|
495 | + * @param string $class_name - simple class name ie: price |
|
496 | + * @param mixed $arguments |
|
497 | + * @param bool $load_only |
|
498 | + * @return mixed | bool |
|
499 | + */ |
|
500 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
501 | + { |
|
502 | + $paths = array( |
|
503 | + EE_MODELS . 'fields' . DS, |
|
504 | + EE_MODELS . 'helpers' . DS, |
|
505 | + EE_MODELS . 'relations' . DS, |
|
506 | + EE_MODELS . 'strategies' . DS, |
|
507 | + ); |
|
508 | + // retrieve instantiated class |
|
509 | + return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * Determines if $model_name is the name of an actual EE model. |
|
516 | + * |
|
517 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
518 | + * @return boolean |
|
519 | + */ |
|
520 | + public function is_model_name($model_name) |
|
521 | + { |
|
522 | + return isset($this->models[$model_name]) ? true : false; |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * generic class loader |
|
529 | + * |
|
530 | + * @param string $path_to_file - directory path to file location, not including filename |
|
531 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
532 | + * @param string $type - file type - core? class? helper? model? |
|
533 | + * @param mixed $arguments |
|
534 | + * @param bool $load_only |
|
535 | + * @return mixed |
|
536 | + */ |
|
537 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
538 | + { |
|
539 | + // retrieve instantiated class |
|
540 | + return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
541 | + } |
|
542 | + |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * load_addon |
|
547 | + * |
|
548 | + * @param string $path_to_file - directory path to file location, not including filename |
|
549 | + * @param string $class_name - full class name ie: My_Class |
|
550 | + * @param string $type - file type - core? class? helper? model? |
|
551 | + * @param mixed $arguments |
|
552 | + * @param bool $load_only |
|
553 | + * @return EE_Addon |
|
554 | + */ |
|
555 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
556 | + { |
|
557 | + // retrieve instantiated class |
|
558 | + return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * instantiates, caches, and automatically resolves dependencies |
|
565 | + * for classes that use a Fully Qualified Class Name. |
|
566 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
567 | + * then you need to use one of the existing load_*() methods |
|
568 | + * which can resolve the classname and filepath from the passed arguments |
|
569 | + * |
|
570 | + * @param bool|string $class_name Fully Qualified Class Name |
|
571 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
572 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
573 | + * @param bool $from_db some classes are instantiated from the db |
|
574 | + * and thus call a different method to instantiate |
|
575 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
576 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
577 | + * @return mixed null = failure to load or instantiate class object. |
|
578 | + * object = class loaded and instantiated successfully. |
|
579 | + * bool = fail or success when $load_only is true |
|
580 | + */ |
|
581 | + public function create( |
|
582 | + $class_name = false, |
|
583 | + $arguments = array(), |
|
584 | + $cache = false, |
|
585 | + $from_db = false, |
|
586 | + $load_only = false, |
|
587 | + $addon = false |
|
588 | + ) { |
|
589 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
590 | + if ( ! class_exists($class_name)) { |
|
591 | + // maybe the class is registered with a preceding \ |
|
592 | + $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
593 | + // still doesn't exist ? |
|
594 | + if ( ! class_exists($class_name)) { |
|
595 | + return null; |
|
596 | + } |
|
597 | + } |
|
598 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
599 | + if ($load_only) { |
|
600 | + return true; |
|
601 | + } |
|
602 | + $addon = $addon ? 'addon' : ''; |
|
603 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
604 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
605 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
606 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
607 | + // return object if it's already cached |
|
608 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
609 | + if ($cached_class !== null) { |
|
610 | + return $cached_class; |
|
611 | + } |
|
612 | + } |
|
613 | + // instantiate the requested object |
|
614 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
615 | + if ($this->_cache_on && $cache) { |
|
616 | + // save it for later... kinda like gum { : $ |
|
617 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
618 | + } |
|
619 | + $this->_cache_on = true; |
|
620 | + return $class_obj; |
|
621 | + } |
|
622 | + |
|
623 | + |
|
624 | + |
|
625 | + /** |
|
626 | + * instantiates, caches, and injects dependencies for classes |
|
627 | + * |
|
628 | + * @param array $file_paths an array of paths to folders to look in |
|
629 | + * @param string $class_prefix EE or EEM or... ??? |
|
630 | + * @param bool|string $class_name $class name |
|
631 | + * @param string $type file type - core? class? helper? model? |
|
632 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
633 | + * @param bool $from_db some classes are instantiated from the db |
|
634 | + * and thus call a different method to instantiate |
|
635 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
636 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
637 | + * @return null|object|bool null = failure to load or instantiate class object. |
|
638 | + * object = class loaded and instantiated successfully. |
|
639 | + * bool = fail or success when $load_only is true |
|
640 | + */ |
|
641 | + protected function _load( |
|
642 | + $file_paths = array(), |
|
643 | + $class_prefix = 'EE_', |
|
644 | + $class_name = false, |
|
645 | + $type = 'class', |
|
646 | + $arguments = array(), |
|
647 | + $from_db = false, |
|
648 | + $cache = true, |
|
649 | + $load_only = false |
|
650 | + ) { |
|
651 | + // strip php file extension |
|
652 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
653 | + // does the class have a prefix ? |
|
654 | + if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
655 | + // make sure $class_prefix is uppercase |
|
656 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
657 | + // add class prefix ONCE!!! |
|
658 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
659 | + } |
|
660 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
661 | + $class_exists = class_exists($class_name); |
|
662 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
663 | + if ($load_only && $class_exists) { |
|
664 | + return true; |
|
665 | + } |
|
666 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
667 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
668 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
669 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
670 | + // return object if it's already cached |
|
671 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
672 | + if ($cached_class !== null) { |
|
673 | + return $cached_class; |
|
674 | + } |
|
675 | + } |
|
676 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
677 | + if ( ! $class_exists) { |
|
678 | + // get full path to file |
|
679 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
680 | + // load the file |
|
681 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
682 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
683 | + if ( ! $loaded || $load_only) { |
|
684 | + // return boolean if only loading, or null if an object was expected |
|
685 | + return $load_only ? $loaded : null; |
|
686 | + } |
|
687 | + } |
|
688 | + // instantiate the requested object |
|
689 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
690 | + if ($this->_cache_on && $cache) { |
|
691 | + // save it for later... kinda like gum { : $ |
|
692 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
693 | + } |
|
694 | + $this->_cache_on = true; |
|
695 | + return $class_obj; |
|
696 | + } |
|
697 | + |
|
698 | + |
|
699 | + |
|
700 | + /** |
|
701 | + * _get_cached_class |
|
702 | + * attempts to find a cached version of the requested class |
|
703 | + * by looking in the following places: |
|
704 | + * $this->{$class_abbreviation} ie: $this->CART |
|
705 | + * $this->{$class_name} ie: $this->Some_Class |
|
706 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
707 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
708 | + * |
|
709 | + * @access protected |
|
710 | + * @param string $class_name |
|
711 | + * @param string $class_prefix |
|
712 | + * @return mixed |
|
713 | + */ |
|
714 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
715 | + { |
|
716 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
717 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
718 | + } else { |
|
719 | + // have to specify something, but not anything that will conflict |
|
720 | + $class_abbreviation = 'FANCY_BATMAN_PANTS'; |
|
721 | + } |
|
722 | + // check if class has already been loaded, and return it if it has been |
|
723 | + if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
724 | + return $this->{$class_abbreviation}; |
|
725 | + } else if (isset ($this->{$class_name})) { |
|
726 | + return $this->{$class_name}; |
|
727 | + } else if (isset ($this->LIB->{$class_name})) { |
|
728 | + return $this->LIB->{$class_name}; |
|
729 | + } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) { |
|
730 | + return $this->addons->{$class_name}; |
|
731 | + } |
|
732 | + return null; |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + |
|
737 | + /** |
|
738 | + * _resolve_path |
|
739 | + * attempts to find a full valid filepath for the requested class. |
|
740 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
741 | + * then returns that path if the target file has been found and is readable |
|
742 | + * |
|
743 | + * @access protected |
|
744 | + * @param string $class_name |
|
745 | + * @param string $type |
|
746 | + * @param array $file_paths |
|
747 | + * @return string | bool |
|
748 | + */ |
|
749 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
750 | + { |
|
751 | + // make sure $file_paths is an array |
|
752 | + $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
753 | + // cycle thru paths |
|
754 | + foreach ($file_paths as $key => $file_path) { |
|
755 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
756 | + $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
757 | + // prep file type |
|
758 | + $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
759 | + // build full file path |
|
760 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
761 | + //does the file exist and can be read ? |
|
762 | + if (is_readable($file_paths[$key])) { |
|
763 | + return $file_paths[$key]; |
|
764 | + } |
|
765 | + } |
|
766 | + return false; |
|
767 | + } |
|
768 | + |
|
769 | + |
|
770 | + |
|
771 | + /** |
|
772 | + * _require_file |
|
773 | + * basically just performs a require_once() |
|
774 | + * but with some error handling |
|
775 | + * |
|
776 | + * @access protected |
|
777 | + * @param string $path |
|
778 | + * @param string $class_name |
|
779 | + * @param string $type |
|
780 | + * @param array $file_paths |
|
781 | + * @return boolean |
|
782 | + * @throws \EE_Error |
|
783 | + */ |
|
784 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
785 | + { |
|
786 | + // don't give up! you gotta... |
|
787 | + try { |
|
788 | + //does the file exist and can it be read ? |
|
789 | + if ( ! $path) { |
|
790 | + // so sorry, can't find the file |
|
791 | + throw new EE_Error ( |
|
792 | + sprintf( |
|
793 | + __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
794 | + trim($type, '.'), |
|
795 | + $class_name, |
|
796 | + '<br />' . implode(',<br />', $file_paths) |
|
797 | + ) |
|
798 | + ); |
|
799 | + } |
|
800 | + // get the file |
|
801 | + require_once($path); |
|
802 | + // if the class isn't already declared somewhere |
|
803 | + if (class_exists($class_name, false) === false) { |
|
804 | + // so sorry, not a class |
|
805 | + throw new EE_Error( |
|
806 | + sprintf( |
|
807 | + __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
808 | + $type, |
|
809 | + $path, |
|
810 | + $class_name |
|
811 | + ) |
|
812 | + ); |
|
813 | + } |
|
814 | + } catch (EE_Error $e) { |
|
815 | + $e->get_error(); |
|
816 | + return false; |
|
817 | + } |
|
818 | + return true; |
|
819 | + } |
|
820 | + |
|
821 | + |
|
822 | + |
|
823 | + /** |
|
824 | + * _create_object |
|
825 | + * Attempts to instantiate the requested class via any of the |
|
826 | + * commonly used instantiation methods employed throughout EE. |
|
827 | + * The priority for instantiation is as follows: |
|
828 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
829 | + * - model objects via their 'new_instance_from_db' method |
|
830 | + * - model objects via their 'new_instance' method |
|
831 | + * - "singleton" classes" via their 'instance' method |
|
832 | + * - standard instantiable classes via their __constructor |
|
833 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
834 | + * then the constructor for the requested class will be examined to determine |
|
835 | + * if any dependencies exist, and if they can be injected. |
|
836 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
837 | + * |
|
838 | + * @access protected |
|
839 | + * @param string $class_name |
|
840 | + * @param array $arguments |
|
841 | + * @param string $type |
|
842 | + * @param bool $from_db |
|
843 | + * @return null | object |
|
844 | + * @throws \EE_Error |
|
845 | + */ |
|
846 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
847 | + { |
|
848 | + $class_obj = null; |
|
849 | + $instantiation_mode = '0) none'; |
|
850 | + // don't give up! you gotta... |
|
851 | + try { |
|
852 | + // create reflection |
|
853 | + $reflector = $this->get_ReflectionClass($class_name); |
|
854 | + // make sure arguments are an array |
|
855 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
856 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
857 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
858 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
859 | + ? $arguments |
|
860 | + : array($arguments); |
|
861 | + // attempt to inject dependencies ? |
|
862 | + if ($this->_dependency_map->has($class_name)) { |
|
863 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
864 | + } |
|
865 | + // instantiate the class if possible |
|
866 | + if ($reflector->isAbstract()) { |
|
867 | + // nothing to instantiate, loading file was enough |
|
868 | + // does not throw an exception so $instantiation_mode is unused |
|
869 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
870 | + $class_obj = true; |
|
871 | + } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
872 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
873 | + $instantiation_mode = "2) no constructor but instantiable"; |
|
874 | + $class_obj = $reflector->newInstance(); |
|
875 | + } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
876 | + $instantiation_mode = "3) new_instance_from_db()"; |
|
877 | + $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
878 | + } else if (method_exists($class_name, 'new_instance')) { |
|
879 | + $instantiation_mode = "4) new_instance()"; |
|
880 | + $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
881 | + } else if (method_exists($class_name, 'instance')) { |
|
882 | + $instantiation_mode = "5) instance()"; |
|
883 | + $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
884 | + } else if ($reflector->isInstantiable()) { |
|
885 | + $instantiation_mode = "6) constructor"; |
|
886 | + $class_obj = $reflector->newInstanceArgs($arguments); |
|
887 | + } else { |
|
888 | + // heh ? something's not right ! |
|
889 | + throw new EE_Error( |
|
890 | + sprintf( |
|
891 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
892 | + $type, |
|
893 | + $class_name |
|
894 | + ) |
|
895 | + ); |
|
896 | + } |
|
897 | + } catch (Exception $e) { |
|
898 | + if ( ! $e instanceof EE_Error) { |
|
899 | + $e = new EE_Error( |
|
900 | + sprintf( |
|
901 | + __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
902 | + $class_name, |
|
903 | + '<br />', |
|
904 | + $e->getMessage(), |
|
905 | + $instantiation_mode |
|
906 | + ) |
|
907 | + ); |
|
908 | + } |
|
909 | + $e->get_error(); |
|
910 | + } |
|
911 | + return $class_obj; |
|
912 | + } |
|
913 | + |
|
914 | + |
|
915 | + |
|
916 | + /** |
|
917 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
918 | + * @param array $array |
|
919 | + * @return bool |
|
920 | + */ |
|
921 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
922 | + { |
|
923 | + return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
924 | + } |
|
925 | + |
|
926 | + |
|
927 | + |
|
928 | + /** |
|
929 | + * getReflectionClass |
|
930 | + * checks if a ReflectionClass object has already been generated for a class |
|
931 | + * and returns that instead of creating a new one |
|
932 | + * |
|
933 | + * @access public |
|
934 | + * @param string $class_name |
|
935 | + * @return ReflectionClass |
|
936 | + */ |
|
937 | + public function get_ReflectionClass($class_name) |
|
938 | + { |
|
939 | + if ( |
|
940 | + ! isset($this->_reflectors[$class_name]) |
|
941 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
942 | + ) { |
|
943 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
944 | + } |
|
945 | + return $this->_reflectors[$class_name]; |
|
946 | + } |
|
947 | + |
|
948 | + |
|
949 | + |
|
950 | + /** |
|
951 | + * _resolve_dependencies |
|
952 | + * examines the constructor for the requested class to determine |
|
953 | + * if any dependencies exist, and if they can be injected. |
|
954 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
955 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
956 | + * For example: |
|
957 | + * if attempting to load a class "Foo" with the following constructor: |
|
958 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
959 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
960 | + * but only IF they are NOT already present in the incoming arguments array, |
|
961 | + * and the correct classes can be loaded |
|
962 | + * |
|
963 | + * @access protected |
|
964 | + * @param ReflectionClass $reflector |
|
965 | + * @param string $class_name |
|
966 | + * @param array $arguments |
|
967 | + * @return array |
|
968 | + * @throws \ReflectionException |
|
969 | + */ |
|
970 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
971 | + { |
|
972 | + // let's examine the constructor |
|
973 | + $constructor = $reflector->getConstructor(); |
|
974 | + // whu? huh? nothing? |
|
975 | + if ( ! $constructor) { |
|
976 | + return $arguments; |
|
977 | + } |
|
978 | + // get constructor parameters |
|
979 | + $params = $constructor->getParameters(); |
|
980 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
981 | + $argument_keys = array_keys($arguments); |
|
982 | + // now loop thru all of the constructors expected parameters |
|
983 | + foreach ($params as $index => $param) { |
|
984 | + // is this a dependency for a specific class ? |
|
985 | + $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
986 | + if ( |
|
987 | + // param is not even a class |
|
988 | + empty($param_class) |
|
989 | + // and something already exists in the incoming arguments for this param |
|
990 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
991 | + ) { |
|
992 | + // so let's skip this argument and move on to the next |
|
993 | + continue; |
|
994 | + } else if ( |
|
995 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
996 | + ! empty($param_class) |
|
997 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
998 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
999 | + ) { |
|
1000 | + // skip this argument and move on to the next |
|
1001 | + continue; |
|
1002 | + } else if ( |
|
1003 | + // parameter is type hinted as a class, and should be injected |
|
1004 | + ! empty($param_class) |
|
1005 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1006 | + ) { |
|
1007 | + $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1008 | + } else { |
|
1009 | + try { |
|
1010 | + $arguments[$index] = $param->getDefaultValue(); |
|
1011 | + } catch (ReflectionException $e) { |
|
1012 | + throw new ReflectionException( |
|
1013 | + sprintf( |
|
1014 | + __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1015 | + $e->getMessage(), |
|
1016 | + $param->getName() |
|
1017 | + ) |
|
1018 | + ); |
|
1019 | + } |
|
1020 | + } |
|
1021 | + } |
|
1022 | + return $arguments; |
|
1023 | + } |
|
1024 | + |
|
1025 | + |
|
1026 | + |
|
1027 | + /** |
|
1028 | + * @access protected |
|
1029 | + * @param string $class_name |
|
1030 | + * @param string $param_class |
|
1031 | + * @param array $arguments |
|
1032 | + * @param mixed $index |
|
1033 | + * @return array |
|
1034 | + */ |
|
1035 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1036 | + { |
|
1037 | + $dependency = null; |
|
1038 | + // should dependency be loaded from cache ? |
|
1039 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1040 | + !== EE_Dependency_Map::load_new_object |
|
1041 | + ? true |
|
1042 | + : false; |
|
1043 | + // we might have a dependency... |
|
1044 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
1045 | + $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1046 | + // and grab it if it exists |
|
1047 | + if ($cached_class instanceof $param_class) { |
|
1048 | + $dependency = $cached_class; |
|
1049 | + } else if ($param_class != $class_name) { |
|
1050 | + // obtain the loader method from the dependency map |
|
1051 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
1052 | + // is loader a custom closure ? |
|
1053 | + if ($loader instanceof Closure) { |
|
1054 | + $dependency = $loader(); |
|
1055 | + } else { |
|
1056 | + // set the cache on property for the recursive loading call |
|
1057 | + $this->_cache_on = $cache_on; |
|
1058 | + // if not, then let's try and load it via the registry |
|
1059 | + if (method_exists($this, $loader)) { |
|
1060 | + $dependency = $this->{$loader}($param_class); |
|
1061 | + } else { |
|
1062 | + $dependency = $this->create($param_class, array(), $cache_on); |
|
1063 | + } |
|
1064 | + } |
|
1065 | + } |
|
1066 | + // did we successfully find the correct dependency ? |
|
1067 | + if ($dependency instanceof $param_class) { |
|
1068 | + // then let's inject it into the incoming array of arguments at the correct location |
|
1069 | + if (isset($argument_keys[$index])) { |
|
1070 | + $arguments[$argument_keys[$index]] = $dependency; |
|
1071 | + } else { |
|
1072 | + $arguments[$index] = $dependency; |
|
1073 | + } |
|
1074 | + } |
|
1075 | + return $arguments; |
|
1076 | + } |
|
1077 | + |
|
1078 | + |
|
1079 | + |
|
1080 | + /** |
|
1081 | + * _set_cached_class |
|
1082 | + * attempts to cache the instantiated class locally |
|
1083 | + * in one of the following places, in the following order: |
|
1084 | + * $this->{class_abbreviation} ie: $this->CART |
|
1085 | + * $this->{$class_name} ie: $this->Some_Class |
|
1086 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1087 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1088 | + * |
|
1089 | + * @access protected |
|
1090 | + * @param object $class_obj |
|
1091 | + * @param string $class_name |
|
1092 | + * @param string $class_prefix |
|
1093 | + * @param bool $from_db |
|
1094 | + * @return void |
|
1095 | + */ |
|
1096 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1097 | + { |
|
1098 | + if (empty($class_obj)) { |
|
1099 | + return; |
|
1100 | + } |
|
1101 | + // return newly instantiated class |
|
1102 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
1103 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1104 | + $this->{$class_abbreviation} = $class_obj; |
|
1105 | + } else if (property_exists($this, $class_name)) { |
|
1106 | + $this->{$class_name} = $class_obj; |
|
1107 | + } else if ($class_prefix == 'addon') { |
|
1108 | + $this->addons->{$class_name} = $class_obj; |
|
1109 | + } else if ( ! $from_db) { |
|
1110 | + $this->LIB->{$class_name} = $class_obj; |
|
1111 | + } |
|
1112 | + } |
|
1113 | + |
|
1114 | + |
|
1115 | + |
|
1116 | + /** |
|
1117 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1118 | + * |
|
1119 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1120 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
1121 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1122 | + * @param array $arguments |
|
1123 | + * @return object |
|
1124 | + */ |
|
1125 | + public static function factory($classname, $arguments = array()) |
|
1126 | + { |
|
1127 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1128 | + if ($loader instanceof Closure) { |
|
1129 | + return $loader($arguments); |
|
1130 | + } else if (method_exists(EE_Registry::instance(), $loader)) { |
|
1131 | + return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1132 | + } |
|
1133 | + return null; |
|
1134 | + } |
|
1135 | + |
|
1136 | + |
|
1137 | + |
|
1138 | + /** |
|
1139 | + * Gets the addon by its name/slug (not classname. For that, just |
|
1140 | + * use the classname as the property name on EE_Config::instance()->addons) |
|
1141 | + * |
|
1142 | + * @param string $name |
|
1143 | + * @return EE_Addon |
|
1144 | + */ |
|
1145 | + public function get_addon_by_name($name) |
|
1146 | + { |
|
1147 | + foreach ($this->addons as $addon) { |
|
1148 | + if ($addon->name() == $name) { |
|
1149 | + return $addon; |
|
1150 | + } |
|
1151 | + } |
|
1152 | + return null; |
|
1153 | + } |
|
1154 | + |
|
1155 | + |
|
1156 | + |
|
1157 | + /** |
|
1158 | + * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
1159 | + * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1160 | + * |
|
1161 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
1162 | + */ |
|
1163 | + public function get_addons_by_name() |
|
1164 | + { |
|
1165 | + $addons = array(); |
|
1166 | + foreach ($this->addons as $addon) { |
|
1167 | + $addons[$addon->name()] = $addon; |
|
1168 | + } |
|
1169 | + return $addons; |
|
1170 | + } |
|
1171 | + |
|
1172 | + |
|
1173 | + |
|
1174 | + /** |
|
1175 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1176 | + * a stale copy of it around |
|
1177 | + * |
|
1178 | + * @param string $model_name |
|
1179 | + * @return \EEM_Base |
|
1180 | + * @throws \EE_Error |
|
1181 | + */ |
|
1182 | + public function reset_model($model_name) |
|
1183 | + { |
|
1184 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1185 | + if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1186 | + return null; |
|
1187 | + } |
|
1188 | + //get that model reset it and make sure we nuke the old reference to it |
|
1189 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1190 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1191 | + } else { |
|
1192 | + throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1193 | + } |
|
1194 | + return $this->LIB->{$model_class_name}; |
|
1195 | + } |
|
1196 | + |
|
1197 | + |
|
1198 | + |
|
1199 | + /** |
|
1200 | + * Resets the registry. |
|
1201 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1202 | + * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1203 | + * - $_dependency_map |
|
1204 | + * - $_class_abbreviations |
|
1205 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1206 | + * - $REQ: Still on the same request so no need to change. |
|
1207 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
1208 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1209 | + * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1210 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1211 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1212 | + * switch or on the restore. |
|
1213 | + * - $modules |
|
1214 | + * - $shortcodes |
|
1215 | + * - $widgets |
|
1216 | + * |
|
1217 | + * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1218 | + * the Registry to its state at the beginning of the request |
|
1219 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1220 | + * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1221 | + * currently reinstantiate the singletons at the moment) |
|
1222 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1223 | + * code instead can just change the model context to a different blog id if necessary |
|
1224 | + * @return EE_Registry |
|
1225 | + */ |
|
1226 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1227 | + { |
|
1228 | + $instance = self::instance(); |
|
1229 | + EEH_Activation::reset(); |
|
1230 | + //properties that get reset |
|
1231 | + $instance->_cache_on = true; |
|
1232 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1233 | + $instance->CART = null; |
|
1234 | + $instance->MRM = null; |
|
1235 | + $instance->AssetsRegistry = new Registry(); |
|
1236 | + //messages reset |
|
1237 | + EED_Messages::reset(); |
|
1238 | + if ($reset_models) { |
|
1239 | + foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1240 | + $instance->reset_model($model_name); |
|
1241 | + } |
|
1242 | + } |
|
1243 | + $instance->LIB = new stdClass(); |
|
1244 | + return $instance; |
|
1245 | + } |
|
1246 | + |
|
1247 | + |
|
1248 | + |
|
1249 | + /** |
|
1250 | + * @override magic methods |
|
1251 | + * @return void |
|
1252 | + */ |
|
1253 | + final function __destruct() |
|
1254 | + { |
|
1255 | + } |
|
1256 | + |
|
1257 | + |
|
1258 | + |
|
1259 | + /** |
|
1260 | + * @param $a |
|
1261 | + * @param $b |
|
1262 | + */ |
|
1263 | + final function __call($a, $b) |
|
1264 | + { |
|
1265 | + } |
|
1266 | + |
|
1267 | + |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * @param $a |
|
1271 | + */ |
|
1272 | + final function __get($a) |
|
1273 | + { |
|
1274 | + } |
|
1275 | + |
|
1276 | + |
|
1277 | + |
|
1278 | + /** |
|
1279 | + * @param $a |
|
1280 | + * @param $b |
|
1281 | + */ |
|
1282 | + final function __set($a, $b) |
|
1283 | + { |
|
1284 | + } |
|
1285 | + |
|
1286 | + |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * @param $a |
|
1290 | + */ |
|
1291 | + final function __isset($a) |
|
1292 | + { |
|
1293 | + } |
|
1294 | 1294 | |
1295 | 1295 | |
1296 | 1296 | |
1297 | - /** |
|
1298 | - * @param $a |
|
1299 | - */ |
|
1300 | - final function __unset($a) |
|
1301 | - { |
|
1302 | - } |
|
1297 | + /** |
|
1298 | + * @param $a |
|
1299 | + */ |
|
1300 | + final function __unset($a) |
|
1301 | + { |
|
1302 | + } |
|
1303 | 1303 | |
1304 | 1304 | |
1305 | 1305 | |
1306 | - /** |
|
1307 | - * @return array |
|
1308 | - */ |
|
1309 | - final function __sleep() |
|
1310 | - { |
|
1311 | - return array(); |
|
1312 | - } |
|
1306 | + /** |
|
1307 | + * @return array |
|
1308 | + */ |
|
1309 | + final function __sleep() |
|
1310 | + { |
|
1311 | + return array(); |
|
1312 | + } |
|
1313 | 1313 | |
1314 | 1314 | |
1315 | 1315 | |
1316 | - final function __wakeup() |
|
1317 | - { |
|
1318 | - } |
|
1316 | + final function __wakeup() |
|
1317 | + { |
|
1318 | + } |
|
1319 | 1319 | |
1320 | 1320 | |
1321 | 1321 | |
1322 | - /** |
|
1323 | - * @return string |
|
1324 | - */ |
|
1325 | - final function __toString() |
|
1326 | - { |
|
1327 | - return ''; |
|
1328 | - } |
|
1322 | + /** |
|
1323 | + * @return string |
|
1324 | + */ |
|
1325 | + final function __toString() |
|
1326 | + { |
|
1327 | + return ''; |
|
1328 | + } |
|
1329 | 1329 | |
1330 | 1330 | |
1331 | 1331 | |
1332 | - final function __invoke() |
|
1333 | - { |
|
1334 | - } |
|
1332 | + final function __invoke() |
|
1333 | + { |
|
1334 | + } |
|
1335 | 1335 | |
1336 | 1336 | |
1337 | 1337 | |
1338 | - final function __set_state() |
|
1339 | - { |
|
1340 | - } |
|
1338 | + final function __set_state() |
|
1339 | + { |
|
1340 | + } |
|
1341 | 1341 | |
1342 | 1342 | |
1343 | 1343 | |
1344 | - final function __clone() |
|
1345 | - { |
|
1346 | - } |
|
1344 | + final function __clone() |
|
1345 | + { |
|
1346 | + } |
|
1347 | 1347 | |
1348 | 1348 | |
1349 | 1349 | |
1350 | - /** |
|
1351 | - * @param $a |
|
1352 | - * @param $b |
|
1353 | - */ |
|
1354 | - final static function __callStatic($a, $b) |
|
1355 | - { |
|
1356 | - } |
|
1350 | + /** |
|
1351 | + * @param $a |
|
1352 | + * @param $b |
|
1353 | + */ |
|
1354 | + final static function __callStatic($a, $b) |
|
1355 | + { |
|
1356 | + } |
|
1357 | 1357 | |
1358 | 1358 | |
1359 | 1359 | |
1360 | - /** |
|
1361 | - * Gets all the custom post type models defined |
|
1362 | - * |
|
1363 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1364 | - */ |
|
1365 | - public function cpt_models() |
|
1366 | - { |
|
1367 | - $cpt_models = array(); |
|
1368 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1369 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1370 | - $cpt_models[$short_name] = $classname; |
|
1371 | - } |
|
1372 | - } |
|
1373 | - return $cpt_models; |
|
1374 | - } |
|
1360 | + /** |
|
1361 | + * Gets all the custom post type models defined |
|
1362 | + * |
|
1363 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1364 | + */ |
|
1365 | + public function cpt_models() |
|
1366 | + { |
|
1367 | + $cpt_models = array(); |
|
1368 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1369 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1370 | + $cpt_models[$short_name] = $classname; |
|
1371 | + } |
|
1372 | + } |
|
1373 | + return $cpt_models; |
|
1374 | + } |
|
1375 | 1375 | |
1376 | 1376 | |
1377 | 1377 | |
1378 | - /** |
|
1379 | - * @return \EE_Config |
|
1380 | - */ |
|
1381 | - public static function CFG() |
|
1382 | - { |
|
1383 | - return self::instance()->CFG; |
|
1384 | - } |
|
1378 | + /** |
|
1379 | + * @return \EE_Config |
|
1380 | + */ |
|
1381 | + public static function CFG() |
|
1382 | + { |
|
1383 | + return self::instance()->CFG; |
|
1384 | + } |
|
1385 | 1385 | |
1386 | 1386 | |
1387 | 1387 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,239 +40,239 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.24.rc.012'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.24.rc.012'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - /** |
|
197 | - * espresso_plugin_activation |
|
198 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
199 | - */ |
|
200 | - function espresso_plugin_activation() |
|
201 | - { |
|
202 | - update_option('ee_espresso_activation', true); |
|
203 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + /** |
|
197 | + * espresso_plugin_activation |
|
198 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
199 | + */ |
|
200 | + function espresso_plugin_activation() |
|
201 | + { |
|
202 | + update_option('ee_espresso_activation', true); |
|
203 | + } |
|
204 | 204 | |
205 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
206 | - /** |
|
207 | - * espresso_load_error_handling |
|
208 | - * this function loads EE's class for handling exceptions and errors |
|
209 | - */ |
|
210 | - function espresso_load_error_handling() |
|
211 | - { |
|
212 | - // load debugging tools |
|
213 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
214 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
215 | - EEH_Debug_Tools::instance(); |
|
216 | - } |
|
217 | - // load error handling |
|
218 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
219 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
220 | - } else { |
|
221 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
222 | - } |
|
223 | - } |
|
205 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
206 | + /** |
|
207 | + * espresso_load_error_handling |
|
208 | + * this function loads EE's class for handling exceptions and errors |
|
209 | + */ |
|
210 | + function espresso_load_error_handling() |
|
211 | + { |
|
212 | + // load debugging tools |
|
213 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
214 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
215 | + EEH_Debug_Tools::instance(); |
|
216 | + } |
|
217 | + // load error handling |
|
218 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
219 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
220 | + } else { |
|
221 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
222 | + } |
|
223 | + } |
|
224 | 224 | |
225 | - /** |
|
226 | - * espresso_load_required |
|
227 | - * given a class name and path, this function will load that file or throw an exception |
|
228 | - * |
|
229 | - * @param string $classname |
|
230 | - * @param string $full_path_to_file |
|
231 | - * @throws EE_Error |
|
232 | - */ |
|
233 | - function espresso_load_required($classname, $full_path_to_file) |
|
234 | - { |
|
235 | - static $error_handling_loaded = false; |
|
236 | - if ( ! $error_handling_loaded) { |
|
237 | - espresso_load_error_handling(); |
|
238 | - $error_handling_loaded = true; |
|
239 | - } |
|
240 | - if (is_readable($full_path_to_file)) { |
|
241 | - require_once($full_path_to_file); |
|
242 | - } else { |
|
243 | - throw new EE_Error ( |
|
244 | - sprintf( |
|
245 | - esc_html__( |
|
246 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
247 | - 'event_espresso' |
|
248 | - ), |
|
249 | - $classname |
|
250 | - ) |
|
251 | - ); |
|
252 | - } |
|
253 | - } |
|
225 | + /** |
|
226 | + * espresso_load_required |
|
227 | + * given a class name and path, this function will load that file or throw an exception |
|
228 | + * |
|
229 | + * @param string $classname |
|
230 | + * @param string $full_path_to_file |
|
231 | + * @throws EE_Error |
|
232 | + */ |
|
233 | + function espresso_load_required($classname, $full_path_to_file) |
|
234 | + { |
|
235 | + static $error_handling_loaded = false; |
|
236 | + if ( ! $error_handling_loaded) { |
|
237 | + espresso_load_error_handling(); |
|
238 | + $error_handling_loaded = true; |
|
239 | + } |
|
240 | + if (is_readable($full_path_to_file)) { |
|
241 | + require_once($full_path_to_file); |
|
242 | + } else { |
|
243 | + throw new EE_Error ( |
|
244 | + sprintf( |
|
245 | + esc_html__( |
|
246 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
247 | + 'event_espresso' |
|
248 | + ), |
|
249 | + $classname |
|
250 | + ) |
|
251 | + ); |
|
252 | + } |
|
253 | + } |
|
254 | 254 | |
255 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
256 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
257 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
258 | - new EE_Bootstrap(); |
|
259 | - } |
|
255 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
256 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
257 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
258 | + new EE_Bootstrap(); |
|
259 | + } |
|
260 | 260 | } |
261 | 261 | if ( ! function_exists('espresso_deactivate_plugin')) { |
262 | - /** |
|
263 | - * deactivate_plugin |
|
264 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
265 | - * |
|
266 | - * @access public |
|
267 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
268 | - * @return void |
|
269 | - */ |
|
270 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
271 | - { |
|
272 | - if ( ! function_exists('deactivate_plugins')) { |
|
273 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
274 | - } |
|
275 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
276 | - deactivate_plugins($plugin_basename); |
|
277 | - } |
|
262 | + /** |
|
263 | + * deactivate_plugin |
|
264 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
265 | + * |
|
266 | + * @access public |
|
267 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
268 | + * @return void |
|
269 | + */ |
|
270 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
271 | + { |
|
272 | + if ( ! function_exists('deactivate_plugins')) { |
|
273 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
274 | + } |
|
275 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
276 | + deactivate_plugins($plugin_basename); |
|
277 | + } |
|
278 | 278 | } |