@@ -36,7 +36,7 @@ |
||
36 | 36 | |
37 | 37 | /** |
38 | 38 | * Taken from https://gist.github.com/jaywilliams/119517 |
39 | - * @param $string |
|
39 | + * @param string $string |
|
40 | 40 | * @return string |
41 | 41 | */ |
42 | 42 | protected function convertAscii($string) |
@@ -1,8 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\services\formatters; |
3 | 3 | |
4 | -use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
5 | - |
|
6 | 4 | defined('EVENT_ESPRESSO_VERSION') || exit; |
7 | 5 | |
8 | 6 |
@@ -18,60 +18,60 @@ |
||
18 | 18 | class AsciiOnly extends FormatterBase |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * Removes all non Ascii characters from string |
|
23 | - * |
|
24 | - * @param string|int|float $input anything easily cast into a string |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public function format($input) |
|
28 | - { |
|
29 | - //in case an int or float etc was passed in |
|
30 | - $input = (string)$input; |
|
31 | - $input = $this->convertAscii($input); |
|
32 | - return $input; |
|
33 | - } |
|
21 | + /** |
|
22 | + * Removes all non Ascii characters from string |
|
23 | + * |
|
24 | + * @param string|int|float $input anything easily cast into a string |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public function format($input) |
|
28 | + { |
|
29 | + //in case an int or float etc was passed in |
|
30 | + $input = (string)$input; |
|
31 | + $input = $this->convertAscii($input); |
|
32 | + return $input; |
|
33 | + } |
|
34 | 34 | |
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Taken from https://gist.github.com/jaywilliams/119517 |
|
39 | - * @param $string |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - protected function convertAscii($string) |
|
43 | - { |
|
44 | - // Replace Single Curly Quotes |
|
45 | - $search[] = chr(226).chr(128).chr(152); |
|
46 | - $replace[] = "'"; |
|
47 | - $search[] = chr(226).chr(128).chr(153); |
|
48 | - $replace[] = "'"; |
|
49 | - // Replace Smart Double Curly Quotes |
|
50 | - $search[] = chr(226).chr(128).chr(156); |
|
51 | - $replace[] = '"'; |
|
52 | - $search[] = chr(226).chr(128).chr(157); |
|
53 | - $replace[] = '"'; |
|
54 | - // Replace En Dash |
|
55 | - $search[] = chr(226).chr(128).chr(147); |
|
56 | - $replace[] = '--'; |
|
57 | - // Replace Em Dash |
|
58 | - $search[] = chr(226).chr(128).chr(148); |
|
59 | - $replace[] = '---'; |
|
60 | - // Replace Bullet |
|
61 | - $search[] = chr(226).chr(128).chr(162); |
|
62 | - $replace[] = '*'; |
|
63 | - // Replace Middle Dot |
|
64 | - $search[] = chr(194).chr(183); |
|
65 | - $replace[] = '*'; |
|
66 | - // Replace Ellipsis with three consecutive dots |
|
67 | - $search[] = chr(226).chr(128).chr(166); |
|
68 | - $replace[] = '...'; |
|
69 | - // Apply Replacements |
|
70 | - $string = str_replace($search, $replace, $string); |
|
71 | - // Remove any non-ASCII Characters |
|
72 | - $string = preg_replace("/[^\x01-\x7F]/","", $string); |
|
73 | - return $string; |
|
74 | - } |
|
37 | + /** |
|
38 | + * Taken from https://gist.github.com/jaywilliams/119517 |
|
39 | + * @param $string |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + protected function convertAscii($string) |
|
43 | + { |
|
44 | + // Replace Single Curly Quotes |
|
45 | + $search[] = chr(226).chr(128).chr(152); |
|
46 | + $replace[] = "'"; |
|
47 | + $search[] = chr(226).chr(128).chr(153); |
|
48 | + $replace[] = "'"; |
|
49 | + // Replace Smart Double Curly Quotes |
|
50 | + $search[] = chr(226).chr(128).chr(156); |
|
51 | + $replace[] = '"'; |
|
52 | + $search[] = chr(226).chr(128).chr(157); |
|
53 | + $replace[] = '"'; |
|
54 | + // Replace En Dash |
|
55 | + $search[] = chr(226).chr(128).chr(147); |
|
56 | + $replace[] = '--'; |
|
57 | + // Replace Em Dash |
|
58 | + $search[] = chr(226).chr(128).chr(148); |
|
59 | + $replace[] = '---'; |
|
60 | + // Replace Bullet |
|
61 | + $search[] = chr(226).chr(128).chr(162); |
|
62 | + $replace[] = '*'; |
|
63 | + // Replace Middle Dot |
|
64 | + $search[] = chr(194).chr(183); |
|
65 | + $replace[] = '*'; |
|
66 | + // Replace Ellipsis with three consecutive dots |
|
67 | + $search[] = chr(226).chr(128).chr(166); |
|
68 | + $replace[] = '...'; |
|
69 | + // Apply Replacements |
|
70 | + $string = str_replace($search, $replace, $string); |
|
71 | + // Remove any non-ASCII Characters |
|
72 | + $string = preg_replace("/[^\x01-\x7F]/","", $string); |
|
73 | + return $string; |
|
74 | + } |
|
75 | 75 | } |
76 | 76 | // End of file EmojiRemoval.php |
77 | 77 | // Location: core\services\formatters/EmojiRemoval.php |
78 | 78 | \ No newline at end of file |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | public function format($input) |
28 | 28 | { |
29 | 29 | //in case an int or float etc was passed in |
30 | - $input = (string)$input; |
|
30 | + $input = (string) $input; |
|
31 | 31 | $input = $this->convertAscii($input); |
32 | 32 | return $input; |
33 | 33 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | // Apply Replacements |
70 | 70 | $string = str_replace($search, $replace, $string); |
71 | 71 | // Remove any non-ASCII Characters |
72 | - $string = preg_replace("/[^\x01-\x7F]/","", $string); |
|
72 | + $string = preg_replace("/[^\x01-\x7F]/", "", $string); |
|
73 | 73 | return $string; |
74 | 74 | } |
75 | 75 | } |
@@ -18,28 +18,28 @@ |
||
18 | 18 | class LeaveAlone extends FormatterBase |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * Removes the emojis from the inputted string |
|
23 | - * |
|
24 | - * @param string|int|float $input anything easily cast into a string |
|
25 | - * @return string |
|
26 | - * @throws InvalidDataTypeException if $input is not a string |
|
27 | - */ |
|
28 | - public function format($input) |
|
29 | - { |
|
30 | - return $input; |
|
31 | - } |
|
21 | + /** |
|
22 | + * Removes the emojis from the inputted string |
|
23 | + * |
|
24 | + * @param string|int|float $input anything easily cast into a string |
|
25 | + * @return string |
|
26 | + * @throws InvalidDataTypeException if $input is not a string |
|
27 | + */ |
|
28 | + public function format($input) |
|
29 | + { |
|
30 | + return $input; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Just returns the inputted $input array |
|
35 | - * |
|
36 | - * @param array $input |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public function formatArray($input) |
|
40 | - { |
|
41 | - return $input; |
|
42 | - } |
|
33 | + /** |
|
34 | + * Just returns the inputted $input array |
|
35 | + * |
|
36 | + * @param array $input |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public function formatArray($input) |
|
40 | + { |
|
41 | + return $input; |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | // End of file LeaveAlonel.php |
45 | 45 | // Location: core\services\formatters/LeaveAlonel.php |
46 | 46 | \ No newline at end of file |
@@ -28,8 +28,8 @@ |
||
28 | 28 | public function format($input) |
29 | 29 | { |
30 | 30 | //in case an int or float etc was passed in |
31 | - $input = (string)$input; |
|
32 | - $input = iconv('utf-8','cp1252//TRANSLIT', $input); |
|
31 | + $input = (string) $input; |
|
32 | + $input = iconv('utf-8', 'cp1252//TRANSLIT', $input); |
|
33 | 33 | return $input; |
34 | 34 | } |
35 | 35 | } |
@@ -11,7 +11,6 @@ discard block |
||
11 | 11 | * Class Windows1252 |
12 | 12 | * Converts from utf8 encoding to windows 1252 (aka cp1252, aka ISO-8859-1, see https://en.wikipedia.org/wiki/Windows-1252). |
13 | 13 | * This is useful if you need to send a string to a site using windows 1252 character encoding |
14 | - |
|
15 | 14 | * |
16 | 15 | *@package Event Espresso |
17 | 16 | * @author Mike Nelson |
@@ -20,19 +19,19 @@ discard block |
||
20 | 19 | class Windows1252 extends FormatterBase |
21 | 20 | { |
22 | 21 | |
23 | - /** |
|
24 | - * Converts the string to windows-1252 encoding. |
|
25 | - * |
|
26 | - * @param string|int|float $input anything easily cast into a string |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function format($input) |
|
30 | - { |
|
31 | - //in case an int or float etc was passed in |
|
32 | - $input = (string)$input; |
|
33 | - $input = iconv('utf-8','cp1252//TRANSLIT', $input); |
|
34 | - return $input; |
|
35 | - } |
|
22 | + /** |
|
23 | + * Converts the string to windows-1252 encoding. |
|
24 | + * |
|
25 | + * @param string|int|float $input anything easily cast into a string |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function format($input) |
|
29 | + { |
|
30 | + //in case an int or float etc was passed in |
|
31 | + $input = (string)$input; |
|
32 | + $input = iconv('utf-8','cp1252//TRANSLIT', $input); |
|
33 | + return $input; |
|
34 | + } |
|
36 | 35 | } |
37 | 36 | // End of file EmojiRemoval.php |
38 | 37 | // Location: core\services\formatters/EmojiRemoval.php |
39 | 38 | \ No newline at end of file |
@@ -22,7 +22,7 @@ |
||
22 | 22 | public function __construct($pm_instance = NULL) { |
23 | 23 | $this->_setup_properties(); |
24 | 24 | parent::__construct($pm_instance); |
25 | - $this->_gateway->set_unsupported_character_remover(new \EventEspresso\core\services\formatters\Windows1252()); |
|
25 | + $this->_gateway->set_unsupported_character_remover(new \EventEspresso\core\services\formatters\Windows1252()); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | $this->_gateway->set_template_helper( new EEH_Template() ); |
107 | 107 | $this->_gateway->set_line_item_helper( new EEH_Line_Item() ); |
108 | 108 | $this->_gateway->set_money_helper( new EEH_Money() ); |
109 | - $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter()); |
|
110 | - $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
|
111 | - do_action( 'AHEE__EE_PMT_Base___construct__done_initializing_gateway_class',$this,$this->_gateway); |
|
109 | + $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter()); |
|
110 | + $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
|
111 | + do_action( 'AHEE__EE_PMT_Base___construct__done_initializing_gateway_class',$this,$this->_gateway); |
|
112 | 112 | } |
113 | 113 | if ( ! isset( $this->_has_billing_form ) ) { |
114 | 114 | // by default, On Site gateways have a billing form |
@@ -282,17 +282,17 @@ discard block |
||
282 | 282 | //if we know who the attendee is, and this is a billing form |
283 | 283 | //that uses attendee info, populate it |
284 | 284 | if ( |
285 | - apply_filters( |
|
286 | - 'FHEE__populate_billing_form_fields_from_attendee', |
|
287 | - ( |
|
288 | - $this->_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
289 | - && $transaction instanceof EE_Transaction |
|
290 | - && $transaction->primary_registration() instanceof EE_Registration |
|
291 | - && $transaction->primary_registration()->attendee() instanceof EE_Attendee |
|
292 | - ), |
|
293 | - $this->_billing_form, |
|
294 | - $transaction |
|
295 | - ) |
|
285 | + apply_filters( |
|
286 | + 'FHEE__populate_billing_form_fields_from_attendee', |
|
287 | + ( |
|
288 | + $this->_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
289 | + && $transaction instanceof EE_Transaction |
|
290 | + && $transaction->primary_registration() instanceof EE_Registration |
|
291 | + && $transaction->primary_registration()->attendee() instanceof EE_Attendee |
|
292 | + ), |
|
293 | + $this->_billing_form, |
|
294 | + $transaction |
|
295 | + ) |
|
296 | 296 | ){ |
297 | 297 | $this->_billing_form->populate_from_attendee( $transaction->primary_registration()->attendee() ); |
298 | 298 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @since $VID:$ |
17 | 17 | * |
18 | 18 | */ |
19 | -abstract class EE_PMT_Base{ |
|
19 | +abstract class EE_PMT_Base { |
|
20 | 20 | |
21 | 21 | const onsite = 'on-site'; |
22 | 22 | const offsite = 'off-site'; |
@@ -97,34 +97,34 @@ discard block |
||
97 | 97 | * @return EE_PMT_Base |
98 | 98 | */ |
99 | 99 | function __construct($pm_instance = NULL) { |
100 | - if ( $pm_instance instanceof EE_Payment_Method ){ |
|
100 | + if ($pm_instance instanceof EE_Payment_Method) { |
|
101 | 101 | $this->set_instance($pm_instance); |
102 | 102 | } |
103 | - if($this->_gateway){ |
|
104 | - $this->_gateway->set_payment_model( EEM_Payment::instance() ); |
|
105 | - $this->_gateway->set_payment_log( EEM_Change_Log::instance() ); |
|
106 | - $this->_gateway->set_template_helper( new EEH_Template() ); |
|
107 | - $this->_gateway->set_line_item_helper( new EEH_Line_Item() ); |
|
108 | - $this->_gateway->set_money_helper( new EEH_Money() ); |
|
103 | + if ($this->_gateway) { |
|
104 | + $this->_gateway->set_payment_model(EEM_Payment::instance()); |
|
105 | + $this->_gateway->set_payment_log(EEM_Change_Log::instance()); |
|
106 | + $this->_gateway->set_template_helper(new EEH_Template()); |
|
107 | + $this->_gateway->set_line_item_helper(new EEH_Line_Item()); |
|
108 | + $this->_gateway->set_money_helper(new EEH_Money()); |
|
109 | 109 | $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter()); |
110 | 110 | $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
111 | - do_action( 'AHEE__EE_PMT_Base___construct__done_initializing_gateway_class',$this,$this->_gateway); |
|
111 | + do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway); |
|
112 | 112 | } |
113 | - if ( ! isset( $this->_has_billing_form ) ) { |
|
113 | + if ( ! isset($this->_has_billing_form)) { |
|
114 | 114 | // by default, On Site gateways have a billing form |
115 | - if ( $this->payment_occurs() == EE_PMT_Base::onsite ) { |
|
116 | - $this->set_has_billing_form( true ); |
|
115 | + if ($this->payment_occurs() == EE_PMT_Base::onsite) { |
|
116 | + $this->set_has_billing_form(true); |
|
117 | 117 | } else { |
118 | - $this->set_has_billing_form( false ); |
|
118 | + $this->set_has_billing_form(false); |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
122 | - if( ! $this->_pretty_name){ |
|
122 | + if ( ! $this->_pretty_name) { |
|
123 | 123 | throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso"))); |
124 | 124 | } |
125 | 125 | //if the child didn't specify a default button, use the credit card one |
126 | - if( $this->_default_button_url === NULL){ |
|
127 | - $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png'; |
|
126 | + if ($this->_default_button_url === NULL) { |
|
127 | + $this->_default_button_url = EE_PLUGIN_DIR_URL.'payment_methods'.DS.'pay-by-credit-card.png'; |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | /** |
134 | 134 | * @param boolean $has_billing_form |
135 | 135 | */ |
136 | - public function set_has_billing_form( $has_billing_form ) { |
|
137 | - $this->_has_billing_form = filter_var( $has_billing_form, FILTER_VALIDATE_BOOLEAN ); |
|
136 | + public function set_has_billing_form($has_billing_form) { |
|
137 | + $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | /** |
143 | 143 | * sets the file_folder property |
144 | 144 | */ |
145 | - protected function _set_file_folder(){ |
|
145 | + protected function _set_file_folder() { |
|
146 | 146 | $reflector = new ReflectionClass(get_class($this)); |
147 | 147 | $fn = $reflector->getFileName(); |
148 | - $this->_file_folder = dirname($fn).DS; |
|
148 | + $this->_file_folder = dirname($fn).DS; |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | /** |
154 | 154 | * sets the file URL with a trailing slash for this PMT |
155 | 155 | */ |
156 | - protected function _set_file_url(){ |
|
157 | - $plugins_dir_fixed = str_replace('\\',DS,WP_PLUGIN_DIR); |
|
158 | - $file_folder_fixed = str_replace('\\',DS,$this->file_folder()); |
|
159 | - $file_path = str_replace($plugins_dir_fixed,WP_PLUGIN_URL,$file_folder_fixed); |
|
156 | + protected function _set_file_url() { |
|
157 | + $plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR); |
|
158 | + $file_folder_fixed = str_replace('\\', DS, $this->file_folder()); |
|
159 | + $file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed); |
|
160 | 160 | $this->_file_url = $file_path; |
161 | 161 | } |
162 | 162 | |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * Gets the default description on all payment methods of this type |
165 | 165 | * @return string |
166 | 166 | */ |
167 | - public function default_description(){ |
|
167 | + public function default_description() { |
|
168 | 168 | return $this->_default_description; |
169 | 169 | } |
170 | 170 | |
@@ -174,8 +174,8 @@ discard block |
||
174 | 174 | * Returns the folder containing the PMT child class, with a trailing slash |
175 | 175 | * @return string |
176 | 176 | */ |
177 | - public function file_folder(){ |
|
178 | - if( ! $this->_file_folder ) { |
|
177 | + public function file_folder() { |
|
178 | + if ( ! $this->_file_folder) { |
|
179 | 179 | $this->_set_file_folder(); |
180 | 180 | } |
181 | 181 | return $this->_file_folder; |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | /** |
187 | 187 | * @return string |
188 | 188 | */ |
189 | - public function file_url(){ |
|
190 | - if( ! $this->_file_url ) { |
|
189 | + public function file_url() { |
|
190 | + if ( ! $this->_file_url) { |
|
191 | 191 | $this->_set_file_url(); |
192 | 192 | } |
193 | 193 | return $this->_file_url; |
@@ -200,14 +200,14 @@ discard block |
||
200 | 200 | * Its important teh payment method instance is set before |
201 | 201 | * @param EE_Payment_Method $payment_method_instance |
202 | 202 | */ |
203 | - function set_instance($payment_method_instance){ |
|
203 | + function set_instance($payment_method_instance) { |
|
204 | 204 | $this->_pm_instance = $payment_method_instance; |
205 | 205 | //if they have already requested the settings form, make sure its |
206 | 206 | //data matches this model object |
207 | - if($this->_settings_form){ |
|
207 | + if ($this->_settings_form) { |
|
208 | 208 | $this->settings_form()->populate_model_obj($payment_method_instance); |
209 | 209 | } |
210 | - if($this->_gateway && $this->_gateway instanceof EE_Gateway){ |
|
210 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
211 | 211 | $this->_gateway->set_settings($payment_method_instance->settings_array()); |
212 | 212 | } |
213 | 213 | } |
@@ -218,13 +218,13 @@ discard block |
||
218 | 218 | * Gets teh form for displaying to admins where they setup the payment method |
219 | 219 | * @return EE_Payment_Method_Form |
220 | 220 | */ |
221 | - function settings_form(){ |
|
222 | - if( ! $this->_settings_form){ |
|
221 | + function settings_form() { |
|
222 | + if ( ! $this->_settings_form) { |
|
223 | 223 | $this->_settings_form = $this->generate_new_settings_form(); |
224 | - $this->_settings_form->set_payment_method_type( $this ); |
|
224 | + $this->_settings_form->set_payment_method_type($this); |
|
225 | 225 | //if we have already assigned a model object to this pmt, make |
226 | 226 | //sure its reflected in teh form we just generated |
227 | - if($this->_pm_instance){ |
|
227 | + if ($this->_pm_instance) { |
|
228 | 228 | $this->_settings_form->populate_model_obj($this->_pm_instance); |
229 | 229 | } |
230 | 230 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * this payment method type's settings form later in the request |
251 | 251 | * @param EE_Payment_Method_Form $form |
252 | 252 | */ |
253 | - public function set_settings_form($form){ |
|
253 | + public function set_settings_form($form) { |
|
254 | 254 | $this->_settings_form = $form; |
255 | 255 | } |
256 | 256 | |
@@ -273,10 +273,10 @@ discard block |
||
273 | 273 | * @param array $extra_args |
274 | 274 | * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null |
275 | 275 | */ |
276 | - public function billing_form( EE_Transaction $transaction = NULL, $extra_args = array() ){ |
|
276 | + public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array()) { |
|
277 | 277 | // has billing form already been regenerated ? or overwrite cache? |
278 | - if ( ! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form ){ |
|
279 | - $this->_billing_form = $this->generate_new_billing_form( $transaction, $extra_args ); |
|
278 | + if ( ! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) { |
|
279 | + $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args); |
|
280 | 280 | } |
281 | 281 | //if we know who the attendee is, and this is a billing form |
282 | 282 | //that uses attendee info, populate it |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | $this->_billing_form, |
293 | 293 | $transaction |
294 | 294 | ) |
295 | - ){ |
|
296 | - $this->_billing_form->populate_from_attendee( $transaction->primary_registration()->attendee() ); |
|
295 | + ) { |
|
296 | + $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee()); |
|
297 | 297 | } |
298 | 298 | return $this->_billing_form; |
299 | 299 | } |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | * @param \EE_Transaction $transaction |
305 | 305 | * @return \EE_Billing_Info_Form |
306 | 306 | */ |
307 | - abstract function generate_new_billing_form( EE_Transaction $transaction = NULL ); |
|
307 | + abstract function generate_new_billing_form(EE_Transaction $transaction = NULL); |
|
308 | 308 | |
309 | 309 | |
310 | 310 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * @param \EE_Billing_Info_Form $billing_form |
316 | 316 | * @return \EE_Billing_Info_Form |
317 | 317 | */ |
318 | - public function apply_billing_form_debug_settings( EE_Billing_Info_Form $billing_form ) { |
|
318 | + public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) { |
|
319 | 319 | return $billing_form; |
320 | 320 | } |
321 | 321 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * if you have form |
327 | 327 | * @param EE_Payment_Method $form |
328 | 328 | */ |
329 | - public function set_billing_form($form){ |
|
329 | + public function set_billing_form($form) { |
|
330 | 330 | $this->_billing_form = $form; |
331 | 331 | } |
332 | 332 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | * Returns whether or not this payment method requires HTTPS to be used |
337 | 337 | * @return boolean |
338 | 338 | */ |
339 | - function requires_https(){ |
|
339 | + function requires_https() { |
|
340 | 340 | return $this->_requires_https; |
341 | 341 | } |
342 | 342 | |
@@ -354,9 +354,9 @@ discard block |
||
354 | 354 | * @return EE_Payment |
355 | 355 | * @throws EE_Error |
356 | 356 | */ |
357 | - function process_payment( EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null,$fail_url = '', $method = 'CART', $by_admin = false ){ |
|
357 | + function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false) { |
|
358 | 358 | // @todo: add surcharge for the payment method, if any |
359 | - if ( $this->_gateway ) { |
|
359 | + if ($this->_gateway) { |
|
360 | 360 | //there is a gateway, so we're going to make a payment object |
361 | 361 | //but wait! do they already have a payment in progress that we thought was failed? |
362 | 362 | $duplicate_properties = array( |
@@ -367,10 +367,10 @@ discard block |
||
367 | 367 | 'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(), |
368 | 368 | 'PAY_gateway_response' => null, |
369 | 369 | ); |
370 | - $payment = EEM_Payment::instance()->get_one( array( $duplicate_properties )); |
|
370 | + $payment = EEM_Payment::instance()->get_one(array($duplicate_properties)); |
|
371 | 371 | //if we didn't already have a payment in progress for the same thing, |
372 | 372 | //then we actually want to make a new payment |
373 | - if ( ! $payment instanceof EE_Payment ){ |
|
373 | + if ( ! $payment instanceof EE_Payment) { |
|
374 | 374 | $payment = EE_Payment::new_instance( |
375 | 375 | array_merge( |
376 | 376 | $duplicate_properties, |
@@ -386,10 +386,10 @@ discard block |
||
386 | 386 | } |
387 | 387 | //make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it |
388 | 388 | $payment->save(); |
389 | - $billing_values = $this->_get_billing_values_from_form( $billing_info ); |
|
389 | + $billing_values = $this->_get_billing_values_from_form($billing_info); |
|
390 | 390 | |
391 | 391 | // Offsite Gateway |
392 | - if( $this->_gateway instanceof EE_Offsite_Gateway ){ |
|
392 | + if ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
393 | 393 | |
394 | 394 | $payment = $this->_gateway->set_redirection_info( |
395 | 395 | $payment, |
@@ -405,17 +405,17 @@ discard block |
||
405 | 405 | ); |
406 | 406 | $payment->save(); |
407 | 407 | // Onsite Gateway |
408 | - } elseif ( $this->_gateway instanceof EE_Onsite_Gateway ) { |
|
408 | + } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
409 | 409 | |
410 | - $payment = $this->_gateway->do_direct_payment($payment,$billing_values); |
|
410 | + $payment = $this->_gateway->do_direct_payment($payment, $billing_values); |
|
411 | 411 | $payment->save(); |
412 | 412 | |
413 | 413 | } else { |
414 | 414 | throw new EE_Error( |
415 | 415 | sprintf( |
416 | - __('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso' ), |
|
416 | + __('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'), |
|
417 | 417 | get_class($this), |
418 | - gettype( $this->_gateway ) |
|
418 | + gettype($this->_gateway) |
|
419 | 419 | ) |
420 | 420 | ); |
421 | 421 | } |
@@ -437,8 +437,8 @@ discard block |
||
437 | 437 | } |
438 | 438 | |
439 | 439 | // if there is billing info, clean it and save it now |
440 | - if( $billing_info instanceof EE_Billing_Attendee_Info_Form ){ |
|
441 | - $this->_save_billing_info_to_attendee( $billing_info, $transaction ); |
|
440 | + if ($billing_info instanceof EE_Billing_Attendee_Info_Form) { |
|
441 | + $this->_save_billing_info_to_attendee($billing_info, $transaction); |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | return $payment; |
@@ -451,10 +451,10 @@ discard block |
||
451 | 451 | * @param EE_Billing_Info_Form $billing_form |
452 | 452 | * @return array |
453 | 453 | */ |
454 | - protected function _get_billing_values_from_form( $billing_form ){ |
|
455 | - if($billing_form instanceof EE_Form_Section_Proper ){ |
|
456 | - return $billing_form->input_pretty_values( true ); |
|
457 | - }else{ |
|
454 | + protected function _get_billing_values_from_form($billing_form) { |
|
455 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
456 | + return $billing_form->input_pretty_values(true); |
|
457 | + } else { |
|
458 | 458 | return NULL; |
459 | 459 | } |
460 | 460 | } |
@@ -468,13 +468,13 @@ discard block |
||
468 | 468 | * @return EE_Payment |
469 | 469 | * @throws EE_Error |
470 | 470 | */ |
471 | - public function handle_ipn($req_data,$transaction){ |
|
471 | + public function handle_ipn($req_data, $transaction) { |
|
472 | 472 | $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
473 | - if( ! $this->_gateway instanceof EE_Offsite_Gateway){ |
|
474 | - throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r( $this->_gateway, TRUE ))); |
|
473 | + if ( ! $this->_gateway instanceof EE_Offsite_Gateway) { |
|
474 | + throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE))); |
|
475 | 475 | |
476 | 476 | } |
477 | - $payment = $this->_gateway->handle_payment_update( $req_data, $transaction ); |
|
477 | + $payment = $this->_gateway->handle_payment_update($req_data, $transaction); |
|
478 | 478 | return $payment; |
479 | 479 | } |
480 | 480 | |
@@ -487,22 +487,22 @@ discard block |
||
487 | 487 | * @param EE_Transaction $transaction |
488 | 488 | * @return boolean success |
489 | 489 | */ |
490 | - protected function _save_billing_info_to_attendee($billing_form, $transaction){ |
|
491 | - if( ! $transaction || ! $transaction instanceof EE_Transaction){ |
|
490 | + protected function _save_billing_info_to_attendee($billing_form, $transaction) { |
|
491 | + if ( ! $transaction || ! $transaction instanceof EE_Transaction) { |
|
492 | 492 | EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
493 | 493 | return false; |
494 | 494 | } |
495 | 495 | $primary_reg = $transaction->primary_registration(); |
496 | - if( ! $primary_reg ){ |
|
496 | + if ( ! $primary_reg) { |
|
497 | 497 | EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
498 | 498 | return false; |
499 | 499 | } |
500 | 500 | $attendee = $primary_reg->attendee(); |
501 | - if( ! $attendee ){ |
|
501 | + if ( ! $attendee) { |
|
502 | 502 | EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
503 | 503 | return false; |
504 | 504 | } |
505 | - return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method() ); |
|
505 | + return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method()); |
|
506 | 506 | |
507 | 507 | } |
508 | 508 | |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | * @param array $req_data |
516 | 516 | * @return EE_Payment |
517 | 517 | */ |
518 | - protected function find_payment_for_ipn( EE_Transaction $transaction, $req_data = array() ){ |
|
518 | + protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array()) { |
|
519 | 519 | return $transaction->last_payment(); |
520 | 520 | } |
521 | 521 | |
@@ -532,8 +532,8 @@ discard block |
||
532 | 532 | * and identifies the IPN as being for this payment method (not just fo ra payment method of this type) |
533 | 533 | * @throws EE_Error |
534 | 534 | */ |
535 | - public function handle_unclaimed_ipn( $req_data = array() ){ |
|
536 | - throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this) )); |
|
535 | + public function handle_unclaimed_ipn($req_data = array()) { |
|
536 | + throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this))); |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | * @param EE_Transaction $transaction |
550 | 550 | * @return EE_Payment |
551 | 551 | */ |
552 | - public function finalize_payment_for($transaction){ |
|
552 | + public function finalize_payment_for($transaction) { |
|
553 | 553 | return $transaction->last_payment(); |
554 | 554 | } |
555 | 555 | |
@@ -559,10 +559,10 @@ discard block |
||
559 | 559 | * Whether or not this payment method's gateway supports sending refund requests |
560 | 560 | * @return boolean |
561 | 561 | */ |
562 | - public function supports_sending_refunds(){ |
|
563 | - if($this->_gateway && $this->_gateway instanceof EE_Gateway){ |
|
562 | + public function supports_sending_refunds() { |
|
563 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
564 | 564 | return $this->_gateway->supports_sending_refunds(); |
565 | - }else{ |
|
565 | + } else { |
|
566 | 566 | return false; |
567 | 567 | } |
568 | 568 | } |
@@ -576,14 +576,14 @@ discard block |
||
576 | 576 | * @throws EE_Error |
577 | 577 | * @return EE_Payment |
578 | 578 | */ |
579 | - public function process_refund( EE_Payment $payment, $refund_info = array()){ |
|
580 | - if ( $this->_gateway && $this->_gateway instanceof EE_Gateway ) { |
|
581 | - return $this->_gateway->do_direct_refund( $payment, $refund_info ); |
|
579 | + public function process_refund(EE_Payment $payment, $refund_info = array()) { |
|
580 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
581 | + return $this->_gateway->do_direct_refund($payment, $refund_info); |
|
582 | 582 | } else { |
583 | 583 | throw new EE_Error( |
584 | 584 | sprintf( |
585 | - __( 'Payment Method Type "%s" does not support sending refund requests', 'event_espresso' ), |
|
586 | - get_class( $this ) |
|
585 | + __('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'), |
|
586 | + get_class($this) |
|
587 | 587 | ) |
588 | 588 | ); |
589 | 589 | } |
@@ -597,15 +597,15 @@ discard block |
||
597 | 597 | * @return string |
598 | 598 | * @throws EE_Error |
599 | 599 | */ |
600 | - public function payment_occurs(){ |
|
601 | - if( ! $this->_gateway){ |
|
600 | + public function payment_occurs() { |
|
601 | + if ( ! $this->_gateway) { |
|
602 | 602 | return EE_PMT_Base::offline; |
603 | - }elseif($this->_gateway instanceof EE_Onsite_Gateway){ |
|
603 | + }elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
604 | 604 | return EE_PMT_Base::onsite; |
605 | - }elseif($this->_gateway instanceof EE_Offsite_Gateway){ |
|
605 | + }elseif ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
606 | 606 | return EE_PMT_Base::offsite; |
607 | - }else{ |
|
608 | - throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"),get_class($this))); |
|
607 | + } else { |
|
608 | + throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this))); |
|
609 | 609 | } |
610 | 610 | } |
611 | 611 | |
@@ -618,8 +618,8 @@ discard block |
||
618 | 618 | * @param EE_Payment $payment |
619 | 619 | * @return string |
620 | 620 | */ |
621 | - public function payment_overview_content(EE_Payment $payment){ |
|
622 | - return EEH_Template::display_template(EE_LIBRARIES.'payment_methods'.DS.'templates'.DS.'payment_details_content.template.php', array('payment_method'=>$this->_pm_instance,'payment'=>$payment) , true); |
|
621 | + public function payment_overview_content(EE_Payment $payment) { |
|
622 | + return EEH_Template::display_template(EE_LIBRARIES.'payment_methods'.DS.'templates'.DS.'payment_details_content.template.php', array('payment_method'=>$this->_pm_instance, 'payment'=>$payment), true); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | * @type array $template_args any arguments you want passed to the template file while rendering. |
633 | 633 | * Keys will be variable names and values with be their values. |
634 | 634 | */ |
635 | - public function help_tabs_config(){ |
|
635 | + public function help_tabs_config() { |
|
636 | 636 | return array(); |
637 | 637 | } |
638 | 638 | |
@@ -643,9 +643,9 @@ discard block |
||
643 | 643 | * the payment method's table's PMT_type column) |
644 | 644 | * @return string |
645 | 645 | */ |
646 | - public function system_name(){ |
|
646 | + public function system_name() { |
|
647 | 647 | $classname = get_class($this); |
648 | - return str_replace("EE_PMT_",'',$classname); |
|
648 | + return str_replace("EE_PMT_", '', $classname); |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | * A pretty i18n version of the PMT name |
655 | 655 | * @return string |
656 | 656 | */ |
657 | - public function pretty_name(){ |
|
657 | + public function pretty_name() { |
|
658 | 658 | return $this->_pretty_name; |
659 | 659 | } |
660 | 660 | |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | * Gets the default absolute URL to the payment method type's button |
665 | 665 | * @return string |
666 | 666 | */ |
667 | - public function default_button_url(){ |
|
667 | + public function default_button_url() { |
|
668 | 668 | return $this->_default_button_url; |
669 | 669 | } |
670 | 670 | |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | * Gets the gateway used by this payment method (if any) |
675 | 675 | * @return EE_Gateway |
676 | 676 | */ |
677 | - public function get_gateway(){ |
|
677 | + public function get_gateway() { |
|
678 | 678 | return $this->_gateway; |
679 | 679 | } |
680 | 680 | |
@@ -683,8 +683,8 @@ discard block |
||
683 | 683 | /** |
684 | 684 | * @return string html for the link to a help tab |
685 | 685 | */ |
686 | - public function get_help_tab_link(){ |
|
687 | - return EEH_Template::get_help_tab_link( $this->get_help_tab_name() ); |
|
686 | + public function get_help_tab_link() { |
|
687 | + return EEH_Template::get_help_tab_link($this->get_help_tab_name()); |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | |
@@ -693,8 +693,8 @@ discard block |
||
693 | 693 | * Returns the name of the help tab for this PMT |
694 | 694 | * @return string |
695 | 695 | */ |
696 | - public function get_help_tab_name(){ |
|
697 | - return 'ee_' . strtolower( $this->system_name() ) . '_help_tab'; |
|
696 | + public function get_help_tab_name() { |
|
697 | + return 'ee_'.strtolower($this->system_name()).'_help_tab'; |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | /** |
@@ -702,8 +702,8 @@ discard block |
||
702 | 702 | * this PMT by an admin |
703 | 703 | * @return string |
704 | 704 | */ |
705 | - public function cap_name(){ |
|
706 | - return 'ee_payment_method_' . strtolower( $this->system_name() ); |
|
705 | + public function cap_name() { |
|
706 | + return 'ee_payment_method_'.strtolower($this->system_name()); |
|
707 | 707 | } |
708 | 708 | |
709 | 709 | /** |
@@ -715,9 +715,9 @@ discard block |
||
715 | 715 | * @param EE_Payment $payment |
716 | 716 | * @return void |
717 | 717 | */ |
718 | - public function update_txn_based_on_payment( $payment ){ |
|
719 | - if( $this->_gateway instanceof EE_Gateway ){ |
|
720 | - $this->_gateway->update_txn_based_on_payment( $payment ); |
|
718 | + public function update_txn_based_on_payment($payment) { |
|
719 | + if ($this->_gateway instanceof EE_Gateway) { |
|
720 | + $this->_gateway->update_txn_based_on_payment($payment); |
|
721 | 721 | } |
722 | 722 | } |
723 | 723 | |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | * @return string |
733 | 733 | */ |
734 | 734 | public function introductory_html() { |
735 | - return EEH_Template::locate_template( $this->file_folder() . 'templates' . DS . strtolower( $this->system_name() ) . '_intro.template.php', array( 'pmt_obj' => $this, 'pm_instance' => $this->_pm_instance ) ); |
|
735 | + return EEH_Template::locate_template($this->file_folder().'templates'.DS.strtolower($this->system_name()).'_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance)); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -16,117 +16,117 @@ discard block |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * Constructor. |
|
21 | - * |
|
22 | - * @param EE_Registration[] $data expecting an array of EE_Registration objects. |
|
23 | - * @throws EE_Error |
|
24 | - * @access protected |
|
25 | - */ |
|
26 | - public function __construct($data = array()) |
|
27 | - { |
|
28 | - |
|
29 | - //validate that the first element in the array is an EE_Registration object. |
|
30 | - if (! reset($data) instanceof EE_Registration) { |
|
31 | - throw new EE_Error(__('The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', |
|
32 | - 'event_espresso')); |
|
33 | - } |
|
34 | - parent::__construct($data); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * setup the data. |
|
40 | - * Sets up the expected data object for the messages prep using incoming registration objects. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - * @access protected |
|
44 | - */ |
|
45 | - protected function _setup_data() |
|
46 | - { |
|
47 | - //we'll loop through each contact and setup the data needed. Note that many properties will just be set as empty |
|
48 | - //because this data handler is for a very specific set of data (i.e. just what's related to the registration). |
|
49 | - |
|
50 | - $this->reg_objs = $this->data(); |
|
51 | - $this->txn = $this->_maybe_get_transaction(); |
|
52 | - $this->_assemble_data(); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * If the incoming registrations all share the same transaction then this will return the transaction object shared |
|
58 | - * among the registrations. Otherwise the transaction object is set to null because its intended to only represent |
|
59 | - * one transaction. |
|
60 | - * |
|
61 | - * @return EE_Transaction|null |
|
62 | - */ |
|
63 | - protected function _maybe_get_transaction() |
|
64 | - { |
|
65 | - $transactions = array(); |
|
66 | - foreach ($this->reg_objs as $registration) { |
|
67 | - if ($registration instanceof EE_Registration) { |
|
68 | - $transaction = $registration->transaction(); |
|
69 | - if ($transaction instanceof EE_Transaction) { |
|
70 | - $transactions[$transaction->ID()] = $transaction; |
|
71 | - } |
|
72 | - } |
|
73 | - } |
|
74 | - return count($transactions) === 1 ? reset($transactions) : null; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * Returns database safe representation of the data later used to when instantiating this object. |
|
80 | - * |
|
81 | - * @param array $registrations The incoming data to be prepped. |
|
82 | - * @return EE_Registration[] The data being prepared for the db |
|
83 | - */ |
|
84 | - static public function convert_data_for_persistent_storage($registrations) |
|
85 | - { |
|
86 | - if ( |
|
87 | - ! is_array($registrations) |
|
88 | - || ! reset($registrations) instanceof EE_Registration |
|
89 | - ) { |
|
90 | - return array(); |
|
91 | - } |
|
92 | - |
|
93 | - $registration_ids = array(); |
|
94 | - |
|
95 | - $registration_ids = array_filter( |
|
96 | - array_map( |
|
97 | - function ($registration) { |
|
98 | - if ($registration instanceof EE_Registration) { |
|
99 | - return $registration->ID(); |
|
100 | - } |
|
101 | - return false; |
|
102 | - }, |
|
103 | - $registrations |
|
104 | - ) |
|
105 | - ); |
|
106 | - |
|
107 | - return $registration_ids; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
113 | - * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
114 | - * |
|
115 | - * @param array $data |
|
116 | - * @return EE_Registration[] |
|
117 | - */ |
|
118 | - static public function convert_data_from_persistent_storage($data) |
|
119 | - { |
|
120 | - //since this was added later, we need to account of possible back compat issues where data already queued for generation |
|
121 | - //is in the old format, which is an array of EE_Registration objects. So if that's the case, then let's just return them |
|
122 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10127 |
|
123 | - if (is_array($data) && reset($data) instanceof EE_Registration) { |
|
124 | - return $data; |
|
125 | - } |
|
126 | - |
|
127 | - $registrations = is_array($data) |
|
128 | - ? EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $data)))) |
|
129 | - : array(); |
|
130 | - return $registrations; |
|
131 | - } |
|
19 | + /** |
|
20 | + * Constructor. |
|
21 | + * |
|
22 | + * @param EE_Registration[] $data expecting an array of EE_Registration objects. |
|
23 | + * @throws EE_Error |
|
24 | + * @access protected |
|
25 | + */ |
|
26 | + public function __construct($data = array()) |
|
27 | + { |
|
28 | + |
|
29 | + //validate that the first element in the array is an EE_Registration object. |
|
30 | + if (! reset($data) instanceof EE_Registration) { |
|
31 | + throw new EE_Error(__('The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', |
|
32 | + 'event_espresso')); |
|
33 | + } |
|
34 | + parent::__construct($data); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * setup the data. |
|
40 | + * Sets up the expected data object for the messages prep using incoming registration objects. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + * @access protected |
|
44 | + */ |
|
45 | + protected function _setup_data() |
|
46 | + { |
|
47 | + //we'll loop through each contact and setup the data needed. Note that many properties will just be set as empty |
|
48 | + //because this data handler is for a very specific set of data (i.e. just what's related to the registration). |
|
49 | + |
|
50 | + $this->reg_objs = $this->data(); |
|
51 | + $this->txn = $this->_maybe_get_transaction(); |
|
52 | + $this->_assemble_data(); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * If the incoming registrations all share the same transaction then this will return the transaction object shared |
|
58 | + * among the registrations. Otherwise the transaction object is set to null because its intended to only represent |
|
59 | + * one transaction. |
|
60 | + * |
|
61 | + * @return EE_Transaction|null |
|
62 | + */ |
|
63 | + protected function _maybe_get_transaction() |
|
64 | + { |
|
65 | + $transactions = array(); |
|
66 | + foreach ($this->reg_objs as $registration) { |
|
67 | + if ($registration instanceof EE_Registration) { |
|
68 | + $transaction = $registration->transaction(); |
|
69 | + if ($transaction instanceof EE_Transaction) { |
|
70 | + $transactions[$transaction->ID()] = $transaction; |
|
71 | + } |
|
72 | + } |
|
73 | + } |
|
74 | + return count($transactions) === 1 ? reset($transactions) : null; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * Returns database safe representation of the data later used to when instantiating this object. |
|
80 | + * |
|
81 | + * @param array $registrations The incoming data to be prepped. |
|
82 | + * @return EE_Registration[] The data being prepared for the db |
|
83 | + */ |
|
84 | + static public function convert_data_for_persistent_storage($registrations) |
|
85 | + { |
|
86 | + if ( |
|
87 | + ! is_array($registrations) |
|
88 | + || ! reset($registrations) instanceof EE_Registration |
|
89 | + ) { |
|
90 | + return array(); |
|
91 | + } |
|
92 | + |
|
93 | + $registration_ids = array(); |
|
94 | + |
|
95 | + $registration_ids = array_filter( |
|
96 | + array_map( |
|
97 | + function ($registration) { |
|
98 | + if ($registration instanceof EE_Registration) { |
|
99 | + return $registration->ID(); |
|
100 | + } |
|
101 | + return false; |
|
102 | + }, |
|
103 | + $registrations |
|
104 | + ) |
|
105 | + ); |
|
106 | + |
|
107 | + return $registration_ids; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
113 | + * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
114 | + * |
|
115 | + * @param array $data |
|
116 | + * @return EE_Registration[] |
|
117 | + */ |
|
118 | + static public function convert_data_from_persistent_storage($data) |
|
119 | + { |
|
120 | + //since this was added later, we need to account of possible back compat issues where data already queued for generation |
|
121 | + //is in the old format, which is an array of EE_Registration objects. So if that's the case, then let's just return them |
|
122 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10127 |
|
123 | + if (is_array($data) && reset($data) instanceof EE_Registration) { |
|
124 | + return $data; |
|
125 | + } |
|
126 | + |
|
127 | + $registrations = is_array($data) |
|
128 | + ? EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $data)))) |
|
129 | + : array(); |
|
130 | + return $registrations; |
|
131 | + } |
|
132 | 132 | } |
@@ -352,7 +352,7 @@ |
||
352 | 352 | * |
353 | 353 | * Note: regex comes in part from the WP `get_shortcode_regex` expression in \wp-includes\shortcodes.php |
354 | 354 | * |
355 | - * @param $shortcode |
|
355 | + * @param string $shortcode |
|
356 | 356 | * @since 4.9.32 |
357 | 357 | * @return string |
358 | 358 | */ |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('NO direct script access allowed'); |
|
4 | + exit('NO direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -30,432 +30,432 @@ discard block |
||
30 | 30 | abstract class EE_Shortcodes extends EE_Base |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * holds label for library |
|
35 | - * This is used for referencing the library label |
|
36 | - * |
|
37 | - * @access public |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - public $label; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * This property is used for referencing a short description of the library |
|
45 | - * |
|
46 | - * @access public |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $description; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * This will hold an array of shortcodes with the key as the shortcode ([shortcode]) and the value as a |
|
54 | - * label/description for the shortcode. |
|
55 | - * |
|
56 | - * @access protected |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - protected $_shortcodes; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * This will hold the incoming data item sent to the parser method |
|
64 | - * |
|
65 | - * @access protected |
|
66 | - * @var mixed (array|object) |
|
67 | - */ |
|
68 | - protected $_data; |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * some shortcodes may require extra data to parse. This property is provided for that. |
|
73 | - * |
|
74 | - * @var array |
|
75 | - */ |
|
76 | - protected $_extra_data; |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * EE_messenger used to generate the template being parsed. |
|
81 | - * |
|
82 | - * @since 4.5.0 |
|
83 | - * @var EE_messenger |
|
84 | - */ |
|
85 | - protected $_messenger; |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * message type used to generate the template being parsed. |
|
90 | - * |
|
91 | - * @since 4.5.0 |
|
92 | - * @var EE_message_type |
|
93 | - */ |
|
94 | - protected $_message_type; |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * context used for the template being parsed |
|
99 | - * |
|
100 | - * @since 4.5.0 |
|
101 | - * @var string |
|
102 | - */ |
|
103 | - protected $_context; |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Specific Message Template Group ID |
|
108 | - * |
|
109 | - * @since 4.5.0 |
|
110 | - * @var int |
|
111 | - */ |
|
112 | - protected $_GRP_ID; |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @since 4.9.0 |
|
117 | - * @type EE_Message |
|
118 | - */ |
|
119 | - protected $_message; |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * This will hold an instance of the EEH_Parse_Shortcodes helper that will be used when handling list type |
|
124 | - * shortcodes |
|
125 | - * |
|
126 | - * @var EEH_Parse_Shortcodes |
|
127 | - */ |
|
128 | - protected $_shortcode_helper; |
|
129 | - |
|
130 | - |
|
131 | - public function __construct() |
|
132 | - { |
|
133 | - $this->_set_defaults(); |
|
134 | - $this->_init_props(); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * This sets the defaults for the properties. Child classes will override these properties in their _init_props |
|
140 | - * method |
|
141 | - */ |
|
142 | - private function _set_defaults() |
|
143 | - { |
|
144 | - $this->name = $this->description = ''; |
|
145 | - $this->_shortcodes = array(); |
|
146 | - $this->_set_shortcode_helper(); |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * loads an instance of the EE_Shortcode_Parser helper when requested |
|
152 | - */ |
|
153 | - protected function _set_shortcode_helper() |
|
154 | - { |
|
155 | - //get shortcode_replace instance- set when _get_messages is called in child... |
|
156 | - $this->_shortcode_helper = new EEH_Parse_Shortcodes(); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - public function get_shortcode_helper() |
|
161 | - { |
|
162 | - if (! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
163 | - $this->_set_shortcode_helper(); |
|
164 | - } |
|
165 | - return $this->_shortcode_helper; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * This is the public method for kicking of the parser included with each child. It can be overridden by child |
|
171 | - * classes if necessary (see EE_Questions_Answers for example) |
|
172 | - * |
|
173 | - * @param string $shortcode incoming shortcode to be parsed |
|
174 | - * @param mixed (object|array) $data incoming data to be be used for parsing |
|
175 | - * @param mixed (object|array) $extra_data extra incoming data (usually EE_Messages_Addressee) |
|
176 | - * @return string parsed shortcode. |
|
177 | - */ |
|
178 | - public function parser($shortcode, $data, $extra_data = array()) |
|
179 | - { |
|
180 | - |
|
181 | - //filter setup shortcodes |
|
182 | - $this->_shortcodes = $this->get_shortcodes(); |
|
183 | - |
|
184 | - //we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
185 | - $sc = preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
186 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
187 | - |
|
188 | - //first we want to make sure this is a valid shortcode |
|
189 | - if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
190 | - return false; |
|
191 | - } //get out, this parser doesn't handle the incoming shortcode. |
|
192 | - $this->_data = $data; |
|
193 | - $this->_extra_data = $extra_data; |
|
194 | - $this->_set_messages_properties(); |
|
195 | - $parsed = apply_filters('FHEE__' . get_class($this) . '__parser_after', $this->_parser($shortcode), $shortcode, |
|
196 | - $data, $extra_data, $this); |
|
197 | - |
|
198 | - //note the below filter applies to ALL shortcode parsers... be careful! |
|
199 | - $parsed = apply_filters('FHEE__EE_Shortcodes__parser_after', $parsed, $shortcode, $data, $extra_data, $this); |
|
200 | - return $parsed; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * This method just returns the shortcodes in the $_shortcodes array property. |
|
206 | - * |
|
207 | - * @access public |
|
208 | - * @return array array of shortcodes => description pairs |
|
209 | - */ |
|
210 | - public function get_shortcodes() |
|
211 | - { |
|
212 | - $this->_shortcodes = apply_filters('FHEE__' . get_class($this) . '__shortcodes', $this->_shortcodes, $this); |
|
213 | - |
|
214 | - //note the below filter applies to ALL shortcode parsers... be careful! |
|
215 | - $this->_shortcodes = apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this); |
|
216 | - |
|
217 | - return $this->_shortcodes; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * Child classes use this method to set the $name, $description, and $_shortcodes properties. |
|
223 | - * |
|
224 | - * @abstract |
|
225 | - * @access protected |
|
226 | - * @return void |
|
227 | - */ |
|
228 | - abstract protected function _init_props(); |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods |
|
233 | - * will have to take care of handling. |
|
234 | - * |
|
235 | - * @abstract |
|
236 | - * @access protected |
|
237 | - * @param string $shortcode the shortcode to be parsed. |
|
238 | - * @param mixed (object|array) $data incoming data for the parser. The data could be either an object or |
|
239 | - * array because there are some shortcodes that might be replaced by prepared data that |
|
240 | - * has multiple items in a list (i.e. list of attendees in an event and we're showing |
|
241 | - * fname/lname for each attendee). In this case data will be in an array. Otherwise |
|
242 | - * the data shoudl be in a properly formatted object. The |
|
243 | - * EEH_Parse_Shortcodes.helper.php describes the data object we're expecting. |
|
244 | - * @return string parsed shortcode |
|
245 | - */ |
|
246 | - abstract protected function _parser($shortcode); |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * This just validates incoming data for list type shortcode parsers (and they call this method) to make sure it |
|
251 | - * meets their requirements |
|
252 | - * |
|
253 | - * @return mixed (void|exception) If validation fails we'll throw an exception. |
|
254 | - */ |
|
255 | - protected function _validate_list_requirements() |
|
256 | - { |
|
257 | - |
|
258 | - //first test to make sure we've got an array! |
|
259 | - if (! is_array($this->_data)) { |
|
260 | - throw new EE_Error(sprintf(__('Expecting an array for the data sent to %s. Instead it was %s', |
|
261 | - 'event_espresso'), get_class($this), gettype($this->_data))); |
|
262 | - } |
|
263 | - |
|
264 | - //next test to make sure we've got the required template in the index! |
|
265 | - if (! isset($this->_data['template'])) { |
|
266 | - throw new EE_Error(sprintf(__('The incoming data does not have the required template index in its array', |
|
267 | - 'event_espresso'))); |
|
268 | - } |
|
269 | - |
|
270 | - //next test to make sure we've got got a data index in the incoming data array |
|
271 | - if (! isset($this->_data['data'])) { |
|
272 | - throw new EE_Error(__('The incoming data does not have the required data index in its array', |
|
273 | - 'event_espresso')); |
|
274 | - } |
|
275 | - |
|
276 | - //all is well let's make sure _extra_data always has the values needed. |
|
277 | - //let's make sure that extra_data includes all templates (for later parsing if necessary) |
|
278 | - if (empty($this->_extra_data) || (empty($this->_extra_data['data']) && empty($this->_extra_data['template']))) { |
|
279 | - $this->_extra_data['data'] = $this->_data['data']; |
|
280 | - $this->_extra_data['template'] = $this->_data['template']; |
|
281 | - } |
|
282 | - |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * This returns any attributes that may be existing on an EE_Shortcode |
|
288 | - * |
|
289 | - * @since 4.5.0 |
|
290 | - * @param string $shortcode incoming shortcode |
|
291 | - * @return array An array with the attributes |
|
292 | - */ |
|
293 | - protected function _get_shortcode_attrs($shortcode) |
|
294 | - { |
|
295 | - //make sure the required wp helper function is present |
|
296 | - //require the shortcode file if necessary |
|
297 | - if (! function_exists('shortcode_parse_atts')) { |
|
298 | - require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
299 | - } |
|
300 | - |
|
301 | - //let's get any attributes that may be present and set the defaults. |
|
302 | - $shortcode_to_parse = str_replace('[', '', str_replace(']', '', $shortcode)); |
|
303 | - return shortcode_parse_atts($shortcode_to_parse); |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * Conditional blocks are shortcode patterns with an opening conditional tag `[IF_*]` and a corresponding |
|
309 | - * closing tag (eg `[/IF_*]`). The content within the tags will be displayed/hidden depending on whatever conditions |
|
310 | - * existed in the opening tag. This method handles parsing the actual template to show/hide this conditional content. |
|
311 | - * |
|
312 | - * @since 4.9.32 |
|
313 | - * |
|
314 | - * @param string $shortcode This should be original shortcode as used in the template and passed to the parser. |
|
315 | - * @param bool $show true means the opening and closing tags are removed and the content is left showing, false |
|
316 | - * means the opening and closing tags and the contained content are removed. |
|
317 | - * @return string The template for the shortcode is returned. |
|
318 | - */ |
|
319 | - protected function _mutate_conditional_block_in_template($shortcode, $show = true) |
|
320 | - { |
|
321 | - //first let's get all the matches in the template for this particular shortcode. |
|
322 | - preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
323 | - |
|
324 | - if ($matches && is_array($matches[0]) && !empty($matches[0])) { |
|
325 | - //we need to hide all instances of the matches |
|
326 | - foreach ($matches[0] as $index => $content_to_show_or_hide) { |
|
327 | - $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
|
328 | - $replacement = $show ? $matches[4][$index] : ''; |
|
329 | - $this->_data['template'] = preg_replace( |
|
330 | - '~' . $content_to_show_or_hide . '~', |
|
331 | - $replacement, |
|
332 | - $this->_data['template'] |
|
333 | - ); |
|
334 | - } |
|
335 | - } |
|
336 | - //return $template |
|
337 | - return $this->_data['template']; |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * This returns the regex pattern to use for conditional shortcodes parsing. |
|
343 | - * |
|
344 | - * Note: regex comes in part from the WP `get_shortcode_regex` expression in \wp-includes\shortcodes.php |
|
345 | - * |
|
346 | - * @param $shortcode |
|
347 | - * @since 4.9.32 |
|
348 | - * @return string |
|
349 | - */ |
|
350 | - private function _get_conditional_block_regex($shortcode) |
|
351 | - { |
|
352 | - //get just the shortcode tag for the match |
|
353 | - preg_match('@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode, $shortcode_tag_matches); |
|
354 | - if (empty($shortcode_tag_matches[1])) { |
|
355 | - return $this->_data['template']; |
|
356 | - } |
|
357 | - |
|
358 | - $shortcode_tag = $shortcode_tag_matches[1]; |
|
359 | - //get attributes_part_of_tag |
|
360 | - $attributes_part = preg_quote(str_replace(array($shortcode_tag,'[',']'), '', $shortcode)); |
|
361 | - //escape |
|
362 | - $shortcode_tag = preg_quote($shortcode_tag); |
|
363 | - |
|
364 | - return |
|
365 | - '\[' //Opening Bracket |
|
366 | - . "($shortcode_tag)$attributes_part" //1: Shortcode Name |
|
367 | - . '(?![\w-])' //Not followed by word character or hyphen |
|
368 | - . '(' //2: Unroll the loop: Inside the opening shortcode tag |
|
369 | - . '[^\]\/]*' //Not a closing bracket or forward slash |
|
370 | - . '(?:' |
|
371 | - . '\/(?!\])' //A forward slash not followed by a closing bracket |
|
372 | - . '[^\]\/]*' //Not a closing bracket or forward slash. |
|
373 | - . ')*?' |
|
374 | - . ')' |
|
375 | - . '(?:' |
|
376 | - . '(\/)' //3. Self closing tag ... |
|
377 | - . '\]' // ... and closing bracket |
|
378 | - . '|' |
|
379 | - . '\]' //Closing bracket |
|
380 | - . '(?:' |
|
381 | - . '(' //4: Unroll the loop: Optionally, anything between the opening and closing brackets |
|
382 | - . '[^\[]*+' //Not an opening bracket |
|
383 | - . '(?:' |
|
384 | - . '\[(?!\/\1\])' //An opening bracket not followed by the closing shortcode tag. |
|
385 | - . '[^\[]*+' //Not an opening bracket |
|
386 | - . ')*+' |
|
387 | - . ')' |
|
388 | - . '\[\/\1\]' //Closing shortcode tag |
|
389 | - . ')?' |
|
390 | - . ')'; |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * This sets the properties related to the messages system |
|
396 | - * |
|
397 | - * @since 4.5.0 |
|
398 | - * @return void |
|
399 | - */ |
|
400 | - protected function _set_messages_properties() |
|
401 | - { |
|
402 | - //should be in _extra_data |
|
403 | - if (isset($this->_extra_data['messenger'])) { |
|
404 | - $this->_messenger = $this->_extra_data['messenger']; |
|
405 | - $this->_message_type = $this->_extra_data['message_type']; |
|
406 | - $this->_context = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message']->context() : ''; |
|
407 | - $this->_GRP_ID = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message']->GRP_ID() : 0; |
|
408 | - $this->_message = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message'] : null; |
|
409 | - } |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * This returns whatever the set message type object is that was set on this shortcode parser. |
|
415 | - * |
|
416 | - * @since 4.5.0 |
|
417 | - * @return EE_message_type |
|
418 | - */ |
|
419 | - public function get_set_message_type() |
|
420 | - { |
|
421 | - return $this->_message_type; |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * This returns whatever the set messenger object is that was set on this shortcode parser |
|
427 | - * |
|
428 | - * @since 4.5.0 |
|
429 | - * @return EE_messenger |
|
430 | - */ |
|
431 | - public function get_set_messenger() |
|
432 | - { |
|
433 | - return $this->_messenger; |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * This returns whatever the set context string is on this shortcode parser. |
|
439 | - * |
|
440 | - * @since 4.5.0 |
|
441 | - * @return string |
|
442 | - */ |
|
443 | - public function get_set_context() |
|
444 | - { |
|
445 | - return $this->_context; |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * This returns whatever the set EE_Message object is on this shortcode. |
|
451 | - * |
|
452 | - * @since 4.9.0 |
|
453 | - * @return EE_Message |
|
454 | - */ |
|
455 | - public function get_set_message() |
|
456 | - { |
|
457 | - return $this->_message; |
|
458 | - } |
|
33 | + /** |
|
34 | + * holds label for library |
|
35 | + * This is used for referencing the library label |
|
36 | + * |
|
37 | + * @access public |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + public $label; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * This property is used for referencing a short description of the library |
|
45 | + * |
|
46 | + * @access public |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $description; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * This will hold an array of shortcodes with the key as the shortcode ([shortcode]) and the value as a |
|
54 | + * label/description for the shortcode. |
|
55 | + * |
|
56 | + * @access protected |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + protected $_shortcodes; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * This will hold the incoming data item sent to the parser method |
|
64 | + * |
|
65 | + * @access protected |
|
66 | + * @var mixed (array|object) |
|
67 | + */ |
|
68 | + protected $_data; |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * some shortcodes may require extra data to parse. This property is provided for that. |
|
73 | + * |
|
74 | + * @var array |
|
75 | + */ |
|
76 | + protected $_extra_data; |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * EE_messenger used to generate the template being parsed. |
|
81 | + * |
|
82 | + * @since 4.5.0 |
|
83 | + * @var EE_messenger |
|
84 | + */ |
|
85 | + protected $_messenger; |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * message type used to generate the template being parsed. |
|
90 | + * |
|
91 | + * @since 4.5.0 |
|
92 | + * @var EE_message_type |
|
93 | + */ |
|
94 | + protected $_message_type; |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * context used for the template being parsed |
|
99 | + * |
|
100 | + * @since 4.5.0 |
|
101 | + * @var string |
|
102 | + */ |
|
103 | + protected $_context; |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Specific Message Template Group ID |
|
108 | + * |
|
109 | + * @since 4.5.0 |
|
110 | + * @var int |
|
111 | + */ |
|
112 | + protected $_GRP_ID; |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @since 4.9.0 |
|
117 | + * @type EE_Message |
|
118 | + */ |
|
119 | + protected $_message; |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * This will hold an instance of the EEH_Parse_Shortcodes helper that will be used when handling list type |
|
124 | + * shortcodes |
|
125 | + * |
|
126 | + * @var EEH_Parse_Shortcodes |
|
127 | + */ |
|
128 | + protected $_shortcode_helper; |
|
129 | + |
|
130 | + |
|
131 | + public function __construct() |
|
132 | + { |
|
133 | + $this->_set_defaults(); |
|
134 | + $this->_init_props(); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * This sets the defaults for the properties. Child classes will override these properties in their _init_props |
|
140 | + * method |
|
141 | + */ |
|
142 | + private function _set_defaults() |
|
143 | + { |
|
144 | + $this->name = $this->description = ''; |
|
145 | + $this->_shortcodes = array(); |
|
146 | + $this->_set_shortcode_helper(); |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * loads an instance of the EE_Shortcode_Parser helper when requested |
|
152 | + */ |
|
153 | + protected function _set_shortcode_helper() |
|
154 | + { |
|
155 | + //get shortcode_replace instance- set when _get_messages is called in child... |
|
156 | + $this->_shortcode_helper = new EEH_Parse_Shortcodes(); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + public function get_shortcode_helper() |
|
161 | + { |
|
162 | + if (! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
163 | + $this->_set_shortcode_helper(); |
|
164 | + } |
|
165 | + return $this->_shortcode_helper; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * This is the public method for kicking of the parser included with each child. It can be overridden by child |
|
171 | + * classes if necessary (see EE_Questions_Answers for example) |
|
172 | + * |
|
173 | + * @param string $shortcode incoming shortcode to be parsed |
|
174 | + * @param mixed (object|array) $data incoming data to be be used for parsing |
|
175 | + * @param mixed (object|array) $extra_data extra incoming data (usually EE_Messages_Addressee) |
|
176 | + * @return string parsed shortcode. |
|
177 | + */ |
|
178 | + public function parser($shortcode, $data, $extra_data = array()) |
|
179 | + { |
|
180 | + |
|
181 | + //filter setup shortcodes |
|
182 | + $this->_shortcodes = $this->get_shortcodes(); |
|
183 | + |
|
184 | + //we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
185 | + $sc = preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
186 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
187 | + |
|
188 | + //first we want to make sure this is a valid shortcode |
|
189 | + if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
190 | + return false; |
|
191 | + } //get out, this parser doesn't handle the incoming shortcode. |
|
192 | + $this->_data = $data; |
|
193 | + $this->_extra_data = $extra_data; |
|
194 | + $this->_set_messages_properties(); |
|
195 | + $parsed = apply_filters('FHEE__' . get_class($this) . '__parser_after', $this->_parser($shortcode), $shortcode, |
|
196 | + $data, $extra_data, $this); |
|
197 | + |
|
198 | + //note the below filter applies to ALL shortcode parsers... be careful! |
|
199 | + $parsed = apply_filters('FHEE__EE_Shortcodes__parser_after', $parsed, $shortcode, $data, $extra_data, $this); |
|
200 | + return $parsed; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * This method just returns the shortcodes in the $_shortcodes array property. |
|
206 | + * |
|
207 | + * @access public |
|
208 | + * @return array array of shortcodes => description pairs |
|
209 | + */ |
|
210 | + public function get_shortcodes() |
|
211 | + { |
|
212 | + $this->_shortcodes = apply_filters('FHEE__' . get_class($this) . '__shortcodes', $this->_shortcodes, $this); |
|
213 | + |
|
214 | + //note the below filter applies to ALL shortcode parsers... be careful! |
|
215 | + $this->_shortcodes = apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this); |
|
216 | + |
|
217 | + return $this->_shortcodes; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * Child classes use this method to set the $name, $description, and $_shortcodes properties. |
|
223 | + * |
|
224 | + * @abstract |
|
225 | + * @access protected |
|
226 | + * @return void |
|
227 | + */ |
|
228 | + abstract protected function _init_props(); |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods |
|
233 | + * will have to take care of handling. |
|
234 | + * |
|
235 | + * @abstract |
|
236 | + * @access protected |
|
237 | + * @param string $shortcode the shortcode to be parsed. |
|
238 | + * @param mixed (object|array) $data incoming data for the parser. The data could be either an object or |
|
239 | + * array because there are some shortcodes that might be replaced by prepared data that |
|
240 | + * has multiple items in a list (i.e. list of attendees in an event and we're showing |
|
241 | + * fname/lname for each attendee). In this case data will be in an array. Otherwise |
|
242 | + * the data shoudl be in a properly formatted object. The |
|
243 | + * EEH_Parse_Shortcodes.helper.php describes the data object we're expecting. |
|
244 | + * @return string parsed shortcode |
|
245 | + */ |
|
246 | + abstract protected function _parser($shortcode); |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * This just validates incoming data for list type shortcode parsers (and they call this method) to make sure it |
|
251 | + * meets their requirements |
|
252 | + * |
|
253 | + * @return mixed (void|exception) If validation fails we'll throw an exception. |
|
254 | + */ |
|
255 | + protected function _validate_list_requirements() |
|
256 | + { |
|
257 | + |
|
258 | + //first test to make sure we've got an array! |
|
259 | + if (! is_array($this->_data)) { |
|
260 | + throw new EE_Error(sprintf(__('Expecting an array for the data sent to %s. Instead it was %s', |
|
261 | + 'event_espresso'), get_class($this), gettype($this->_data))); |
|
262 | + } |
|
263 | + |
|
264 | + //next test to make sure we've got the required template in the index! |
|
265 | + if (! isset($this->_data['template'])) { |
|
266 | + throw new EE_Error(sprintf(__('The incoming data does not have the required template index in its array', |
|
267 | + 'event_espresso'))); |
|
268 | + } |
|
269 | + |
|
270 | + //next test to make sure we've got got a data index in the incoming data array |
|
271 | + if (! isset($this->_data['data'])) { |
|
272 | + throw new EE_Error(__('The incoming data does not have the required data index in its array', |
|
273 | + 'event_espresso')); |
|
274 | + } |
|
275 | + |
|
276 | + //all is well let's make sure _extra_data always has the values needed. |
|
277 | + //let's make sure that extra_data includes all templates (for later parsing if necessary) |
|
278 | + if (empty($this->_extra_data) || (empty($this->_extra_data['data']) && empty($this->_extra_data['template']))) { |
|
279 | + $this->_extra_data['data'] = $this->_data['data']; |
|
280 | + $this->_extra_data['template'] = $this->_data['template']; |
|
281 | + } |
|
282 | + |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * This returns any attributes that may be existing on an EE_Shortcode |
|
288 | + * |
|
289 | + * @since 4.5.0 |
|
290 | + * @param string $shortcode incoming shortcode |
|
291 | + * @return array An array with the attributes |
|
292 | + */ |
|
293 | + protected function _get_shortcode_attrs($shortcode) |
|
294 | + { |
|
295 | + //make sure the required wp helper function is present |
|
296 | + //require the shortcode file if necessary |
|
297 | + if (! function_exists('shortcode_parse_atts')) { |
|
298 | + require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
299 | + } |
|
300 | + |
|
301 | + //let's get any attributes that may be present and set the defaults. |
|
302 | + $shortcode_to_parse = str_replace('[', '', str_replace(']', '', $shortcode)); |
|
303 | + return shortcode_parse_atts($shortcode_to_parse); |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * Conditional blocks are shortcode patterns with an opening conditional tag `[IF_*]` and a corresponding |
|
309 | + * closing tag (eg `[/IF_*]`). The content within the tags will be displayed/hidden depending on whatever conditions |
|
310 | + * existed in the opening tag. This method handles parsing the actual template to show/hide this conditional content. |
|
311 | + * |
|
312 | + * @since 4.9.32 |
|
313 | + * |
|
314 | + * @param string $shortcode This should be original shortcode as used in the template and passed to the parser. |
|
315 | + * @param bool $show true means the opening and closing tags are removed and the content is left showing, false |
|
316 | + * means the opening and closing tags and the contained content are removed. |
|
317 | + * @return string The template for the shortcode is returned. |
|
318 | + */ |
|
319 | + protected function _mutate_conditional_block_in_template($shortcode, $show = true) |
|
320 | + { |
|
321 | + //first let's get all the matches in the template for this particular shortcode. |
|
322 | + preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
323 | + |
|
324 | + if ($matches && is_array($matches[0]) && !empty($matches[0])) { |
|
325 | + //we need to hide all instances of the matches |
|
326 | + foreach ($matches[0] as $index => $content_to_show_or_hide) { |
|
327 | + $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
|
328 | + $replacement = $show ? $matches[4][$index] : ''; |
|
329 | + $this->_data['template'] = preg_replace( |
|
330 | + '~' . $content_to_show_or_hide . '~', |
|
331 | + $replacement, |
|
332 | + $this->_data['template'] |
|
333 | + ); |
|
334 | + } |
|
335 | + } |
|
336 | + //return $template |
|
337 | + return $this->_data['template']; |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * This returns the regex pattern to use for conditional shortcodes parsing. |
|
343 | + * |
|
344 | + * Note: regex comes in part from the WP `get_shortcode_regex` expression in \wp-includes\shortcodes.php |
|
345 | + * |
|
346 | + * @param $shortcode |
|
347 | + * @since 4.9.32 |
|
348 | + * @return string |
|
349 | + */ |
|
350 | + private function _get_conditional_block_regex($shortcode) |
|
351 | + { |
|
352 | + //get just the shortcode tag for the match |
|
353 | + preg_match('@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode, $shortcode_tag_matches); |
|
354 | + if (empty($shortcode_tag_matches[1])) { |
|
355 | + return $this->_data['template']; |
|
356 | + } |
|
357 | + |
|
358 | + $shortcode_tag = $shortcode_tag_matches[1]; |
|
359 | + //get attributes_part_of_tag |
|
360 | + $attributes_part = preg_quote(str_replace(array($shortcode_tag,'[',']'), '', $shortcode)); |
|
361 | + //escape |
|
362 | + $shortcode_tag = preg_quote($shortcode_tag); |
|
363 | + |
|
364 | + return |
|
365 | + '\[' //Opening Bracket |
|
366 | + . "($shortcode_tag)$attributes_part" //1: Shortcode Name |
|
367 | + . '(?![\w-])' //Not followed by word character or hyphen |
|
368 | + . '(' //2: Unroll the loop: Inside the opening shortcode tag |
|
369 | + . '[^\]\/]*' //Not a closing bracket or forward slash |
|
370 | + . '(?:' |
|
371 | + . '\/(?!\])' //A forward slash not followed by a closing bracket |
|
372 | + . '[^\]\/]*' //Not a closing bracket or forward slash. |
|
373 | + . ')*?' |
|
374 | + . ')' |
|
375 | + . '(?:' |
|
376 | + . '(\/)' //3. Self closing tag ... |
|
377 | + . '\]' // ... and closing bracket |
|
378 | + . '|' |
|
379 | + . '\]' //Closing bracket |
|
380 | + . '(?:' |
|
381 | + . '(' //4: Unroll the loop: Optionally, anything between the opening and closing brackets |
|
382 | + . '[^\[]*+' //Not an opening bracket |
|
383 | + . '(?:' |
|
384 | + . '\[(?!\/\1\])' //An opening bracket not followed by the closing shortcode tag. |
|
385 | + . '[^\[]*+' //Not an opening bracket |
|
386 | + . ')*+' |
|
387 | + . ')' |
|
388 | + . '\[\/\1\]' //Closing shortcode tag |
|
389 | + . ')?' |
|
390 | + . ')'; |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * This sets the properties related to the messages system |
|
396 | + * |
|
397 | + * @since 4.5.0 |
|
398 | + * @return void |
|
399 | + */ |
|
400 | + protected function _set_messages_properties() |
|
401 | + { |
|
402 | + //should be in _extra_data |
|
403 | + if (isset($this->_extra_data['messenger'])) { |
|
404 | + $this->_messenger = $this->_extra_data['messenger']; |
|
405 | + $this->_message_type = $this->_extra_data['message_type']; |
|
406 | + $this->_context = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message']->context() : ''; |
|
407 | + $this->_GRP_ID = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message']->GRP_ID() : 0; |
|
408 | + $this->_message = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message'] : null; |
|
409 | + } |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * This returns whatever the set message type object is that was set on this shortcode parser. |
|
415 | + * |
|
416 | + * @since 4.5.0 |
|
417 | + * @return EE_message_type |
|
418 | + */ |
|
419 | + public function get_set_message_type() |
|
420 | + { |
|
421 | + return $this->_message_type; |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * This returns whatever the set messenger object is that was set on this shortcode parser |
|
427 | + * |
|
428 | + * @since 4.5.0 |
|
429 | + * @return EE_messenger |
|
430 | + */ |
|
431 | + public function get_set_messenger() |
|
432 | + { |
|
433 | + return $this->_messenger; |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * This returns whatever the set context string is on this shortcode parser. |
|
439 | + * |
|
440 | + * @since 4.5.0 |
|
441 | + * @return string |
|
442 | + */ |
|
443 | + public function get_set_context() |
|
444 | + { |
|
445 | + return $this->_context; |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * This returns whatever the set EE_Message object is on this shortcode. |
|
451 | + * |
|
452 | + * @since 4.9.0 |
|
453 | + * @return EE_Message |
|
454 | + */ |
|
455 | + public function get_set_message() |
|
456 | + { |
|
457 | + return $this->_message; |
|
458 | + } |
|
459 | 459 | |
460 | 460 | |
461 | 461 | } //end EE_Shortcodes |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('NO direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | |
160 | 160 | public function get_shortcode_helper() |
161 | 161 | { |
162 | - if (! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
162 | + if ( ! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
163 | 163 | $this->_set_shortcode_helper(); |
164 | 164 | } |
165 | 165 | return $this->_shortcode_helper; |
@@ -183,16 +183,16 @@ discard block |
||
183 | 183 | |
184 | 184 | //we need to setup any dynamic shortcodes so that they work with the array_key_exists |
185 | 185 | $sc = preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
186 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
186 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0].']' : $shortcode; |
|
187 | 187 | |
188 | 188 | //first we want to make sure this is a valid shortcode |
189 | - if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
189 | + if ( ! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
190 | 190 | return false; |
191 | 191 | } //get out, this parser doesn't handle the incoming shortcode. |
192 | 192 | $this->_data = $data; |
193 | 193 | $this->_extra_data = $extra_data; |
194 | 194 | $this->_set_messages_properties(); |
195 | - $parsed = apply_filters('FHEE__' . get_class($this) . '__parser_after', $this->_parser($shortcode), $shortcode, |
|
195 | + $parsed = apply_filters('FHEE__'.get_class($this).'__parser_after', $this->_parser($shortcode), $shortcode, |
|
196 | 196 | $data, $extra_data, $this); |
197 | 197 | |
198 | 198 | //note the below filter applies to ALL shortcode parsers... be careful! |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public function get_shortcodes() |
211 | 211 | { |
212 | - $this->_shortcodes = apply_filters('FHEE__' . get_class($this) . '__shortcodes', $this->_shortcodes, $this); |
|
212 | + $this->_shortcodes = apply_filters('FHEE__'.get_class($this).'__shortcodes', $this->_shortcodes, $this); |
|
213 | 213 | |
214 | 214 | //note the below filter applies to ALL shortcode parsers... be careful! |
215 | 215 | $this->_shortcodes = apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this); |
@@ -256,19 +256,19 @@ discard block |
||
256 | 256 | { |
257 | 257 | |
258 | 258 | //first test to make sure we've got an array! |
259 | - if (! is_array($this->_data)) { |
|
259 | + if ( ! is_array($this->_data)) { |
|
260 | 260 | throw new EE_Error(sprintf(__('Expecting an array for the data sent to %s. Instead it was %s', |
261 | 261 | 'event_espresso'), get_class($this), gettype($this->_data))); |
262 | 262 | } |
263 | 263 | |
264 | 264 | //next test to make sure we've got the required template in the index! |
265 | - if (! isset($this->_data['template'])) { |
|
265 | + if ( ! isset($this->_data['template'])) { |
|
266 | 266 | throw new EE_Error(sprintf(__('The incoming data does not have the required template index in its array', |
267 | 267 | 'event_espresso'))); |
268 | 268 | } |
269 | 269 | |
270 | 270 | //next test to make sure we've got got a data index in the incoming data array |
271 | - if (! isset($this->_data['data'])) { |
|
271 | + if ( ! isset($this->_data['data'])) { |
|
272 | 272 | throw new EE_Error(__('The incoming data does not have the required data index in its array', |
273 | 273 | 'event_espresso')); |
274 | 274 | } |
@@ -294,8 +294,8 @@ discard block |
||
294 | 294 | { |
295 | 295 | //make sure the required wp helper function is present |
296 | 296 | //require the shortcode file if necessary |
297 | - if (! function_exists('shortcode_parse_atts')) { |
|
298 | - require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
297 | + if ( ! function_exists('shortcode_parse_atts')) { |
|
298 | + require_once(ABSPATH.WPINC.'/shortcodes.php'); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | //let's get any attributes that may be present and set the defaults. |
@@ -319,15 +319,15 @@ discard block |
||
319 | 319 | protected function _mutate_conditional_block_in_template($shortcode, $show = true) |
320 | 320 | { |
321 | 321 | //first let's get all the matches in the template for this particular shortcode. |
322 | - preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
322 | + preg_match_all('~'.$this->_get_conditional_block_regex($shortcode).'~', $this->_data['template'], $matches); |
|
323 | 323 | |
324 | - if ($matches && is_array($matches[0]) && !empty($matches[0])) { |
|
324 | + if ($matches && is_array($matches[0]) && ! empty($matches[0])) { |
|
325 | 325 | //we need to hide all instances of the matches |
326 | 326 | foreach ($matches[0] as $index => $content_to_show_or_hide) { |
327 | 327 | $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
328 | 328 | $replacement = $show ? $matches[4][$index] : ''; |
329 | 329 | $this->_data['template'] = preg_replace( |
330 | - '~' . $content_to_show_or_hide . '~', |
|
330 | + '~'.$content_to_show_or_hide.'~', |
|
331 | 331 | $replacement, |
332 | 332 | $this->_data['template'] |
333 | 333 | ); |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | |
358 | 358 | $shortcode_tag = $shortcode_tag_matches[1]; |
359 | 359 | //get attributes_part_of_tag |
360 | - $attributes_part = preg_quote(str_replace(array($shortcode_tag,'[',']'), '', $shortcode)); |
|
360 | + $attributes_part = preg_quote(str_replace(array($shortcode_tag, '[', ']'), '', $shortcode)); |
|
361 | 361 | //escape |
362 | 362 | $shortcode_tag = preg_quote($shortcode_tag); |
363 | 363 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('NO direct script access allowed'); |
|
4 | + exit('NO direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -26,269 +26,269 @@ discard block |
||
26 | 26 | { |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * holds the template |
|
31 | - * |
|
32 | - * @access private |
|
33 | - * @var mixed (string|array) |
|
34 | - */ |
|
35 | - private $_template; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * holds the incoming data object |
|
40 | - * |
|
41 | - * @access private |
|
42 | - * @var object |
|
43 | - */ |
|
44 | - private $_data; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * will hold an array of EE_Shortcodes library objects. |
|
49 | - * |
|
50 | - * @access private |
|
51 | - * @var EE_Shortcodes[] |
|
52 | - */ |
|
53 | - private $_shortcode_objs = array(); |
|
54 | - |
|
55 | - |
|
56 | - public function __construct() |
|
57 | - { |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * This kicks off the parsing of shortcodes in message templates |
|
63 | - * |
|
64 | - * @param string $template This is the incoming string to be parsed |
|
65 | - * @param EE_Messages_Addressee $data This is the incoming data object |
|
66 | - * @param array $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries |
|
67 | - * @param EE_message_type $message_type The message type that called the parser |
|
68 | - * @param EE_messenger $messenger The active messenger for this parsing session. |
|
69 | - * @param EE_Message $message |
|
70 | - * @return string The parsed template string |
|
71 | - */ |
|
72 | - public function parse_message_template( |
|
73 | - $template, |
|
74 | - EE_Messages_Addressee $data, |
|
75 | - $valid_shortcodes, |
|
76 | - EE_message_type $message_type, |
|
77 | - EE_messenger $messenger, |
|
78 | - EE_Message $message |
|
79 | - ) { |
|
80 | - $extra_data = array( |
|
81 | - 'messenger' => $messenger, |
|
82 | - 'message_type' => $message_type, |
|
83 | - 'message' => $message, |
|
84 | - ); |
|
85 | - $this->_init_data($template, $data, $valid_shortcodes, $extra_data); |
|
86 | - $this->_template = is_array($template) ? $template['main'] : $template; |
|
87 | - return $this->_parse_message_template(); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - public function parse_attendee_list_template( |
|
92 | - $template, |
|
93 | - EE_Registration $registration, |
|
94 | - $valid_shortcodes, |
|
95 | - $extra_data = array() |
|
96 | - ) { |
|
97 | - $this->_init_data($template, $registration, $valid_shortcodes, $extra_data); |
|
98 | - $this->_template = is_array($template) ? $template['attendee_list'] : $template; |
|
99 | - return $this->_parse_message_template(); |
|
100 | - } |
|
101 | - |
|
102 | - public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array()) |
|
103 | - { |
|
104 | - $this->_init_data($template, $event, $valid_shortcodes, $extra_data); |
|
105 | - $this->_template = is_array($template) ? $template['event_list'] : $template; |
|
106 | - return $this->_parse_message_template(); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array()) |
|
111 | - { |
|
112 | - $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data); |
|
113 | - $this->_template = is_array($template) ? $template['ticket_list'] : $template; |
|
114 | - return $this->_parse_message_template(); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - public function parse_line_item_list_template( |
|
119 | - $template, |
|
120 | - EE_Line_Item $line_item, |
|
121 | - $valid_shortcodes, |
|
122 | - $extra_data = array() |
|
123 | - ) { |
|
124 | - $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data); |
|
125 | - $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template; |
|
126 | - return $this->_parse_message_template(); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - public function parse_payment_list_template( |
|
131 | - $template, |
|
132 | - EE_Payment $payment_item, |
|
133 | - $valid_shortcodes, |
|
134 | - $extra_data = array() |
|
135 | - ) { |
|
136 | - $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data); |
|
137 | - $this->_template = is_array($template) ? $template['payment_list'] : $template; |
|
138 | - return $this->_parse_message_template(); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - public function parse_datetime_list_template( |
|
143 | - $template, |
|
144 | - EE_Datetime $datetime, |
|
145 | - $valid_shortcodes, |
|
146 | - $extra_data = array() |
|
147 | - ) { |
|
148 | - $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data); |
|
149 | - $this->_template = is_array($template) ? $template['datetime_list'] : $template; |
|
150 | - return $this->_parse_message_template(); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array()) |
|
155 | - { |
|
156 | - $this->_init_data($template, $answer, $valid_shortcodes, $extra_data); |
|
157 | - $this->_template = is_array($template) ? $template['question_list'] : $template; |
|
158 | - return $this->_parse_message_template(); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - private function _init_data($template, $data, $valid_shortcodes, $extra_data = array()) |
|
163 | - { |
|
164 | - $this->_reset_props(); |
|
165 | - $this->_data['template'] = $template; |
|
166 | - $this->_data['data'] = $data; |
|
167 | - $this->_data['extra_data'] = $extra_data; |
|
168 | - $this->_set_shortcodes($valid_shortcodes); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - private function _reset_props() |
|
173 | - { |
|
174 | - $this->_template = $this->_data = null; |
|
175 | - $this->_shortcode_objs = array(); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * takes the given template and parses it with the $_shortcodes property |
|
181 | - * |
|
182 | - * @access private |
|
183 | - * @return string |
|
184 | - */ |
|
185 | - private function _parse_message_template() |
|
186 | - { |
|
187 | - //now let's get a list of shortcodes that are found in the given template |
|
188 | - preg_match_all('/(\[.+?\])/', $this->_template, $matches); |
|
189 | - $shortcodes = (array)$matches[0]; //this should be an array of shortcodes in the template string. |
|
190 | - |
|
191 | - $matched_code = array(); |
|
192 | - $sc_values = array(); |
|
193 | - |
|
194 | - $list_type_shortcodes = array( |
|
195 | - '[ATTENDEE_LIST]', |
|
196 | - '[EVENT_LIST]', |
|
197 | - '[TICKET_LIST]', |
|
198 | - '[DATETIME_LIST]', |
|
199 | - '[QUESTION_LIST]', |
|
200 | - '[RECIPIENT_QUESTION_LIST]', |
|
201 | - '[PRIMARY_REGISTRANT_QUESTION_LIST]', |
|
202 | - '[RECIPIENT_TICKET_LIST]', |
|
203 | - '[PRIMARY_REGISTRANT_TICKET_LIST]', |
|
204 | - '[RECIPIENT_DATETIME_LIST]', |
|
205 | - '[PRIMARY_REGISTRANT_DATETIME_LIST]', |
|
206 | - '[TICKET_LINE_ITEM_LIST]', |
|
207 | - '[TAX_LINE_ITEM_LIST]', |
|
208 | - '[ADDITIONAL_LINE_ITEM_LIST]', |
|
209 | - '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
210 | - '[PAYMENT_LIST_*]', |
|
211 | - ); |
|
212 | - |
|
213 | - $list_type_shortcodes = apply_filters('FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
214 | - $list_type_shortcodes); |
|
215 | - |
|
216 | - //now lets go ahead and loop through our parsers for each shortcode and setup the values |
|
217 | - foreach ($shortcodes as $shortcode) { |
|
218 | - |
|
219 | - foreach ($this->_shortcode_objs as $sc_obj) { |
|
220 | - if ($sc_obj instanceof EE_Shortcodes) { |
|
221 | - //we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
222 | - preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
223 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
224 | - |
|
225 | - if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
226 | - continue; //the given shortcode isn't in this object |
|
227 | - } |
|
228 | - |
|
229 | - //if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
|
230 | - if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
231 | - $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
|
232 | - } else { |
|
233 | - $data_send = $this->_data; |
|
234 | - } |
|
235 | - |
|
236 | - //is this a conditional type shortcode? If it is then we actually parse the template here. |
|
237 | - if ($this->_is_conditional_shortcode($shortcode)) { |
|
238 | - //most shortcode parsers are not going to have a match for this shortcode and will return an |
|
239 | - //empty string so we need to make sure that we're only replacing the template when there is a non empty string. |
|
240 | - $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
241 | - if ($parsed) { |
|
242 | - $this->_template = $parsed; |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
247 | - |
|
248 | - $matched_code[] = $shortcode; |
|
249 | - $sc_values[] = $parsed; |
|
250 | - } |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - //now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out. |
|
255 | - $parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template); |
|
256 | - return $parsed; |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * Simply returns whether the given shortcode matches the structure for a conditional shortcode. |
|
262 | - * |
|
263 | - * Does it match this format: `[IF_` |
|
264 | - * |
|
265 | - * @param $shortcode |
|
266 | - */ |
|
267 | - protected function _is_conditional_shortcode($shortcode) |
|
268 | - { |
|
269 | - return strpos($shortcode, '[IF_') === 0; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of |
|
275 | - * various EE_Shortcode library objects |
|
276 | - * |
|
277 | - * @access private |
|
278 | - * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects |
|
279 | - * @return void |
|
280 | - */ |
|
281 | - private function _set_shortcodes($valid_shortcodes) |
|
282 | - { |
|
283 | - foreach ($valid_shortcodes as $shortcode_ref) { |
|
284 | - $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
|
285 | - $ref = str_replace(' ', '_', $ref); |
|
286 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
287 | - if (class_exists($classname)) { |
|
288 | - $this->_shortcode_objs[] = new $classname; |
|
289 | - } |
|
290 | - } |
|
291 | - } |
|
29 | + /** |
|
30 | + * holds the template |
|
31 | + * |
|
32 | + * @access private |
|
33 | + * @var mixed (string|array) |
|
34 | + */ |
|
35 | + private $_template; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * holds the incoming data object |
|
40 | + * |
|
41 | + * @access private |
|
42 | + * @var object |
|
43 | + */ |
|
44 | + private $_data; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * will hold an array of EE_Shortcodes library objects. |
|
49 | + * |
|
50 | + * @access private |
|
51 | + * @var EE_Shortcodes[] |
|
52 | + */ |
|
53 | + private $_shortcode_objs = array(); |
|
54 | + |
|
55 | + |
|
56 | + public function __construct() |
|
57 | + { |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * This kicks off the parsing of shortcodes in message templates |
|
63 | + * |
|
64 | + * @param string $template This is the incoming string to be parsed |
|
65 | + * @param EE_Messages_Addressee $data This is the incoming data object |
|
66 | + * @param array $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries |
|
67 | + * @param EE_message_type $message_type The message type that called the parser |
|
68 | + * @param EE_messenger $messenger The active messenger for this parsing session. |
|
69 | + * @param EE_Message $message |
|
70 | + * @return string The parsed template string |
|
71 | + */ |
|
72 | + public function parse_message_template( |
|
73 | + $template, |
|
74 | + EE_Messages_Addressee $data, |
|
75 | + $valid_shortcodes, |
|
76 | + EE_message_type $message_type, |
|
77 | + EE_messenger $messenger, |
|
78 | + EE_Message $message |
|
79 | + ) { |
|
80 | + $extra_data = array( |
|
81 | + 'messenger' => $messenger, |
|
82 | + 'message_type' => $message_type, |
|
83 | + 'message' => $message, |
|
84 | + ); |
|
85 | + $this->_init_data($template, $data, $valid_shortcodes, $extra_data); |
|
86 | + $this->_template = is_array($template) ? $template['main'] : $template; |
|
87 | + return $this->_parse_message_template(); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + public function parse_attendee_list_template( |
|
92 | + $template, |
|
93 | + EE_Registration $registration, |
|
94 | + $valid_shortcodes, |
|
95 | + $extra_data = array() |
|
96 | + ) { |
|
97 | + $this->_init_data($template, $registration, $valid_shortcodes, $extra_data); |
|
98 | + $this->_template = is_array($template) ? $template['attendee_list'] : $template; |
|
99 | + return $this->_parse_message_template(); |
|
100 | + } |
|
101 | + |
|
102 | + public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array()) |
|
103 | + { |
|
104 | + $this->_init_data($template, $event, $valid_shortcodes, $extra_data); |
|
105 | + $this->_template = is_array($template) ? $template['event_list'] : $template; |
|
106 | + return $this->_parse_message_template(); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array()) |
|
111 | + { |
|
112 | + $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data); |
|
113 | + $this->_template = is_array($template) ? $template['ticket_list'] : $template; |
|
114 | + return $this->_parse_message_template(); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + public function parse_line_item_list_template( |
|
119 | + $template, |
|
120 | + EE_Line_Item $line_item, |
|
121 | + $valid_shortcodes, |
|
122 | + $extra_data = array() |
|
123 | + ) { |
|
124 | + $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data); |
|
125 | + $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template; |
|
126 | + return $this->_parse_message_template(); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + public function parse_payment_list_template( |
|
131 | + $template, |
|
132 | + EE_Payment $payment_item, |
|
133 | + $valid_shortcodes, |
|
134 | + $extra_data = array() |
|
135 | + ) { |
|
136 | + $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data); |
|
137 | + $this->_template = is_array($template) ? $template['payment_list'] : $template; |
|
138 | + return $this->_parse_message_template(); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + public function parse_datetime_list_template( |
|
143 | + $template, |
|
144 | + EE_Datetime $datetime, |
|
145 | + $valid_shortcodes, |
|
146 | + $extra_data = array() |
|
147 | + ) { |
|
148 | + $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data); |
|
149 | + $this->_template = is_array($template) ? $template['datetime_list'] : $template; |
|
150 | + return $this->_parse_message_template(); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array()) |
|
155 | + { |
|
156 | + $this->_init_data($template, $answer, $valid_shortcodes, $extra_data); |
|
157 | + $this->_template = is_array($template) ? $template['question_list'] : $template; |
|
158 | + return $this->_parse_message_template(); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + private function _init_data($template, $data, $valid_shortcodes, $extra_data = array()) |
|
163 | + { |
|
164 | + $this->_reset_props(); |
|
165 | + $this->_data['template'] = $template; |
|
166 | + $this->_data['data'] = $data; |
|
167 | + $this->_data['extra_data'] = $extra_data; |
|
168 | + $this->_set_shortcodes($valid_shortcodes); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + private function _reset_props() |
|
173 | + { |
|
174 | + $this->_template = $this->_data = null; |
|
175 | + $this->_shortcode_objs = array(); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * takes the given template and parses it with the $_shortcodes property |
|
181 | + * |
|
182 | + * @access private |
|
183 | + * @return string |
|
184 | + */ |
|
185 | + private function _parse_message_template() |
|
186 | + { |
|
187 | + //now let's get a list of shortcodes that are found in the given template |
|
188 | + preg_match_all('/(\[.+?\])/', $this->_template, $matches); |
|
189 | + $shortcodes = (array)$matches[0]; //this should be an array of shortcodes in the template string. |
|
190 | + |
|
191 | + $matched_code = array(); |
|
192 | + $sc_values = array(); |
|
193 | + |
|
194 | + $list_type_shortcodes = array( |
|
195 | + '[ATTENDEE_LIST]', |
|
196 | + '[EVENT_LIST]', |
|
197 | + '[TICKET_LIST]', |
|
198 | + '[DATETIME_LIST]', |
|
199 | + '[QUESTION_LIST]', |
|
200 | + '[RECIPIENT_QUESTION_LIST]', |
|
201 | + '[PRIMARY_REGISTRANT_QUESTION_LIST]', |
|
202 | + '[RECIPIENT_TICKET_LIST]', |
|
203 | + '[PRIMARY_REGISTRANT_TICKET_LIST]', |
|
204 | + '[RECIPIENT_DATETIME_LIST]', |
|
205 | + '[PRIMARY_REGISTRANT_DATETIME_LIST]', |
|
206 | + '[TICKET_LINE_ITEM_LIST]', |
|
207 | + '[TAX_LINE_ITEM_LIST]', |
|
208 | + '[ADDITIONAL_LINE_ITEM_LIST]', |
|
209 | + '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
210 | + '[PAYMENT_LIST_*]', |
|
211 | + ); |
|
212 | + |
|
213 | + $list_type_shortcodes = apply_filters('FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
214 | + $list_type_shortcodes); |
|
215 | + |
|
216 | + //now lets go ahead and loop through our parsers for each shortcode and setup the values |
|
217 | + foreach ($shortcodes as $shortcode) { |
|
218 | + |
|
219 | + foreach ($this->_shortcode_objs as $sc_obj) { |
|
220 | + if ($sc_obj instanceof EE_Shortcodes) { |
|
221 | + //we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
222 | + preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
223 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
224 | + |
|
225 | + if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
226 | + continue; //the given shortcode isn't in this object |
|
227 | + } |
|
228 | + |
|
229 | + //if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
|
230 | + if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
231 | + $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
|
232 | + } else { |
|
233 | + $data_send = $this->_data; |
|
234 | + } |
|
235 | + |
|
236 | + //is this a conditional type shortcode? If it is then we actually parse the template here. |
|
237 | + if ($this->_is_conditional_shortcode($shortcode)) { |
|
238 | + //most shortcode parsers are not going to have a match for this shortcode and will return an |
|
239 | + //empty string so we need to make sure that we're only replacing the template when there is a non empty string. |
|
240 | + $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
241 | + if ($parsed) { |
|
242 | + $this->_template = $parsed; |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
247 | + |
|
248 | + $matched_code[] = $shortcode; |
|
249 | + $sc_values[] = $parsed; |
|
250 | + } |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + //now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out. |
|
255 | + $parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template); |
|
256 | + return $parsed; |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * Simply returns whether the given shortcode matches the structure for a conditional shortcode. |
|
262 | + * |
|
263 | + * Does it match this format: `[IF_` |
|
264 | + * |
|
265 | + * @param $shortcode |
|
266 | + */ |
|
267 | + protected function _is_conditional_shortcode($shortcode) |
|
268 | + { |
|
269 | + return strpos($shortcode, '[IF_') === 0; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of |
|
275 | + * various EE_Shortcode library objects |
|
276 | + * |
|
277 | + * @access private |
|
278 | + * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects |
|
279 | + * @return void |
|
280 | + */ |
|
281 | + private function _set_shortcodes($valid_shortcodes) |
|
282 | + { |
|
283 | + foreach ($valid_shortcodes as $shortcode_ref) { |
|
284 | + $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
|
285 | + $ref = str_replace(' ', '_', $ref); |
|
286 | + $classname = 'EE_' . $ref . '_Shortcodes'; |
|
287 | + if (class_exists($classname)) { |
|
288 | + $this->_shortcode_objs[] = new $classname; |
|
289 | + } |
|
290 | + } |
|
291 | + } |
|
292 | 292 | |
293 | 293 | |
294 | 294 | } //end EEH_Parse_Shortcodes |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | protected static $_incompatible_addons = array( |
49 | 49 | 'Multi_Event_Registration' => '2.0.11.rc.002', |
50 | 50 | 'Promotions' => '1.0.0.rc.084', |
51 | - ); |
|
51 | + ); |
|
52 | 52 | |
53 | 53 | |
54 | 54 | |
@@ -219,660 +219,660 @@ discard block |
||
219 | 219 | */ |
220 | 220 | public static function register( $addon_name = '', $setup_args = array() ) { |
221 | 221 | // required fields MUST be present, so let's make sure they are. |
222 | - \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
223 | - // get class name for addon |
|
222 | + \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
223 | + // get class name for addon |
|
224 | 224 | $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
225 | 225 | //setup $_settings array from incoming values. |
226 | - $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
227 | - // setup PUE |
|
228 | - \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
229 | - // does this addon work with this version of core or WordPress ? |
|
230 | - if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) { |
|
231 | - return; |
|
226 | + $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
227 | + // setup PUE |
|
228 | + \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
229 | + // does this addon work with this version of core or WordPress ? |
|
230 | + if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) { |
|
231 | + return; |
|
232 | 232 | } |
233 | 233 | // register namespaces |
234 | - \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
235 | - // check if this is an activation request |
|
236 | - if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
237 | - // dont bother setting up the rest of the addon atm |
|
238 | - return; |
|
239 | - } |
|
240 | - // we need cars |
|
241 | - \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
242 | - // register new models and extensions |
|
243 | - \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
244 | - // setup DMS |
|
245 | - \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
246 | - // if config_class is present let's register config. |
|
247 | - \EE_Register_Addon::_register_config($addon_name); |
|
248 | - // register admin pages |
|
249 | - \EE_Register_Addon::_register_admin_pages($addon_name); |
|
250 | - // add to list of modules to be registered |
|
251 | - \EE_Register_Addon::_register_modules($addon_name); |
|
252 | - // add to list of shortcodes to be registered |
|
253 | - \EE_Register_Addon::_register_shortcodes($addon_name); |
|
254 | - // add to list of widgets to be registered |
|
255 | - \EE_Register_Addon::_register_widgets($addon_name); |
|
256 | - // register capability related stuff. |
|
257 | - \EE_Register_Addon::_register_capabilities($addon_name); |
|
258 | - // any message type to register? |
|
259 | - \EE_Register_Addon::_register_message_types($addon_name); |
|
234 | + \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
235 | + // check if this is an activation request |
|
236 | + if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
237 | + // dont bother setting up the rest of the addon atm |
|
238 | + return; |
|
239 | + } |
|
240 | + // we need cars |
|
241 | + \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
242 | + // register new models and extensions |
|
243 | + \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
244 | + // setup DMS |
|
245 | + \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
246 | + // if config_class is present let's register config. |
|
247 | + \EE_Register_Addon::_register_config($addon_name); |
|
248 | + // register admin pages |
|
249 | + \EE_Register_Addon::_register_admin_pages($addon_name); |
|
250 | + // add to list of modules to be registered |
|
251 | + \EE_Register_Addon::_register_modules($addon_name); |
|
252 | + // add to list of shortcodes to be registered |
|
253 | + \EE_Register_Addon::_register_shortcodes($addon_name); |
|
254 | + // add to list of widgets to be registered |
|
255 | + \EE_Register_Addon::_register_widgets($addon_name); |
|
256 | + // register capability related stuff. |
|
257 | + \EE_Register_Addon::_register_capabilities($addon_name); |
|
258 | + // any message type to register? |
|
259 | + \EE_Register_Addon::_register_message_types($addon_name); |
|
260 | 260 | // any custom post type/ custom capabilities or default terms to register |
261 | - \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
262 | - // and any payment methods |
|
263 | - \EE_Register_Addon::_register_payment_methods($addon_name); |
|
261 | + \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
262 | + // and any payment methods |
|
263 | + \EE_Register_Addon::_register_payment_methods($addon_name); |
|
264 | 264 | // load and instantiate main addon class |
265 | - $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
266 | - $addon->after_registration(); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * @param string $addon_name |
|
273 | - * @param array $setup_args |
|
274 | - * @return void |
|
275 | - * @throws \EE_Error |
|
276 | - */ |
|
277 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
278 | - { |
|
279 | - // required fields MUST be present, so let's make sure they are. |
|
280 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
281 | - throw new EE_Error( |
|
282 | - __( |
|
283 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
284 | - 'event_espresso' |
|
285 | - ) |
|
286 | - ); |
|
287 | - } |
|
288 | - if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
289 | - throw new EE_Error( |
|
290 | - sprintf( |
|
291 | - __( |
|
292 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
293 | - 'event_espresso' |
|
294 | - ), |
|
295 | - implode(',', array_keys($setup_args)) |
|
296 | - ) |
|
297 | - ); |
|
298 | - } |
|
299 | - // check that addon has not already been registered with that name |
|
300 | - if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
301 | - throw new EE_Error( |
|
302 | - sprintf( |
|
303 | - __( |
|
304 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
305 | - 'event_espresso' |
|
306 | - ), |
|
307 | - $addon_name |
|
308 | - ) |
|
309 | - ); |
|
310 | - } |
|
265 | + $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
266 | + $addon->after_registration(); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * @param string $addon_name |
|
273 | + * @param array $setup_args |
|
274 | + * @return void |
|
275 | + * @throws \EE_Error |
|
276 | + */ |
|
277 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
278 | + { |
|
279 | + // required fields MUST be present, so let's make sure they are. |
|
280 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
281 | + throw new EE_Error( |
|
282 | + __( |
|
283 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
284 | + 'event_espresso' |
|
285 | + ) |
|
286 | + ); |
|
287 | + } |
|
288 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
289 | + throw new EE_Error( |
|
290 | + sprintf( |
|
291 | + __( |
|
292 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
293 | + 'event_espresso' |
|
294 | + ), |
|
295 | + implode(',', array_keys($setup_args)) |
|
296 | + ) |
|
297 | + ); |
|
298 | + } |
|
299 | + // check that addon has not already been registered with that name |
|
300 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
301 | + throw new EE_Error( |
|
302 | + sprintf( |
|
303 | + __( |
|
304 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
305 | + 'event_espresso' |
|
306 | + ), |
|
307 | + $addon_name |
|
308 | + ) |
|
309 | + ); |
|
310 | + } |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | |
314 | 314 | |
315 | - /** |
|
316 | - * @param string $addon_name |
|
317 | - * @param array $setup_args |
|
318 | - * @return string |
|
319 | - */ |
|
320 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
321 | - { |
|
322 | - if (empty($setup_args['class_name'])) { |
|
323 | - // generate one by first separating name with spaces |
|
324 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
325 | - //capitalize, then replace spaces with underscores |
|
326 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
327 | - } else { |
|
328 | - $class_name = $setup_args['class_name']; |
|
329 | - } |
|
330 | - return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * @param string $class_name |
|
337 | - * @param array $setup_args |
|
338 | - * @return array |
|
339 | - */ |
|
340 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
341 | - { |
|
342 | - //setup $_settings array from incoming values. |
|
343 | - $addon_settings = array( |
|
344 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
345 | - 'class_name' => $class_name, |
|
346 | - // the addon slug for use in URLs, etc |
|
347 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
348 | - ? (string)$setup_args['plugin_slug'] |
|
349 | - : '', |
|
350 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
351 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
352 | - ? (string)$setup_args['plugin_action_slug'] |
|
353 | - : '', |
|
354 | - // the "software" version for the addon |
|
355 | - 'version' => isset($setup_args['version']) |
|
356 | - ? (string)$setup_args['version'] |
|
357 | - : '', |
|
358 | - // the minimum version of EE Core that the addon will work with |
|
359 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
360 | - ? (string)$setup_args['min_core_version'] |
|
361 | - : '', |
|
362 | - // the minimum version of WordPress that the addon will work with |
|
363 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
364 | - ? (string)$setup_args['min_wp_version'] |
|
365 | - : EE_MIN_WP_VER_REQUIRED, |
|
366 | - // full server path to main file (file loaded directly by WP) |
|
367 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
368 | - ? (string)$setup_args['main_file_path'] |
|
369 | - : '', |
|
370 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
371 | - 'admin_path' => isset($setup_args['admin_path']) |
|
372 | - ? (string)$setup_args['admin_path'] : '', |
|
373 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
374 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
375 | - ? (string)$setup_args['admin_callback'] |
|
376 | - : '', |
|
377 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
378 | - 'config_section' => isset($setup_args['config_section']) |
|
379 | - ? (string)$setup_args['config_section'] |
|
380 | - : 'addons', |
|
381 | - // the class name for this addon's configuration settings object |
|
382 | - 'config_class' => isset($setup_args['config_class']) |
|
383 | - ? (string)$setup_args['config_class'] : '', |
|
384 | - //the name given to the config for this addons' configuration settings object (optional) |
|
385 | - 'config_name' => isset($setup_args['config_name']) |
|
386 | - ? (string)$setup_args['config_name'] : '', |
|
387 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
388 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
389 | - ? (array)$setup_args['autoloader_paths'] |
|
390 | - : array(), |
|
391 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
392 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
393 | - ? (array)$setup_args['autoloader_folders'] |
|
394 | - : array(), |
|
395 | - // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
396 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
397 | - ? (array)$setup_args['dms_paths'] |
|
398 | - : array(), |
|
399 | - // array of full server paths to any EED_Modules used by the addon |
|
400 | - 'module_paths' => isset($setup_args['module_paths']) |
|
401 | - ? (array)$setup_args['module_paths'] |
|
402 | - : array(), |
|
403 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
404 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
405 | - ? (array)$setup_args['shortcode_paths'] |
|
406 | - : array(), |
|
407 | - // array of full server paths to any WP_Widgets used by the addon |
|
408 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
409 | - ? (array)$setup_args['widget_paths'] |
|
410 | - : array(), |
|
411 | - // array of PUE options used by the addon |
|
412 | - 'pue_options' => isset($setup_args['pue_options']) |
|
413 | - ? (array)$setup_args['pue_options'] |
|
414 | - : array(), |
|
415 | - 'message_types' => isset($setup_args['message_types']) |
|
416 | - ? (array)$setup_args['message_types'] |
|
417 | - : array(), |
|
418 | - 'capabilities' => isset($setup_args['capabilities']) |
|
419 | - ? (array)$setup_args['capabilities'] |
|
420 | - : array(), |
|
421 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
422 | - ? (array)$setup_args['capability_maps'] |
|
423 | - : array(), |
|
424 | - 'model_paths' => isset($setup_args['model_paths']) |
|
425 | - ? (array)$setup_args['model_paths'] |
|
426 | - : array(), |
|
427 | - 'class_paths' => isset($setup_args['class_paths']) |
|
428 | - ? (array)$setup_args['class_paths'] |
|
429 | - : array(), |
|
430 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
431 | - ? (array)$setup_args['model_extension_paths'] |
|
432 | - : array(), |
|
433 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
434 | - ? (array)$setup_args['class_extension_paths'] |
|
435 | - : array(), |
|
436 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
437 | - ? (array)$setup_args['custom_post_types'] |
|
438 | - : array(), |
|
439 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
440 | - ? (array)$setup_args['custom_taxonomies'] |
|
441 | - : array(), |
|
442 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
443 | - ? (array)$setup_args['payment_method_paths'] |
|
444 | - : array(), |
|
445 | - 'default_terms' => isset($setup_args['default_terms']) |
|
446 | - ? (array)$setup_args['default_terms'] |
|
447 | - : array(), |
|
448 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
449 | - // that can be used for adding upgrading/marketing info |
|
450 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
451 | - ? $setup_args['plugins_page_row'] |
|
452 | - : '', |
|
453 | - 'namespace' => isset( |
|
454 | - $setup_args['namespace'], |
|
455 | - $setup_args['namespace']['FQNS'], |
|
456 | - $setup_args['namespace']['DIR'] |
|
457 | - ) |
|
458 | - ? (array)$setup_args['namespace'] |
|
459 | - : array(), |
|
460 | - ); |
|
461 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
462 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
463 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
464 | - && ! empty($addon_settings['admin_path']) |
|
465 | - ? $addon_settings['plugin_slug'] |
|
466 | - : $addon_settings['plugin_action_slug']; |
|
467 | - // full server path to main file (file loaded directly by WP) |
|
468 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
469 | - return $addon_settings; |
|
315 | + /** |
|
316 | + * @param string $addon_name |
|
317 | + * @param array $setup_args |
|
318 | + * @return string |
|
319 | + */ |
|
320 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
321 | + { |
|
322 | + if (empty($setup_args['class_name'])) { |
|
323 | + // generate one by first separating name with spaces |
|
324 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
325 | + //capitalize, then replace spaces with underscores |
|
326 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
327 | + } else { |
|
328 | + $class_name = $setup_args['class_name']; |
|
329 | + } |
|
330 | + return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
470 | 331 | } |
471 | 332 | |
472 | 333 | |
473 | 334 | |
474 | - /** |
|
475 | - * @param string $addon_name |
|
476 | - * @param array $addon_settings |
|
477 | - * @return boolean |
|
478 | - */ |
|
335 | + /** |
|
336 | + * @param string $class_name |
|
337 | + * @param array $setup_args |
|
338 | + * @return array |
|
339 | + */ |
|
340 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
341 | + { |
|
342 | + //setup $_settings array from incoming values. |
|
343 | + $addon_settings = array( |
|
344 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
345 | + 'class_name' => $class_name, |
|
346 | + // the addon slug for use in URLs, etc |
|
347 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
348 | + ? (string)$setup_args['plugin_slug'] |
|
349 | + : '', |
|
350 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
351 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
352 | + ? (string)$setup_args['plugin_action_slug'] |
|
353 | + : '', |
|
354 | + // the "software" version for the addon |
|
355 | + 'version' => isset($setup_args['version']) |
|
356 | + ? (string)$setup_args['version'] |
|
357 | + : '', |
|
358 | + // the minimum version of EE Core that the addon will work with |
|
359 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
360 | + ? (string)$setup_args['min_core_version'] |
|
361 | + : '', |
|
362 | + // the minimum version of WordPress that the addon will work with |
|
363 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
364 | + ? (string)$setup_args['min_wp_version'] |
|
365 | + : EE_MIN_WP_VER_REQUIRED, |
|
366 | + // full server path to main file (file loaded directly by WP) |
|
367 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
368 | + ? (string)$setup_args['main_file_path'] |
|
369 | + : '', |
|
370 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
371 | + 'admin_path' => isset($setup_args['admin_path']) |
|
372 | + ? (string)$setup_args['admin_path'] : '', |
|
373 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
374 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
375 | + ? (string)$setup_args['admin_callback'] |
|
376 | + : '', |
|
377 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
378 | + 'config_section' => isset($setup_args['config_section']) |
|
379 | + ? (string)$setup_args['config_section'] |
|
380 | + : 'addons', |
|
381 | + // the class name for this addon's configuration settings object |
|
382 | + 'config_class' => isset($setup_args['config_class']) |
|
383 | + ? (string)$setup_args['config_class'] : '', |
|
384 | + //the name given to the config for this addons' configuration settings object (optional) |
|
385 | + 'config_name' => isset($setup_args['config_name']) |
|
386 | + ? (string)$setup_args['config_name'] : '', |
|
387 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
388 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
389 | + ? (array)$setup_args['autoloader_paths'] |
|
390 | + : array(), |
|
391 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
392 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
393 | + ? (array)$setup_args['autoloader_folders'] |
|
394 | + : array(), |
|
395 | + // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
396 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
397 | + ? (array)$setup_args['dms_paths'] |
|
398 | + : array(), |
|
399 | + // array of full server paths to any EED_Modules used by the addon |
|
400 | + 'module_paths' => isset($setup_args['module_paths']) |
|
401 | + ? (array)$setup_args['module_paths'] |
|
402 | + : array(), |
|
403 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
404 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
405 | + ? (array)$setup_args['shortcode_paths'] |
|
406 | + : array(), |
|
407 | + // array of full server paths to any WP_Widgets used by the addon |
|
408 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
409 | + ? (array)$setup_args['widget_paths'] |
|
410 | + : array(), |
|
411 | + // array of PUE options used by the addon |
|
412 | + 'pue_options' => isset($setup_args['pue_options']) |
|
413 | + ? (array)$setup_args['pue_options'] |
|
414 | + : array(), |
|
415 | + 'message_types' => isset($setup_args['message_types']) |
|
416 | + ? (array)$setup_args['message_types'] |
|
417 | + : array(), |
|
418 | + 'capabilities' => isset($setup_args['capabilities']) |
|
419 | + ? (array)$setup_args['capabilities'] |
|
420 | + : array(), |
|
421 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
422 | + ? (array)$setup_args['capability_maps'] |
|
423 | + : array(), |
|
424 | + 'model_paths' => isset($setup_args['model_paths']) |
|
425 | + ? (array)$setup_args['model_paths'] |
|
426 | + : array(), |
|
427 | + 'class_paths' => isset($setup_args['class_paths']) |
|
428 | + ? (array)$setup_args['class_paths'] |
|
429 | + : array(), |
|
430 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
431 | + ? (array)$setup_args['model_extension_paths'] |
|
432 | + : array(), |
|
433 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
434 | + ? (array)$setup_args['class_extension_paths'] |
|
435 | + : array(), |
|
436 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
437 | + ? (array)$setup_args['custom_post_types'] |
|
438 | + : array(), |
|
439 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
440 | + ? (array)$setup_args['custom_taxonomies'] |
|
441 | + : array(), |
|
442 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
443 | + ? (array)$setup_args['payment_method_paths'] |
|
444 | + : array(), |
|
445 | + 'default_terms' => isset($setup_args['default_terms']) |
|
446 | + ? (array)$setup_args['default_terms'] |
|
447 | + : array(), |
|
448 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
449 | + // that can be used for adding upgrading/marketing info |
|
450 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
451 | + ? $setup_args['plugins_page_row'] |
|
452 | + : '', |
|
453 | + 'namespace' => isset( |
|
454 | + $setup_args['namespace'], |
|
455 | + $setup_args['namespace']['FQNS'], |
|
456 | + $setup_args['namespace']['DIR'] |
|
457 | + ) |
|
458 | + ? (array)$setup_args['namespace'] |
|
459 | + : array(), |
|
460 | + ); |
|
461 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
462 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
463 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
464 | + && ! empty($addon_settings['admin_path']) |
|
465 | + ? $addon_settings['plugin_slug'] |
|
466 | + : $addon_settings['plugin_action_slug']; |
|
467 | + // full server path to main file (file loaded directly by WP) |
|
468 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
469 | + return $addon_settings; |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * @param string $addon_name |
|
476 | + * @param array $addon_settings |
|
477 | + * @return boolean |
|
478 | + */ |
|
479 | 479 | private static function _addon_is_compatible( $addon_name, array $addon_settings ) { |
480 | - global $wp_version; |
|
481 | - $incompatibility_message = ''; |
|
482 | - //check whether this addon version is compatible with EE core |
|
483 | - if ( |
|
484 | - isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
485 | - && ! self::_meets_min_core_version_requirement( |
|
486 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
487 | - $addon_settings['version'] |
|
488 | - ) |
|
489 | - ) { |
|
490 | - $incompatibility_message = sprintf( |
|
491 | - __( |
|
492 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
493 | - ), |
|
494 | - $addon_name, |
|
495 | - '<br />', |
|
496 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
497 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
498 | - '</span><br />' |
|
499 | - ); |
|
500 | - } else if ( |
|
501 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
502 | - ) { |
|
503 | - $incompatibility_message = sprintf( |
|
504 | - __( |
|
505 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
506 | - 'event_espresso' |
|
507 | - ), |
|
508 | - $addon_name, |
|
509 | - self::_effective_version($addon_settings['min_core_version']), |
|
510 | - self::_effective_version(espresso_version()), |
|
511 | - '<br />', |
|
512 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
513 | - '</span><br />' |
|
514 | - ); |
|
515 | - } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
516 | - $incompatibility_message = sprintf( |
|
517 | - __( |
|
518 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
519 | - 'event_espresso' |
|
520 | - ), |
|
521 | - $addon_name, |
|
522 | - $addon_settings['min_wp_version'], |
|
523 | - '<br />', |
|
524 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
525 | - '</span><br />' |
|
526 | - ); |
|
527 | - } |
|
528 | - if ( ! empty($incompatibility_message)) { |
|
529 | - // remove 'activate' from the REQUEST |
|
530 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
531 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
532 | - if (current_user_can('activate_plugins')) { |
|
533 | - // show an error message indicating the plugin didn't activate properly |
|
534 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
535 | - } |
|
536 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
537 | - return false; |
|
538 | - } |
|
539 | - // addon IS compatible |
|
540 | - return true; |
|
480 | + global $wp_version; |
|
481 | + $incompatibility_message = ''; |
|
482 | + //check whether this addon version is compatible with EE core |
|
483 | + if ( |
|
484 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
485 | + && ! self::_meets_min_core_version_requirement( |
|
486 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
487 | + $addon_settings['version'] |
|
488 | + ) |
|
489 | + ) { |
|
490 | + $incompatibility_message = sprintf( |
|
491 | + __( |
|
492 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
493 | + ), |
|
494 | + $addon_name, |
|
495 | + '<br />', |
|
496 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
497 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
498 | + '</span><br />' |
|
499 | + ); |
|
500 | + } else if ( |
|
501 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
502 | + ) { |
|
503 | + $incompatibility_message = sprintf( |
|
504 | + __( |
|
505 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
506 | + 'event_espresso' |
|
507 | + ), |
|
508 | + $addon_name, |
|
509 | + self::_effective_version($addon_settings['min_core_version']), |
|
510 | + self::_effective_version(espresso_version()), |
|
511 | + '<br />', |
|
512 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
513 | + '</span><br />' |
|
514 | + ); |
|
515 | + } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
516 | + $incompatibility_message = sprintf( |
|
517 | + __( |
|
518 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
519 | + 'event_espresso' |
|
520 | + ), |
|
521 | + $addon_name, |
|
522 | + $addon_settings['min_wp_version'], |
|
523 | + '<br />', |
|
524 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
525 | + '</span><br />' |
|
526 | + ); |
|
527 | + } |
|
528 | + if ( ! empty($incompatibility_message)) { |
|
529 | + // remove 'activate' from the REQUEST |
|
530 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
531 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
532 | + if (current_user_can('activate_plugins')) { |
|
533 | + // show an error message indicating the plugin didn't activate properly |
|
534 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
535 | + } |
|
536 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
537 | + return false; |
|
538 | + } |
|
539 | + // addon IS compatible |
|
540 | + return true; |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | |
544 | 544 | |
545 | - /** |
|
546 | - * if plugin update engine is being used for auto-updates, |
|
547 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
548 | - * (not needed if PUE is not being used) |
|
549 | - * |
|
550 | - * @param string $addon_name |
|
551 | - * @param string $class_name |
|
552 | - * @param array $setup_args |
|
553 | - * @return void |
|
554 | - */ |
|
545 | + /** |
|
546 | + * if plugin update engine is being used for auto-updates, |
|
547 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
548 | + * (not needed if PUE is not being used) |
|
549 | + * |
|
550 | + * @param string $addon_name |
|
551 | + * @param string $class_name |
|
552 | + * @param array $setup_args |
|
553 | + * @return void |
|
554 | + */ |
|
555 | 555 | private static function _parse_pue_options( $addon_name, $class_name, array $setup_args ) { |
556 | - if ( ! empty($setup_args['pue_options'])) { |
|
557 | - self::$_settings[$addon_name]['pue_options'] = array( |
|
558 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
559 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
560 | - : 'espresso_' . strtolower($class_name), |
|
561 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
562 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
563 | - : plugin_basename($setup_args['main_file_path']), |
|
564 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
565 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
566 | - : '24', |
|
567 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
568 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
569 | - : false, |
|
570 | - ); |
|
571 | - add_action( |
|
572 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
573 | - array('EE_Register_Addon', 'load_pue_update') |
|
574 | - ); |
|
575 | - } |
|
556 | + if ( ! empty($setup_args['pue_options'])) { |
|
557 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
558 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
559 | + ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
560 | + : 'espresso_' . strtolower($class_name), |
|
561 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
562 | + ? (string)$setup_args['pue_options']['plugin_basename'] |
|
563 | + : plugin_basename($setup_args['main_file_path']), |
|
564 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
565 | + ? (string)$setup_args['pue_options']['checkPeriod'] |
|
566 | + : '24', |
|
567 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
568 | + ? (string)$setup_args['pue_options']['use_wp_update'] |
|
569 | + : false, |
|
570 | + ); |
|
571 | + add_action( |
|
572 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
573 | + array('EE_Register_Addon', 'load_pue_update') |
|
574 | + ); |
|
575 | + } |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | |
579 | 579 | |
580 | - /** |
|
581 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
582 | - * |
|
583 | - * @param array $addon_settings |
|
584 | - * @return void |
|
585 | - */ |
|
586 | - private static function _setup_namespaces(array $addon_settings) |
|
587 | - { |
|
588 | - // |
|
589 | - if ( |
|
590 | - isset( |
|
591 | - $addon_settings['namespace'], |
|
592 | - $addon_settings['namespace']['FQNS'], |
|
593 | - $addon_settings['namespace']['DIR'] |
|
594 | - ) |
|
595 | - ) { |
|
596 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
597 | - $addon_settings['namespace']['FQNS'], |
|
598 | - $addon_settings['namespace']['DIR'] |
|
599 | - ); |
|
600 | - } |
|
601 | - } |
|
602 | - |
|
603 | - |
|
604 | - |
|
605 | - /** |
|
606 | - * @param string $addon_name |
|
607 | - * @param array $addon_settings |
|
608 | - * @return bool |
|
609 | - */ |
|
580 | + /** |
|
581 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
582 | + * |
|
583 | + * @param array $addon_settings |
|
584 | + * @return void |
|
585 | + */ |
|
586 | + private static function _setup_namespaces(array $addon_settings) |
|
587 | + { |
|
588 | + // |
|
589 | + if ( |
|
590 | + isset( |
|
591 | + $addon_settings['namespace'], |
|
592 | + $addon_settings['namespace']['FQNS'], |
|
593 | + $addon_settings['namespace']['DIR'] |
|
594 | + ) |
|
595 | + ) { |
|
596 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
597 | + $addon_settings['namespace']['FQNS'], |
|
598 | + $addon_settings['namespace']['DIR'] |
|
599 | + ); |
|
600 | + } |
|
601 | + } |
|
602 | + |
|
603 | + |
|
604 | + |
|
605 | + /** |
|
606 | + * @param string $addon_name |
|
607 | + * @param array $addon_settings |
|
608 | + * @return bool |
|
609 | + */ |
|
610 | 610 | private static function _addon_activation( $addon_name, array $addon_settings ) { |
611 | - // this is an activation request |
|
612 | - if (did_action('activate_plugin')) { |
|
613 | - //to find if THIS is the addon that was activated, |
|
614 | - //just check if we have already registered it or not |
|
615 | - //(as the newly-activated addon wasn't around the first time addons were registered) |
|
616 | - if ( ! isset(self::$_settings[$addon_name])) { |
|
617 | - self::$_settings[$addon_name] = $addon_settings; |
|
618 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
619 | - $addon->set_activation_indicator_option(); |
|
620 | - // dont bother setting up the rest of the addon. |
|
621 | - // we know it was just activated and the request will end soon |
|
622 | - } |
|
623 | - return true; |
|
624 | - } else { |
|
625 | - // make sure this was called in the right place! |
|
626 | - if ( |
|
627 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
628 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
629 | - ) { |
|
630 | - EE_Error::doing_it_wrong( |
|
631 | - __METHOD__, |
|
632 | - sprintf( |
|
633 | - __( |
|
634 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
635 | - 'event_espresso' |
|
636 | - ), |
|
637 | - $addon_name |
|
638 | - ), |
|
639 | - '4.3.0' |
|
640 | - ); |
|
641 | - } |
|
642 | - // make sure addon settings are set correctly without overwriting anything existing |
|
643 | - if (isset(self::$_settings[$addon_name])) { |
|
644 | - self::$_settings[$addon_name] += $addon_settings; |
|
645 | - } else { |
|
646 | - self::$_settings[$addon_name] = $addon_settings; |
|
647 | - } |
|
648 | - } |
|
649 | - return false; |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - |
|
654 | - /** |
|
655 | - * @param string $addon_name |
|
656 | - * @return void |
|
657 | - * @throws \EE_Error |
|
658 | - */ |
|
659 | - private static function _setup_autoloaders($addon_name) |
|
660 | - { |
|
661 | - if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
662 | - // setup autoloader for single file |
|
663 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
664 | - } |
|
665 | - // setup autoloaders for folders |
|
666 | - if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
667 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
668 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
669 | - } |
|
670 | - } |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - |
|
675 | - /** |
|
676 | - * register new models and extensions |
|
677 | - * |
|
678 | - * @param string $addon_name |
|
679 | - * @return void |
|
680 | - * @throws \EE_Error |
|
681 | - */ |
|
611 | + // this is an activation request |
|
612 | + if (did_action('activate_plugin')) { |
|
613 | + //to find if THIS is the addon that was activated, |
|
614 | + //just check if we have already registered it or not |
|
615 | + //(as the newly-activated addon wasn't around the first time addons were registered) |
|
616 | + if ( ! isset(self::$_settings[$addon_name])) { |
|
617 | + self::$_settings[$addon_name] = $addon_settings; |
|
618 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
619 | + $addon->set_activation_indicator_option(); |
|
620 | + // dont bother setting up the rest of the addon. |
|
621 | + // we know it was just activated and the request will end soon |
|
622 | + } |
|
623 | + return true; |
|
624 | + } else { |
|
625 | + // make sure this was called in the right place! |
|
626 | + if ( |
|
627 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
628 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
629 | + ) { |
|
630 | + EE_Error::doing_it_wrong( |
|
631 | + __METHOD__, |
|
632 | + sprintf( |
|
633 | + __( |
|
634 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
635 | + 'event_espresso' |
|
636 | + ), |
|
637 | + $addon_name |
|
638 | + ), |
|
639 | + '4.3.0' |
|
640 | + ); |
|
641 | + } |
|
642 | + // make sure addon settings are set correctly without overwriting anything existing |
|
643 | + if (isset(self::$_settings[$addon_name])) { |
|
644 | + self::$_settings[$addon_name] += $addon_settings; |
|
645 | + } else { |
|
646 | + self::$_settings[$addon_name] = $addon_settings; |
|
647 | + } |
|
648 | + } |
|
649 | + return false; |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + |
|
654 | + /** |
|
655 | + * @param string $addon_name |
|
656 | + * @return void |
|
657 | + * @throws \EE_Error |
|
658 | + */ |
|
659 | + private static function _setup_autoloaders($addon_name) |
|
660 | + { |
|
661 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
662 | + // setup autoloader for single file |
|
663 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
664 | + } |
|
665 | + // setup autoloaders for folders |
|
666 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
667 | + foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
668 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
669 | + } |
|
670 | + } |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + |
|
675 | + /** |
|
676 | + * register new models and extensions |
|
677 | + * |
|
678 | + * @param string $addon_name |
|
679 | + * @return void |
|
680 | + * @throws \EE_Error |
|
681 | + */ |
|
682 | 682 | private static function _register_models_and_extensions( $addon_name ) { |
683 | - // register new models |
|
684 | - if ( |
|
685 | - ! empty(self::$_settings[$addon_name]['model_paths']) |
|
686 | - || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
687 | - ) { |
|
688 | - EE_Register_Model::register( |
|
689 | - $addon_name, |
|
690 | - array( |
|
691 | - 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
692 | - 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
693 | - ) |
|
694 | - ); |
|
695 | - } |
|
696 | - // register model extensions |
|
697 | - if ( |
|
698 | - ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
699 | - || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
700 | - ) { |
|
701 | - EE_Register_Model_Extensions::register( |
|
702 | - $addon_name, |
|
703 | - array( |
|
704 | - 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
705 | - 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
706 | - ) |
|
707 | - ); |
|
708 | - } |
|
709 | - } |
|
710 | - |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * @param string $addon_name |
|
715 | - * @return void |
|
716 | - * @throws \EE_Error |
|
717 | - */ |
|
683 | + // register new models |
|
684 | + if ( |
|
685 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
686 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
687 | + ) { |
|
688 | + EE_Register_Model::register( |
|
689 | + $addon_name, |
|
690 | + array( |
|
691 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
692 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
693 | + ) |
|
694 | + ); |
|
695 | + } |
|
696 | + // register model extensions |
|
697 | + if ( |
|
698 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
699 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
700 | + ) { |
|
701 | + EE_Register_Model_Extensions::register( |
|
702 | + $addon_name, |
|
703 | + array( |
|
704 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
705 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
706 | + ) |
|
707 | + ); |
|
708 | + } |
|
709 | + } |
|
710 | + |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * @param string $addon_name |
|
715 | + * @return void |
|
716 | + * @throws \EE_Error |
|
717 | + */ |
|
718 | 718 | private static function _register_data_migration_scripts( $addon_name ) { |
719 | - // setup DMS |
|
720 | - if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
721 | - EE_Register_Data_Migration_Scripts::register( |
|
722 | - $addon_name, |
|
723 | - array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
724 | - ); |
|
725 | - } |
|
726 | - } |
|
727 | - |
|
728 | - |
|
729 | - /** |
|
730 | - * @param string $addon_name |
|
731 | - * @return void |
|
732 | - * @throws \EE_Error |
|
733 | - */ |
|
719 | + // setup DMS |
|
720 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
721 | + EE_Register_Data_Migration_Scripts::register( |
|
722 | + $addon_name, |
|
723 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
724 | + ); |
|
725 | + } |
|
726 | + } |
|
727 | + |
|
728 | + |
|
729 | + /** |
|
730 | + * @param string $addon_name |
|
731 | + * @return void |
|
732 | + * @throws \EE_Error |
|
733 | + */ |
|
734 | 734 | private static function _register_config( $addon_name ) { |
735 | - // if config_class is present let's register config. |
|
736 | - if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
737 | - EE_Register_Config::register( |
|
738 | - self::$_settings[$addon_name]['config_class'], |
|
739 | - array( |
|
740 | - 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
741 | - 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
742 | - ) |
|
743 | - ); |
|
744 | - } |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - /** |
|
749 | - * @param string $addon_name |
|
750 | - * @return void |
|
751 | - * @throws \EE_Error |
|
752 | - */ |
|
735 | + // if config_class is present let's register config. |
|
736 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
737 | + EE_Register_Config::register( |
|
738 | + self::$_settings[$addon_name]['config_class'], |
|
739 | + array( |
|
740 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
741 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
742 | + ) |
|
743 | + ); |
|
744 | + } |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + /** |
|
749 | + * @param string $addon_name |
|
750 | + * @return void |
|
751 | + * @throws \EE_Error |
|
752 | + */ |
|
753 | 753 | private static function _register_admin_pages( $addon_name ) { |
754 | - if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
755 | - EE_Register_Admin_Page::register( |
|
756 | - $addon_name, |
|
757 | - array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
758 | - ); |
|
759 | - } |
|
760 | - } |
|
761 | - |
|
762 | - |
|
763 | - /** |
|
764 | - * @param string $addon_name |
|
765 | - * @return void |
|
766 | - * @throws \EE_Error |
|
767 | - */ |
|
754 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
755 | + EE_Register_Admin_Page::register( |
|
756 | + $addon_name, |
|
757 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
758 | + ); |
|
759 | + } |
|
760 | + } |
|
761 | + |
|
762 | + |
|
763 | + /** |
|
764 | + * @param string $addon_name |
|
765 | + * @return void |
|
766 | + * @throws \EE_Error |
|
767 | + */ |
|
768 | 768 | private static function _register_modules( $addon_name ) { |
769 | - if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
770 | - EE_Register_Module::register( |
|
771 | - $addon_name, |
|
772 | - array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
773 | - ); |
|
774 | - } |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * @param string $addon_name |
|
780 | - * @return void |
|
781 | - * @throws \EE_Error |
|
782 | - */ |
|
769 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
770 | + EE_Register_Module::register( |
|
771 | + $addon_name, |
|
772 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
773 | + ); |
|
774 | + } |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * @param string $addon_name |
|
780 | + * @return void |
|
781 | + * @throws \EE_Error |
|
782 | + */ |
|
783 | 783 | private static function _register_shortcodes( $addon_name ) { |
784 | - if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
785 | - EE_Register_Shortcode::register( |
|
786 | - $addon_name, |
|
787 | - array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths']) |
|
788 | - ); |
|
789 | - } |
|
790 | - } |
|
791 | - |
|
792 | - |
|
793 | - /** |
|
794 | - * @param string $addon_name |
|
795 | - * @return void |
|
796 | - * @throws \EE_Error |
|
797 | - */ |
|
784 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
785 | + EE_Register_Shortcode::register( |
|
786 | + $addon_name, |
|
787 | + array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths']) |
|
788 | + ); |
|
789 | + } |
|
790 | + } |
|
791 | + |
|
792 | + |
|
793 | + /** |
|
794 | + * @param string $addon_name |
|
795 | + * @return void |
|
796 | + * @throws \EE_Error |
|
797 | + */ |
|
798 | 798 | private static function _register_widgets( $addon_name ) { |
799 | - if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
800 | - EE_Register_Widget::register( |
|
801 | - $addon_name, |
|
802 | - array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
803 | - ); |
|
804 | - } |
|
805 | - } |
|
806 | - |
|
807 | - |
|
808 | - /** |
|
809 | - * @param string $addon_name |
|
810 | - * @return void |
|
811 | - * @throws \EE_Error |
|
812 | - */ |
|
799 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
800 | + EE_Register_Widget::register( |
|
801 | + $addon_name, |
|
802 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
803 | + ); |
|
804 | + } |
|
805 | + } |
|
806 | + |
|
807 | + |
|
808 | + /** |
|
809 | + * @param string $addon_name |
|
810 | + * @return void |
|
811 | + * @throws \EE_Error |
|
812 | + */ |
|
813 | 813 | private static function _register_capabilities( $addon_name ) { |
814 | - if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
815 | - EE_Register_Capabilities::register( |
|
816 | - $addon_name, |
|
817 | - array( |
|
818 | - 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
819 | - 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
820 | - ) |
|
821 | - ); |
|
822 | - } |
|
823 | - } |
|
824 | - |
|
825 | - |
|
826 | - /** |
|
827 | - * @param string $addon_name |
|
828 | - * @return void |
|
829 | - * @throws \EE_Error |
|
830 | - */ |
|
814 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
815 | + EE_Register_Capabilities::register( |
|
816 | + $addon_name, |
|
817 | + array( |
|
818 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
819 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
820 | + ) |
|
821 | + ); |
|
822 | + } |
|
823 | + } |
|
824 | + |
|
825 | + |
|
826 | + /** |
|
827 | + * @param string $addon_name |
|
828 | + * @return void |
|
829 | + * @throws \EE_Error |
|
830 | + */ |
|
831 | 831 | private static function _register_message_types( $addon_name ) { |
832 | - if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
833 | - add_action( |
|
834 | - 'EE_Brewing_Regular___messages_caf', |
|
835 | - array('EE_Register_Addon', 'register_message_types') |
|
836 | - ); |
|
837 | - } |
|
838 | - } |
|
839 | - |
|
840 | - |
|
841 | - /** |
|
842 | - * @param string $addon_name |
|
843 | - * @return void |
|
844 | - * @throws \EE_Error |
|
845 | - */ |
|
832 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
833 | + add_action( |
|
834 | + 'EE_Brewing_Regular___messages_caf', |
|
835 | + array('EE_Register_Addon', 'register_message_types') |
|
836 | + ); |
|
837 | + } |
|
838 | + } |
|
839 | + |
|
840 | + |
|
841 | + /** |
|
842 | + * @param string $addon_name |
|
843 | + * @return void |
|
844 | + * @throws \EE_Error |
|
845 | + */ |
|
846 | 846 | private static function _register_custom_post_types( $addon_name ) { |
847 | - if ( |
|
848 | - ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
849 | - || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
850 | - ) { |
|
851 | - EE_Register_CPT::register( |
|
852 | - $addon_name, |
|
853 | - array( |
|
854 | - 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
855 | - 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
856 | - 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
857 | - ) |
|
858 | - ); |
|
859 | - } |
|
860 | - } |
|
861 | - |
|
862 | - |
|
863 | - /** |
|
864 | - * @param string $addon_name |
|
865 | - * @return void |
|
866 | - * @throws \EE_Error |
|
867 | - */ |
|
847 | + if ( |
|
848 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
849 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
850 | + ) { |
|
851 | + EE_Register_CPT::register( |
|
852 | + $addon_name, |
|
853 | + array( |
|
854 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
855 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
856 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
857 | + ) |
|
858 | + ); |
|
859 | + } |
|
860 | + } |
|
861 | + |
|
862 | + |
|
863 | + /** |
|
864 | + * @param string $addon_name |
|
865 | + * @return void |
|
866 | + * @throws \EE_Error |
|
867 | + */ |
|
868 | 868 | private static function _register_payment_methods( $addon_name ) { |
869 | - if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
870 | - EE_Register_Payment_Method::register( |
|
871 | - $addon_name, |
|
872 | - array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
873 | - ); |
|
874 | - } |
|
875 | - } |
|
869 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
870 | + EE_Register_Payment_Method::register( |
|
871 | + $addon_name, |
|
872 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
873 | + ); |
|
874 | + } |
|
875 | + } |
|
876 | 876 | |
877 | 877 | |
878 | 878 | |
@@ -901,14 +901,14 @@ discard block |
||
901 | 901 | //unfortunately this can't be hooked in upon construction, because we don't have |
902 | 902 | //the plugin mainfile's path upon construction. |
903 | 903 | register_deactivation_hook( $addon->get_main_plugin_file(), array( $addon, 'deactivation' ) ); |
904 | - // call any additional admin_callback functions during load_admin_controller hook |
|
905 | - if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
906 | - add_action( |
|
907 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
908 | - array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
909 | - ); |
|
910 | - } |
|
911 | - return $addon; |
|
904 | + // call any additional admin_callback functions during load_admin_controller hook |
|
905 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
906 | + add_action( |
|
907 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
908 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
909 | + ); |
|
910 | + } |
|
911 | + return $addon; |
|
912 | 912 | } |
913 | 913 | |
914 | 914 | |
@@ -924,7 +924,7 @@ discard block |
||
924 | 924 | // cycle thru settings |
925 | 925 | foreach ( self::$_settings as $settings ) { |
926 | 926 | if ( ! empty( $settings['pue_options'] ) ) { |
927 | - // initiate the class and start the plugin update engine! |
|
927 | + // initiate the class and start the plugin update engine! |
|
928 | 928 | new PluginUpdateEngineChecker( |
929 | 929 | // host file URL |
930 | 930 | 'https://eventespresso.com', |
@@ -960,11 +960,11 @@ discard block |
||
960 | 960 | */ |
961 | 961 | public static function register_message_types() { |
962 | 962 | foreach ( self::$_settings as $addon_name => $settings ) { |
963 | - if ( ! empty($settings['message_types'])) { |
|
964 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
965 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
966 | - } |
|
967 | - } |
|
963 | + if ( ! empty($settings['message_types'])) { |
|
964 | + foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
965 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
966 | + } |
|
967 | + } |
|
968 | 968 | } |
969 | 969 | } |
970 | 970 | |
@@ -980,7 +980,7 @@ discard block |
||
980 | 980 | */ |
981 | 981 | public static function deregister( $addon_name = null ) { |
982 | 982 | if ( isset( self::$_settings[ $addon_name ], self::$_settings[$addon_name]['class_name'] ) ) { |
983 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
983 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
984 | 984 | $class_name = self::$_settings[ $addon_name ]['class_name']; |
985 | 985 | if ( ! empty( self::$_settings[ $addon_name ]['dms_paths'] ) ) { |
986 | 986 | // setup DMS |
@@ -1007,15 +1007,15 @@ discard block |
||
1007 | 1007 | EE_Register_Widget::deregister( $addon_name ); |
1008 | 1008 | } |
1009 | 1009 | if ( ! empty( self::$_settings[ $addon_name ]['model_paths'] ) |
1010 | - || |
|
1011 | - ! empty( self::$_settings[ $addon_name ]['class_paths'] ) |
|
1010 | + || |
|
1011 | + ! empty( self::$_settings[ $addon_name ]['class_paths'] ) |
|
1012 | 1012 | ) { |
1013 | 1013 | // add to list of shortcodes to be registered |
1014 | 1014 | EE_Register_Model::deregister( $addon_name ); |
1015 | 1015 | } |
1016 | 1016 | if ( ! empty( self::$_settings[ $addon_name ]['model_extension_paths'] ) |
1017 | - || |
|
1018 | - ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] ) |
|
1017 | + || |
|
1018 | + ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] ) |
|
1019 | 1019 | ) { |
1020 | 1020 | // add to list of shortcodes to be registered |
1021 | 1021 | EE_Register_Model_Extensions::deregister( $addon_name ); |
@@ -1046,7 +1046,7 @@ discard block |
||
1046 | 1046 | array( EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required' ) |
1047 | 1047 | ); |
1048 | 1048 | unset( EE_Registry::instance()->addons->{$class_name}, self::$_settings[ $addon_name ] ); |
1049 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1049 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1050 | 1050 | } |
1051 | 1051 | } |
1052 | 1052 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -61,23 +61,23 @@ discard block |
||
61 | 61 | * @param string $min_core_version |
62 | 62 | * @return string always like '4.3.0.rc.000' |
63 | 63 | */ |
64 | - protected static function _effective_version( $min_core_version ) { |
|
64 | + protected static function _effective_version($min_core_version) { |
|
65 | 65 | // versions: 4 . 3 . 1 . p . 123 |
66 | 66 | // offsets: 0 . 1 . 2 . 3 . 4 |
67 | - $version_parts = explode( '.', $min_core_version ); |
|
67 | + $version_parts = explode('.', $min_core_version); |
|
68 | 68 | //check they specified the micro version (after 2nd period) |
69 | - if ( ! isset( $version_parts[2] ) ) { |
|
69 | + if ( ! isset($version_parts[2])) { |
|
70 | 70 | $version_parts[2] = '0'; |
71 | 71 | } |
72 | 72 | //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
73 | 73 | //soon we can assume that's 'rc', but this current version is 'alpha' |
74 | - if ( ! isset( $version_parts[3] ) ) { |
|
74 | + if ( ! isset($version_parts[3])) { |
|
75 | 75 | $version_parts[3] = 'dev'; |
76 | 76 | } |
77 | - if ( ! isset( $version_parts[4] ) ) { |
|
77 | + if ( ! isset($version_parts[4])) { |
|
78 | 78 | $version_parts[4] = '000'; |
79 | 79 | } |
80 | - return implode( '.', $version_parts ); |
|
80 | + return implode('.', $version_parts); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | $actual_core_version = EVENT_ESPRESSO_VERSION |
95 | 95 | ) { |
96 | 96 | return version_compare( |
97 | - self::_effective_version( $actual_core_version ), |
|
98 | - self::_effective_version( $min_core_version ), |
|
97 | + self::_effective_version($actual_core_version), |
|
98 | + self::_effective_version($min_core_version), |
|
99 | 99 | '>=' |
100 | 100 | ); |
101 | 101 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @throws EE_Error |
218 | 218 | * @return void |
219 | 219 | */ |
220 | - public static function register( $addon_name = '', $setup_args = array() ) { |
|
220 | + public static function register($addon_name = '', $setup_args = array()) { |
|
221 | 221 | // required fields MUST be present, so let's make sure they are. |
222 | 222 | \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
223 | 223 | // get class name for addon |
@@ -227,13 +227,13 @@ discard block |
||
227 | 227 | // setup PUE |
228 | 228 | \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
229 | 229 | // does this addon work with this version of core or WordPress ? |
230 | - if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) { |
|
230 | + if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
231 | 231 | return; |
232 | 232 | } |
233 | 233 | // register namespaces |
234 | 234 | \EE_Register_Addon::_setup_namespaces($addon_settings); |
235 | 235 | // check if this is an activation request |
236 | - if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
236 | + if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
237 | 237 | // dont bother setting up the rest of the addon atm |
238 | 238 | return; |
239 | 239 | } |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | } else { |
328 | 328 | $class_name = $setup_args['class_name']; |
329 | 329 | } |
330 | - return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
330 | + return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_'.$class_name; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | |
@@ -345,105 +345,105 @@ discard block |
||
345 | 345 | 'class_name' => $class_name, |
346 | 346 | // the addon slug for use in URLs, etc |
347 | 347 | 'plugin_slug' => isset($setup_args['plugin_slug']) |
348 | - ? (string)$setup_args['plugin_slug'] |
|
348 | + ? (string) $setup_args['plugin_slug'] |
|
349 | 349 | : '', |
350 | 350 | // page slug to be used when generating the "Settings" link on the WP plugin page |
351 | 351 | 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
352 | - ? (string)$setup_args['plugin_action_slug'] |
|
352 | + ? (string) $setup_args['plugin_action_slug'] |
|
353 | 353 | : '', |
354 | 354 | // the "software" version for the addon |
355 | 355 | 'version' => isset($setup_args['version']) |
356 | - ? (string)$setup_args['version'] |
|
356 | + ? (string) $setup_args['version'] |
|
357 | 357 | : '', |
358 | 358 | // the minimum version of EE Core that the addon will work with |
359 | 359 | 'min_core_version' => isset($setup_args['min_core_version']) |
360 | - ? (string)$setup_args['min_core_version'] |
|
360 | + ? (string) $setup_args['min_core_version'] |
|
361 | 361 | : '', |
362 | 362 | // the minimum version of WordPress that the addon will work with |
363 | 363 | 'min_wp_version' => isset($setup_args['min_wp_version']) |
364 | - ? (string)$setup_args['min_wp_version'] |
|
364 | + ? (string) $setup_args['min_wp_version'] |
|
365 | 365 | : EE_MIN_WP_VER_REQUIRED, |
366 | 366 | // full server path to main file (file loaded directly by WP) |
367 | 367 | 'main_file_path' => isset($setup_args['main_file_path']) |
368 | - ? (string)$setup_args['main_file_path'] |
|
368 | + ? (string) $setup_args['main_file_path'] |
|
369 | 369 | : '', |
370 | 370 | // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
371 | 371 | 'admin_path' => isset($setup_args['admin_path']) |
372 | - ? (string)$setup_args['admin_path'] : '', |
|
372 | + ? (string) $setup_args['admin_path'] : '', |
|
373 | 373 | // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
374 | 374 | 'admin_callback' => isset($setup_args['admin_callback']) |
375 | - ? (string)$setup_args['admin_callback'] |
|
375 | + ? (string) $setup_args['admin_callback'] |
|
376 | 376 | : '', |
377 | 377 | // the section name for this addon's configuration settings section (defaults to "addons") |
378 | 378 | 'config_section' => isset($setup_args['config_section']) |
379 | - ? (string)$setup_args['config_section'] |
|
379 | + ? (string) $setup_args['config_section'] |
|
380 | 380 | : 'addons', |
381 | 381 | // the class name for this addon's configuration settings object |
382 | 382 | 'config_class' => isset($setup_args['config_class']) |
383 | - ? (string)$setup_args['config_class'] : '', |
|
383 | + ? (string) $setup_args['config_class'] : '', |
|
384 | 384 | //the name given to the config for this addons' configuration settings object (optional) |
385 | 385 | 'config_name' => isset($setup_args['config_name']) |
386 | - ? (string)$setup_args['config_name'] : '', |
|
386 | + ? (string) $setup_args['config_name'] : '', |
|
387 | 387 | // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
388 | 388 | 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
389 | - ? (array)$setup_args['autoloader_paths'] |
|
389 | + ? (array) $setup_args['autoloader_paths'] |
|
390 | 390 | : array(), |
391 | 391 | // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
392 | 392 | 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
393 | - ? (array)$setup_args['autoloader_folders'] |
|
393 | + ? (array) $setup_args['autoloader_folders'] |
|
394 | 394 | : array(), |
395 | 395 | // array of full server paths to any EE_DMS data migration scripts used by the addon |
396 | 396 | 'dms_paths' => isset($setup_args['dms_paths']) |
397 | - ? (array)$setup_args['dms_paths'] |
|
397 | + ? (array) $setup_args['dms_paths'] |
|
398 | 398 | : array(), |
399 | 399 | // array of full server paths to any EED_Modules used by the addon |
400 | 400 | 'module_paths' => isset($setup_args['module_paths']) |
401 | - ? (array)$setup_args['module_paths'] |
|
401 | + ? (array) $setup_args['module_paths'] |
|
402 | 402 | : array(), |
403 | 403 | // array of full server paths to any EES_Shortcodes used by the addon |
404 | 404 | 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
405 | - ? (array)$setup_args['shortcode_paths'] |
|
405 | + ? (array) $setup_args['shortcode_paths'] |
|
406 | 406 | : array(), |
407 | 407 | // array of full server paths to any WP_Widgets used by the addon |
408 | 408 | 'widget_paths' => isset($setup_args['widget_paths']) |
409 | - ? (array)$setup_args['widget_paths'] |
|
409 | + ? (array) $setup_args['widget_paths'] |
|
410 | 410 | : array(), |
411 | 411 | // array of PUE options used by the addon |
412 | 412 | 'pue_options' => isset($setup_args['pue_options']) |
413 | - ? (array)$setup_args['pue_options'] |
|
413 | + ? (array) $setup_args['pue_options'] |
|
414 | 414 | : array(), |
415 | 415 | 'message_types' => isset($setup_args['message_types']) |
416 | - ? (array)$setup_args['message_types'] |
|
416 | + ? (array) $setup_args['message_types'] |
|
417 | 417 | : array(), |
418 | 418 | 'capabilities' => isset($setup_args['capabilities']) |
419 | - ? (array)$setup_args['capabilities'] |
|
419 | + ? (array) $setup_args['capabilities'] |
|
420 | 420 | : array(), |
421 | 421 | 'capability_maps' => isset($setup_args['capability_maps']) |
422 | - ? (array)$setup_args['capability_maps'] |
|
422 | + ? (array) $setup_args['capability_maps'] |
|
423 | 423 | : array(), |
424 | 424 | 'model_paths' => isset($setup_args['model_paths']) |
425 | - ? (array)$setup_args['model_paths'] |
|
425 | + ? (array) $setup_args['model_paths'] |
|
426 | 426 | : array(), |
427 | 427 | 'class_paths' => isset($setup_args['class_paths']) |
428 | - ? (array)$setup_args['class_paths'] |
|
428 | + ? (array) $setup_args['class_paths'] |
|
429 | 429 | : array(), |
430 | 430 | 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
431 | - ? (array)$setup_args['model_extension_paths'] |
|
431 | + ? (array) $setup_args['model_extension_paths'] |
|
432 | 432 | : array(), |
433 | 433 | 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
434 | - ? (array)$setup_args['class_extension_paths'] |
|
434 | + ? (array) $setup_args['class_extension_paths'] |
|
435 | 435 | : array(), |
436 | 436 | 'custom_post_types' => isset($setup_args['custom_post_types']) |
437 | - ? (array)$setup_args['custom_post_types'] |
|
437 | + ? (array) $setup_args['custom_post_types'] |
|
438 | 438 | : array(), |
439 | 439 | 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
440 | - ? (array)$setup_args['custom_taxonomies'] |
|
440 | + ? (array) $setup_args['custom_taxonomies'] |
|
441 | 441 | : array(), |
442 | 442 | 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
443 | - ? (array)$setup_args['payment_method_paths'] |
|
443 | + ? (array) $setup_args['payment_method_paths'] |
|
444 | 444 | : array(), |
445 | 445 | 'default_terms' => isset($setup_args['default_terms']) |
446 | - ? (array)$setup_args['default_terms'] |
|
446 | + ? (array) $setup_args['default_terms'] |
|
447 | 447 | : array(), |
448 | 448 | // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
449 | 449 | // that can be used for adding upgrading/marketing info |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | $setup_args['namespace']['FQNS'], |
456 | 456 | $setup_args['namespace']['DIR'] |
457 | 457 | ) |
458 | - ? (array)$setup_args['namespace'] |
|
458 | + ? (array) $setup_args['namespace'] |
|
459 | 459 | : array(), |
460 | 460 | ); |
461 | 461 | // if plugin_action_slug is NOT set, but an admin page path IS set, |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | * @param array $addon_settings |
477 | 477 | * @return boolean |
478 | 478 | */ |
479 | - private static function _addon_is_compatible( $addon_name, array $addon_settings ) { |
|
479 | + private static function _addon_is_compatible($addon_name, array $addon_settings) { |
|
480 | 480 | global $wp_version; |
481 | 481 | $incompatibility_message = ''; |
482 | 482 | //check whether this addon version is compatible with EE core |
@@ -552,20 +552,20 @@ discard block |
||
552 | 552 | * @param array $setup_args |
553 | 553 | * @return void |
554 | 554 | */ |
555 | - private static function _parse_pue_options( $addon_name, $class_name, array $setup_args ) { |
|
555 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) { |
|
556 | 556 | if ( ! empty($setup_args['pue_options'])) { |
557 | 557 | self::$_settings[$addon_name]['pue_options'] = array( |
558 | 558 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
559 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
560 | - : 'espresso_' . strtolower($class_name), |
|
559 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
560 | + : 'espresso_'.strtolower($class_name), |
|
561 | 561 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
562 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
562 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
563 | 563 | : plugin_basename($setup_args['main_file_path']), |
564 | 564 | 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
565 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
565 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
566 | 566 | : '24', |
567 | 567 | 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
568 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
568 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
569 | 569 | : false, |
570 | 570 | ); |
571 | 571 | add_action( |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | * @param array $addon_settings |
608 | 608 | * @return bool |
609 | 609 | */ |
610 | - private static function _addon_activation( $addon_name, array $addon_settings ) { |
|
610 | + private static function _addon_activation($addon_name, array $addon_settings) { |
|
611 | 611 | // this is an activation request |
612 | 612 | if (did_action('activate_plugin')) { |
613 | 613 | //to find if THIS is the addon that was activated, |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | } |
665 | 665 | // setup autoloaders for folders |
666 | 666 | if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
667 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
667 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
668 | 668 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
669 | 669 | } |
670 | 670 | } |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | * @return void |
680 | 680 | * @throws \EE_Error |
681 | 681 | */ |
682 | - private static function _register_models_and_extensions( $addon_name ) { |
|
682 | + private static function _register_models_and_extensions($addon_name) { |
|
683 | 683 | // register new models |
684 | 684 | if ( |
685 | 685 | ! empty(self::$_settings[$addon_name]['model_paths']) |
@@ -715,7 +715,7 @@ discard block |
||
715 | 715 | * @return void |
716 | 716 | * @throws \EE_Error |
717 | 717 | */ |
718 | - private static function _register_data_migration_scripts( $addon_name ) { |
|
718 | + private static function _register_data_migration_scripts($addon_name) { |
|
719 | 719 | // setup DMS |
720 | 720 | if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
721 | 721 | EE_Register_Data_Migration_Scripts::register( |
@@ -731,7 +731,7 @@ discard block |
||
731 | 731 | * @return void |
732 | 732 | * @throws \EE_Error |
733 | 733 | */ |
734 | - private static function _register_config( $addon_name ) { |
|
734 | + private static function _register_config($addon_name) { |
|
735 | 735 | // if config_class is present let's register config. |
736 | 736 | if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
737 | 737 | EE_Register_Config::register( |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | * @return void |
751 | 751 | * @throws \EE_Error |
752 | 752 | */ |
753 | - private static function _register_admin_pages( $addon_name ) { |
|
753 | + private static function _register_admin_pages($addon_name) { |
|
754 | 754 | if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
755 | 755 | EE_Register_Admin_Page::register( |
756 | 756 | $addon_name, |
@@ -765,7 +765,7 @@ discard block |
||
765 | 765 | * @return void |
766 | 766 | * @throws \EE_Error |
767 | 767 | */ |
768 | - private static function _register_modules( $addon_name ) { |
|
768 | + private static function _register_modules($addon_name) { |
|
769 | 769 | if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
770 | 770 | EE_Register_Module::register( |
771 | 771 | $addon_name, |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | * @return void |
781 | 781 | * @throws \EE_Error |
782 | 782 | */ |
783 | - private static function _register_shortcodes( $addon_name ) { |
|
783 | + private static function _register_shortcodes($addon_name) { |
|
784 | 784 | if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
785 | 785 | EE_Register_Shortcode::register( |
786 | 786 | $addon_name, |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | * @return void |
796 | 796 | * @throws \EE_Error |
797 | 797 | */ |
798 | - private static function _register_widgets( $addon_name ) { |
|
798 | + private static function _register_widgets($addon_name) { |
|
799 | 799 | if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
800 | 800 | EE_Register_Widget::register( |
801 | 801 | $addon_name, |
@@ -810,7 +810,7 @@ discard block |
||
810 | 810 | * @return void |
811 | 811 | * @throws \EE_Error |
812 | 812 | */ |
813 | - private static function _register_capabilities( $addon_name ) { |
|
813 | + private static function _register_capabilities($addon_name) { |
|
814 | 814 | if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
815 | 815 | EE_Register_Capabilities::register( |
816 | 816 | $addon_name, |
@@ -828,7 +828,7 @@ discard block |
||
828 | 828 | * @return void |
829 | 829 | * @throws \EE_Error |
830 | 830 | */ |
831 | - private static function _register_message_types( $addon_name ) { |
|
831 | + private static function _register_message_types($addon_name) { |
|
832 | 832 | if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
833 | 833 | add_action( |
834 | 834 | 'EE_Brewing_Regular___messages_caf', |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | * @return void |
844 | 844 | * @throws \EE_Error |
845 | 845 | */ |
846 | - private static function _register_custom_post_types( $addon_name ) { |
|
846 | + private static function _register_custom_post_types($addon_name) { |
|
847 | 847 | if ( |
848 | 848 | ! empty(self::$_settings[$addon_name]['custom_post_types']) |
849 | 849 | || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | * @return void |
866 | 866 | * @throws \EE_Error |
867 | 867 | */ |
868 | - private static function _register_payment_methods( $addon_name ) { |
|
868 | + private static function _register_payment_methods($addon_name) { |
|
869 | 869 | if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
870 | 870 | EE_Register_Payment_Method::register( |
871 | 871 | $addon_name, |
@@ -882,25 +882,25 @@ discard block |
||
882 | 882 | * @param string $addon_name |
883 | 883 | * @return EE_Addon |
884 | 884 | */ |
885 | - private static function _load_and_init_addon_class( $addon_name ) { |
|
885 | + private static function _load_and_init_addon_class($addon_name) { |
|
886 | 886 | $addon = EE_Registry::instance()->load_addon( |
887 | - dirname( self::$_settings[ $addon_name ]['main_file_path'] ), |
|
888 | - self::$_settings[ $addon_name ]['class_name'] |
|
887 | + dirname(self::$_settings[$addon_name]['main_file_path']), |
|
888 | + self::$_settings[$addon_name]['class_name'] |
|
889 | 889 | ); |
890 | - $addon->set_name( $addon_name ); |
|
891 | - $addon->set_plugin_slug( self::$_settings[ $addon_name ]['plugin_slug'] ); |
|
892 | - $addon->set_plugin_basename( self::$_settings[ $addon_name ]['plugin_basename'] ); |
|
893 | - $addon->set_main_plugin_file( self::$_settings[ $addon_name ]['main_file_path'] ); |
|
894 | - $addon->set_plugin_action_slug( self::$_settings[ $addon_name ]['plugin_action_slug'] ); |
|
895 | - $addon->set_plugins_page_row( self::$_settings[ $addon_name ]['plugins_page_row'] ); |
|
896 | - $addon->set_version( self::$_settings[ $addon_name ]['version'] ); |
|
897 | - $addon->set_min_core_version( self::_effective_version( self::$_settings[ $addon_name ]['min_core_version'] ) ); |
|
898 | - $addon->set_config_section( self::$_settings[ $addon_name ]['config_section'] ); |
|
899 | - $addon->set_config_class( self::$_settings[ $addon_name ]['config_class'] ); |
|
900 | - $addon->set_config_name( self::$_settings[ $addon_name ]['config_name'] ); |
|
890 | + $addon->set_name($addon_name); |
|
891 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
892 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
893 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
894 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
895 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
896 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
897 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
898 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
899 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
900 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
901 | 901 | //unfortunately this can't be hooked in upon construction, because we don't have |
902 | 902 | //the plugin mainfile's path upon construction. |
903 | - register_deactivation_hook( $addon->get_main_plugin_file(), array( $addon, 'deactivation' ) ); |
|
903 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
904 | 904 | // call any additional admin_callback functions during load_admin_controller hook |
905 | 905 | if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
906 | 906 | add_action( |
@@ -920,18 +920,18 @@ discard block |
||
920 | 920 | */ |
921 | 921 | public static function load_pue_update() { |
922 | 922 | // load PUE client |
923 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
923 | + require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php'; |
|
924 | 924 | // cycle thru settings |
925 | - foreach ( self::$_settings as $settings ) { |
|
926 | - if ( ! empty( $settings['pue_options'] ) ) { |
|
925 | + foreach (self::$_settings as $settings) { |
|
926 | + if ( ! empty($settings['pue_options'])) { |
|
927 | 927 | // initiate the class and start the plugin update engine! |
928 | 928 | new PluginUpdateEngineChecker( |
929 | 929 | // host file URL |
930 | 930 | 'https://eventespresso.com', |
931 | 931 | // plugin slug(s) |
932 | 932 | array( |
933 | - 'premium' => array( 'p' => $settings['pue_options']['pue_plugin_slug'] ), |
|
934 | - 'prerelease' => array( 'beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr' ), |
|
933 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
934 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
935 | 935 | ), |
936 | 936 | // options |
937 | 937 | array( |
@@ -959,9 +959,9 @@ discard block |
||
959 | 959 | * @throws \EE_Error |
960 | 960 | */ |
961 | 961 | public static function register_message_types() { |
962 | - foreach ( self::$_settings as $addon_name => $settings ) { |
|
962 | + foreach (self::$_settings as $addon_name => $settings) { |
|
963 | 963 | if ( ! empty($settings['message_types'])) { |
964 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
964 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
965 | 965 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
966 | 966 | } |
967 | 967 | } |
@@ -978,74 +978,74 @@ discard block |
||
978 | 978 | * @throws EE_Error |
979 | 979 | * @return void |
980 | 980 | */ |
981 | - public static function deregister( $addon_name = null ) { |
|
982 | - if ( isset( self::$_settings[ $addon_name ], self::$_settings[$addon_name]['class_name'] ) ) { |
|
981 | + public static function deregister($addon_name = null) { |
|
982 | + if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) { |
|
983 | 983 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
984 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
985 | - if ( ! empty( self::$_settings[ $addon_name ]['dms_paths'] ) ) { |
|
984 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
985 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
986 | 986 | // setup DMS |
987 | - EE_Register_Data_Migration_Scripts::deregister( $addon_name ); |
|
987 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
988 | 988 | } |
989 | - if ( ! empty( self::$_settings[ $addon_name ]['admin_path'] ) ) { |
|
989 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
990 | 990 | // register admin page |
991 | - EE_Register_Admin_Page::deregister( $addon_name ); |
|
991 | + EE_Register_Admin_Page::deregister($addon_name); |
|
992 | 992 | } |
993 | - if ( ! empty( self::$_settings[ $addon_name ]['module_paths'] ) ) { |
|
993 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
994 | 994 | // add to list of modules to be registered |
995 | - EE_Register_Module::deregister( $addon_name ); |
|
995 | + EE_Register_Module::deregister($addon_name); |
|
996 | 996 | } |
997 | - if ( ! empty( self::$_settings[ $addon_name ]['shortcode_paths'] ) ) { |
|
997 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
998 | 998 | // add to list of shortcodes to be registered |
999 | - EE_Register_Shortcode::deregister( $addon_name ); |
|
999 | + EE_Register_Shortcode::deregister($addon_name); |
|
1000 | 1000 | } |
1001 | - if ( ! empty( self::$_settings[ $addon_name ]['config_class'] ) ) { |
|
1001 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1002 | 1002 | // if config_class present let's register config. |
1003 | - EE_Register_Config::deregister( self::$_settings[ $addon_name ]['config_class'] ); |
|
1003 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
1004 | 1004 | } |
1005 | - if ( ! empty( self::$_settings[ $addon_name ]['widget_paths'] ) ) { |
|
1005 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1006 | 1006 | // add to list of widgets to be registered |
1007 | - EE_Register_Widget::deregister( $addon_name ); |
|
1007 | + EE_Register_Widget::deregister($addon_name); |
|
1008 | 1008 | } |
1009 | - if ( ! empty( self::$_settings[ $addon_name ]['model_paths'] ) |
|
1009 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
1010 | 1010 | || |
1011 | - ! empty( self::$_settings[ $addon_name ]['class_paths'] ) |
|
1011 | + ! empty(self::$_settings[$addon_name]['class_paths']) |
|
1012 | 1012 | ) { |
1013 | 1013 | // add to list of shortcodes to be registered |
1014 | - EE_Register_Model::deregister( $addon_name ); |
|
1014 | + EE_Register_Model::deregister($addon_name); |
|
1015 | 1015 | } |
1016 | - if ( ! empty( self::$_settings[ $addon_name ]['model_extension_paths'] ) |
|
1016 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1017 | 1017 | || |
1018 | - ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] ) |
|
1018 | + ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
1019 | 1019 | ) { |
1020 | 1020 | // add to list of shortcodes to be registered |
1021 | - EE_Register_Model_Extensions::deregister( $addon_name ); |
|
1021 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
1022 | 1022 | } |
1023 | - if ( ! empty( self::$_settings[ $addon_name ]['message_types'] ) ) { |
|
1024 | - foreach ((array)self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings ) |
|
1023 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1024 | + foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) |
|
1025 | 1025 | { |
1026 | - EE_Register_Message_Type::deregister( $message_type ); |
|
1026 | + EE_Register_Message_Type::deregister($message_type); |
|
1027 | 1027 | } |
1028 | 1028 | } |
1029 | 1029 | //deregister capabilities for addon |
1030 | 1030 | if ( |
1031 | - ! empty( self::$_settings[ $addon_name ]['capabilities'] ) |
|
1032 | - || ! empty( self::$_settings[ $addon_name ]['capability_maps'] ) |
|
1031 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
1032 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
1033 | 1033 | ) { |
1034 | - EE_Register_Capabilities::deregister( $addon_name ); |
|
1034 | + EE_Register_Capabilities::deregister($addon_name); |
|
1035 | 1035 | } |
1036 | 1036 | //deregister custom_post_types for addon |
1037 | - if ( ! empty( self::$_settings[ $addon_name ]['custom_post_types'] ) ) { |
|
1038 | - EE_Register_CPT::deregister( $addon_name ); |
|
1037 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1038 | + EE_Register_CPT::deregister($addon_name); |
|
1039 | 1039 | } |
1040 | 1040 | remove_action( |
1041 | - 'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
1042 | - array( EE_Registry::instance()->addons->{$class_name}, 'deactivation' ) |
|
1041 | + 'deactivate_'.EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
1042 | + array(EE_Registry::instance()->addons->{$class_name}, 'deactivation') |
|
1043 | 1043 | ); |
1044 | 1044 | remove_action( |
1045 | 1045 | 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
1046 | - array( EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required' ) |
|
1046 | + array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required') |
|
1047 | 1047 | ); |
1048 | - unset( EE_Registry::instance()->addons->{$class_name}, self::$_settings[ $addon_name ] ); |
|
1048 | + unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]); |
|
1049 | 1049 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
1050 | 1050 | } |
1051 | 1051 | } |