@@ -3,79 +3,79 @@ |
||
3 | 3 | </p> |
4 | 4 | <p> |
5 | 5 | <?php esc_html_e( |
6 | - 'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab. When you click one of those tabs it will display that messenger.', |
|
7 | - 'event_espresso' |
|
8 | - ); ?> |
|
6 | + 'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab. When you click one of those tabs it will display that messenger.', |
|
7 | + 'event_espresso' |
|
8 | + ); ?> |
|
9 | 9 | </p> |
10 | 10 | <p> |
11 | 11 | <?php esc_html_e( |
12 | - 'There are two ways to determine whether a messenger is active or not. The first way is via the messenger tab itself.', |
|
13 | - 'event_espresso' |
|
14 | - ); ?> |
|
12 | + 'There are two ways to determine whether a messenger is active or not. The first way is via the messenger tab itself.', |
|
13 | + 'event_espresso' |
|
14 | + ); ?> |
|
15 | 15 | </p> |
16 | 16 | <p> |
17 | 17 | <?php printf( |
18 | - esc_html__( |
|
19 | - 'The green colored gear %s indicates that this messenger is currently active.', |
|
20 | - 'event_espresso' |
|
21 | - ), |
|
22 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"' |
|
23 | - . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />' |
|
24 | - ); |
|
25 | - printf( |
|
26 | - esc_html__( |
|
27 | - ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.', |
|
28 | - 'event_espresso' |
|
29 | - ), |
|
30 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
31 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />' |
|
32 | - ); ?> |
|
18 | + esc_html__( |
|
19 | + 'The green colored gear %s indicates that this messenger is currently active.', |
|
20 | + 'event_espresso' |
|
21 | + ), |
|
22 | + '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"' |
|
23 | + . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />' |
|
24 | + ); |
|
25 | + printf( |
|
26 | + esc_html__( |
|
27 | + ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.', |
|
28 | + 'event_espresso' |
|
29 | + ), |
|
30 | + '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
31 | + . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />' |
|
32 | + ); ?> |
|
33 | 33 | </p> |
34 | 34 | <p> |
35 | 35 | <?php esc_html_e( |
36 | - 'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:', |
|
37 | - 'event_espresso' |
|
38 | - ); ?> |
|
36 | + 'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:', |
|
37 | + 'event_espresso' |
|
38 | + ); ?> |
|
39 | 39 | </p> |
40 | 40 | <p> |
41 | 41 | <?php printf( |
42 | - esc_html__( |
|
43 | - '%1$s means of course that the messenger is active and %2$s means the messenger is inactive.', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - '<div class="switch">' |
|
47 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>' |
|
48 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
49 | - . '</div>', |
|
50 | - '<div class="switch">' |
|
51 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>' |
|
52 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
53 | - . '</div>' |
|
54 | - ); ?> |
|
42 | + esc_html__( |
|
43 | + '%1$s means of course that the messenger is active and %2$s means the messenger is inactive.', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + '<div class="switch">' |
|
47 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>' |
|
48 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
49 | + . '</div>', |
|
50 | + '<div class="switch">' |
|
51 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>' |
|
52 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
53 | + . '</div>' |
|
54 | + ); ?> |
|
55 | 55 | </p> |
56 | 56 | <p> |
57 | 57 | <?php |
58 | - esc_html_e( |
|
59 | - 'The on/off toggle is also what you use to activate or deactivate a messenger.', |
|
60 | - 'event_espresso' |
|
61 | - ); ?> |
|
58 | + esc_html_e( |
|
59 | + 'The on/off toggle is also what you use to activate or deactivate a messenger.', |
|
60 | + 'event_espresso' |
|
61 | + ); ?> |
|
62 | 62 | </p> |
63 | 63 | <p> |
64 | 64 | <?php esc_html_e( |
65 | - 'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger. Then, if there are any default settings for either the messenger or message types those settings are saved. Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated). Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.', |
|
66 | - 'event_espresso' |
|
67 | - ); ?> |
|
65 | + 'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger. Then, if there are any default settings for either the messenger or message types those settings are saved. Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated). Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.', |
|
66 | + 'event_espresso' |
|
67 | + ); ?> |
|
68 | 68 | </p> |
69 | 69 | <p> |
70 | 70 | <?php esc_html_e( |
71 | - 'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate. If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.', |
|
72 | - 'event_espresso' |
|
73 | - ); ?> |
|
71 | + 'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate. If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.', |
|
72 | + 'event_espresso' |
|
73 | + ); ?> |
|
74 | 74 | </p> |
75 | 75 | <p> |
76 | 76 | <strong><?php esc_html_e('Important', 'event_espresso'); ?></strong><br/> |
77 | 77 | <?php esc_html_e( |
78 | - 'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation. Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.', |
|
79 | - 'event_espresso' |
|
80 | - ); ?> |
|
78 | + 'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation. Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.', |
|
79 | + 'event_espresso' |
|
80 | + ); ?> |
|
81 | 81 | </p> |
@@ -19,16 +19,16 @@ |
||
19 | 19 | 'The green colored gear %s indicates that this messenger is currently active.', |
20 | 20 | 'event_espresso' |
21 | 21 | ), |
22 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"' |
|
23 | - . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />' |
|
22 | + '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'"' |
|
23 | + . ' alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />' |
|
24 | 24 | ); |
25 | 25 | printf( |
26 | 26 | esc_html__( |
27 | 27 | ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.', |
28 | 28 | 'event_espresso' |
29 | 29 | ), |
30 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
31 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />' |
|
30 | + '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png' |
|
31 | + . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />' |
|
32 | 32 | ); ?> |
33 | 33 | </p> |
34 | 34 | <p> |
@@ -176,7 +176,7 @@ |
||
176 | 176 | /** |
177 | 177 | * This retrieves the EE_Venue from the available data object. |
178 | 178 | * |
179 | - * @return EE_Venue|null |
|
179 | + * @return EE_Base_Class|null |
|
180 | 180 | * @throws EE_Error |
181 | 181 | * @throws EntityNotFoundException |
182 | 182 | */ |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | { |
91 | 91 | $this->_venue = $this->_get_venue(); |
92 | 92 | //If there is no venue object by now then get out. |
93 | - if (! $this->_venue instanceof EE_Venue) { |
|
93 | + if ( ! $this->_venue instanceof EE_Venue) { |
|
94 | 94 | return ''; |
95 | 95 | } |
96 | 96 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | //if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
190 | 190 | // reg_obj instead. |
191 | - if (! $this->_event instanceof EE_Event) { |
|
191 | + if ( ! $this->_event instanceof EE_Event) { |
|
192 | 192 | $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
193 | 193 | $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
194 | 194 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | |
206 | 206 | //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
207 | 207 | // and use that. |
208 | - $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee |
|
208 | + $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee |
|
209 | 209 | ? reset($aee->events) |
210 | 210 | : $this->_event; |
211 | 211 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | private function _venue($field) |
230 | 230 | { |
231 | 231 | |
232 | - if (! $this->_venue instanceof EE_Venue) { |
|
232 | + if ( ! $this->_venue instanceof EE_Venue) { |
|
233 | 233 | return ''; |
234 | 234 | } //no venue so get out. |
235 | 235 | |
@@ -252,11 +252,11 @@ discard block |
||
252 | 252 | break; |
253 | 253 | |
254 | 254 | case 'image': |
255 | - return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
256 | - . '" alt="' . sprintf( |
|
255 | + return '<img src="'.$this->_venue->feature_image_url(array(200, 200,)) |
|
256 | + . '" alt="'.sprintf( |
|
257 | 257 | esc_attr__('%s Feature Image', 'event_espresso'), |
258 | 258 | $this->_venue->get('VNU_name') |
259 | - ) . '" />'; |
|
259 | + ).'" />'; |
|
260 | 260 | break; |
261 | 261 | |
262 | 262 | case 'phone': |
@@ -19,317 +19,317 @@ |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * Will hold the EE_Event if available |
|
24 | - * |
|
25 | - * @var EE_Event |
|
26 | - */ |
|
27 | - protected $_event; |
|
28 | - |
|
29 | - /** |
|
30 | - * Will hold the EE_Venue if available |
|
31 | - * |
|
32 | - * @var EE_Venue |
|
33 | - */ |
|
34 | - protected $_venue; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * Initialize properties |
|
39 | - */ |
|
40 | - protected function _init_props() |
|
41 | - { |
|
42 | - $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
43 | - $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
44 | - $this->_shortcodes = array( |
|
45 | - '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
46 | - '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
47 | - '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
48 | - '[VENUE_DETAILS_URL]' => sprintf( |
|
49 | - esc_html__( |
|
50 | - 'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.', |
|
51 | - 'event_espresso' |
|
52 | - ), |
|
53 | - '[VENUE_URL]' |
|
54 | - ), |
|
55 | - '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
56 | - '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
57 | - '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
58 | - '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
59 | - '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
60 | - '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
61 | - '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
62 | - '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
63 | - 'This just outputs the venue address in a semantic address format.', |
|
64 | - 'event_espresso' |
|
65 | - ), |
|
66 | - '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
67 | - '[VENUE_META_*]' => esc_html__( |
|
68 | - 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', |
|
69 | - 'event_espresso' |
|
70 | - ), |
|
71 | - '[GOOGLE_MAP_URL]' => esc_html__( |
|
72 | - 'URL for the google map associated with the venue.', |
|
73 | - 'event_espresso' |
|
74 | - ), |
|
75 | - '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
76 | - '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
77 | - ); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * Parse incoming shortcode |
|
83 | - * |
|
84 | - * @param string $shortcode |
|
85 | - * @return string |
|
86 | - * @throws EE_Error |
|
87 | - * @throws EntityNotFoundException |
|
88 | - */ |
|
89 | - protected function _parser($shortcode) |
|
90 | - { |
|
91 | - $this->_venue = $this->_get_venue(); |
|
92 | - //If there is no venue object by now then get out. |
|
93 | - if (! $this->_venue instanceof EE_Venue) { |
|
94 | - return ''; |
|
95 | - } |
|
96 | - |
|
97 | - switch ($shortcode) { |
|
98 | - case '[VENUE_TITLE]': |
|
99 | - return $this->_venue('title'); |
|
100 | - break; |
|
101 | - |
|
102 | - case '[VENUE_DESCRIPTION]': |
|
103 | - return $this->_venue('description'); |
|
104 | - break; |
|
105 | - |
|
106 | - case '[VENUE_URL]': |
|
107 | - return $this->_venue('url'); |
|
108 | - break; |
|
109 | - |
|
110 | - case '[VENUE_IMAGE]': |
|
111 | - return $this->_venue('image'); |
|
112 | - break; |
|
113 | - |
|
114 | - case '[VENUE_PHONE]': |
|
115 | - return $this->_venue('phone'); |
|
116 | - break; |
|
117 | - |
|
118 | - case '[VENUE_ADDRESS]': |
|
119 | - return $this->_venue('address'); |
|
120 | - break; |
|
121 | - |
|
122 | - case '[VENUE_ADDRESS2]': |
|
123 | - return $this->_venue('address2'); |
|
124 | - break; |
|
125 | - |
|
126 | - case '[VENUE_CITY]': |
|
127 | - return $this->_venue('city'); |
|
128 | - break; |
|
129 | - |
|
130 | - case '[VENUE_COUNTRY]': |
|
131 | - return $this->_venue('country'); |
|
132 | - break; |
|
133 | - |
|
134 | - case '[VENUE_STATE]': |
|
135 | - return $this->_venue('state'); |
|
136 | - break; |
|
137 | - |
|
138 | - case '[VENUE_ZIP]': |
|
139 | - return $this->_venue('zip'); |
|
140 | - break; |
|
141 | - |
|
142 | - case '[VENUE_FORMATTED_ADDRESS]': |
|
143 | - return $this->_venue('formatted_address'); |
|
144 | - break; |
|
145 | - |
|
146 | - case '[GOOGLE_MAP_URL]': |
|
147 | - return $this->_venue('gmap_url'); |
|
148 | - break; |
|
149 | - |
|
150 | - case '[GOOGLE_MAP_LINK]': |
|
151 | - return $this->_venue('gmap_link'); |
|
152 | - break; |
|
153 | - |
|
154 | - case '[GOOGLE_MAP_IMAGE]': |
|
155 | - return $this->_venue('gmap_link_img'); |
|
156 | - break; |
|
157 | - |
|
158 | - case '[VENUE_DETAILS_URL]': |
|
159 | - return $this->_venue('permalink'); |
|
160 | - break; |
|
161 | - |
|
162 | - } |
|
163 | - |
|
164 | - if (strpos($shortcode, '[VENUE_META_*') !== false) { |
|
165 | - $shortcode = str_replace('[VENUE_META_*', '', $shortcode); |
|
166 | - $shortcode = trim(str_replace(']', '', $shortcode)); |
|
167 | - |
|
168 | - //pull the meta value from the venue post |
|
169 | - $venue_meta = $this->_venue->get_post_meta($shortcode, true); |
|
170 | - |
|
171 | - return ! empty($venue_meta) ? $venue_meta : ''; |
|
172 | - |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * This retrieves the EE_Venue from the available data object. |
|
178 | - * |
|
179 | - * @return EE_Venue|null |
|
180 | - * @throws EE_Error |
|
181 | - * @throws EntityNotFoundException |
|
182 | - */ |
|
183 | - private function _get_venue() |
|
184 | - { |
|
185 | - |
|
186 | - //we need the EE_Event object to get the venue. |
|
187 | - $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
188 | - |
|
189 | - //if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
|
190 | - // reg_obj instead. |
|
191 | - if (! $this->_event instanceof EE_Event) { |
|
192 | - $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
193 | - $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
194 | - |
|
195 | - $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
196 | - ? $aee->reg_obj->event() |
|
197 | - : null; |
|
198 | - |
|
199 | - //if still empty do we have a ticket data item? |
|
200 | - $this->_event = ! $this->_event instanceof EE_Event |
|
201 | - && $this->_data instanceof EE_Ticket |
|
202 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
203 | - ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event'] |
|
204 | - : $this->_event; |
|
205 | - |
|
206 | - //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
|
207 | - // and use that. |
|
208 | - $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee |
|
209 | - ? reset($aee->events) |
|
210 | - : $this->_event; |
|
211 | - } |
|
212 | - |
|
213 | - //If we have an event object use it to pull the venue. |
|
214 | - if ($this->_event instanceof EE_Event) { |
|
215 | - return $this->_event->get_first_related('Venue'); |
|
216 | - } |
|
217 | - |
|
218 | - return null; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * This retrieves the specified venue information |
|
223 | - * |
|
224 | - * @param string $field What Venue field to retrieve |
|
225 | - * @return string What was retrieved! |
|
226 | - * @throws EE_Error |
|
227 | - * @throws EntityNotFoundException |
|
228 | - */ |
|
229 | - private function _venue($field) |
|
230 | - { |
|
231 | - |
|
232 | - if (! $this->_venue instanceof EE_Venue) { |
|
233 | - return ''; |
|
234 | - } //no venue so get out. |
|
235 | - |
|
236 | - switch ($field) { |
|
237 | - case 'title': |
|
238 | - return $this->_venue->get('VNU_name'); |
|
239 | - break; |
|
240 | - |
|
241 | - case 'description': |
|
242 | - return $this->_venue->get('VNU_desc'); |
|
243 | - break; |
|
244 | - |
|
245 | - case 'url': |
|
246 | - $url = $this->_venue->get('VNU_url'); |
|
247 | - return empty($url) ? $this->_venue->get_permalink() : $url; |
|
248 | - break; |
|
249 | - |
|
250 | - case 'permalink': |
|
251 | - return $this->_venue->get_permalink(); |
|
252 | - break; |
|
253 | - |
|
254 | - case 'image': |
|
255 | - return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
256 | - . '" alt="' . sprintf( |
|
257 | - esc_attr__('%s Feature Image', 'event_espresso'), |
|
258 | - $this->_venue->get('VNU_name') |
|
259 | - ) . '" />'; |
|
260 | - break; |
|
261 | - |
|
262 | - case 'phone': |
|
263 | - return $this->_venue->get('VNU_phone'); |
|
264 | - break; |
|
265 | - |
|
266 | - case 'address': |
|
267 | - return $this->_venue->get('VNU_address'); |
|
268 | - break; |
|
269 | - |
|
270 | - case 'address2': |
|
271 | - return $this->_venue->get('VNU_address2'); |
|
272 | - break; |
|
273 | - |
|
274 | - case 'city': |
|
275 | - return $this->_venue->get('VNU_city'); |
|
276 | - break; |
|
277 | - |
|
278 | - case 'state': |
|
279 | - $state = $this->_venue->state_obj(); |
|
280 | - return is_object($state) ? $state->get('STA_name') : ''; |
|
281 | - break; |
|
282 | - |
|
283 | - case 'country': |
|
284 | - $country = $this->_venue->country_obj(); |
|
285 | - return is_object($country) ? $country->get('CNT_name') : ''; |
|
286 | - break; |
|
287 | - |
|
288 | - case 'zip': |
|
289 | - return $this->_venue->get('VNU_zip'); |
|
290 | - break; |
|
291 | - |
|
292 | - case 'formatted_address': |
|
293 | - return EEH_Address::format($this->_venue); |
|
294 | - break; |
|
295 | - |
|
296 | - case 'gmap_link': |
|
297 | - case 'gmap_url': |
|
298 | - case 'gmap_link_img': |
|
299 | - $atts = $this->get_map_attributes($this->_venue, $field); |
|
300 | - return EEH_Maps::google_map_link($atts); |
|
301 | - break; |
|
302 | - } |
|
303 | - return ''; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * Generates the attributes for retrieving a google_map artifact. |
|
309 | - * |
|
310 | - * @param EE_Venue $venue |
|
311 | - * @param string $field |
|
312 | - * @return array |
|
313 | - * @throws EE_Error |
|
314 | - */ |
|
315 | - protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
316 | - { |
|
317 | - $state = $venue->state_obj(); |
|
318 | - $country = $venue->country_obj(); |
|
319 | - $atts = array( |
|
320 | - 'id' => $venue->ID(), |
|
321 | - 'address' => $venue->get('VNU_address'), |
|
322 | - 'city' => $venue->get('VNU_city'), |
|
323 | - 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
324 | - 'zip' => $venue->get('VNU_zip'), |
|
325 | - 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
326 | - 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
327 | - 'map_w' => 200, |
|
328 | - 'map_h' => 200, |
|
329 | - ); |
|
330 | - if ($field === 'gmap_url') { |
|
331 | - $atts['type'] = 'url_only'; |
|
332 | - } |
|
333 | - return $atts; |
|
334 | - } |
|
22 | + /** |
|
23 | + * Will hold the EE_Event if available |
|
24 | + * |
|
25 | + * @var EE_Event |
|
26 | + */ |
|
27 | + protected $_event; |
|
28 | + |
|
29 | + /** |
|
30 | + * Will hold the EE_Venue if available |
|
31 | + * |
|
32 | + * @var EE_Venue |
|
33 | + */ |
|
34 | + protected $_venue; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * Initialize properties |
|
39 | + */ |
|
40 | + protected function _init_props() |
|
41 | + { |
|
42 | + $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
43 | + $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
44 | + $this->_shortcodes = array( |
|
45 | + '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
46 | + '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
47 | + '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
48 | + '[VENUE_DETAILS_URL]' => sprintf( |
|
49 | + esc_html__( |
|
50 | + 'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.', |
|
51 | + 'event_espresso' |
|
52 | + ), |
|
53 | + '[VENUE_URL]' |
|
54 | + ), |
|
55 | + '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
56 | + '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
57 | + '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
58 | + '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
59 | + '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
60 | + '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
61 | + '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
62 | + '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
63 | + 'This just outputs the venue address in a semantic address format.', |
|
64 | + 'event_espresso' |
|
65 | + ), |
|
66 | + '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
67 | + '[VENUE_META_*]' => esc_html__( |
|
68 | + 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', |
|
69 | + 'event_espresso' |
|
70 | + ), |
|
71 | + '[GOOGLE_MAP_URL]' => esc_html__( |
|
72 | + 'URL for the google map associated with the venue.', |
|
73 | + 'event_espresso' |
|
74 | + ), |
|
75 | + '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
76 | + '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
77 | + ); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * Parse incoming shortcode |
|
83 | + * |
|
84 | + * @param string $shortcode |
|
85 | + * @return string |
|
86 | + * @throws EE_Error |
|
87 | + * @throws EntityNotFoundException |
|
88 | + */ |
|
89 | + protected function _parser($shortcode) |
|
90 | + { |
|
91 | + $this->_venue = $this->_get_venue(); |
|
92 | + //If there is no venue object by now then get out. |
|
93 | + if (! $this->_venue instanceof EE_Venue) { |
|
94 | + return ''; |
|
95 | + } |
|
96 | + |
|
97 | + switch ($shortcode) { |
|
98 | + case '[VENUE_TITLE]': |
|
99 | + return $this->_venue('title'); |
|
100 | + break; |
|
101 | + |
|
102 | + case '[VENUE_DESCRIPTION]': |
|
103 | + return $this->_venue('description'); |
|
104 | + break; |
|
105 | + |
|
106 | + case '[VENUE_URL]': |
|
107 | + return $this->_venue('url'); |
|
108 | + break; |
|
109 | + |
|
110 | + case '[VENUE_IMAGE]': |
|
111 | + return $this->_venue('image'); |
|
112 | + break; |
|
113 | + |
|
114 | + case '[VENUE_PHONE]': |
|
115 | + return $this->_venue('phone'); |
|
116 | + break; |
|
117 | + |
|
118 | + case '[VENUE_ADDRESS]': |
|
119 | + return $this->_venue('address'); |
|
120 | + break; |
|
121 | + |
|
122 | + case '[VENUE_ADDRESS2]': |
|
123 | + return $this->_venue('address2'); |
|
124 | + break; |
|
125 | + |
|
126 | + case '[VENUE_CITY]': |
|
127 | + return $this->_venue('city'); |
|
128 | + break; |
|
129 | + |
|
130 | + case '[VENUE_COUNTRY]': |
|
131 | + return $this->_venue('country'); |
|
132 | + break; |
|
133 | + |
|
134 | + case '[VENUE_STATE]': |
|
135 | + return $this->_venue('state'); |
|
136 | + break; |
|
137 | + |
|
138 | + case '[VENUE_ZIP]': |
|
139 | + return $this->_venue('zip'); |
|
140 | + break; |
|
141 | + |
|
142 | + case '[VENUE_FORMATTED_ADDRESS]': |
|
143 | + return $this->_venue('formatted_address'); |
|
144 | + break; |
|
145 | + |
|
146 | + case '[GOOGLE_MAP_URL]': |
|
147 | + return $this->_venue('gmap_url'); |
|
148 | + break; |
|
149 | + |
|
150 | + case '[GOOGLE_MAP_LINK]': |
|
151 | + return $this->_venue('gmap_link'); |
|
152 | + break; |
|
153 | + |
|
154 | + case '[GOOGLE_MAP_IMAGE]': |
|
155 | + return $this->_venue('gmap_link_img'); |
|
156 | + break; |
|
157 | + |
|
158 | + case '[VENUE_DETAILS_URL]': |
|
159 | + return $this->_venue('permalink'); |
|
160 | + break; |
|
161 | + |
|
162 | + } |
|
163 | + |
|
164 | + if (strpos($shortcode, '[VENUE_META_*') !== false) { |
|
165 | + $shortcode = str_replace('[VENUE_META_*', '', $shortcode); |
|
166 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
167 | + |
|
168 | + //pull the meta value from the venue post |
|
169 | + $venue_meta = $this->_venue->get_post_meta($shortcode, true); |
|
170 | + |
|
171 | + return ! empty($venue_meta) ? $venue_meta : ''; |
|
172 | + |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * This retrieves the EE_Venue from the available data object. |
|
178 | + * |
|
179 | + * @return EE_Venue|null |
|
180 | + * @throws EE_Error |
|
181 | + * @throws EntityNotFoundException |
|
182 | + */ |
|
183 | + private function _get_venue() |
|
184 | + { |
|
185 | + |
|
186 | + //we need the EE_Event object to get the venue. |
|
187 | + $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
188 | + |
|
189 | + //if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
|
190 | + // reg_obj instead. |
|
191 | + if (! $this->_event instanceof EE_Event) { |
|
192 | + $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
193 | + $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
194 | + |
|
195 | + $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
196 | + ? $aee->reg_obj->event() |
|
197 | + : null; |
|
198 | + |
|
199 | + //if still empty do we have a ticket data item? |
|
200 | + $this->_event = ! $this->_event instanceof EE_Event |
|
201 | + && $this->_data instanceof EE_Ticket |
|
202 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
203 | + ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event'] |
|
204 | + : $this->_event; |
|
205 | + |
|
206 | + //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
|
207 | + // and use that. |
|
208 | + $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee |
|
209 | + ? reset($aee->events) |
|
210 | + : $this->_event; |
|
211 | + } |
|
212 | + |
|
213 | + //If we have an event object use it to pull the venue. |
|
214 | + if ($this->_event instanceof EE_Event) { |
|
215 | + return $this->_event->get_first_related('Venue'); |
|
216 | + } |
|
217 | + |
|
218 | + return null; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * This retrieves the specified venue information |
|
223 | + * |
|
224 | + * @param string $field What Venue field to retrieve |
|
225 | + * @return string What was retrieved! |
|
226 | + * @throws EE_Error |
|
227 | + * @throws EntityNotFoundException |
|
228 | + */ |
|
229 | + private function _venue($field) |
|
230 | + { |
|
231 | + |
|
232 | + if (! $this->_venue instanceof EE_Venue) { |
|
233 | + return ''; |
|
234 | + } //no venue so get out. |
|
235 | + |
|
236 | + switch ($field) { |
|
237 | + case 'title': |
|
238 | + return $this->_venue->get('VNU_name'); |
|
239 | + break; |
|
240 | + |
|
241 | + case 'description': |
|
242 | + return $this->_venue->get('VNU_desc'); |
|
243 | + break; |
|
244 | + |
|
245 | + case 'url': |
|
246 | + $url = $this->_venue->get('VNU_url'); |
|
247 | + return empty($url) ? $this->_venue->get_permalink() : $url; |
|
248 | + break; |
|
249 | + |
|
250 | + case 'permalink': |
|
251 | + return $this->_venue->get_permalink(); |
|
252 | + break; |
|
253 | + |
|
254 | + case 'image': |
|
255 | + return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
256 | + . '" alt="' . sprintf( |
|
257 | + esc_attr__('%s Feature Image', 'event_espresso'), |
|
258 | + $this->_venue->get('VNU_name') |
|
259 | + ) . '" />'; |
|
260 | + break; |
|
261 | + |
|
262 | + case 'phone': |
|
263 | + return $this->_venue->get('VNU_phone'); |
|
264 | + break; |
|
265 | + |
|
266 | + case 'address': |
|
267 | + return $this->_venue->get('VNU_address'); |
|
268 | + break; |
|
269 | + |
|
270 | + case 'address2': |
|
271 | + return $this->_venue->get('VNU_address2'); |
|
272 | + break; |
|
273 | + |
|
274 | + case 'city': |
|
275 | + return $this->_venue->get('VNU_city'); |
|
276 | + break; |
|
277 | + |
|
278 | + case 'state': |
|
279 | + $state = $this->_venue->state_obj(); |
|
280 | + return is_object($state) ? $state->get('STA_name') : ''; |
|
281 | + break; |
|
282 | + |
|
283 | + case 'country': |
|
284 | + $country = $this->_venue->country_obj(); |
|
285 | + return is_object($country) ? $country->get('CNT_name') : ''; |
|
286 | + break; |
|
287 | + |
|
288 | + case 'zip': |
|
289 | + return $this->_venue->get('VNU_zip'); |
|
290 | + break; |
|
291 | + |
|
292 | + case 'formatted_address': |
|
293 | + return EEH_Address::format($this->_venue); |
|
294 | + break; |
|
295 | + |
|
296 | + case 'gmap_link': |
|
297 | + case 'gmap_url': |
|
298 | + case 'gmap_link_img': |
|
299 | + $atts = $this->get_map_attributes($this->_venue, $field); |
|
300 | + return EEH_Maps::google_map_link($atts); |
|
301 | + break; |
|
302 | + } |
|
303 | + return ''; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * Generates the attributes for retrieving a google_map artifact. |
|
309 | + * |
|
310 | + * @param EE_Venue $venue |
|
311 | + * @param string $field |
|
312 | + * @return array |
|
313 | + * @throws EE_Error |
|
314 | + */ |
|
315 | + protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
316 | + { |
|
317 | + $state = $venue->state_obj(); |
|
318 | + $country = $venue->country_obj(); |
|
319 | + $atts = array( |
|
320 | + 'id' => $venue->ID(), |
|
321 | + 'address' => $venue->get('VNU_address'), |
|
322 | + 'city' => $venue->get('VNU_city'), |
|
323 | + 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
324 | + 'zip' => $venue->get('VNU_zip'), |
|
325 | + 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
326 | + 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
327 | + 'map_w' => 200, |
|
328 | + 'map_h' => 200, |
|
329 | + ); |
|
330 | + if ($field === 'gmap_url') { |
|
331 | + $atts['type'] = 'url_only'; |
|
332 | + } |
|
333 | + return $atts; |
|
334 | + } |
|
335 | 335 | } |
@@ -17,362 +17,362 @@ |
||
17 | 17 | class EE_Maintenance_Mode implements ResettableInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * constants available to client code for interpreting the values of EE_Maintenance_Mode::level(). |
|
22 | - * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal) |
|
23 | - */ |
|
24 | - const level_0_not_in_maintenance = 0; |
|
25 | - |
|
26 | - /** |
|
27 | - * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled |
|
28 | - * but the admin backend should be running as normal. Maybe an admin can view the frontend though |
|
29 | - */ |
|
30 | - const level_1_frontend_only_maintenance = 1; |
|
31 | - |
|
32 | - /** |
|
33 | - * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running |
|
34 | - * is the maintenance mode stuff, which will require users to update all addons, and then finish running all |
|
35 | - * migration scripts before taking the site out of maintenance mode |
|
36 | - */ |
|
37 | - const level_2_complete_maintenance = 2; |
|
38 | - |
|
39 | - /** |
|
40 | - * the name of the option which stores the current level of maintenance mode |
|
41 | - */ |
|
42 | - const option_name_maintenance_mode = 'ee_maintenance_mode'; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @var EE_Maintenance_Mode $_instance |
|
47 | - */ |
|
48 | - private static $_instance; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var EE_Registry $EE |
|
52 | - */ |
|
53 | - protected $EE; |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @singleton method used to instantiate class object |
|
59 | - * @return EE_Maintenance_Mode |
|
60 | - */ |
|
61 | - public static function instance() |
|
62 | - { |
|
63 | - // check if class object is instantiated |
|
64 | - if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
65 | - self::$_instance = new self(); |
|
66 | - } |
|
67 | - return self::$_instance; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode) |
|
74 | - * |
|
75 | - * @return EE_Maintenance_Mode |
|
76 | - */ |
|
77 | - public static function reset() |
|
78 | - { |
|
79 | - self::instance()->set_maintenance_mode_if_db_old(); |
|
80 | - return self::instance(); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - *private constructor to prevent direct creation |
|
87 | - */ |
|
88 | - private function __construct() |
|
89 | - { |
|
90 | - // if M-Mode level 2 is engaged, we still need basic assets loaded |
|
91 | - add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode')); |
|
92 | - // shut 'er down down for maintenance ? |
|
93 | - add_filter('the_content', array($this, 'the_content'), 2); |
|
94 | - // add powered by EE msg |
|
95 | - add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * retrieves the maintenance mode option value from the db |
|
102 | - * |
|
103 | - * @return int |
|
104 | - */ |
|
105 | - public function real_level() |
|
106 | - { |
|
107 | - return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Returns whether or not the models reportedly are able to run queries or not |
|
114 | - * (ie, if the system thinks their tables are present and up-to-date). |
|
115 | - * |
|
116 | - * @return boolean |
|
117 | - */ |
|
118 | - public function models_can_query() |
|
119 | - { |
|
120 | - return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Determines whether or not we're in maintenance mode and what level. However, while the site |
|
127 | - * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear |
|
128 | - * to them as if teh site isn't in maintenance mode. |
|
129 | - * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode) |
|
130 | - * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode |
|
131 | - * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode |
|
132 | - * |
|
133 | - * @return int |
|
134 | - */ |
|
135 | - public function level() |
|
136 | - { |
|
137 | - $maintenance_mode_level = $this->real_level(); |
|
138 | - // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend |
|
139 | - if ( |
|
140 | - $maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1 |
|
141 | - && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests |
|
142 | - && current_user_can('administrator') // when the user is an admin |
|
143 | - ) { |
|
144 | - $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance; |
|
145 | - } |
|
146 | - return $maintenance_mode_level; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * Determines if we need to put EE in maintenance mode because the database needs updating |
|
153 | - * |
|
154 | - * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
|
155 | - */ |
|
156 | - public function set_maintenance_mode_if_db_old() |
|
157 | - { |
|
158 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
159 | - if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
160 | - update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance); |
|
161 | - return true; |
|
162 | - } |
|
163 | - if ($this->level() === self::level_2_complete_maintenance) { |
|
164 | - //we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
|
165 | - //then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
|
166 | - update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance); |
|
167 | - return false; |
|
168 | - } |
|
169 | - return false; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Updates the maintenance level on the site |
|
176 | - * |
|
177 | - * @param int $level |
|
178 | - * @return void |
|
179 | - */ |
|
180 | - public function set_maintenance_level($level) |
|
181 | - { |
|
182 | - do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level); |
|
183 | - update_option(self::option_name_maintenance_mode, (int)$level); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * returns TRUE if M-Mode is engaged and the current request is not for the admin |
|
190 | - * |
|
191 | - * @return string |
|
192 | - */ |
|
193 | - public static function disable_frontend_for_maintenance() |
|
194 | - { |
|
195 | - return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @return void |
|
202 | - */ |
|
203 | - public function load_assets_required_for_m_mode() |
|
204 | - { |
|
205 | - if ( |
|
206 | - $this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
207 | - && ! wp_script_is('espresso_core') |
|
208 | - ) { |
|
209 | - wp_register_style( |
|
210 | - 'espresso_default', |
|
211 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
212 | - array('dashicons'), |
|
213 | - EVENT_ESPRESSO_VERSION |
|
214 | - ); |
|
215 | - wp_enqueue_style('espresso_default'); |
|
216 | - wp_register_script( |
|
217 | - 'espresso_core', |
|
218 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
219 | - array('jquery'), |
|
220 | - EVENT_ESPRESSO_VERSION, |
|
221 | - true |
|
222 | - ); |
|
223 | - wp_enqueue_script('espresso_core'); |
|
224 | - } |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * replacement EE CPT template that displays message notifying site visitors |
|
231 | - * that EE has been temporarily placed into maintenance mode |
|
232 | - * does NOT get called on non-EE-CPT requests |
|
233 | - * |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public static function template_include() |
|
237 | - { |
|
238 | - // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints |
|
239 | - return get_template_directory() . '/index.php'; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * displays message notifying site visitors that EE has been temporarily |
|
246 | - * placed into maintenance mode when post_type != EE CPT |
|
247 | - * |
|
248 | - * @param string $the_content |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function the_content($the_content) |
|
252 | - { |
|
253 | - // check if M-mode is engaged and for EE shortcode |
|
254 | - if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) { |
|
255 | - // this can eventually be moved to a template, or edited via admin. But for now... |
|
256 | - $the_content = sprintf( |
|
257 | - esc_html__( |
|
258 | - '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', |
|
259 | - 'event_espresso' |
|
260 | - ), |
|
261 | - '<h3>', |
|
262 | - '</h3><p>', |
|
263 | - '</p>' |
|
264 | - ); |
|
265 | - } |
|
266 | - return $the_content; |
|
267 | - } |
|
20 | + /** |
|
21 | + * constants available to client code for interpreting the values of EE_Maintenance_Mode::level(). |
|
22 | + * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal) |
|
23 | + */ |
|
24 | + const level_0_not_in_maintenance = 0; |
|
25 | + |
|
26 | + /** |
|
27 | + * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled |
|
28 | + * but the admin backend should be running as normal. Maybe an admin can view the frontend though |
|
29 | + */ |
|
30 | + const level_1_frontend_only_maintenance = 1; |
|
31 | + |
|
32 | + /** |
|
33 | + * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running |
|
34 | + * is the maintenance mode stuff, which will require users to update all addons, and then finish running all |
|
35 | + * migration scripts before taking the site out of maintenance mode |
|
36 | + */ |
|
37 | + const level_2_complete_maintenance = 2; |
|
38 | + |
|
39 | + /** |
|
40 | + * the name of the option which stores the current level of maintenance mode |
|
41 | + */ |
|
42 | + const option_name_maintenance_mode = 'ee_maintenance_mode'; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @var EE_Maintenance_Mode $_instance |
|
47 | + */ |
|
48 | + private static $_instance; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var EE_Registry $EE |
|
52 | + */ |
|
53 | + protected $EE; |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @singleton method used to instantiate class object |
|
59 | + * @return EE_Maintenance_Mode |
|
60 | + */ |
|
61 | + public static function instance() |
|
62 | + { |
|
63 | + // check if class object is instantiated |
|
64 | + if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
65 | + self::$_instance = new self(); |
|
66 | + } |
|
67 | + return self::$_instance; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode) |
|
74 | + * |
|
75 | + * @return EE_Maintenance_Mode |
|
76 | + */ |
|
77 | + public static function reset() |
|
78 | + { |
|
79 | + self::instance()->set_maintenance_mode_if_db_old(); |
|
80 | + return self::instance(); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + *private constructor to prevent direct creation |
|
87 | + */ |
|
88 | + private function __construct() |
|
89 | + { |
|
90 | + // if M-Mode level 2 is engaged, we still need basic assets loaded |
|
91 | + add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode')); |
|
92 | + // shut 'er down down for maintenance ? |
|
93 | + add_filter('the_content', array($this, 'the_content'), 2); |
|
94 | + // add powered by EE msg |
|
95 | + add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * retrieves the maintenance mode option value from the db |
|
102 | + * |
|
103 | + * @return int |
|
104 | + */ |
|
105 | + public function real_level() |
|
106 | + { |
|
107 | + return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Returns whether or not the models reportedly are able to run queries or not |
|
114 | + * (ie, if the system thinks their tables are present and up-to-date). |
|
115 | + * |
|
116 | + * @return boolean |
|
117 | + */ |
|
118 | + public function models_can_query() |
|
119 | + { |
|
120 | + return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Determines whether or not we're in maintenance mode and what level. However, while the site |
|
127 | + * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear |
|
128 | + * to them as if teh site isn't in maintenance mode. |
|
129 | + * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode) |
|
130 | + * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode |
|
131 | + * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode |
|
132 | + * |
|
133 | + * @return int |
|
134 | + */ |
|
135 | + public function level() |
|
136 | + { |
|
137 | + $maintenance_mode_level = $this->real_level(); |
|
138 | + // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend |
|
139 | + if ( |
|
140 | + $maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1 |
|
141 | + && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests |
|
142 | + && current_user_can('administrator') // when the user is an admin |
|
143 | + ) { |
|
144 | + $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance; |
|
145 | + } |
|
146 | + return $maintenance_mode_level; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * Determines if we need to put EE in maintenance mode because the database needs updating |
|
153 | + * |
|
154 | + * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
|
155 | + */ |
|
156 | + public function set_maintenance_mode_if_db_old() |
|
157 | + { |
|
158 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
159 | + if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
160 | + update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance); |
|
161 | + return true; |
|
162 | + } |
|
163 | + if ($this->level() === self::level_2_complete_maintenance) { |
|
164 | + //we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
|
165 | + //then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
|
166 | + update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance); |
|
167 | + return false; |
|
168 | + } |
|
169 | + return false; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Updates the maintenance level on the site |
|
176 | + * |
|
177 | + * @param int $level |
|
178 | + * @return void |
|
179 | + */ |
|
180 | + public function set_maintenance_level($level) |
|
181 | + { |
|
182 | + do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level); |
|
183 | + update_option(self::option_name_maintenance_mode, (int)$level); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * returns TRUE if M-Mode is engaged and the current request is not for the admin |
|
190 | + * |
|
191 | + * @return string |
|
192 | + */ |
|
193 | + public static function disable_frontend_for_maintenance() |
|
194 | + { |
|
195 | + return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @return void |
|
202 | + */ |
|
203 | + public function load_assets_required_for_m_mode() |
|
204 | + { |
|
205 | + if ( |
|
206 | + $this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
207 | + && ! wp_script_is('espresso_core') |
|
208 | + ) { |
|
209 | + wp_register_style( |
|
210 | + 'espresso_default', |
|
211 | + EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
212 | + array('dashicons'), |
|
213 | + EVENT_ESPRESSO_VERSION |
|
214 | + ); |
|
215 | + wp_enqueue_style('espresso_default'); |
|
216 | + wp_register_script( |
|
217 | + 'espresso_core', |
|
218 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
219 | + array('jquery'), |
|
220 | + EVENT_ESPRESSO_VERSION, |
|
221 | + true |
|
222 | + ); |
|
223 | + wp_enqueue_script('espresso_core'); |
|
224 | + } |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * replacement EE CPT template that displays message notifying site visitors |
|
231 | + * that EE has been temporarily placed into maintenance mode |
|
232 | + * does NOT get called on non-EE-CPT requests |
|
233 | + * |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public static function template_include() |
|
237 | + { |
|
238 | + // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints |
|
239 | + return get_template_directory() . '/index.php'; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * displays message notifying site visitors that EE has been temporarily |
|
246 | + * placed into maintenance mode when post_type != EE CPT |
|
247 | + * |
|
248 | + * @param string $the_content |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function the_content($the_content) |
|
252 | + { |
|
253 | + // check if M-mode is engaged and for EE shortcode |
|
254 | + if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) { |
|
255 | + // this can eventually be moved to a template, or edited via admin. But for now... |
|
256 | + $the_content = sprintf( |
|
257 | + esc_html__( |
|
258 | + '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', |
|
259 | + 'event_espresso' |
|
260 | + ), |
|
261 | + '<h3>', |
|
262 | + '</h3><p>', |
|
263 | + '</p>' |
|
264 | + ); |
|
265 | + } |
|
266 | + return $the_content; |
|
267 | + } |
|
268 | 268 | |
269 | 269 | |
270 | 270 | |
271 | - /** |
|
272 | - * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
273 | - */ |
|
274 | - public function display_maintenance_mode_notice() |
|
275 | - { |
|
276 | - // check if M-mode is engaged and for EE shortcode |
|
277 | - if ( |
|
278 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
279 | - && $this->real_level() |
|
280 | - && ! is_admin() |
|
281 | - && current_user_can('administrator') |
|
282 | - && EE_Registry::instance()->REQ->is_espresso_page() |
|
283 | - ) { |
|
284 | - printf( |
|
285 | - esc_html__( |
|
286 | - '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', |
|
287 | - 'event_espresso' |
|
288 | - ), |
|
289 | - '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
|
290 | - '"><span class="dashicons dashicons-no"></span></a><p>', |
|
291 | - ' » <a href="' . add_query_arg( |
|
292 | - array('page' => 'espresso_maintenance_settings'), admin_url('admin.php') |
|
293 | - ) . '">', |
|
294 | - '</a></p></div>' |
|
295 | - ); |
|
296 | - } |
|
297 | - } |
|
298 | - // espresso-notices important-notice ee-attention |
|
271 | + /** |
|
272 | + * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
273 | + */ |
|
274 | + public function display_maintenance_mode_notice() |
|
275 | + { |
|
276 | + // check if M-mode is engaged and for EE shortcode |
|
277 | + if ( |
|
278 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
279 | + && $this->real_level() |
|
280 | + && ! is_admin() |
|
281 | + && current_user_can('administrator') |
|
282 | + && EE_Registry::instance()->REQ->is_espresso_page() |
|
283 | + ) { |
|
284 | + printf( |
|
285 | + esc_html__( |
|
286 | + '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', |
|
287 | + 'event_espresso' |
|
288 | + ), |
|
289 | + '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
|
290 | + '"><span class="dashicons dashicons-no"></span></a><p>', |
|
291 | + ' » <a href="' . add_query_arg( |
|
292 | + array('page' => 'espresso_maintenance_settings'), admin_url('admin.php') |
|
293 | + ) . '">', |
|
294 | + '</a></p></div>' |
|
295 | + ); |
|
296 | + } |
|
297 | + } |
|
298 | + // espresso-notices important-notice ee-attention |
|
299 | 299 | |
300 | 300 | |
301 | 301 | |
302 | - /** |
|
303 | - * override magic methods |
|
304 | - */ |
|
305 | - final public function __destruct() |
|
306 | - { |
|
307 | - } |
|
302 | + /** |
|
303 | + * override magic methods |
|
304 | + */ |
|
305 | + final public function __destruct() |
|
306 | + { |
|
307 | + } |
|
308 | 308 | |
309 | 309 | |
310 | 310 | |
311 | - final public function __call($a, $b) |
|
312 | - { |
|
313 | - } |
|
311 | + final public function __call($a, $b) |
|
312 | + { |
|
313 | + } |
|
314 | 314 | |
315 | 315 | |
316 | 316 | |
317 | - final public function __get($a) |
|
318 | - { |
|
319 | - } |
|
317 | + final public function __get($a) |
|
318 | + { |
|
319 | + } |
|
320 | 320 | |
321 | 321 | |
322 | 322 | |
323 | - final public function __set($a, $b) |
|
324 | - { |
|
325 | - } |
|
323 | + final public function __set($a, $b) |
|
324 | + { |
|
325 | + } |
|
326 | 326 | |
327 | 327 | |
328 | 328 | |
329 | - final public function __isset($a) |
|
330 | - { |
|
331 | - } |
|
329 | + final public function __isset($a) |
|
330 | + { |
|
331 | + } |
|
332 | 332 | |
333 | 333 | |
334 | 334 | |
335 | - final public function __unset($a) |
|
336 | - { |
|
337 | - } |
|
335 | + final public function __unset($a) |
|
336 | + { |
|
337 | + } |
|
338 | 338 | |
339 | 339 | |
340 | 340 | |
341 | - final public function __sleep() |
|
342 | - { |
|
343 | - return array(); |
|
344 | - } |
|
341 | + final public function __sleep() |
|
342 | + { |
|
343 | + return array(); |
|
344 | + } |
|
345 | 345 | |
346 | 346 | |
347 | 347 | |
348 | - final public function __wakeup() |
|
349 | - { |
|
350 | - } |
|
348 | + final public function __wakeup() |
|
349 | + { |
|
350 | + } |
|
351 | 351 | |
352 | 352 | |
353 | 353 | |
354 | - final public function __invoke() |
|
355 | - { |
|
356 | - } |
|
354 | + final public function __invoke() |
|
355 | + { |
|
356 | + } |
|
357 | 357 | |
358 | 358 | |
359 | 359 | |
360 | - final public static function __set_state($a = null) |
|
361 | - { |
|
362 | - return EE_Maintenance_Mode::instance(); |
|
363 | - } |
|
360 | + final public static function __set_state($a = null) |
|
361 | + { |
|
362 | + return EE_Maintenance_Mode::instance(); |
|
363 | + } |
|
364 | 364 | |
365 | 365 | |
366 | 366 | |
367 | - final public function __clone() |
|
368 | - { |
|
369 | - } |
|
367 | + final public function __clone() |
|
368 | + { |
|
369 | + } |
|
370 | 370 | |
371 | 371 | |
372 | 372 | |
373 | - final public static function __callStatic($a, $b) |
|
374 | - { |
|
375 | - } |
|
373 | + final public static function __callStatic($a, $b) |
|
374 | + { |
|
375 | + } |
|
376 | 376 | |
377 | 377 | } |
378 | 378 | // End of file EE_Maintenance_Mode.core.php |
@@ -698,7 +698,7 @@ |
||
698 | 698 | |
699 | 699 | /** |
700 | 700 | * @param EE_State[] $state_options |
701 | - * @return array |
|
701 | + * @return EE_State[] |
|
702 | 702 | * @throws EE_Error |
703 | 703 | * @throws InvalidArgumentException |
704 | 704 | * @throws InvalidDataTypeException |
@@ -19,730 +19,730 @@ |
||
19 | 19 | |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @return EED_Module|EED_Add_New_State |
|
24 | - */ |
|
25 | - public static function instance() |
|
26 | - { |
|
27 | - return parent::get_instance(__CLASS__); |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
34 | - * |
|
35 | - * @return void |
|
36 | - */ |
|
37 | - public static function set_hooks() |
|
38 | - { |
|
39 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
40 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
41 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
42 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
43 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
44 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
45 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
46 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
47 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
48 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
49 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
50 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
51 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
52 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
53 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
54 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
55 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public static function set_hooks_admin() |
|
66 | - { |
|
67 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
68 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
69 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
70 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
71 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
72 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
73 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
74 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
75 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
76 | - add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
77 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
78 | - add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
79 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
80 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
81 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
82 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
83 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
84 | - add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
85 | - array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
86 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
87 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
88 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
89 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - public static function set_definitions() |
|
98 | - { |
|
99 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
100 | - define('ANS_TEMPLATES_PATH', str_replace( |
|
101 | - '\\', |
|
102 | - DS, |
|
103 | - plugin_dir_path(__FILE__)) . 'templates' . DS |
|
104 | - ); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @param WP $WP |
|
111 | - * @return void |
|
112 | - */ |
|
113 | - public function run($WP) |
|
114 | - { |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - public static function translate_js_strings() |
|
123 | - { |
|
124 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
125 | - 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
126 | - 'event_espresso' |
|
127 | - ); |
|
128 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
129 | - 'In order to proceed, you need to enter the name of your State/Province.', |
|
130 | - 'event_espresso' |
|
131 | - ); |
|
132 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
133 | - 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
134 | - 'event_espresso' |
|
135 | - ); |
|
136 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
137 | - 'The new state was successfully saved to the database.', |
|
138 | - 'event_espresso' |
|
139 | - ); |
|
140 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
141 | - 'An unknown error has occurred on the server while saving the new state to the database.', |
|
142 | - 'event_espresso' |
|
143 | - ); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @return void |
|
150 | - */ |
|
151 | - public static function wp_enqueue_scripts() |
|
152 | - { |
|
153 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
154 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
155 | - array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
156 | - wp_enqueue_script('add_new_state'); |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * display_add_new_state_micro_form |
|
164 | - * |
|
165 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
166 | - * @return string |
|
167 | - * @throws EE_Error |
|
168 | - * @throws InvalidArgumentException |
|
169 | - * @throws InvalidDataTypeException |
|
170 | - * @throws InvalidInterfaceException |
|
171 | - */ |
|
172 | - // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
173 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
174 | - { |
|
175 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
176 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
177 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
178 | - // is the "state" question in this form section? |
|
179 | - $input = $question_group_reg_form->get_subsection('state'); |
|
180 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
181 | - //ok then all we need to do is make sure the input's HTML name is consistent |
|
182 | - //by forcing it to set it now, like it did while getting the form for display |
|
183 | - if ($input instanceof EE_State_Select_Input) { |
|
184 | - $input->html_name(); |
|
185 | - } |
|
186 | - return $question_group_reg_form; |
|
187 | - } |
|
188 | - // we're only doing this for state select inputs |
|
189 | - if ($input instanceof EE_State_Select_Input) { |
|
190 | - // grab any set values from the request |
|
191 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
192 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
193 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
194 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
195 | - $country_options = array(); |
|
196 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
197 | - if (! empty($countries)) { |
|
198 | - foreach ($countries as $country) { |
|
199 | - if ($country instanceof EE_Country) { |
|
200 | - $country_options[$country->ID()] = $country->name(); |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
204 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
205 | - array( |
|
206 | - 'name' => 'new_state_micro_form', |
|
207 | - 'html_id' => 'new_state_micro_form', |
|
208 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
209 | - 'subsections' => array( |
|
210 | - // add hidden input to indicate that a new state is being added |
|
211 | - 'add_new_state' => new EE_Hidden_Input( |
|
212 | - array( |
|
213 | - 'html_name' => str_replace( |
|
214 | - 'state', |
|
215 | - 'nsmf_add_new_state', |
|
216 | - $input->html_name() |
|
217 | - ), |
|
218 | - 'html_id' => str_replace( |
|
219 | - 'state', |
|
220 | - 'nsmf_add_new_state', |
|
221 | - $input->html_id() |
|
222 | - ), |
|
223 | - 'default' => 0, |
|
224 | - ) |
|
225 | - ), |
|
226 | - // add link for displaying hidden container |
|
227 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
228 | - apply_filters( |
|
229 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
230 | - EEH_HTML::link( |
|
231 | - '', |
|
232 | - esc_html__('click here to add a new state/province', 'event_espresso'), |
|
233 | - '', |
|
234 | - 'display-' . $input->html_id(), |
|
235 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
236 | - '', |
|
237 | - 'data-target="' . $input->html_id() . '"' |
|
238 | - ) |
|
239 | - ) |
|
240 | - ), |
|
241 | - // add initial html for hidden container |
|
242 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
243 | - apply_filters( |
|
244 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
245 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
246 | - 'display: none;') . |
|
247 | - EEH_HTML::h6( |
|
248 | - esc_html__( |
|
249 | - 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
250 | - 'event_espresso' |
|
251 | - ) |
|
252 | - ) . |
|
253 | - EEH_HTML::ul() . |
|
254 | - EEH_HTML::li( |
|
255 | - esc_html__( |
|
256 | - 'first select the Country that your State/Province belongs to', |
|
257 | - 'event_espresso' |
|
258 | - ) |
|
259 | - ) . |
|
260 | - EEH_HTML::li( |
|
261 | - esc_html__('enter the name of your State/Province', 'event_espresso') |
|
262 | - ) . |
|
263 | - EEH_HTML::li( |
|
264 | - esc_html__( |
|
265 | - 'enter a two to six letter abbreviation for the name of your State/Province', |
|
266 | - 'event_espresso' |
|
267 | - ) |
|
268 | - ) . |
|
269 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
270 | - EEH_HTML::ulx() |
|
271 | - ) |
|
272 | - ), |
|
273 | - // NEW STATE COUNTRY |
|
274 | - 'new_state_country' => new EE_Country_Select_Input( |
|
275 | - $country_options, |
|
276 | - array( |
|
277 | - 'html_name' => $country_name, |
|
278 | - 'html_id' => str_replace( |
|
279 | - 'state', |
|
280 | - 'nsmf_new_state_country', $input->html_id() |
|
281 | - ), |
|
282 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
283 | - 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
284 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
285 | - 'required' => false, |
|
286 | - ) |
|
287 | - ), |
|
288 | - // NEW STATE NAME |
|
289 | - 'new_state_name' => new EE_Text_Input( |
|
290 | - array( |
|
291 | - 'html_name' => $state_name, |
|
292 | - 'html_id' => str_replace( |
|
293 | - 'state', |
|
294 | - 'nsmf_new_state_name', $input->html_id() |
|
295 | - ), |
|
296 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
297 | - 'html_label_text' => esc_html__('New State/Province Name', |
|
298 | - 'event_espresso'), |
|
299 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
300 | - 'required' => false, |
|
301 | - ) |
|
302 | - ), |
|
303 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
304 | - // NEW STATE NAME |
|
305 | - 'new_state_abbrv' => new EE_Text_Input( |
|
306 | - array( |
|
307 | - 'html_name' => $abbrv_name, |
|
308 | - 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
309 | - $input->html_id()), |
|
310 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
311 | - 'html_label_text' => esc_html__( |
|
312 | - 'New State/Province Abbreviation', |
|
313 | - 'event_espresso' |
|
314 | - ) . ' *', |
|
315 | - 'html_other_attributes' => 'size="24"', |
|
316 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
317 | - 'required' => false, |
|
318 | - ) |
|
319 | - ), |
|
320 | - // "submit" button |
|
321 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
322 | - apply_filters( |
|
323 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
324 | - EEH_HTML::nbsp(3) . |
|
325 | - EEH_HTML::link( |
|
326 | - '', |
|
327 | - esc_html__('ADD', 'event_espresso'), |
|
328 | - '', |
|
329 | - 'submit-' . $new_state_submit_id, |
|
330 | - 'ee-form-add-new-state-submit button button-secondary', |
|
331 | - '', |
|
332 | - 'data-target="' . $new_state_submit_id . '"' |
|
333 | - ) |
|
334 | - ) |
|
335 | - ), |
|
336 | - // extra info |
|
337 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
338 | - apply_filters( |
|
339 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
340 | - EEH_HTML::br(2) |
|
341 | - . |
|
342 | - EEH_HTML::div('', '', 'small-text') |
|
343 | - . |
|
344 | - EEH_HTML::strong( |
|
345 | - '* ' . |
|
346 | - esc_html__( |
|
347 | - 'Don\'t know your State/Province Abbreviation?', |
|
348 | - 'event_espresso' |
|
349 | - ) |
|
350 | - ) |
|
351 | - . |
|
352 | - EEH_HTML::br() |
|
353 | - . |
|
354 | - sprintf( |
|
355 | - esc_html__( |
|
356 | - 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
357 | - 'event_espresso' |
|
358 | - ), |
|
359 | - EEH_HTML::link( |
|
360 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
361 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
362 | - '', |
|
363 | - '', |
|
364 | - 'ee-form-add-new-state-wiki-lnk', |
|
365 | - '', |
|
366 | - 'target="_blank"' |
|
367 | - ) |
|
368 | - ) |
|
369 | - . |
|
370 | - EEH_HTML::divx() |
|
371 | - . |
|
372 | - EEH_HTML::br() |
|
373 | - . |
|
374 | - EEH_HTML::link( |
|
375 | - '', |
|
376 | - esc_html__('cancel new State/Province', 'event_espresso'), |
|
377 | - '', |
|
378 | - 'hide-' . $input->html_id(), |
|
379 | - 'ee-form-cancel-new-state-lnk smaller-text', |
|
380 | - '', |
|
381 | - 'data-target="' . $input->html_id() . '"' |
|
382 | - ) |
|
383 | - . |
|
384 | - EEH_HTML::divx() |
|
385 | - . |
|
386 | - EEH_HTML::br() |
|
387 | - ) |
|
388 | - ), |
|
389 | - ), |
|
390 | - ) |
|
391 | - ); |
|
392 | - $question_group_reg_form->add_subsections( |
|
393 | - array('new_state_micro_form' => $new_state_micro_form), |
|
394 | - 'state', |
|
395 | - false |
|
396 | - ); |
|
397 | - } |
|
398 | - return $question_group_reg_form; |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * set_new_state_input_width |
|
405 | - * |
|
406 | - * @return int|string |
|
407 | - * @throws EE_Error |
|
408 | - * @throws InvalidArgumentException |
|
409 | - * @throws InvalidDataTypeException |
|
410 | - * @throws InvalidInterfaceException |
|
411 | - * @throws ReflectionException |
|
412 | - */ |
|
413 | - public static function add_new_state() |
|
414 | - { |
|
415 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
416 | - if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
417 | - EE_Registry::instance()->load_model('State'); |
|
418 | - // grab country ISO code, new state name, and new state abbreviation |
|
419 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
420 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
421 | - : false; |
|
422 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
423 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
424 | - : false; |
|
425 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
426 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
427 | - : false; |
|
428 | - if ($state_country && $state_name && $state_abbr) { |
|
429 | - $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
430 | - 'CNT_ISO' => strtoupper($state_country), |
|
431 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
432 | - 'STA_name' => ucwords($state_name), |
|
433 | - 'STA_active' => false, |
|
434 | - )); |
|
435 | - if ($new_state instanceof EE_State) { |
|
436 | - // clean house |
|
437 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
438 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
439 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
440 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
441 | - // get any existing new states |
|
442 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
443 | - 'nsmf_new_states' |
|
444 | - ); |
|
445 | - $new_states[$new_state->ID()] = $new_state; |
|
446 | - EE_Registry::instance()->SSN->set_session_data( |
|
447 | - array('nsmf_new_states' => $new_states) |
|
448 | - ); |
|
449 | - if (EE_Registry::instance()->REQ->ajax) { |
|
450 | - echo wp_json_encode(array( |
|
451 | - 'success' => true, |
|
452 | - 'id' => $new_state->ID(), |
|
453 | - 'name' => $new_state->name(), |
|
454 | - 'abbrev' => $new_state->abbrev(), |
|
455 | - 'country_iso' => $new_state->country_iso(), |
|
456 | - 'country_name' => $new_state->country()->name(), |
|
457 | - )); |
|
458 | - exit(); |
|
459 | - } |
|
460 | - return $new_state->ID(); |
|
461 | - } |
|
462 | - } else { |
|
463 | - $error = esc_html__( |
|
464 | - 'A new State/Province could not be added because invalid or missing data was received.', |
|
465 | - 'event_espresso' |
|
466 | - ); |
|
467 | - if (EE_Registry::instance()->REQ->ajax) { |
|
468 | - echo wp_json_encode(array('error' => $error)); |
|
469 | - exit(); |
|
470 | - } |
|
471 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
472 | - } |
|
473 | - } |
|
474 | - return false; |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * recursively drills down through request params to remove any that were added by this module |
|
481 | - * |
|
482 | - * @param array $request_params |
|
483 | - * @return array |
|
484 | - */ |
|
485 | - public static function filter_checkout_request_params($request_params) |
|
486 | - { |
|
487 | - foreach ($request_params as $form_section) { |
|
488 | - if (is_array($form_section)) { |
|
489 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
490 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
491 | - } |
|
492 | - } |
|
493 | - return $request_params; |
|
494 | - } |
|
495 | - |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * @param array $request_params |
|
500 | - * @return array |
|
501 | - */ |
|
502 | - public static function unset_new_state_request_params($request_params) |
|
503 | - { |
|
504 | - unset( |
|
505 | - $request_params['new_state_micro_form'], |
|
506 | - $request_params['new_state_micro_add_new_state'], |
|
507 | - $request_params['new_state_micro_new_state_country'], |
|
508 | - $request_params['new_state_micro_new_state_name'], |
|
509 | - $request_params['new_state_micro_new_state_abbrv'] |
|
510 | - ); |
|
511 | - return $request_params; |
|
512 | - } |
|
513 | - |
|
514 | - |
|
515 | - |
|
516 | - /** |
|
517 | - * @param array $props_n_values |
|
518 | - * @return bool |
|
519 | - * @throws EE_Error |
|
520 | - * @throws InvalidArgumentException |
|
521 | - * @throws InvalidDataTypeException |
|
522 | - * @throws InvalidInterfaceException |
|
523 | - */ |
|
524 | - public static function save_new_state_to_db($props_n_values = array()) |
|
525 | - { |
|
526 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
527 | - if (! empty($existing_state)) { |
|
528 | - return array_pop($existing_state); |
|
529 | - } |
|
530 | - $new_state = EE_State::new_instance($props_n_values); |
|
531 | - if ($new_state instanceof EE_State) { |
|
532 | - // if not non-ajax admin |
|
533 | - $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
534 | - $new_state_notice = sprintf( |
|
535 | - esc_html__( |
|
536 | - 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
537 | - 'event_espresso' |
|
538 | - ), |
|
539 | - '<b>' . $new_state->name() . '</b>', |
|
540 | - '<b>' . $new_state->abbrev() . '</b>', |
|
541 | - '<b>' . $new_state->country()->name() . '</b>', |
|
542 | - '<a href="' . add_query_arg(array( |
|
543 | - 'page' => 'espresso_general_settings', |
|
544 | - 'action' => 'country_settings', |
|
545 | - 'country' => $new_state->country_iso(), |
|
546 | - ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
547 | - 'event_espresso') . '</a>', |
|
548 | - '<br />' |
|
549 | - ); |
|
550 | - EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
|
551 | - $new_state->save(); |
|
552 | - EEM_State::instance()->reset_cached_states(); |
|
553 | - return $new_state; |
|
554 | - } |
|
555 | - return false; |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - |
|
560 | - /** |
|
561 | - * @param string $CNT_ISO |
|
562 | - * @param string $STA_ID |
|
563 | - * @param array $cols_n_values |
|
564 | - * @return void |
|
565 | - * @throws EE_Error |
|
566 | - * @throws InvalidArgumentException |
|
567 | - * @throws InvalidDataTypeException |
|
568 | - * @throws InvalidInterfaceException |
|
569 | - */ |
|
570 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
571 | - { |
|
572 | - if (! $CNT_ISO) { |
|
573 | - EE_Error::add_error( |
|
574 | - esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
575 | - __FILE__, |
|
576 | - __FUNCTION__, |
|
577 | - __LINE__ |
|
578 | - ); |
|
579 | - } |
|
580 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
581 | - : false; |
|
582 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
583 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
584 | - if ($state instanceof EE_State) { |
|
585 | - $STA_abbrev = $state->abbrev(); |
|
586 | - } |
|
587 | - } |
|
588 | - if (! $STA_abbrev) { |
|
589 | - EE_Error::add_error( |
|
590 | - esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
591 | - __FILE__, |
|
592 | - __FUNCTION__, |
|
593 | - __LINE__ |
|
594 | - ); |
|
595 | - } |
|
596 | - EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * @param EE_State[] $state_options |
|
603 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
604 | - * @param EE_Registration $registration |
|
605 | - * @param EE_Question $question |
|
606 | - * @param $answer |
|
607 | - * @return array |
|
608 | - * @throws EE_Error |
|
609 | - * @throws InvalidArgumentException |
|
610 | - * @throws InvalidDataTypeException |
|
611 | - * @throws InvalidInterfaceException |
|
612 | - */ |
|
613 | - public static function inject_new_reg_state_into_options( |
|
614 | - $state_options = array(), |
|
615 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
616 | - EE_Registration $registration, |
|
617 | - EE_Question $question, |
|
618 | - $answer |
|
619 | - ) { |
|
620 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
621 | - && $question->type() === EEM_Question::QST_type_state |
|
622 | - ) { |
|
623 | - $STA_ID = $answer->value(); |
|
624 | - if (! empty($STA_ID)) { |
|
625 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
626 | - if ($state instanceof EE_State) { |
|
627 | - $country = $state->country(); |
|
628 | - if ($country instanceof EE_Country) { |
|
629 | - if (! isset($state_options[$country->name()])) { |
|
630 | - $state_options[$country->name()] = array(); |
|
631 | - } |
|
632 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
633 | - $state_options[$country->name()][$STA_ID] = $state->name(); |
|
634 | - } |
|
635 | - } |
|
636 | - } |
|
637 | - } |
|
638 | - } |
|
639 | - return $state_options; |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * @param EE_Country[] $country_options |
|
646 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
647 | - * @param EE_Registration $registration |
|
648 | - * @param EE_Question $question |
|
649 | - * @param $answer |
|
650 | - * @return array |
|
651 | - * @throws EE_Error |
|
652 | - * @throws InvalidArgumentException |
|
653 | - * @throws InvalidDataTypeException |
|
654 | - * @throws InvalidInterfaceException |
|
655 | - */ |
|
656 | - public static function inject_new_reg_country_into_options( |
|
657 | - $country_options = array(), |
|
658 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
659 | - EE_Registration $registration, |
|
660 | - EE_Question $question, |
|
661 | - $answer |
|
662 | - ) { |
|
663 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
664 | - && $question->type() |
|
665 | - === EEM_Question::QST_type_country |
|
666 | - ) { |
|
667 | - $CNT_ISO = $answer->value(); |
|
668 | - if (! empty($CNT_ISO)) { |
|
669 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
670 | - if ($country instanceof EE_Country) { |
|
671 | - if (! isset($country_options[$CNT_ISO])) { |
|
672 | - $country_options[$CNT_ISO] = $country->name(); |
|
673 | - } |
|
674 | - } |
|
675 | - } |
|
676 | - } |
|
677 | - return $country_options; |
|
678 | - } |
|
679 | - |
|
680 | - |
|
681 | - |
|
682 | - /** |
|
683 | - * @param EE_State[] $state_options |
|
684 | - * @return array |
|
685 | - * @throws EE_Error |
|
686 | - * @throws InvalidArgumentException |
|
687 | - * @throws InvalidDataTypeException |
|
688 | - * @throws InvalidInterfaceException |
|
689 | - */ |
|
690 | - public static function state_options($state_options = array()) |
|
691 | - { |
|
692 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
693 | - foreach ($new_states as $new_state) { |
|
694 | - if ( |
|
695 | - $new_state instanceof EE_State |
|
696 | - && $new_state->country() instanceof EE_Country |
|
697 | - ) { |
|
698 | - $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
699 | - } |
|
700 | - } |
|
701 | - return $state_options; |
|
702 | - } |
|
703 | - |
|
704 | - |
|
705 | - |
|
706 | - /** |
|
707 | - * @return array |
|
708 | - * @throws InvalidArgumentException |
|
709 | - * @throws InvalidDataTypeException |
|
710 | - * @throws InvalidInterfaceException |
|
711 | - */ |
|
712 | - protected static function _get_new_states() |
|
713 | - { |
|
714 | - $new_states = array(); |
|
715 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
716 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
717 | - 'nsmf_new_states' |
|
718 | - ); |
|
719 | - } |
|
720 | - return is_array($new_states) ? $new_states : array(); |
|
721 | - } |
|
722 | - |
|
723 | - |
|
724 | - |
|
725 | - /** |
|
726 | - * @param EE_Country[] $country_options |
|
727 | - * @return array |
|
728 | - * @throws EE_Error |
|
729 | - * @throws InvalidArgumentException |
|
730 | - * @throws InvalidDataTypeException |
|
731 | - * @throws InvalidInterfaceException |
|
732 | - */ |
|
733 | - public static function country_options($country_options = array()) |
|
734 | - { |
|
735 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
736 | - foreach ($new_states as $new_state) { |
|
737 | - if ( |
|
738 | - $new_state instanceof EE_State |
|
739 | - && $new_state->country() instanceof EE_Country |
|
740 | - ) { |
|
741 | - $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
742 | - } |
|
743 | - } |
|
744 | - return $country_options; |
|
745 | - } |
|
22 | + /** |
|
23 | + * @return EED_Module|EED_Add_New_State |
|
24 | + */ |
|
25 | + public static function instance() |
|
26 | + { |
|
27 | + return parent::get_instance(__CLASS__); |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
34 | + * |
|
35 | + * @return void |
|
36 | + */ |
|
37 | + public static function set_hooks() |
|
38 | + { |
|
39 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
40 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
41 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
42 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
43 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
44 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
45 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
46 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
47 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
48 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
49 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
50 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
51 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
52 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
53 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
54 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
55 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public static function set_hooks_admin() |
|
66 | + { |
|
67 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
68 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
69 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
70 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
71 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
72 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
73 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
74 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
75 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
76 | + add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
77 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
78 | + add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
79 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
80 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
81 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
82 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
83 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
84 | + add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
85 | + array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
86 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
87 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
88 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
89 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + public static function set_definitions() |
|
98 | + { |
|
99 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
100 | + define('ANS_TEMPLATES_PATH', str_replace( |
|
101 | + '\\', |
|
102 | + DS, |
|
103 | + plugin_dir_path(__FILE__)) . 'templates' . DS |
|
104 | + ); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @param WP $WP |
|
111 | + * @return void |
|
112 | + */ |
|
113 | + public function run($WP) |
|
114 | + { |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + public static function translate_js_strings() |
|
123 | + { |
|
124 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
125 | + 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
126 | + 'event_espresso' |
|
127 | + ); |
|
128 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
129 | + 'In order to proceed, you need to enter the name of your State/Province.', |
|
130 | + 'event_espresso' |
|
131 | + ); |
|
132 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
133 | + 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
134 | + 'event_espresso' |
|
135 | + ); |
|
136 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
137 | + 'The new state was successfully saved to the database.', |
|
138 | + 'event_espresso' |
|
139 | + ); |
|
140 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
141 | + 'An unknown error has occurred on the server while saving the new state to the database.', |
|
142 | + 'event_espresso' |
|
143 | + ); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @return void |
|
150 | + */ |
|
151 | + public static function wp_enqueue_scripts() |
|
152 | + { |
|
153 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
154 | + wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
155 | + array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
156 | + wp_enqueue_script('add_new_state'); |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * display_add_new_state_micro_form |
|
164 | + * |
|
165 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
166 | + * @return string |
|
167 | + * @throws EE_Error |
|
168 | + * @throws InvalidArgumentException |
|
169 | + * @throws InvalidDataTypeException |
|
170 | + * @throws InvalidInterfaceException |
|
171 | + */ |
|
172 | + // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
173 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
174 | + { |
|
175 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
176 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
177 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
178 | + // is the "state" question in this form section? |
|
179 | + $input = $question_group_reg_form->get_subsection('state'); |
|
180 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
181 | + //ok then all we need to do is make sure the input's HTML name is consistent |
|
182 | + //by forcing it to set it now, like it did while getting the form for display |
|
183 | + if ($input instanceof EE_State_Select_Input) { |
|
184 | + $input->html_name(); |
|
185 | + } |
|
186 | + return $question_group_reg_form; |
|
187 | + } |
|
188 | + // we're only doing this for state select inputs |
|
189 | + if ($input instanceof EE_State_Select_Input) { |
|
190 | + // grab any set values from the request |
|
191 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
192 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
193 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
194 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
195 | + $country_options = array(); |
|
196 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
197 | + if (! empty($countries)) { |
|
198 | + foreach ($countries as $country) { |
|
199 | + if ($country instanceof EE_Country) { |
|
200 | + $country_options[$country->ID()] = $country->name(); |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
205 | + array( |
|
206 | + 'name' => 'new_state_micro_form', |
|
207 | + 'html_id' => 'new_state_micro_form', |
|
208 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
209 | + 'subsections' => array( |
|
210 | + // add hidden input to indicate that a new state is being added |
|
211 | + 'add_new_state' => new EE_Hidden_Input( |
|
212 | + array( |
|
213 | + 'html_name' => str_replace( |
|
214 | + 'state', |
|
215 | + 'nsmf_add_new_state', |
|
216 | + $input->html_name() |
|
217 | + ), |
|
218 | + 'html_id' => str_replace( |
|
219 | + 'state', |
|
220 | + 'nsmf_add_new_state', |
|
221 | + $input->html_id() |
|
222 | + ), |
|
223 | + 'default' => 0, |
|
224 | + ) |
|
225 | + ), |
|
226 | + // add link for displaying hidden container |
|
227 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
228 | + apply_filters( |
|
229 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
230 | + EEH_HTML::link( |
|
231 | + '', |
|
232 | + esc_html__('click here to add a new state/province', 'event_espresso'), |
|
233 | + '', |
|
234 | + 'display-' . $input->html_id(), |
|
235 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
236 | + '', |
|
237 | + 'data-target="' . $input->html_id() . '"' |
|
238 | + ) |
|
239 | + ) |
|
240 | + ), |
|
241 | + // add initial html for hidden container |
|
242 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
243 | + apply_filters( |
|
244 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
245 | + EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
246 | + 'display: none;') . |
|
247 | + EEH_HTML::h6( |
|
248 | + esc_html__( |
|
249 | + 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
250 | + 'event_espresso' |
|
251 | + ) |
|
252 | + ) . |
|
253 | + EEH_HTML::ul() . |
|
254 | + EEH_HTML::li( |
|
255 | + esc_html__( |
|
256 | + 'first select the Country that your State/Province belongs to', |
|
257 | + 'event_espresso' |
|
258 | + ) |
|
259 | + ) . |
|
260 | + EEH_HTML::li( |
|
261 | + esc_html__('enter the name of your State/Province', 'event_espresso') |
|
262 | + ) . |
|
263 | + EEH_HTML::li( |
|
264 | + esc_html__( |
|
265 | + 'enter a two to six letter abbreviation for the name of your State/Province', |
|
266 | + 'event_espresso' |
|
267 | + ) |
|
268 | + ) . |
|
269 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
270 | + EEH_HTML::ulx() |
|
271 | + ) |
|
272 | + ), |
|
273 | + // NEW STATE COUNTRY |
|
274 | + 'new_state_country' => new EE_Country_Select_Input( |
|
275 | + $country_options, |
|
276 | + array( |
|
277 | + 'html_name' => $country_name, |
|
278 | + 'html_id' => str_replace( |
|
279 | + 'state', |
|
280 | + 'nsmf_new_state_country', $input->html_id() |
|
281 | + ), |
|
282 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
283 | + 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
284 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
285 | + 'required' => false, |
|
286 | + ) |
|
287 | + ), |
|
288 | + // NEW STATE NAME |
|
289 | + 'new_state_name' => new EE_Text_Input( |
|
290 | + array( |
|
291 | + 'html_name' => $state_name, |
|
292 | + 'html_id' => str_replace( |
|
293 | + 'state', |
|
294 | + 'nsmf_new_state_name', $input->html_id() |
|
295 | + ), |
|
296 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
297 | + 'html_label_text' => esc_html__('New State/Province Name', |
|
298 | + 'event_espresso'), |
|
299 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
300 | + 'required' => false, |
|
301 | + ) |
|
302 | + ), |
|
303 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
304 | + // NEW STATE NAME |
|
305 | + 'new_state_abbrv' => new EE_Text_Input( |
|
306 | + array( |
|
307 | + 'html_name' => $abbrv_name, |
|
308 | + 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
309 | + $input->html_id()), |
|
310 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
311 | + 'html_label_text' => esc_html__( |
|
312 | + 'New State/Province Abbreviation', |
|
313 | + 'event_espresso' |
|
314 | + ) . ' *', |
|
315 | + 'html_other_attributes' => 'size="24"', |
|
316 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
317 | + 'required' => false, |
|
318 | + ) |
|
319 | + ), |
|
320 | + // "submit" button |
|
321 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
322 | + apply_filters( |
|
323 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
324 | + EEH_HTML::nbsp(3) . |
|
325 | + EEH_HTML::link( |
|
326 | + '', |
|
327 | + esc_html__('ADD', 'event_espresso'), |
|
328 | + '', |
|
329 | + 'submit-' . $new_state_submit_id, |
|
330 | + 'ee-form-add-new-state-submit button button-secondary', |
|
331 | + '', |
|
332 | + 'data-target="' . $new_state_submit_id . '"' |
|
333 | + ) |
|
334 | + ) |
|
335 | + ), |
|
336 | + // extra info |
|
337 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
338 | + apply_filters( |
|
339 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
340 | + EEH_HTML::br(2) |
|
341 | + . |
|
342 | + EEH_HTML::div('', '', 'small-text') |
|
343 | + . |
|
344 | + EEH_HTML::strong( |
|
345 | + '* ' . |
|
346 | + esc_html__( |
|
347 | + 'Don\'t know your State/Province Abbreviation?', |
|
348 | + 'event_espresso' |
|
349 | + ) |
|
350 | + ) |
|
351 | + . |
|
352 | + EEH_HTML::br() |
|
353 | + . |
|
354 | + sprintf( |
|
355 | + esc_html__( |
|
356 | + 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
357 | + 'event_espresso' |
|
358 | + ), |
|
359 | + EEH_HTML::link( |
|
360 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
361 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
362 | + '', |
|
363 | + '', |
|
364 | + 'ee-form-add-new-state-wiki-lnk', |
|
365 | + '', |
|
366 | + 'target="_blank"' |
|
367 | + ) |
|
368 | + ) |
|
369 | + . |
|
370 | + EEH_HTML::divx() |
|
371 | + . |
|
372 | + EEH_HTML::br() |
|
373 | + . |
|
374 | + EEH_HTML::link( |
|
375 | + '', |
|
376 | + esc_html__('cancel new State/Province', 'event_espresso'), |
|
377 | + '', |
|
378 | + 'hide-' . $input->html_id(), |
|
379 | + 'ee-form-cancel-new-state-lnk smaller-text', |
|
380 | + '', |
|
381 | + 'data-target="' . $input->html_id() . '"' |
|
382 | + ) |
|
383 | + . |
|
384 | + EEH_HTML::divx() |
|
385 | + . |
|
386 | + EEH_HTML::br() |
|
387 | + ) |
|
388 | + ), |
|
389 | + ), |
|
390 | + ) |
|
391 | + ); |
|
392 | + $question_group_reg_form->add_subsections( |
|
393 | + array('new_state_micro_form' => $new_state_micro_form), |
|
394 | + 'state', |
|
395 | + false |
|
396 | + ); |
|
397 | + } |
|
398 | + return $question_group_reg_form; |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * set_new_state_input_width |
|
405 | + * |
|
406 | + * @return int|string |
|
407 | + * @throws EE_Error |
|
408 | + * @throws InvalidArgumentException |
|
409 | + * @throws InvalidDataTypeException |
|
410 | + * @throws InvalidInterfaceException |
|
411 | + * @throws ReflectionException |
|
412 | + */ |
|
413 | + public static function add_new_state() |
|
414 | + { |
|
415 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
416 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
417 | + EE_Registry::instance()->load_model('State'); |
|
418 | + // grab country ISO code, new state name, and new state abbreviation |
|
419 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
420 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
421 | + : false; |
|
422 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
423 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
424 | + : false; |
|
425 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
426 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
427 | + : false; |
|
428 | + if ($state_country && $state_name && $state_abbr) { |
|
429 | + $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
430 | + 'CNT_ISO' => strtoupper($state_country), |
|
431 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
432 | + 'STA_name' => ucwords($state_name), |
|
433 | + 'STA_active' => false, |
|
434 | + )); |
|
435 | + if ($new_state instanceof EE_State) { |
|
436 | + // clean house |
|
437 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
438 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
439 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
440 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
441 | + // get any existing new states |
|
442 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
443 | + 'nsmf_new_states' |
|
444 | + ); |
|
445 | + $new_states[$new_state->ID()] = $new_state; |
|
446 | + EE_Registry::instance()->SSN->set_session_data( |
|
447 | + array('nsmf_new_states' => $new_states) |
|
448 | + ); |
|
449 | + if (EE_Registry::instance()->REQ->ajax) { |
|
450 | + echo wp_json_encode(array( |
|
451 | + 'success' => true, |
|
452 | + 'id' => $new_state->ID(), |
|
453 | + 'name' => $new_state->name(), |
|
454 | + 'abbrev' => $new_state->abbrev(), |
|
455 | + 'country_iso' => $new_state->country_iso(), |
|
456 | + 'country_name' => $new_state->country()->name(), |
|
457 | + )); |
|
458 | + exit(); |
|
459 | + } |
|
460 | + return $new_state->ID(); |
|
461 | + } |
|
462 | + } else { |
|
463 | + $error = esc_html__( |
|
464 | + 'A new State/Province could not be added because invalid or missing data was received.', |
|
465 | + 'event_espresso' |
|
466 | + ); |
|
467 | + if (EE_Registry::instance()->REQ->ajax) { |
|
468 | + echo wp_json_encode(array('error' => $error)); |
|
469 | + exit(); |
|
470 | + } |
|
471 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
472 | + } |
|
473 | + } |
|
474 | + return false; |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * recursively drills down through request params to remove any that were added by this module |
|
481 | + * |
|
482 | + * @param array $request_params |
|
483 | + * @return array |
|
484 | + */ |
|
485 | + public static function filter_checkout_request_params($request_params) |
|
486 | + { |
|
487 | + foreach ($request_params as $form_section) { |
|
488 | + if (is_array($form_section)) { |
|
489 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
490 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
491 | + } |
|
492 | + } |
|
493 | + return $request_params; |
|
494 | + } |
|
495 | + |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * @param array $request_params |
|
500 | + * @return array |
|
501 | + */ |
|
502 | + public static function unset_new_state_request_params($request_params) |
|
503 | + { |
|
504 | + unset( |
|
505 | + $request_params['new_state_micro_form'], |
|
506 | + $request_params['new_state_micro_add_new_state'], |
|
507 | + $request_params['new_state_micro_new_state_country'], |
|
508 | + $request_params['new_state_micro_new_state_name'], |
|
509 | + $request_params['new_state_micro_new_state_abbrv'] |
|
510 | + ); |
|
511 | + return $request_params; |
|
512 | + } |
|
513 | + |
|
514 | + |
|
515 | + |
|
516 | + /** |
|
517 | + * @param array $props_n_values |
|
518 | + * @return bool |
|
519 | + * @throws EE_Error |
|
520 | + * @throws InvalidArgumentException |
|
521 | + * @throws InvalidDataTypeException |
|
522 | + * @throws InvalidInterfaceException |
|
523 | + */ |
|
524 | + public static function save_new_state_to_db($props_n_values = array()) |
|
525 | + { |
|
526 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
527 | + if (! empty($existing_state)) { |
|
528 | + return array_pop($existing_state); |
|
529 | + } |
|
530 | + $new_state = EE_State::new_instance($props_n_values); |
|
531 | + if ($new_state instanceof EE_State) { |
|
532 | + // if not non-ajax admin |
|
533 | + $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
534 | + $new_state_notice = sprintf( |
|
535 | + esc_html__( |
|
536 | + 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
537 | + 'event_espresso' |
|
538 | + ), |
|
539 | + '<b>' . $new_state->name() . '</b>', |
|
540 | + '<b>' . $new_state->abbrev() . '</b>', |
|
541 | + '<b>' . $new_state->country()->name() . '</b>', |
|
542 | + '<a href="' . add_query_arg(array( |
|
543 | + 'page' => 'espresso_general_settings', |
|
544 | + 'action' => 'country_settings', |
|
545 | + 'country' => $new_state->country_iso(), |
|
546 | + ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
547 | + 'event_espresso') . '</a>', |
|
548 | + '<br />' |
|
549 | + ); |
|
550 | + EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
|
551 | + $new_state->save(); |
|
552 | + EEM_State::instance()->reset_cached_states(); |
|
553 | + return $new_state; |
|
554 | + } |
|
555 | + return false; |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + |
|
560 | + /** |
|
561 | + * @param string $CNT_ISO |
|
562 | + * @param string $STA_ID |
|
563 | + * @param array $cols_n_values |
|
564 | + * @return void |
|
565 | + * @throws EE_Error |
|
566 | + * @throws InvalidArgumentException |
|
567 | + * @throws InvalidDataTypeException |
|
568 | + * @throws InvalidInterfaceException |
|
569 | + */ |
|
570 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
571 | + { |
|
572 | + if (! $CNT_ISO) { |
|
573 | + EE_Error::add_error( |
|
574 | + esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
575 | + __FILE__, |
|
576 | + __FUNCTION__, |
|
577 | + __LINE__ |
|
578 | + ); |
|
579 | + } |
|
580 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
581 | + : false; |
|
582 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
583 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
584 | + if ($state instanceof EE_State) { |
|
585 | + $STA_abbrev = $state->abbrev(); |
|
586 | + } |
|
587 | + } |
|
588 | + if (! $STA_abbrev) { |
|
589 | + EE_Error::add_error( |
|
590 | + esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
591 | + __FILE__, |
|
592 | + __FUNCTION__, |
|
593 | + __LINE__ |
|
594 | + ); |
|
595 | + } |
|
596 | + EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * @param EE_State[] $state_options |
|
603 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
604 | + * @param EE_Registration $registration |
|
605 | + * @param EE_Question $question |
|
606 | + * @param $answer |
|
607 | + * @return array |
|
608 | + * @throws EE_Error |
|
609 | + * @throws InvalidArgumentException |
|
610 | + * @throws InvalidDataTypeException |
|
611 | + * @throws InvalidInterfaceException |
|
612 | + */ |
|
613 | + public static function inject_new_reg_state_into_options( |
|
614 | + $state_options = array(), |
|
615 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
616 | + EE_Registration $registration, |
|
617 | + EE_Question $question, |
|
618 | + $answer |
|
619 | + ) { |
|
620 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
621 | + && $question->type() === EEM_Question::QST_type_state |
|
622 | + ) { |
|
623 | + $STA_ID = $answer->value(); |
|
624 | + if (! empty($STA_ID)) { |
|
625 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
626 | + if ($state instanceof EE_State) { |
|
627 | + $country = $state->country(); |
|
628 | + if ($country instanceof EE_Country) { |
|
629 | + if (! isset($state_options[$country->name()])) { |
|
630 | + $state_options[$country->name()] = array(); |
|
631 | + } |
|
632 | + if (! isset($state_options[$country->name()][$STA_ID])) { |
|
633 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
634 | + } |
|
635 | + } |
|
636 | + } |
|
637 | + } |
|
638 | + } |
|
639 | + return $state_options; |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * @param EE_Country[] $country_options |
|
646 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
647 | + * @param EE_Registration $registration |
|
648 | + * @param EE_Question $question |
|
649 | + * @param $answer |
|
650 | + * @return array |
|
651 | + * @throws EE_Error |
|
652 | + * @throws InvalidArgumentException |
|
653 | + * @throws InvalidDataTypeException |
|
654 | + * @throws InvalidInterfaceException |
|
655 | + */ |
|
656 | + public static function inject_new_reg_country_into_options( |
|
657 | + $country_options = array(), |
|
658 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
659 | + EE_Registration $registration, |
|
660 | + EE_Question $question, |
|
661 | + $answer |
|
662 | + ) { |
|
663 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
664 | + && $question->type() |
|
665 | + === EEM_Question::QST_type_country |
|
666 | + ) { |
|
667 | + $CNT_ISO = $answer->value(); |
|
668 | + if (! empty($CNT_ISO)) { |
|
669 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
670 | + if ($country instanceof EE_Country) { |
|
671 | + if (! isset($country_options[$CNT_ISO])) { |
|
672 | + $country_options[$CNT_ISO] = $country->name(); |
|
673 | + } |
|
674 | + } |
|
675 | + } |
|
676 | + } |
|
677 | + return $country_options; |
|
678 | + } |
|
679 | + |
|
680 | + |
|
681 | + |
|
682 | + /** |
|
683 | + * @param EE_State[] $state_options |
|
684 | + * @return array |
|
685 | + * @throws EE_Error |
|
686 | + * @throws InvalidArgumentException |
|
687 | + * @throws InvalidDataTypeException |
|
688 | + * @throws InvalidInterfaceException |
|
689 | + */ |
|
690 | + public static function state_options($state_options = array()) |
|
691 | + { |
|
692 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
693 | + foreach ($new_states as $new_state) { |
|
694 | + if ( |
|
695 | + $new_state instanceof EE_State |
|
696 | + && $new_state->country() instanceof EE_Country |
|
697 | + ) { |
|
698 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
699 | + } |
|
700 | + } |
|
701 | + return $state_options; |
|
702 | + } |
|
703 | + |
|
704 | + |
|
705 | + |
|
706 | + /** |
|
707 | + * @return array |
|
708 | + * @throws InvalidArgumentException |
|
709 | + * @throws InvalidDataTypeException |
|
710 | + * @throws InvalidInterfaceException |
|
711 | + */ |
|
712 | + protected static function _get_new_states() |
|
713 | + { |
|
714 | + $new_states = array(); |
|
715 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
716 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
717 | + 'nsmf_new_states' |
|
718 | + ); |
|
719 | + } |
|
720 | + return is_array($new_states) ? $new_states : array(); |
|
721 | + } |
|
722 | + |
|
723 | + |
|
724 | + |
|
725 | + /** |
|
726 | + * @param EE_Country[] $country_options |
|
727 | + * @return array |
|
728 | + * @throws EE_Error |
|
729 | + * @throws InvalidArgumentException |
|
730 | + * @throws InvalidDataTypeException |
|
731 | + * @throws InvalidInterfaceException |
|
732 | + */ |
|
733 | + public static function country_options($country_options = array()) |
|
734 | + { |
|
735 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
736 | + foreach ($new_states as $new_state) { |
|
737 | + if ( |
|
738 | + $new_state instanceof EE_State |
|
739 | + && $new_state->country() instanceof EE_Country |
|
740 | + ) { |
|
741 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
742 | + } |
|
743 | + } |
|
744 | + return $country_options; |
|
745 | + } |
|
746 | 746 | |
747 | 747 | |
748 | 748 |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public static function set_definitions() |
98 | 98 | { |
99 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
99 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
100 | 100 | define('ANS_TEMPLATES_PATH', str_replace( |
101 | 101 | '\\', |
102 | 102 | DS, |
103 | - plugin_dir_path(__FILE__)) . 'templates' . DS |
|
103 | + plugin_dir_path(__FILE__)).'templates'.DS |
|
104 | 104 | ); |
105 | 105 | } |
106 | 106 | |
@@ -121,19 +121,19 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public static function translate_js_strings() |
123 | 123 | { |
124 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
124 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
125 | 125 | 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
126 | 126 | 'event_espresso' |
127 | 127 | ); |
128 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
128 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
129 | 129 | 'In order to proceed, you need to enter the name of your State/Province.', |
130 | 130 | 'event_espresso' |
131 | 131 | ); |
132 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
132 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
133 | 133 | 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
134 | 134 | 'event_espresso' |
135 | 135 | ); |
136 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
136 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
137 | 137 | 'The new state was successfully saved to the database.', |
138 | 138 | 'event_espresso' |
139 | 139 | ); |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | public static function wp_enqueue_scripts() |
152 | 152 | { |
153 | 153 | if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
154 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
154 | + wp_register_script('add_new_state', ANS_ASSETS_URL.'add_new_state.js', |
|
155 | 155 | array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
156 | 156 | wp_enqueue_script('add_new_state'); |
157 | 157 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
195 | 195 | $country_options = array(); |
196 | 196 | $countries = EEM_Country::instance()->get_all_countries(); |
197 | - if (! empty($countries)) { |
|
197 | + if ( ! empty($countries)) { |
|
198 | 198 | foreach ($countries as $country) { |
199 | 199 | if ($country instanceof EE_Country) { |
200 | 200 | $country_options[$country->ID()] = $country->name(); |
@@ -231,10 +231,10 @@ discard block |
||
231 | 231 | '', |
232 | 232 | esc_html__('click here to add a new state/province', 'event_espresso'), |
233 | 233 | '', |
234 | - 'display-' . $input->html_id(), |
|
234 | + 'display-'.$input->html_id(), |
|
235 | 235 | 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
236 | 236 | '', |
237 | - 'data-target="' . $input->html_id() . '"' |
|
237 | + 'data-target="'.$input->html_id().'"' |
|
238 | 238 | ) |
239 | 239 | ) |
240 | 240 | ), |
@@ -242,31 +242,31 @@ discard block |
||
242 | 242 | 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
243 | 243 | apply_filters( |
244 | 244 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
245 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
246 | - 'display: none;') . |
|
245 | + EEH_HTML::div('', $input->html_id().'-dv', 'ee-form-add-new-state-dv', |
|
246 | + 'display: none;'). |
|
247 | 247 | EEH_HTML::h6( |
248 | 248 | esc_html__( |
249 | 249 | 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
250 | 250 | 'event_espresso' |
251 | 251 | ) |
252 | - ) . |
|
253 | - EEH_HTML::ul() . |
|
252 | + ). |
|
253 | + EEH_HTML::ul(). |
|
254 | 254 | EEH_HTML::li( |
255 | 255 | esc_html__( |
256 | 256 | 'first select the Country that your State/Province belongs to', |
257 | 257 | 'event_espresso' |
258 | 258 | ) |
259 | - ) . |
|
259 | + ). |
|
260 | 260 | EEH_HTML::li( |
261 | 261 | esc_html__('enter the name of your State/Province', 'event_espresso') |
262 | - ) . |
|
262 | + ). |
|
263 | 263 | EEH_HTML::li( |
264 | 264 | esc_html__( |
265 | 265 | 'enter a two to six letter abbreviation for the name of your State/Province', |
266 | 266 | 'event_espresso' |
267 | 267 | ) |
268 | - ) . |
|
269 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
268 | + ). |
|
269 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')). |
|
270 | 270 | EEH_HTML::ulx() |
271 | 271 | ) |
272 | 272 | ), |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | 'state', |
280 | 280 | 'nsmf_new_state_country', $input->html_id() |
281 | 281 | ), |
282 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
282 | + 'html_class' => $input->html_class().' new-state-country', |
|
283 | 283 | 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
284 | 284 | 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
285 | 285 | 'required' => false, |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | 'state', |
294 | 294 | 'nsmf_new_state_name', $input->html_id() |
295 | 295 | ), |
296 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
296 | + 'html_class' => $input->html_class().' new-state-state', |
|
297 | 297 | 'html_label_text' => esc_html__('New State/Province Name', |
298 | 298 | 'event_espresso'), |
299 | 299 | 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
@@ -307,11 +307,11 @@ discard block |
||
307 | 307 | 'html_name' => $abbrv_name, |
308 | 308 | 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
309 | 309 | $input->html_id()), |
310 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
310 | + 'html_class' => $input->html_class().' new-state-abbrv', |
|
311 | 311 | 'html_label_text' => esc_html__( |
312 | 312 | 'New State/Province Abbreviation', |
313 | 313 | 'event_espresso' |
314 | - ) . ' *', |
|
314 | + ).' *', |
|
315 | 315 | 'html_other_attributes' => 'size="24"', |
316 | 316 | 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
317 | 317 | 'required' => false, |
@@ -321,15 +321,15 @@ discard block |
||
321 | 321 | 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
322 | 322 | apply_filters( |
323 | 323 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
324 | - EEH_HTML::nbsp(3) . |
|
324 | + EEH_HTML::nbsp(3). |
|
325 | 325 | EEH_HTML::link( |
326 | 326 | '', |
327 | 327 | esc_html__('ADD', 'event_espresso'), |
328 | 328 | '', |
329 | - 'submit-' . $new_state_submit_id, |
|
329 | + 'submit-'.$new_state_submit_id, |
|
330 | 330 | 'ee-form-add-new-state-submit button button-secondary', |
331 | 331 | '', |
332 | - 'data-target="' . $new_state_submit_id . '"' |
|
332 | + 'data-target="'.$new_state_submit_id.'"' |
|
333 | 333 | ) |
334 | 334 | ) |
335 | 335 | ), |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | EEH_HTML::div('', '', 'small-text') |
343 | 343 | . |
344 | 344 | EEH_HTML::strong( |
345 | - '* ' . |
|
345 | + '* '. |
|
346 | 346 | esc_html__( |
347 | 347 | 'Don\'t know your State/Province Abbreviation?', |
348 | 348 | 'event_espresso' |
@@ -375,10 +375,10 @@ discard block |
||
375 | 375 | '', |
376 | 376 | esc_html__('cancel new State/Province', 'event_espresso'), |
377 | 377 | '', |
378 | - 'hide-' . $input->html_id(), |
|
378 | + 'hide-'.$input->html_id(), |
|
379 | 379 | 'ee-form-cancel-new-state-lnk smaller-text', |
380 | 380 | '', |
381 | - 'data-target="' . $input->html_id() . '"' |
|
381 | + 'data-target="'.$input->html_id().'"' |
|
382 | 382 | ) |
383 | 383 | . |
384 | 384 | EEH_HTML::divx() |
@@ -524,27 +524,27 @@ discard block |
||
524 | 524 | public static function save_new_state_to_db($props_n_values = array()) |
525 | 525 | { |
526 | 526 | $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
527 | - if (! empty($existing_state)) { |
|
527 | + if ( ! empty($existing_state)) { |
|
528 | 528 | return array_pop($existing_state); |
529 | 529 | } |
530 | 530 | $new_state = EE_State::new_instance($props_n_values); |
531 | 531 | if ($new_state instanceof EE_State) { |
532 | 532 | // if not non-ajax admin |
533 | - $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
533 | + $new_state_key = 'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(); |
|
534 | 534 | $new_state_notice = sprintf( |
535 | 535 | esc_html__( |
536 | 536 | 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
537 | 537 | 'event_espresso' |
538 | 538 | ), |
539 | - '<b>' . $new_state->name() . '</b>', |
|
540 | - '<b>' . $new_state->abbrev() . '</b>', |
|
541 | - '<b>' . $new_state->country()->name() . '</b>', |
|
542 | - '<a href="' . add_query_arg(array( |
|
539 | + '<b>'.$new_state->name().'</b>', |
|
540 | + '<b>'.$new_state->abbrev().'</b>', |
|
541 | + '<b>'.$new_state->country()->name().'</b>', |
|
542 | + '<a href="'.add_query_arg(array( |
|
543 | 543 | 'page' => 'espresso_general_settings', |
544 | 544 | 'action' => 'country_settings', |
545 | 545 | 'country' => $new_state->country_iso(), |
546 | - ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
547 | - 'event_espresso') . '</a>', |
|
546 | + ), admin_url('admin.php')).'">'.esc_html__('Event Espresso - General Settings > Countries Tab', |
|
547 | + 'event_espresso').'</a>', |
|
548 | 548 | '<br />' |
549 | 549 | ); |
550 | 550 | EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | */ |
570 | 570 | public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
571 | 571 | { |
572 | - if (! $CNT_ISO) { |
|
572 | + if ( ! $CNT_ISO) { |
|
573 | 573 | EE_Error::add_error( |
574 | 574 | esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
575 | 575 | __FILE__, |
@@ -579,13 +579,13 @@ discard block |
||
579 | 579 | } |
580 | 580 | $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
581 | 581 | : false; |
582 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
582 | + if ( ! $STA_abbrev && ! empty($STA_ID)) { |
|
583 | 583 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
584 | 584 | if ($state instanceof EE_State) { |
585 | 585 | $STA_abbrev = $state->abbrev(); |
586 | 586 | } |
587 | 587 | } |
588 | - if (! $STA_abbrev) { |
|
588 | + if ( ! $STA_abbrev) { |
|
589 | 589 | EE_Error::add_error( |
590 | 590 | esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
591 | 591 | __FILE__, |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | __LINE__ |
594 | 594 | ); |
595 | 595 | } |
596 | - EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
596 | + EE_Error::dismiss_persistent_admin_notice($CNT_ISO.'-'.$STA_abbrev, true, true); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | |
@@ -621,15 +621,15 @@ discard block |
||
621 | 621 | && $question->type() === EEM_Question::QST_type_state |
622 | 622 | ) { |
623 | 623 | $STA_ID = $answer->value(); |
624 | - if (! empty($STA_ID)) { |
|
624 | + if ( ! empty($STA_ID)) { |
|
625 | 625 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
626 | 626 | if ($state instanceof EE_State) { |
627 | 627 | $country = $state->country(); |
628 | 628 | if ($country instanceof EE_Country) { |
629 | - if (! isset($state_options[$country->name()])) { |
|
629 | + if ( ! isset($state_options[$country->name()])) { |
|
630 | 630 | $state_options[$country->name()] = array(); |
631 | 631 | } |
632 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
632 | + if ( ! isset($state_options[$country->name()][$STA_ID])) { |
|
633 | 633 | $state_options[$country->name()][$STA_ID] = $state->name(); |
634 | 634 | } |
635 | 635 | } |
@@ -665,10 +665,10 @@ discard block |
||
665 | 665 | === EEM_Question::QST_type_country |
666 | 666 | ) { |
667 | 667 | $CNT_ISO = $answer->value(); |
668 | - if (! empty($CNT_ISO)) { |
|
668 | + if ( ! empty($CNT_ISO)) { |
|
669 | 669 | $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
670 | 670 | if ($country instanceof EE_Country) { |
671 | - if (! isset($country_options[$CNT_ISO])) { |
|
671 | + if ( ! isset($country_options[$CNT_ISO])) { |
|
672 | 672 | $country_options[$CNT_ISO] = $country->name(); |
673 | 673 | } |
674 | 674 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @since $VID:$ |
20 | 20 | */ |
21 | 21 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
22 | - exit('No direct script access allowed'); |
|
22 | + exit('No direct script access allowed'); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | |
@@ -27,404 +27,404 @@ discard block |
||
27 | 27 | class Event extends Calculations_Base |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Calculates the total spaces on the event (not subtracting sales, but taking |
|
32 | - * sales into account; so this is the optimum sales that CAN still be achieved) |
|
33 | - * See EE_Event::total_available_spaces( true ); |
|
34 | - * |
|
35 | - * @param array $wpdb_row |
|
36 | - * @param \WP_REST_Request $request |
|
37 | - * @param Base $controller |
|
38 | - * @return int |
|
39 | - * @throws EE_Error |
|
40 | - */ |
|
41 | - public static function optimumSalesAtStart($wpdb_row, $request, $controller) |
|
42 | - { |
|
43 | - $event_obj = null; |
|
44 | - if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
45 | - $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
46 | - } |
|
47 | - if ($event_obj instanceof EE_Event) { |
|
48 | - return $event_obj->total_available_spaces(); |
|
49 | - } |
|
50 | - throw new EE_Error( |
|
51 | - sprintf( |
|
52 | - __( |
|
53 | - // @codingStandardsIgnoreStart |
|
54 | - 'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', |
|
55 | - // @codingStandardsIgnoreEnd |
|
56 | - 'event_espresso' |
|
57 | - ), |
|
58 | - $wpdb_row['Event_CPT.ID'], |
|
59 | - print_r($wpdb_row, true) |
|
60 | - ) |
|
61 | - ); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * Calculates the total spaces on the event (ignoring all sales; so this is the optimum |
|
68 | - * sales that COULD have been achieved) |
|
69 | - * See EE_Event::total_available_spaces( true ); |
|
70 | - * |
|
71 | - * @param array $wpdb_row |
|
72 | - * @param \WP_REST_Request $request |
|
73 | - * @param Base $controller |
|
74 | - * @return int |
|
75 | - * @throws EE_Error |
|
76 | - */ |
|
77 | - public static function optimumSalesNow($wpdb_row, $request, $controller) |
|
78 | - { |
|
79 | - $event_obj = null; |
|
80 | - if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
81 | - $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
82 | - } |
|
83 | - if ($event_obj instanceof EE_Event) { |
|
84 | - return $event_obj->total_available_spaces(true); |
|
85 | - } |
|
86 | - throw new EE_Error( |
|
87 | - sprintf( |
|
88 | - __( |
|
89 | - // @codingStandardsIgnoreStart |
|
90 | - 'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', |
|
91 | - // @codingStandardsIgnoreEnd |
|
92 | - 'event_espresso' |
|
93 | - ), |
|
94 | - $wpdb_row['Event_CPT.ID'], |
|
95 | - print_r($wpdb_row, true) |
|
96 | - ) |
|
97 | - ); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * Like optimum_sales_now, but minus total sales so far. |
|
104 | - * See EE_Event::spaces_remaining_for_sale( true ); |
|
105 | - * |
|
106 | - * @param array $wpdb_row |
|
107 | - * @param \WP_REST_Request $request |
|
108 | - * @param Base $controller |
|
109 | - * @return int |
|
110 | - * @throws EE_Error |
|
111 | - */ |
|
112 | - public static function spacesRemaining($wpdb_row, $request, $controller) |
|
113 | - { |
|
114 | - $event_obj = null; |
|
115 | - if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
116 | - $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
117 | - } |
|
118 | - if ($event_obj instanceof EE_Event) { |
|
119 | - return $event_obj->spaces_remaining_for_sale(); |
|
120 | - } |
|
121 | - throw new EE_Error( |
|
122 | - sprintf( |
|
123 | - __( |
|
124 | - // @codingStandardsIgnoreStart |
|
125 | - 'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', |
|
126 | - // @codingStandardsIgnoreEnd |
|
127 | - 'event_espresso' |
|
128 | - ), |
|
129 | - $wpdb_row['Event_CPT.ID'], |
|
130 | - print_r($wpdb_row, true) |
|
131 | - ) |
|
132 | - ); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * Counts the number of approved registrations for this event (regardless |
|
139 | - * of how many datetimes each registrations' ticket purchase is for) |
|
140 | - * |
|
141 | - * @param array $wpdb_row |
|
142 | - * @param \WP_REST_Request $request |
|
143 | - * @param Base $controller |
|
144 | - * @return int |
|
145 | - * @throws EE_Error |
|
146 | - */ |
|
147 | - public static function spotsTaken($wpdb_row, $request, $controller) |
|
148 | - { |
|
149 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
150 | - throw new EE_Error( |
|
151 | - sprintf( |
|
152 | - __( |
|
153 | - // @codingStandardsIgnoreStart |
|
154 | - 'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"', |
|
155 | - // @codingStandardsIgnoreEnd |
|
156 | - 'event_espresso' |
|
157 | - ), |
|
158 | - print_r($wpdb_row, true) |
|
159 | - ) |
|
160 | - ); |
|
161 | - } |
|
162 | - return EEM_Registration::instance()->count( |
|
163 | - array( |
|
164 | - array( |
|
165 | - 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
166 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
167 | - ), |
|
168 | - ), |
|
169 | - 'REG_ID', |
|
170 | - true |
|
171 | - ); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * Counts the number of pending-payment registrations for this event (regardless |
|
178 | - * of how many datetimes each registrations' ticket purchase is for) |
|
179 | - * |
|
180 | - * @param array $wpdb_row |
|
181 | - * @param \WP_REST_Request $request |
|
182 | - * @param Base $controller |
|
183 | - * @return int |
|
184 | - * @throws EE_Error |
|
185 | - * @throws RestException |
|
186 | - */ |
|
187 | - public static function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
188 | - { |
|
189 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
190 | - throw new EE_Error( |
|
191 | - sprintf( |
|
192 | - __( |
|
193 | - // @codingStandardsIgnoreStart |
|
194 | - 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
195 | - // @codingStandardsIgnoreEnd |
|
196 | - 'event_espresso' |
|
197 | - ), |
|
198 | - print_r($wpdb_row, true) |
|
199 | - ) |
|
200 | - ); |
|
201 | - } |
|
202 | - self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
203 | - return EEM_Registration::instance()->count( |
|
204 | - array( |
|
205 | - array( |
|
206 | - 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
207 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
208 | - ), |
|
209 | - ), |
|
210 | - 'REG_ID', |
|
211 | - true |
|
212 | - ); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * Counts all the registrations who have checked into one of this events' datetimes |
|
219 | - * See EE_Event::total_available_spaces( false ); |
|
220 | - * |
|
221 | - * @param array $wpdb_row |
|
222 | - * @param \WP_REST_Request $request |
|
223 | - * @param Base $controller |
|
224 | - * @return int|null if permission denied |
|
225 | - * @throws EE_Error |
|
226 | - * @throws RestException |
|
227 | - */ |
|
228 | - public static function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
229 | - { |
|
230 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
231 | - throw new EE_Error( |
|
232 | - sprintf( |
|
233 | - __( |
|
234 | - // @codingStandardsIgnoreStart |
|
235 | - 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
236 | - // @codingStandardsIgnoreEnd |
|
237 | - 'event_espresso' |
|
238 | - ), |
|
239 | - print_r($wpdb_row, true) |
|
240 | - ) |
|
241 | - ); |
|
242 | - } |
|
243 | - self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
244 | - return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true); |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * Counts all the registrations who have checked out of one of this events' datetimes |
|
251 | - * See EE_Event::total_available_spaces( false ); |
|
252 | - * |
|
253 | - * @param array $wpdb_row |
|
254 | - * @param \WP_REST_Request $request |
|
255 | - * @param Base $controller |
|
256 | - * @return int |
|
257 | - * @throws EE_Error |
|
258 | - * @throws RestException |
|
259 | - */ |
|
260 | - public static function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
261 | - { |
|
262 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
263 | - throw new EE_Error( |
|
264 | - sprintf( |
|
265 | - __( |
|
266 | - // @codingStandardsIgnoreStart |
|
267 | - 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
268 | - // @codingStandardsIgnoreEnd |
|
269 | - 'event_espresso' |
|
270 | - ), |
|
271 | - print_r($wpdb_row, true) |
|
272 | - ) |
|
273 | - ); |
|
274 | - } |
|
275 | - self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
276 | - return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Gets the thumbnail image |
|
283 | - * |
|
284 | - * @param array $wpdb_row |
|
285 | - * @param \WP_REST_Request $request |
|
286 | - * @param Base $controller |
|
287 | - * @return array |
|
288 | - * @throws EE_Error |
|
289 | - */ |
|
290 | - public static function imageThumbnail($wpdb_row, $request, $controller) |
|
291 | - { |
|
292 | - return self::calculateImageData($wpdb_row, 'thumbnail'); |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Gets the medium image |
|
299 | - * |
|
300 | - * @param array $wpdb_row |
|
301 | - * @param \WP_REST_Request $request |
|
302 | - * @param Base $controller |
|
303 | - * @return array |
|
304 | - * @throws EE_Error |
|
305 | - */ |
|
306 | - public static function imageMedium($wpdb_row, $request, $controller) |
|
307 | - { |
|
308 | - return self::calculateImageData($wpdb_row, 'medium'); |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Gets the medium-large image |
|
315 | - * |
|
316 | - * @param array $wpdb_row |
|
317 | - * @param \WP_REST_Request $request |
|
318 | - * @param Base $controller |
|
319 | - * @return array |
|
320 | - * @throws EE_Error |
|
321 | - */ |
|
322 | - public static function imageMediumLarge($wpdb_row, $request, $controller) |
|
323 | - { |
|
324 | - return self::calculateImageData($wpdb_row, 'medium_large'); |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Gets the large image |
|
331 | - * |
|
332 | - * @param array $wpdb_row |
|
333 | - * @param \WP_REST_Request $request |
|
334 | - * @param Base $controller |
|
335 | - * @return array |
|
336 | - * @throws EE_Error |
|
337 | - */ |
|
338 | - public static function imageLarge($wpdb_row, $request, $controller) |
|
339 | - { |
|
340 | - return self::calculateImageData($wpdb_row, 'large'); |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * Gets the post-thumbnail image |
|
347 | - * |
|
348 | - * @param array $wpdb_row |
|
349 | - * @param \WP_REST_Request $request |
|
350 | - * @param Base $controller |
|
351 | - * @return array |
|
352 | - * @throws EE_Error |
|
353 | - */ |
|
354 | - public static function imagePostThumbnail($wpdb_row, $request, $controller) |
|
355 | - { |
|
356 | - return self::calculateImageData($wpdb_row, 'post-thumbnail'); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * Gets the full size image |
|
363 | - * |
|
364 | - * @param array $wpdb_row |
|
365 | - * @param \WP_REST_Request $request |
|
366 | - * @param Base $controller |
|
367 | - * @return array |
|
368 | - * @throws EE_Error |
|
369 | - */ |
|
370 | - public static function imageFull($wpdb_row, $request, $controller) |
|
371 | - { |
|
372 | - return self::calculateImageData($wpdb_row, 'full'); |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Gets image specs and formats them for the display in the API, |
|
379 | - * according to the image size requested |
|
380 | - * |
|
381 | - * @param array $wpdb_row |
|
382 | - * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full |
|
383 | - * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original' |
|
384 | - * @throws EE_Error |
|
385 | - */ |
|
386 | - protected static function calculateImageData($wpdb_row, $image_size) |
|
387 | - { |
|
388 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
389 | - throw new EE_Error( |
|
390 | - sprintf( |
|
391 | - __( |
|
392 | - // @codingStandardsIgnoreStart |
|
393 | - 'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
394 | - // @codingStandardsIgnoreEnd |
|
395 | - 'event_espresso' |
|
396 | - ), |
|
397 | - print_r($wpdb_row, true) |
|
398 | - ) |
|
399 | - ); |
|
400 | - } |
|
401 | - $EVT_ID = $wpdb_row['Event_CPT.ID']; |
|
402 | - $attachment_id = get_post_thumbnail_id($EVT_ID); |
|
403 | - $data = wp_get_attachment_image_src($attachment_id, $image_size); |
|
404 | - if (! $data) { |
|
405 | - return null; |
|
406 | - } |
|
407 | - $generated = true; |
|
408 | - if (isset($data[3])) { |
|
409 | - $generated = $data[3]; |
|
410 | - } |
|
411 | - return array( |
|
412 | - 'url' => $data[0], |
|
413 | - 'width' => $data[1], |
|
414 | - 'height' => $data[2], |
|
415 | - 'generated' => $generated, |
|
416 | - ); |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise |
|
423 | - * @param array $wpdb_row |
|
424 | - * @return bool |
|
425 | - */ |
|
426 | - protected static function wpdbRowHasEventId($wpdb_row) |
|
427 | - { |
|
428 | - return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID'])); |
|
429 | - } |
|
30 | + /** |
|
31 | + * Calculates the total spaces on the event (not subtracting sales, but taking |
|
32 | + * sales into account; so this is the optimum sales that CAN still be achieved) |
|
33 | + * See EE_Event::total_available_spaces( true ); |
|
34 | + * |
|
35 | + * @param array $wpdb_row |
|
36 | + * @param \WP_REST_Request $request |
|
37 | + * @param Base $controller |
|
38 | + * @return int |
|
39 | + * @throws EE_Error |
|
40 | + */ |
|
41 | + public static function optimumSalesAtStart($wpdb_row, $request, $controller) |
|
42 | + { |
|
43 | + $event_obj = null; |
|
44 | + if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
45 | + $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
46 | + } |
|
47 | + if ($event_obj instanceof EE_Event) { |
|
48 | + return $event_obj->total_available_spaces(); |
|
49 | + } |
|
50 | + throw new EE_Error( |
|
51 | + sprintf( |
|
52 | + __( |
|
53 | + // @codingStandardsIgnoreStart |
|
54 | + 'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', |
|
55 | + // @codingStandardsIgnoreEnd |
|
56 | + 'event_espresso' |
|
57 | + ), |
|
58 | + $wpdb_row['Event_CPT.ID'], |
|
59 | + print_r($wpdb_row, true) |
|
60 | + ) |
|
61 | + ); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * Calculates the total spaces on the event (ignoring all sales; so this is the optimum |
|
68 | + * sales that COULD have been achieved) |
|
69 | + * See EE_Event::total_available_spaces( true ); |
|
70 | + * |
|
71 | + * @param array $wpdb_row |
|
72 | + * @param \WP_REST_Request $request |
|
73 | + * @param Base $controller |
|
74 | + * @return int |
|
75 | + * @throws EE_Error |
|
76 | + */ |
|
77 | + public static function optimumSalesNow($wpdb_row, $request, $controller) |
|
78 | + { |
|
79 | + $event_obj = null; |
|
80 | + if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
81 | + $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
82 | + } |
|
83 | + if ($event_obj instanceof EE_Event) { |
|
84 | + return $event_obj->total_available_spaces(true); |
|
85 | + } |
|
86 | + throw new EE_Error( |
|
87 | + sprintf( |
|
88 | + __( |
|
89 | + // @codingStandardsIgnoreStart |
|
90 | + 'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', |
|
91 | + // @codingStandardsIgnoreEnd |
|
92 | + 'event_espresso' |
|
93 | + ), |
|
94 | + $wpdb_row['Event_CPT.ID'], |
|
95 | + print_r($wpdb_row, true) |
|
96 | + ) |
|
97 | + ); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * Like optimum_sales_now, but minus total sales so far. |
|
104 | + * See EE_Event::spaces_remaining_for_sale( true ); |
|
105 | + * |
|
106 | + * @param array $wpdb_row |
|
107 | + * @param \WP_REST_Request $request |
|
108 | + * @param Base $controller |
|
109 | + * @return int |
|
110 | + * @throws EE_Error |
|
111 | + */ |
|
112 | + public static function spacesRemaining($wpdb_row, $request, $controller) |
|
113 | + { |
|
114 | + $event_obj = null; |
|
115 | + if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
116 | + $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
117 | + } |
|
118 | + if ($event_obj instanceof EE_Event) { |
|
119 | + return $event_obj->spaces_remaining_for_sale(); |
|
120 | + } |
|
121 | + throw new EE_Error( |
|
122 | + sprintf( |
|
123 | + __( |
|
124 | + // @codingStandardsIgnoreStart |
|
125 | + 'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', |
|
126 | + // @codingStandardsIgnoreEnd |
|
127 | + 'event_espresso' |
|
128 | + ), |
|
129 | + $wpdb_row['Event_CPT.ID'], |
|
130 | + print_r($wpdb_row, true) |
|
131 | + ) |
|
132 | + ); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * Counts the number of approved registrations for this event (regardless |
|
139 | + * of how many datetimes each registrations' ticket purchase is for) |
|
140 | + * |
|
141 | + * @param array $wpdb_row |
|
142 | + * @param \WP_REST_Request $request |
|
143 | + * @param Base $controller |
|
144 | + * @return int |
|
145 | + * @throws EE_Error |
|
146 | + */ |
|
147 | + public static function spotsTaken($wpdb_row, $request, $controller) |
|
148 | + { |
|
149 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
150 | + throw new EE_Error( |
|
151 | + sprintf( |
|
152 | + __( |
|
153 | + // @codingStandardsIgnoreStart |
|
154 | + 'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"', |
|
155 | + // @codingStandardsIgnoreEnd |
|
156 | + 'event_espresso' |
|
157 | + ), |
|
158 | + print_r($wpdb_row, true) |
|
159 | + ) |
|
160 | + ); |
|
161 | + } |
|
162 | + return EEM_Registration::instance()->count( |
|
163 | + array( |
|
164 | + array( |
|
165 | + 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
166 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
167 | + ), |
|
168 | + ), |
|
169 | + 'REG_ID', |
|
170 | + true |
|
171 | + ); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * Counts the number of pending-payment registrations for this event (regardless |
|
178 | + * of how many datetimes each registrations' ticket purchase is for) |
|
179 | + * |
|
180 | + * @param array $wpdb_row |
|
181 | + * @param \WP_REST_Request $request |
|
182 | + * @param Base $controller |
|
183 | + * @return int |
|
184 | + * @throws EE_Error |
|
185 | + * @throws RestException |
|
186 | + */ |
|
187 | + public static function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
188 | + { |
|
189 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
190 | + throw new EE_Error( |
|
191 | + sprintf( |
|
192 | + __( |
|
193 | + // @codingStandardsIgnoreStart |
|
194 | + 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
195 | + // @codingStandardsIgnoreEnd |
|
196 | + 'event_espresso' |
|
197 | + ), |
|
198 | + print_r($wpdb_row, true) |
|
199 | + ) |
|
200 | + ); |
|
201 | + } |
|
202 | + self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
203 | + return EEM_Registration::instance()->count( |
|
204 | + array( |
|
205 | + array( |
|
206 | + 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
207 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
208 | + ), |
|
209 | + ), |
|
210 | + 'REG_ID', |
|
211 | + true |
|
212 | + ); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * Counts all the registrations who have checked into one of this events' datetimes |
|
219 | + * See EE_Event::total_available_spaces( false ); |
|
220 | + * |
|
221 | + * @param array $wpdb_row |
|
222 | + * @param \WP_REST_Request $request |
|
223 | + * @param Base $controller |
|
224 | + * @return int|null if permission denied |
|
225 | + * @throws EE_Error |
|
226 | + * @throws RestException |
|
227 | + */ |
|
228 | + public static function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
229 | + { |
|
230 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
231 | + throw new EE_Error( |
|
232 | + sprintf( |
|
233 | + __( |
|
234 | + // @codingStandardsIgnoreStart |
|
235 | + 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
236 | + // @codingStandardsIgnoreEnd |
|
237 | + 'event_espresso' |
|
238 | + ), |
|
239 | + print_r($wpdb_row, true) |
|
240 | + ) |
|
241 | + ); |
|
242 | + } |
|
243 | + self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
244 | + return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true); |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * Counts all the registrations who have checked out of one of this events' datetimes |
|
251 | + * See EE_Event::total_available_spaces( false ); |
|
252 | + * |
|
253 | + * @param array $wpdb_row |
|
254 | + * @param \WP_REST_Request $request |
|
255 | + * @param Base $controller |
|
256 | + * @return int |
|
257 | + * @throws EE_Error |
|
258 | + * @throws RestException |
|
259 | + */ |
|
260 | + public static function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
261 | + { |
|
262 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
263 | + throw new EE_Error( |
|
264 | + sprintf( |
|
265 | + __( |
|
266 | + // @codingStandardsIgnoreStart |
|
267 | + 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
268 | + // @codingStandardsIgnoreEnd |
|
269 | + 'event_espresso' |
|
270 | + ), |
|
271 | + print_r($wpdb_row, true) |
|
272 | + ) |
|
273 | + ); |
|
274 | + } |
|
275 | + self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
276 | + return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Gets the thumbnail image |
|
283 | + * |
|
284 | + * @param array $wpdb_row |
|
285 | + * @param \WP_REST_Request $request |
|
286 | + * @param Base $controller |
|
287 | + * @return array |
|
288 | + * @throws EE_Error |
|
289 | + */ |
|
290 | + public static function imageThumbnail($wpdb_row, $request, $controller) |
|
291 | + { |
|
292 | + return self::calculateImageData($wpdb_row, 'thumbnail'); |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Gets the medium image |
|
299 | + * |
|
300 | + * @param array $wpdb_row |
|
301 | + * @param \WP_REST_Request $request |
|
302 | + * @param Base $controller |
|
303 | + * @return array |
|
304 | + * @throws EE_Error |
|
305 | + */ |
|
306 | + public static function imageMedium($wpdb_row, $request, $controller) |
|
307 | + { |
|
308 | + return self::calculateImageData($wpdb_row, 'medium'); |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Gets the medium-large image |
|
315 | + * |
|
316 | + * @param array $wpdb_row |
|
317 | + * @param \WP_REST_Request $request |
|
318 | + * @param Base $controller |
|
319 | + * @return array |
|
320 | + * @throws EE_Error |
|
321 | + */ |
|
322 | + public static function imageMediumLarge($wpdb_row, $request, $controller) |
|
323 | + { |
|
324 | + return self::calculateImageData($wpdb_row, 'medium_large'); |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Gets the large image |
|
331 | + * |
|
332 | + * @param array $wpdb_row |
|
333 | + * @param \WP_REST_Request $request |
|
334 | + * @param Base $controller |
|
335 | + * @return array |
|
336 | + * @throws EE_Error |
|
337 | + */ |
|
338 | + public static function imageLarge($wpdb_row, $request, $controller) |
|
339 | + { |
|
340 | + return self::calculateImageData($wpdb_row, 'large'); |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * Gets the post-thumbnail image |
|
347 | + * |
|
348 | + * @param array $wpdb_row |
|
349 | + * @param \WP_REST_Request $request |
|
350 | + * @param Base $controller |
|
351 | + * @return array |
|
352 | + * @throws EE_Error |
|
353 | + */ |
|
354 | + public static function imagePostThumbnail($wpdb_row, $request, $controller) |
|
355 | + { |
|
356 | + return self::calculateImageData($wpdb_row, 'post-thumbnail'); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * Gets the full size image |
|
363 | + * |
|
364 | + * @param array $wpdb_row |
|
365 | + * @param \WP_REST_Request $request |
|
366 | + * @param Base $controller |
|
367 | + * @return array |
|
368 | + * @throws EE_Error |
|
369 | + */ |
|
370 | + public static function imageFull($wpdb_row, $request, $controller) |
|
371 | + { |
|
372 | + return self::calculateImageData($wpdb_row, 'full'); |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Gets image specs and formats them for the display in the API, |
|
379 | + * according to the image size requested |
|
380 | + * |
|
381 | + * @param array $wpdb_row |
|
382 | + * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full |
|
383 | + * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original' |
|
384 | + * @throws EE_Error |
|
385 | + */ |
|
386 | + protected static function calculateImageData($wpdb_row, $image_size) |
|
387 | + { |
|
388 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
389 | + throw new EE_Error( |
|
390 | + sprintf( |
|
391 | + __( |
|
392 | + // @codingStandardsIgnoreStart |
|
393 | + 'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
394 | + // @codingStandardsIgnoreEnd |
|
395 | + 'event_espresso' |
|
396 | + ), |
|
397 | + print_r($wpdb_row, true) |
|
398 | + ) |
|
399 | + ); |
|
400 | + } |
|
401 | + $EVT_ID = $wpdb_row['Event_CPT.ID']; |
|
402 | + $attachment_id = get_post_thumbnail_id($EVT_ID); |
|
403 | + $data = wp_get_attachment_image_src($attachment_id, $image_size); |
|
404 | + if (! $data) { |
|
405 | + return null; |
|
406 | + } |
|
407 | + $generated = true; |
|
408 | + if (isset($data[3])) { |
|
409 | + $generated = $data[3]; |
|
410 | + } |
|
411 | + return array( |
|
412 | + 'url' => $data[0], |
|
413 | + 'width' => $data[1], |
|
414 | + 'height' => $data[2], |
|
415 | + 'generated' => $generated, |
|
416 | + ); |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise |
|
423 | + * @param array $wpdb_row |
|
424 | + * @return bool |
|
425 | + */ |
|
426 | + protected static function wpdbRowHasEventId($wpdb_row) |
|
427 | + { |
|
428 | + return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID'])); |
|
429 | + } |
|
430 | 430 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @author Mike Nelson |
19 | 19 | * @since $VID:$ |
20 | 20 | */ |
21 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
21 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
22 | 22 | exit('No direct script access allowed'); |
23 | 23 | } |
24 | 24 | |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public static function spotsTaken($wpdb_row, $request, $controller) |
148 | 148 | { |
149 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
149 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
150 | 150 | throw new EE_Error( |
151 | 151 | sprintf( |
152 | 152 | __( |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | public static function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
188 | 188 | { |
189 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
189 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
190 | 190 | throw new EE_Error( |
191 | 191 | sprintf( |
192 | 192 | __( |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public static function registrationsCheckedInCount($wpdb_row, $request, $controller) |
229 | 229 | { |
230 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
230 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
231 | 231 | throw new EE_Error( |
232 | 232 | sprintf( |
233 | 233 | __( |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | */ |
260 | 260 | public static function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
261 | 261 | { |
262 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
262 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
263 | 263 | throw new EE_Error( |
264 | 264 | sprintf( |
265 | 265 | __( |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | */ |
386 | 386 | protected static function calculateImageData($wpdb_row, $image_size) |
387 | 387 | { |
388 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
388 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
389 | 389 | throw new EE_Error( |
390 | 390 | sprintf( |
391 | 391 | __( |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | $EVT_ID = $wpdb_row['Event_CPT.ID']; |
402 | 402 | $attachment_id = get_post_thumbnail_id($EVT_ID); |
403 | 403 | $data = wp_get_attachment_image_src($attachment_id, $image_size); |
404 | - if (! $data) { |
|
404 | + if ( ! $data) { |
|
405 | 405 | return null; |
406 | 406 | } |
407 | 407 | $generated = true; |
@@ -1,16 +1,16 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2 | 2 | /** |
3 | - * |
|
4 | - * Class EE_Checkout |
|
5 | - * |
|
6 | - * Description |
|
7 | - * |
|
8 | - * @package Event Espresso |
|
9 | - * @subpackage core |
|
10 | - * @author Brent Christensen |
|
11 | - * @since 4.5.0 |
|
12 | - * |
|
13 | - */ |
|
3 | + * |
|
4 | + * Class EE_Checkout |
|
5 | + * |
|
6 | + * Description |
|
7 | + * |
|
8 | + * @package Event Espresso |
|
9 | + * @subpackage core |
|
10 | + * @author Brent Christensen |
|
11 | + * @since 4.5.0 |
|
12 | + * |
|
13 | + */ |
|
14 | 14 | class EE_Checkout { |
15 | 15 | |
16 | 16 | /** |
@@ -250,9 +250,9 @@ discard block |
||
250 | 250 | $this->continue_reg = apply_filters( 'FHEE__EE_Checkout___construct___continue_reg', TRUE ); |
251 | 251 | $this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->ajax; |
252 | 252 | $this->reg_cache_where_params = array( |
253 | - 0 => array( 'REG_deleted' => false ), |
|
254 | - 'order_by' => array( 'REG_count' => 'ASC' ) |
|
255 | - ); |
|
253 | + 0 => array( 'REG_deleted' => false ), |
|
254 | + 'order_by' => array( 'REG_count' => 'ASC' ) |
|
255 | + ); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | |
@@ -807,10 +807,10 @@ discard block |
||
807 | 807 | */ |
808 | 808 | public function visit_allows_processing_of_this_registration( EE_Registration $registration ) { |
809 | 809 | return ! $this->revisit |
810 | - || $this->primary_revisit |
|
811 | - || ( |
|
812 | - $this->revisit && $this->reg_url_link === $registration->reg_url_link() |
|
813 | - ) |
|
810 | + || $this->primary_revisit |
|
811 | + || ( |
|
812 | + $this->revisit && $this->reg_url_link === $registration->reg_url_link() |
|
813 | + ) |
|
814 | 814 | ? true |
815 | 815 | : false; |
816 | 816 | } |
@@ -1202,16 +1202,16 @@ discard block |
||
1202 | 1202 | * @return array |
1203 | 1203 | * @throws \EE_Error |
1204 | 1204 | */ |
1205 | - public function __sleep() |
|
1206 | - { |
|
1207 | - if ( $this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID() ) { |
|
1208 | - $this->primary_attendee_obj = $this->primary_attendee_obj->ID(); |
|
1209 | - } // remove the reg form and the checkout |
|
1210 | - if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) { |
|
1211 | - $this->transaction = $this->transaction->ID(); |
|
1212 | - } // remove the reg form and the checkout |
|
1213 | - return array_diff( array_keys( get_object_vars( $this ) ), array( 'billing_form', 'registration_form' ) ); |
|
1214 | - } |
|
1205 | + public function __sleep() |
|
1206 | + { |
|
1207 | + if ( $this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID() ) { |
|
1208 | + $this->primary_attendee_obj = $this->primary_attendee_obj->ID(); |
|
1209 | + } // remove the reg form and the checkout |
|
1210 | + if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) { |
|
1211 | + $this->transaction = $this->transaction->ID(); |
|
1212 | + } // remove the reg form and the checkout |
|
1213 | + return array_diff( array_keys( get_object_vars( $this ) ), array( 'billing_form', 'registration_form' ) ); |
|
1214 | + } |
|
1215 | 1215 | |
1216 | 1216 | |
1217 | 1217 | /** |
@@ -247,11 +247,11 @@ discard block |
||
247 | 247 | $this->reg_page_base_url = EE_Registry::instance()->CFG->core->reg_page_url(); |
248 | 248 | $this->thank_you_page_url = EE_Registry::instance()->CFG->core->thank_you_page_url(); |
249 | 249 | $this->cancel_page_url = EE_Registry::instance()->CFG->core->cancel_page_url(); |
250 | - $this->continue_reg = apply_filters( 'FHEE__EE_Checkout___construct___continue_reg', TRUE ); |
|
250 | + $this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', TRUE); |
|
251 | 251 | $this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->ajax; |
252 | 252 | $this->reg_cache_where_params = array( |
253 | - 0 => array( 'REG_deleted' => false ), |
|
254 | - 'order_by' => array( 'REG_count' => 'ASC' ) |
|
253 | + 0 => array('REG_deleted' => false), |
|
254 | + 'order_by' => array('REG_count' => 'ASC') |
|
255 | 255 | ); |
256 | 256 | } |
257 | 257 | |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | * @return boolean |
264 | 264 | */ |
265 | 265 | public function any_reg_status_updated() { |
266 | - foreach ( $this->reg_status_updated as $reg_status ) { |
|
267 | - if ( $reg_status ) { |
|
266 | + foreach ($this->reg_status_updated as $reg_status) { |
|
267 | + if ($reg_status) { |
|
268 | 268 | return true; |
269 | 269 | } |
270 | 270 | } |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | * @param $REG_ID |
278 | 278 | * @return boolean |
279 | 279 | */ |
280 | - public function reg_status_updated( $REG_ID ) { |
|
281 | - return isset( $this->reg_status_updated[ $REG_ID ] ) ? $this->reg_status_updated[ $REG_ID ] : false; |
|
280 | + public function reg_status_updated($REG_ID) { |
|
281 | + return isset($this->reg_status_updated[$REG_ID]) ? $this->reg_status_updated[$REG_ID] : false; |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | |
@@ -287,8 +287,8 @@ discard block |
||
287 | 287 | * @param $REG_ID |
288 | 288 | * @param $reg_status |
289 | 289 | */ |
290 | - public function set_reg_status_updated( $REG_ID, $reg_status ) { |
|
291 | - $this->reg_status_updated[ $REG_ID ] = filter_var( $reg_status, FILTER_VALIDATE_BOOLEAN ); |
|
290 | + public function set_reg_status_updated($REG_ID, $reg_status) { |
|
291 | + $this->reg_status_updated[$REG_ID] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * can ONLY be set by the Finalize_Registration reg step |
310 | 310 | */ |
311 | 311 | public function set_exit_spco() { |
312 | - if ( $this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration ) { |
|
312 | + if ($this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
313 | 313 | $this->exit_spco = true; |
314 | 314 | } |
315 | 315 | } |
@@ -326,12 +326,12 @@ discard block |
||
326 | 326 | */ |
327 | 327 | public function reset_for_current_request() { |
328 | 328 | $this->process_form_submission = FALSE; |
329 | - $this->continue_reg = apply_filters( 'FHEE__EE_Checkout___construct___continue_reg', true ); |
|
329 | + $this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true); |
|
330 | 330 | $this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->front_ajax; |
331 | 331 | $this->continue_reg = true; |
332 | 332 | $this->redirect = false; |
333 | 333 | // don't reset the cached redirect form if we're about to be asked to display it !!! |
334 | - if ( EE_Registry::instance()->REQ->get( 'action', 'display_spco_reg_step' ) !== 'redirect_form' ) { |
|
334 | + if (EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step') !== 'redirect_form') { |
|
335 | 335 | $this->redirect_form = ''; |
336 | 336 | } |
337 | 337 | $this->redirect_url = ''; |
@@ -348,8 +348,8 @@ discard block |
||
348 | 348 | * @param EE_SPCO_Reg_Step $reg_step_obj |
349 | 349 | * @return void |
350 | 350 | */ |
351 | - public function add_reg_step( EE_SPCO_Reg_Step $reg_step_obj ) { |
|
352 | - $this->reg_steps[ $reg_step_obj->slug() ] = $reg_step_obj; |
|
351 | + public function add_reg_step(EE_SPCO_Reg_Step $reg_step_obj) { |
|
352 | + $this->reg_steps[$reg_step_obj->slug()] = $reg_step_obj; |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | |
@@ -365,22 +365,22 @@ discard block |
||
365 | 365 | * @return void |
366 | 366 | * @throws \EE_Error |
367 | 367 | */ |
368 | - public function skip_reg_step( $reg_step_slug = '' ) { |
|
369 | - $step_to_skip = $this->find_reg_step( $reg_step_slug ); |
|
370 | - if ( $step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step() ) { |
|
371 | - $step_to_skip->set_is_current_step( false ); |
|
368 | + public function skip_reg_step($reg_step_slug = '') { |
|
369 | + $step_to_skip = $this->find_reg_step($reg_step_slug); |
|
370 | + if ($step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step()) { |
|
371 | + $step_to_skip->set_is_current_step(false); |
|
372 | 372 | $step_to_skip->set_completed(); |
373 | 373 | // advance to the next step |
374 | - $this->set_current_step( $this->next_step->slug() ); |
|
374 | + $this->set_current_step($this->next_step->slug()); |
|
375 | 375 | // also reset the step param in the request in case any other code references that directly |
376 | - EE_Registry::instance()->REQ->set( 'step', $this->current_step->slug() ); |
|
376 | + EE_Registry::instance()->REQ->set('step', $this->current_step->slug()); |
|
377 | 377 | // since we are skipping a step and setting the current step to be what was previously the next step, |
378 | 378 | // we need to check that the next step is now correct, and not still set to the current step. |
379 | - if ( $this->current_step->slug() === $this->next_step->slug() ) { |
|
379 | + if ($this->current_step->slug() === $this->next_step->slug()) { |
|
380 | 380 | // correctly setup the next step |
381 | 381 | $this->set_next_step(); |
382 | 382 | } |
383 | - $this->set_reg_step_initiated( $this->current_step ); |
|
383 | + $this->set_reg_step_initiated($this->current_step); |
|
384 | 384 | } |
385 | 385 | } |
386 | 386 | |
@@ -394,14 +394,14 @@ discard block |
||
394 | 394 | * @param bool $reset whether to reset reg steps after removal |
395 | 395 | * @throws EE_Error |
396 | 396 | */ |
397 | - public function remove_reg_step( $reg_step_slug = '', $reset = true ) { |
|
398 | - unset( $this->reg_steps[ $reg_step_slug ] ); |
|
399 | - if ( $this->transaction instanceof EE_Transaction ) { |
|
397 | + public function remove_reg_step($reg_step_slug = '', $reset = true) { |
|
398 | + unset($this->reg_steps[$reg_step_slug]); |
|
399 | + if ($this->transaction instanceof EE_Transaction) { |
|
400 | 400 | // now remove reg step from TXN and save |
401 | - $this->transaction->remove_reg_step( $reg_step_slug ); |
|
401 | + $this->transaction->remove_reg_step($reg_step_slug); |
|
402 | 402 | $this->transaction->save(); |
403 | 403 | } |
404 | - if ( $reset ) { |
|
404 | + if ($reset) { |
|
405 | 405 | $this->reset_reg_steps(); |
406 | 406 | } |
407 | 407 | } |
@@ -416,9 +416,9 @@ discard block |
||
416 | 416 | * @param int $order |
417 | 417 | * @return void |
418 | 418 | */ |
419 | - public function set_reg_step_order( $reg_step_slug = '', $order = 100 ) { |
|
420 | - if ( isset( $this->reg_steps[ $reg_step_slug ] )) { |
|
421 | - $this->reg_steps[ $reg_step_slug ]->set_order( $order ); |
|
419 | + public function set_reg_step_order($reg_step_slug = '', $order = 100) { |
|
420 | + if (isset($this->reg_steps[$reg_step_slug])) { |
|
421 | + $this->reg_steps[$reg_step_slug]->set_order($order); |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
@@ -431,25 +431,25 @@ discard block |
||
431 | 431 | * @param string $current_step |
432 | 432 | * @return void |
433 | 433 | */ |
434 | - public function set_current_step( $current_step ) { |
|
434 | + public function set_current_step($current_step) { |
|
435 | 435 | // grab what step we're on |
436 | - $this->current_step = isset( $this->reg_steps[ $current_step ] ) ? $this->reg_steps[ $current_step ] : reset( $this->reg_steps ); |
|
436 | + $this->current_step = isset($this->reg_steps[$current_step]) ? $this->reg_steps[$current_step] : reset($this->reg_steps); |
|
437 | 437 | // verify instance |
438 | - if ( $this->current_step instanceof EE_SPCO_Reg_Step ) { |
|
438 | + if ($this->current_step instanceof EE_SPCO_Reg_Step) { |
|
439 | 439 | // we don't want to repeat completed steps if this is the first time through SPCO |
440 | - if ( $this->continue_reg && ! $this->revisit && $this->current_step->completed() ) { |
|
440 | + if ($this->continue_reg && ! $this->revisit && $this->current_step->completed()) { |
|
441 | 441 | // so advance to the next step |
442 | 442 | $this->set_next_step(); |
443 | - if ( $this->next_step instanceof EE_SPCO_Reg_Step ) { |
|
443 | + if ($this->next_step instanceof EE_SPCO_Reg_Step) { |
|
444 | 444 | // and attempt to set it as the current step |
445 | - $this->set_current_step( $this->next_step->slug() ); |
|
445 | + $this->set_current_step($this->next_step->slug()); |
|
446 | 446 | } |
447 | 447 | return; |
448 | 448 | } |
449 | - $this->current_step->set_is_current_step( TRUE ); |
|
449 | + $this->current_step->set_is_current_step(TRUE); |
|
450 | 450 | } else { |
451 | 451 | EE_Error::add_error( |
452 | - __( 'The current step could not be set.', 'event_espresso' ), |
|
452 | + __('The current step could not be set.', 'event_espresso'), |
|
453 | 453 | __FILE__, __FUNCTION__, __LINE__ |
454 | 454 | ); |
455 | 455 | } |
@@ -466,20 +466,20 @@ discard block |
||
466 | 466 | */ |
467 | 467 | public function set_next_step() { |
468 | 468 | // set pointer to start of array |
469 | - reset( $this->reg_steps ); |
|
469 | + reset($this->reg_steps); |
|
470 | 470 | // if there is more than one step |
471 | - if ( count( $this->reg_steps ) > 1 ) { |
|
471 | + if (count($this->reg_steps) > 1) { |
|
472 | 472 | // advance to the current step and set pointer |
473 | - while ( key( $this->reg_steps ) !== $this->current_step->slug() && key( $this->reg_steps ) !== '' ) { |
|
474 | - next( $this->reg_steps ); |
|
473 | + while (key($this->reg_steps) !== $this->current_step->slug() && key($this->reg_steps) !== '') { |
|
474 | + next($this->reg_steps); |
|
475 | 475 | } |
476 | 476 | } |
477 | 477 | // advance one more spot ( if it exists ) |
478 | - $this->next_step = next( $this->reg_steps ); |
|
478 | + $this->next_step = next($this->reg_steps); |
|
479 | 479 | // verify instance |
480 | - $this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : NULL; |
|
480 | + $this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : NULL; |
|
481 | 481 | // then back to current step to reset |
482 | - prev( $this->reg_steps ); |
|
482 | + prev($this->reg_steps); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | |
@@ -493,8 +493,8 @@ discard block |
||
493 | 493 | * @return EE_SPCO_Reg_Step | null |
494 | 494 | */ |
495 | 495 | public function get_next_reg_step() { |
496 | - $next = next( $this->reg_steps ); |
|
497 | - prev( $this->reg_steps ); |
|
496 | + $next = next($this->reg_steps); |
|
497 | + prev($this->reg_steps); |
|
498 | 498 | return $next instanceof EE_SPCO_Reg_Step ? $next : null; |
499 | 499 | } |
500 | 500 | |
@@ -509,8 +509,8 @@ discard block |
||
509 | 509 | * @return EE_SPCO_Reg_Step | null |
510 | 510 | */ |
511 | 511 | public function get_prev_reg_step() { |
512 | - $prev = prev( $this->reg_steps ); |
|
513 | - next( $this->reg_steps ); |
|
512 | + $prev = prev($this->reg_steps); |
|
513 | + next($this->reg_steps); |
|
514 | 514 | return $prev instanceof EE_SPCO_Reg_Step ? $prev : null; |
515 | 515 | } |
516 | 516 | |
@@ -523,8 +523,8 @@ discard block |
||
523 | 523 | * @return void |
524 | 524 | */ |
525 | 525 | public function sort_reg_steps() { |
526 | - $reg_step_sorting_callback = apply_filters( 'FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback', 'reg_step_sorting_callback' ); |
|
527 | - uasort( $this->reg_steps, array( $this, $reg_step_sorting_callback )); |
|
526 | + $reg_step_sorting_callback = apply_filters('FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback', 'reg_step_sorting_callback'); |
|
527 | + uasort($this->reg_steps, array($this, $reg_step_sorting_callback)); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | |
@@ -537,19 +537,19 @@ discard block |
||
537 | 537 | * @param string $reg_step_slug |
538 | 538 | * @return EE_SPCO_Reg_Step|null |
539 | 539 | */ |
540 | - public function find_reg_step( $reg_step_slug = '' ) { |
|
541 | - if ( ! empty( $reg_step_slug ) ) { |
|
540 | + public function find_reg_step($reg_step_slug = '') { |
|
541 | + if ( ! empty($reg_step_slug)) { |
|
542 | 542 | // copy reg step array |
543 | 543 | $reg_steps = $this->reg_steps; |
544 | 544 | // set pointer to start of array |
545 | - reset( $reg_steps ); |
|
545 | + reset($reg_steps); |
|
546 | 546 | // if there is more than one step |
547 | - if ( count( $reg_steps ) > 1 ) { |
|
547 | + if (count($reg_steps) > 1) { |
|
548 | 548 | // advance to the current step and set pointer |
549 | - while ( key( $reg_steps ) !== $reg_step_slug && key( $reg_steps ) !== '' ) { |
|
550 | - next( $reg_steps ); |
|
549 | + while (key($reg_steps) !== $reg_step_slug && key($reg_steps) !== '') { |
|
550 | + next($reg_steps); |
|
551 | 551 | } |
552 | - return current( $reg_steps ); |
|
552 | + return current($reg_steps); |
|
553 | 553 | } |
554 | 554 | } |
555 | 555 | return null; |
@@ -565,17 +565,17 @@ discard block |
||
565 | 565 | * @param EE_SPCO_Reg_Step $reg_step_B |
566 | 566 | * @return int |
567 | 567 | */ |
568 | - public function reg_step_sorting_callback( EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B ) { |
|
568 | + public function reg_step_sorting_callback(EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B) { |
|
569 | 569 | // send finalize_registration step to the end of the array |
570 | - if ( $reg_step_A->slug() === 'finalize_registration' ) { |
|
570 | + if ($reg_step_A->slug() === 'finalize_registration') { |
|
571 | 571 | return 1; |
572 | - } else if ( $reg_step_B->slug() === 'finalize_registration' ) { |
|
572 | + } else if ($reg_step_B->slug() === 'finalize_registration') { |
|
573 | 573 | return -1; |
574 | 574 | } |
575 | - if ( $reg_step_A->order() === $reg_step_B->order() ) { |
|
575 | + if ($reg_step_A->order() === $reg_step_B->order()) { |
|
576 | 576 | return 0; |
577 | 577 | } |
578 | - return ( $reg_step_A->order() > $reg_step_B->order() ) ? 1 : -1; |
|
578 | + return ($reg_step_A->order() > $reg_step_B->order()) ? 1 : -1; |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | * @param EE_SPCO_Reg_Step $reg_step |
588 | 588 | * @throws \EE_Error |
589 | 589 | */ |
590 | - public function set_reg_step_initiated( EE_SPCO_Reg_Step $reg_step ) { |
|
590 | + public function set_reg_step_initiated(EE_SPCO_Reg_Step $reg_step) { |
|
591 | 591 | // call set_reg_step_initiated ??? |
592 | 592 | if ( |
593 | 593 | // first time visiting SPCO ? |
@@ -600,11 +600,11 @@ discard block |
||
600 | 600 | ) |
601 | 601 | ) { |
602 | 602 | // set the start time for this reg step |
603 | - if ( ! $this->transaction->set_reg_step_initiated( $reg_step->slug() ) ) { |
|
604 | - if ( WP_DEBUG ) { |
|
603 | + if ( ! $this->transaction->set_reg_step_initiated($reg_step->slug())) { |
|
604 | + if (WP_DEBUG) { |
|
605 | 605 | EE_Error::add_error( |
606 | 606 | sprintf( |
607 | - __( 'The "%1$s" registration step was not initialized properly.', 'event_espresso' ), |
|
607 | + __('The "%1$s" registration step was not initialized properly.', 'event_espresso'), |
|
608 | 608 | $reg_step->name() |
609 | 609 | ), |
610 | 610 | __FILE__, __FUNCTION__, __LINE__ |
@@ -623,10 +623,10 @@ discard block |
||
623 | 623 | * @return void |
624 | 624 | */ |
625 | 625 | public function set_reg_step_JSON_info() { |
626 | - EE_Registry::$i18n_js_strings[ 'reg_steps' ] = array(); |
|
626 | + EE_Registry::$i18n_js_strings['reg_steps'] = array(); |
|
627 | 627 | // pass basic reg step data to JS |
628 | - foreach ( $this->reg_steps as $reg_step ) { |
|
629 | - EE_Registry::$i18n_js_strings[ 'reg_steps' ][] = $reg_step->slug(); |
|
628 | + foreach ($this->reg_steps as $reg_step) { |
|
629 | + EE_Registry::$i18n_js_strings['reg_steps'][] = $reg_step->slug(); |
|
630 | 630 | } |
631 | 631 | // reset reg step html |
632 | 632 | // $this->json_response->set_reg_step_html( '' ); |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | */ |
643 | 643 | public function reset_reg_steps() { |
644 | 644 | $this->sort_reg_steps(); |
645 | - $this->set_current_step( EE_Registry::instance()->REQ->get( 'step' )); |
|
645 | + $this->set_current_step(EE_Registry::instance()->REQ->get('step')); |
|
646 | 646 | $this->set_next_step(); |
647 | 647 | // the text that appears on the reg step form submit button |
648 | 648 | $this->current_step->set_submit_button_text(); |
@@ -659,9 +659,9 @@ discard block |
||
659 | 659 | */ |
660 | 660 | public function get_registration_time_limit() { |
661 | 661 | |
662 | - $registration_time_limit = (float)( EE_Registry::instance() ->SSN->expiration() - time() ); |
|
662 | + $registration_time_limit = (float) (EE_Registry::instance() ->SSN->expiration() - time()); |
|
663 | 663 | $time_limit_format = $registration_time_limit > 60 * MINUTE_IN_SECONDS ? 'H:i:s' : 'i:s'; |
664 | - $registration_time_limit = date( $time_limit_format, $registration_time_limit ); |
|
664 | + $registration_time_limit = date($time_limit_format, $registration_time_limit); |
|
665 | 665 | return apply_filters( |
666 | 666 | 'FHEE__EE_Checkout__get_registration_time_limit__registration_time_limit', |
667 | 667 | $registration_time_limit |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | // overpaid TXN |
682 | 682 | // free TXN ( total = 0.00 ) |
683 | 683 | // then payment required is TRUE |
684 | - return ! ( $this->admin_request || $this->transaction->is_completed() || $this->transaction->is_overpaid() || $this->transaction->is_free() ) ? TRUE : FALSE; |
|
684 | + return ! ($this->admin_request || $this->transaction->is_completed() || $this->transaction->is_overpaid() || $this->transaction->is_free()) ? TRUE : FALSE; |
|
685 | 685 | } |
686 | 686 | |
687 | 687 | |
@@ -693,12 +693,12 @@ discard block |
||
693 | 693 | * @param EE_Transaction $transaction |
694 | 694 | * @return EE_Cart |
695 | 695 | */ |
696 | - public function get_cart_for_transaction( $transaction ) { |
|
697 | - $session = EE_Registry::instance()->load_core( 'Session' ); |
|
698 | - $cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn( $transaction, $session ) : null; |
|
696 | + public function get_cart_for_transaction($transaction) { |
|
697 | + $session = EE_Registry::instance()->load_core('Session'); |
|
698 | + $cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn($transaction, $session) : null; |
|
699 | 699 | // verify cart |
700 | - if ( ! $cart instanceof EE_Cart ) { |
|
701 | - $cart = EE_Registry::instance()->load_core( 'Cart' ); |
|
700 | + if ( ! $cart instanceof EE_Cart) { |
|
701 | + $cart = EE_Registry::instance()->load_core('Cart'); |
|
702 | 702 | } |
703 | 703 | |
704 | 704 | return $cart; |
@@ -714,8 +714,8 @@ discard block |
||
714 | 714 | */ |
715 | 715 | public function initialize_txn_reg_steps_array() { |
716 | 716 | $txn_reg_steps_array = array(); |
717 | - foreach ( $this->reg_steps as $reg_step ) { |
|
718 | - $txn_reg_steps_array[ $reg_step->slug() ] = FALSE; |
|
717 | + foreach ($this->reg_steps as $reg_step) { |
|
718 | + $txn_reg_steps_array[$reg_step->slug()] = FALSE; |
|
719 | 719 | } |
720 | 720 | return $txn_reg_steps_array; |
721 | 721 | } |
@@ -731,14 +731,14 @@ discard block |
||
731 | 731 | */ |
732 | 732 | public function update_txn_reg_steps_array() { |
733 | 733 | $updated = false; |
734 | - foreach ( $this->reg_steps as $reg_step ) { |
|
735 | - if ( $reg_step->completed() ) { |
|
736 | - $updated = $this->transaction->set_reg_step_completed( $reg_step->slug() ) |
|
734 | + foreach ($this->reg_steps as $reg_step) { |
|
735 | + if ($reg_step->completed()) { |
|
736 | + $updated = $this->transaction->set_reg_step_completed($reg_step->slug()) |
|
737 | 737 | ? true |
738 | 738 | : $updated; |
739 | 739 | } |
740 | 740 | } |
741 | - if ( $updated ) { |
|
741 | + if ($updated) { |
|
742 | 742 | $this->transaction->save(); |
743 | 743 | } |
744 | 744 | return $updated; |
@@ -754,14 +754,14 @@ discard block |
||
754 | 754 | * @throws \EE_Error |
755 | 755 | */ |
756 | 756 | public function stash_transaction_and_checkout() { |
757 | - if ( ! $this->revisit ) { |
|
757 | + if ( ! $this->revisit) { |
|
758 | 758 | $this->update_txn_reg_steps_array(); |
759 | 759 | } |
760 | 760 | $this->track_transaction_and_registration_status_updates(); |
761 | 761 | // save all data to the db, but suppress errors |
762 | 762 | //$this->save_all_data( FALSE ); |
763 | 763 | // cache the checkout in the session |
764 | - EE_Registry::instance()->SSN->set_checkout( $this ); |
|
764 | + EE_Registry::instance()->SSN->set_checkout($this); |
|
765 | 765 | } |
766 | 766 | |
767 | 767 | |
@@ -776,15 +776,15 @@ discard block |
||
776 | 776 | */ |
777 | 777 | public function track_transaction_and_registration_status_updates() { |
778 | 778 | // verify the transaction |
779 | - if ( $this->transaction instanceof EE_Transaction ) { |
|
779 | + if ($this->transaction instanceof EE_Transaction) { |
|
780 | 780 | // has there been a TXN status change during this checkout? |
781 | 781 | $this->txn_status_updated = $this->transaction->txn_status_updated(); |
782 | 782 | /** @type EE_Registration_Processor $registration_processor */ |
783 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
783 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
784 | 784 | // grab the saved registrations from the transaction |
785 | - foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $registration ) { |
|
786 | - if ( $registration_processor->reg_status_updated( $registration->ID() ) ) { |
|
787 | - $this->set_reg_status_updated( $registration->ID(), true ); |
|
785 | + foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) { |
|
786 | + if ($registration_processor->reg_status_updated($registration->ID())) { |
|
787 | + $this->set_reg_status_updated($registration->ID(), true); |
|
788 | 788 | } |
789 | 789 | } |
790 | 790 | } |
@@ -805,7 +805,7 @@ discard block |
||
805 | 805 | * @return bool |
806 | 806 | * @throws \EE_Error |
807 | 807 | */ |
808 | - public function visit_allows_processing_of_this_registration( EE_Registration $registration ) { |
|
808 | + public function visit_allows_processing_of_this_registration(EE_Registration $registration) { |
|
809 | 809 | return ! $this->revisit |
810 | 810 | || $this->primary_revisit |
811 | 811 | || ( |
@@ -838,18 +838,18 @@ discard block |
||
838 | 838 | * @return bool |
839 | 839 | * @throws \EE_Error |
840 | 840 | */ |
841 | - public function save_all_data( $show_errors = TRUE ) { |
|
841 | + public function save_all_data($show_errors = TRUE) { |
|
842 | 842 | // verify the transaction |
843 | - if ( $this->transaction instanceof EE_Transaction ) { |
|
843 | + if ($this->transaction instanceof EE_Transaction) { |
|
844 | 844 | // save to ensure that TXN has ID |
845 | 845 | $this->transaction->save(); |
846 | 846 | // grab the saved registrations from the transaction |
847 | - foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $registration ) { |
|
848 | - $this->_save_registration( $registration, $show_errors ); |
|
847 | + foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) { |
|
848 | + $this->_save_registration($registration, $show_errors); |
|
849 | 849 | } |
850 | 850 | } else { |
851 | - if ( $show_errors ) { |
|
852 | - EE_Error::add_error( __( 'A valid Transaction was not found when attempting to save your registration information.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
851 | + if ($show_errors) { |
|
852 | + EE_Error::add_error(__('A valid Transaction was not found when attempting to save your registration information.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
853 | 853 | } |
854 | 854 | return FALSE; |
855 | 855 | } |
@@ -866,32 +866,32 @@ discard block |
||
866 | 866 | * @return void |
867 | 867 | * @throws \EE_Error |
868 | 868 | */ |
869 | - private function _save_registration( $registration, $show_errors = TRUE ) { |
|
869 | + private function _save_registration($registration, $show_errors = TRUE) { |
|
870 | 870 | // verify object |
871 | - if ( $registration instanceof EE_Registration ) { |
|
871 | + if ($registration instanceof EE_Registration) { |
|
872 | 872 | // should this registration be processed during this visit ? |
873 | - if ( $this->visit_allows_processing_of_this_registration( $registration ) ) { |
|
873 | + if ($this->visit_allows_processing_of_this_registration($registration)) { |
|
874 | 874 | //set TXN ID |
875 | - if ( ! $registration->transaction_ID() ) { |
|
876 | - $registration->set_transaction_id( $this->transaction->ID() ); |
|
875 | + if ( ! $registration->transaction_ID()) { |
|
876 | + $registration->set_transaction_id($this->transaction->ID()); |
|
877 | 877 | } |
878 | 878 | // verify and save the attendee |
879 | - $this->_save_registration_attendee( $registration, $show_errors ); |
|
879 | + $this->_save_registration_attendee($registration, $show_errors); |
|
880 | 880 | // save answers to reg form questions |
881 | - $this->_save_registration_answers( $registration, $show_errors ); |
|
881 | + $this->_save_registration_answers($registration, $show_errors); |
|
882 | 882 | // save changes |
883 | 883 | $registration->save(); |
884 | 884 | // update txn cache |
885 | - if ( ! $this->transaction->update_cache_after_object_save( 'Registration', $registration )) { |
|
886 | - if ( $show_errors ) { |
|
887 | - EE_Error::add_error( __( 'The newly saved Registration object could not be cached on the Transaction.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
885 | + if ( ! $this->transaction->update_cache_after_object_save('Registration', $registration)) { |
|
886 | + if ($show_errors) { |
|
887 | + EE_Error::add_error(__('The newly saved Registration object could not be cached on the Transaction.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
888 | 888 | } |
889 | 889 | } |
890 | 890 | } |
891 | 891 | } else { |
892 | - if ( $show_errors ) { |
|
892 | + if ($show_errors) { |
|
893 | 893 | EE_Error::add_error( |
894 | - __( 'An invalid Registration object was discovered when attempting to save your registration information.', 'event_espresso' ), |
|
894 | + __('An invalid Registration object was discovered when attempting to save your registration information.', 'event_espresso'), |
|
895 | 895 | __FILE__, __FUNCTION__, __LINE__ |
896 | 896 | ); |
897 | 897 | } |
@@ -908,25 +908,25 @@ discard block |
||
908 | 908 | * @return void |
909 | 909 | * @throws \EE_Error |
910 | 910 | */ |
911 | - private function _save_registration_attendee( $registration, $show_errors = TRUE ) { |
|
912 | - if ( $registration->attendee() instanceof EE_Attendee ) { |
|
911 | + private function _save_registration_attendee($registration, $show_errors = TRUE) { |
|
912 | + if ($registration->attendee() instanceof EE_Attendee) { |
|
913 | 913 | // save so that ATT has ID |
914 | 914 | $registration->attendee()->save(); |
915 | - if ( ! $registration->update_cache_after_object_save( 'Attendee', $registration->attendee() ) ) { |
|
916 | - if ( $show_errors ) { |
|
915 | + if ( ! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) { |
|
916 | + if ($show_errors) { |
|
917 | 917 | EE_Error::add_error( |
918 | - __( 'The newly saved Attendee object could not be cached on the registration.', 'event_espresso' ), |
|
918 | + __('The newly saved Attendee object could not be cached on the registration.', 'event_espresso'), |
|
919 | 919 | __FILE__, __FUNCTION__, __LINE__ |
920 | 920 | ); |
921 | 921 | } |
922 | 922 | } |
923 | 923 | } else { |
924 | - if ( $show_errors ) { |
|
924 | + if ($show_errors) { |
|
925 | 925 | EE_Error::add_error( |
926 | 926 | sprintf( |
927 | 927 | '%1$s||%1$s $attendee = %2$s', |
928 | - __( 'Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.', 'event_espresso' ), |
|
929 | - var_export( $registration->attendee(), true ) |
|
928 | + __('Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.', 'event_espresso'), |
|
929 | + var_export($registration->attendee(), true) |
|
930 | 930 | ), |
931 | 931 | __FILE__, __FUNCTION__, __LINE__ |
932 | 932 | ); |
@@ -944,25 +944,25 @@ discard block |
||
944 | 944 | * @return void |
945 | 945 | * @throws \EE_Error |
946 | 946 | */ |
947 | - private function _save_registration_answers( $registration, $show_errors = TRUE ) { |
|
947 | + private function _save_registration_answers($registration, $show_errors = TRUE) { |
|
948 | 948 | // now save the answers |
949 | - foreach ( $registration->answers() as $cache_key => $answer ) { |
|
949 | + foreach ($registration->answers() as $cache_key => $answer) { |
|
950 | 950 | // verify object |
951 | - if ( $answer instanceof EE_Answer ) { |
|
952 | - $answer->set_registration( $registration->ID() ); |
|
951 | + if ($answer instanceof EE_Answer) { |
|
952 | + $answer->set_registration($registration->ID()); |
|
953 | 953 | $answer->save(); |
954 | - if ( ! $registration->update_cache_after_object_save( 'Answer', $answer, $cache_key )) { |
|
955 | - if ( $show_errors ) { |
|
954 | + if ( ! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) { |
|
955 | + if ($show_errors) { |
|
956 | 956 | EE_Error::add_error( |
957 | - __( 'The newly saved Answer object could not be cached on the registration.', 'event_espresso' ), |
|
957 | + __('The newly saved Answer object could not be cached on the registration.', 'event_espresso'), |
|
958 | 958 | __FILE__, __FUNCTION__, __LINE__ |
959 | 959 | ); |
960 | 960 | } |
961 | 961 | } |
962 | 962 | } else { |
963 | - if ( $show_errors ) { |
|
963 | + if ($show_errors) { |
|
964 | 964 | EE_Error::add_error( |
965 | - __( 'An invalid Answer object was discovered when attempting to save your registration information.', 'event_espresso' ), |
|
965 | + __('An invalid Answer object was discovered when attempting to save your registration information.', 'event_espresso'), |
|
966 | 966 | __FILE__, __FUNCTION__, __LINE__ |
967 | 967 | ); |
968 | 968 | } |
@@ -981,7 +981,7 @@ discard block |
||
981 | 981 | * @return bool |
982 | 982 | * @throws \EE_Error |
983 | 983 | */ |
984 | - public function refresh_all_entities( $from_db = false ) { |
|
984 | + public function refresh_all_entities($from_db = false) { |
|
985 | 985 | $from_db = $this->current_step->is_final_step() || $this->action === 'process_gateway_response' |
986 | 986 | ? true |
987 | 987 | : $from_db; |
@@ -1005,11 +1005,11 @@ discard block |
||
1005 | 1005 | */ |
1006 | 1006 | protected function refresh_from_db() { |
1007 | 1007 | // verify the transaction |
1008 | - if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) { |
|
1008 | + if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) { |
|
1009 | 1009 | // pull fresh TXN data from the db |
1010 | - $this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db( $this->transaction->ID() ); |
|
1010 | + $this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db($this->transaction->ID()); |
|
1011 | 1011 | // update EE_Checkout's cached primary_attendee object |
1012 | - $this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db( $this->transaction ); |
|
1012 | + $this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db($this->transaction); |
|
1013 | 1013 | // update EE_Checkout's cached payment object |
1014 | 1014 | $payment = $this->transaction->last_payment(); |
1015 | 1015 | $this->payment = $payment instanceof EE_Payment ? $payment : $this->payment; |
@@ -1017,9 +1017,9 @@ discard block |
||
1017 | 1017 | $payment_method = $this->payment instanceof EE_Payment ? $this->payment->payment_method() : null; |
1018 | 1018 | $this->payment_method = $payment_method instanceof EE_Payment_Method ? $payment_method : $this->payment_method; |
1019 | 1019 | //now refresh the cart, based on the TXN |
1020 | - $this->cart = $this->get_cart_for_transaction( $this->transaction ); |
|
1020 | + $this->cart = $this->get_cart_for_transaction($this->transaction); |
|
1021 | 1021 | } else { |
1022 | - EE_Error::add_error( __( 'A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
1022 | + EE_Error::add_error(__('A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1023 | 1023 | return FALSE; |
1024 | 1024 | } |
1025 | 1025 | return TRUE; |
@@ -1034,21 +1034,21 @@ discard block |
||
1034 | 1034 | * @return EE_Attendee | null |
1035 | 1035 | * @throws \EE_Error |
1036 | 1036 | */ |
1037 | - protected function _refresh_primary_attendee_obj_from_db( EE_Transaction $transaction ) { |
|
1037 | + protected function _refresh_primary_attendee_obj_from_db(EE_Transaction $transaction) { |
|
1038 | 1038 | |
1039 | 1039 | $primary_attendee_obj = null; |
1040 | 1040 | // grab the saved registrations from the transaction |
1041 | - foreach ( $transaction->registrations( $this->reg_cache_where_params, true ) as $registration ) { |
|
1041 | + foreach ($transaction->registrations($this->reg_cache_where_params, true) as $registration) { |
|
1042 | 1042 | // verify object |
1043 | - if ( $registration instanceof EE_Registration ) { |
|
1043 | + if ($registration instanceof EE_Registration) { |
|
1044 | 1044 | $attendee = $registration->attendee(); |
1045 | 1045 | // verify object && maybe cache primary_attendee_obj ? |
1046 | - if ( $attendee instanceof EE_Attendee&& $registration->is_primary_registrant() ) { |
|
1046 | + if ($attendee instanceof EE_Attendee && $registration->is_primary_registrant()) { |
|
1047 | 1047 | $primary_attendee_obj = $attendee; |
1048 | 1048 | } |
1049 | 1049 | } else { |
1050 | 1050 | EE_Error::add_error( |
1051 | - __( 'An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso' ), |
|
1051 | + __('An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso'), |
|
1052 | 1052 | __FILE__, __FUNCTION__, __LINE__ |
1053 | 1053 | ); |
1054 | 1054 | } |
@@ -1069,43 +1069,43 @@ discard block |
||
1069 | 1069 | */ |
1070 | 1070 | protected function refresh_entity_map() { |
1071 | 1071 | // verify the transaction |
1072 | - if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) { |
|
1072 | + if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) { |
|
1073 | 1073 | // never cache payment info |
1074 | - $this->transaction->clear_cache( 'Payment' ); |
|
1074 | + $this->transaction->clear_cache('Payment'); |
|
1075 | 1075 | // is the Payment Options Reg Step completed ? |
1076 | - if ( $this->transaction->reg_step_completed( 'payment_options' ) ) { |
|
1076 | + if ($this->transaction->reg_step_completed('payment_options')) { |
|
1077 | 1077 | // then check for payments and update TXN accordingly |
1078 | 1078 | /** @type EE_Transaction_Payments $transaction_payments */ |
1079 | - $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
|
1080 | - $transaction_payments->calculate_total_payments_and_update_status( $this->transaction ); |
|
1079 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1080 | + $transaction_payments->calculate_total_payments_and_update_status($this->transaction); |
|
1081 | 1081 | } |
1082 | 1082 | // grab the saved registrations from the transaction |
1083 | 1083 | foreach ( |
1084 | - $this->transaction->registrations( $this->reg_cache_where_params ) as $reg_cache_ID => $registration |
|
1084 | + $this->transaction->registrations($this->reg_cache_where_params) as $reg_cache_ID => $registration |
|
1085 | 1085 | ) { |
1086 | - $this->_refresh_registration( $reg_cache_ID, $registration ); |
|
1086 | + $this->_refresh_registration($reg_cache_ID, $registration); |
|
1087 | 1087 | } |
1088 | 1088 | // make sure our cached TXN is added to the model entity mapper |
1089 | - $this->transaction = $this->transaction->get_model()->refresh_entity_map_with( $this->transaction->ID(), $this->transaction ); |
|
1089 | + $this->transaction = $this->transaction->get_model()->refresh_entity_map_with($this->transaction->ID(), $this->transaction); |
|
1090 | 1090 | |
1091 | 1091 | } else { |
1092 | - EE_Error::add_error( __( 'A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
1092 | + EE_Error::add_error(__('A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1093 | 1093 | return FALSE; |
1094 | 1094 | } |
1095 | 1095 | // verify and update the cart because inaccurate totals are not so much fun |
1096 | - if ( $this->cart instanceof EE_Cart ) { |
|
1096 | + if ($this->cart instanceof EE_Cart) { |
|
1097 | 1097 | $grand_total = $this->cart->get_grand_total(); |
1098 | - if ( $grand_total instanceof EE_Line_Item && $grand_total->ID() ) { |
|
1098 | + if ($grand_total instanceof EE_Line_Item && $grand_total->ID()) { |
|
1099 | 1099 | $grand_total->recalculate_total_including_taxes(); |
1100 | 1100 | $grand_total = $grand_total->get_model()->refresh_entity_map_with( |
1101 | 1101 | $this->cart->get_grand_total()->ID(), |
1102 | 1102 | $this->cart->get_grand_total() |
1103 | 1103 | ); |
1104 | 1104 | } |
1105 | - if ( $grand_total instanceof EE_Line_Item ) { |
|
1106 | - $this->cart = EE_Cart::instance( $grand_total ); |
|
1105 | + if ($grand_total instanceof EE_Line_Item) { |
|
1106 | + $this->cart = EE_Cart::instance($grand_total); |
|
1107 | 1107 | } else { |
1108 | - EE_Error::add_error( __( 'A valid Cart was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
1108 | + EE_Error::add_error(__('A valid Cart was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1109 | 1109 | return false; |
1110 | 1110 | } |
1111 | 1111 | } |
@@ -1122,19 +1122,19 @@ discard block |
||
1122 | 1122 | * @return void |
1123 | 1123 | * @throws \EE_Error |
1124 | 1124 | */ |
1125 | - protected function _refresh_registration( $reg_cache_ID, $registration ) { |
|
1125 | + protected function _refresh_registration($reg_cache_ID, $registration) { |
|
1126 | 1126 | |
1127 | 1127 | // verify object |
1128 | - if ( $registration instanceof EE_Registration ) { |
|
1128 | + if ($registration instanceof EE_Registration) { |
|
1129 | 1129 | // update the entity mapper attendee |
1130 | - $this->_refresh_registration_attendee( $registration ); |
|
1130 | + $this->_refresh_registration_attendee($registration); |
|
1131 | 1131 | // update the entity mapper answers for reg form questions |
1132 | - $this->_refresh_registration_answers( $registration ); |
|
1132 | + $this->_refresh_registration_answers($registration); |
|
1133 | 1133 | // make sure the cached registration is added to the model entity mapper |
1134 | - $registration->get_model()->refresh_entity_map_with( $reg_cache_ID, $registration ); |
|
1134 | + $registration->get_model()->refresh_entity_map_with($reg_cache_ID, $registration); |
|
1135 | 1135 | } else { |
1136 | 1136 | EE_Error::add_error( |
1137 | - __( 'An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso' ), |
|
1137 | + __('An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso'), |
|
1138 | 1138 | __FILE__, __FUNCTION__, __LINE__ |
1139 | 1139 | ); |
1140 | 1140 | } |
@@ -1149,15 +1149,15 @@ discard block |
||
1149 | 1149 | * @return void |
1150 | 1150 | * @throws \EE_Error |
1151 | 1151 | */ |
1152 | - protected function _refresh_registration_attendee( $registration ) { |
|
1152 | + protected function _refresh_registration_attendee($registration) { |
|
1153 | 1153 | |
1154 | 1154 | $attendee = $registration->attendee(); |
1155 | 1155 | // verify object |
1156 | - if ( $attendee instanceof EE_Attendee && $attendee->ID() ) { |
|
1156 | + if ($attendee instanceof EE_Attendee && $attendee->ID()) { |
|
1157 | 1157 | // make sure the cached attendee is added to the model entity mapper |
1158 | - $registration->attendee()->get_model()->refresh_entity_map_with( $attendee->ID(), $attendee ); |
|
1158 | + $registration->attendee()->get_model()->refresh_entity_map_with($attendee->ID(), $attendee); |
|
1159 | 1159 | // maybe cache primary_attendee_obj ? |
1160 | - if ( $registration->is_primary_registrant() ) { |
|
1160 | + if ($registration->is_primary_registrant()) { |
|
1161 | 1161 | $this->primary_attendee_obj = $attendee; |
1162 | 1162 | } |
1163 | 1163 | } |
@@ -1172,19 +1172,19 @@ discard block |
||
1172 | 1172 | * @return void |
1173 | 1173 | * @throws \EE_Error |
1174 | 1174 | */ |
1175 | - protected function _refresh_registration_answers( $registration ) { |
|
1175 | + protected function _refresh_registration_answers($registration) { |
|
1176 | 1176 | |
1177 | 1177 | // now update the answers |
1178 | - foreach ( $registration->answers() as $cache_key => $answer ) { |
|
1178 | + foreach ($registration->answers() as $cache_key => $answer) { |
|
1179 | 1179 | // verify object |
1180 | - if ( $answer instanceof EE_Answer ) { |
|
1181 | - if ( $answer->ID() ) { |
|
1180 | + if ($answer instanceof EE_Answer) { |
|
1181 | + if ($answer->ID()) { |
|
1182 | 1182 | // make sure the cached answer is added to the model entity mapper |
1183 | - $answer->get_model()->refresh_entity_map_with( $answer->ID(), $answer ); |
|
1183 | + $answer->get_model()->refresh_entity_map_with($answer->ID(), $answer); |
|
1184 | 1184 | } |
1185 | 1185 | } else { |
1186 | 1186 | EE_Error::add_error( |
1187 | - __( 'An invalid Answer object was discovered when attempting to update the model entity mapper.', 'event_espresso' ), |
|
1187 | + __('An invalid Answer object was discovered when attempting to update the model entity mapper.', 'event_espresso'), |
|
1188 | 1188 | __FILE__, __FUNCTION__, __LINE__ |
1189 | 1189 | ); |
1190 | 1190 | } |
@@ -1204,13 +1204,13 @@ discard block |
||
1204 | 1204 | */ |
1205 | 1205 | public function __sleep() |
1206 | 1206 | { |
1207 | - if ( $this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID() ) { |
|
1207 | + if ($this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID()) { |
|
1208 | 1208 | $this->primary_attendee_obj = $this->primary_attendee_obj->ID(); |
1209 | 1209 | } // remove the reg form and the checkout |
1210 | - if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) { |
|
1210 | + if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) { |
|
1211 | 1211 | $this->transaction = $this->transaction->ID(); |
1212 | 1212 | } // remove the reg form and the checkout |
1213 | - return array_diff( array_keys( get_object_vars( $this ) ), array( 'billing_form', 'registration_form' ) ); |
|
1213 | + return array_diff(array_keys(get_object_vars($this)), array('billing_form', 'registration_form')); |
|
1214 | 1214 | } |
1215 | 1215 | |
1216 | 1216 | |
@@ -1220,15 +1220,15 @@ discard block |
||
1220 | 1220 | * this will reinstate the EE_Checkout object on each EE_SPCO_Reg_Step object |
1221 | 1221 | */ |
1222 | 1222 | public function __wakeup() { |
1223 | - if ( ! $this->primary_attendee_obj instanceof EE_Attendee && absint( $this->primary_attendee_obj ) !== 0 ) { |
|
1223 | + if ( ! $this->primary_attendee_obj instanceof EE_Attendee && absint($this->primary_attendee_obj) !== 0) { |
|
1224 | 1224 | // $this->primary_attendee_obj is actually just an ID, so use it to get the object from the db |
1225 | - $this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID( $this->primary_attendee_obj ); |
|
1225 | + $this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID($this->primary_attendee_obj); |
|
1226 | 1226 | } |
1227 | - if ( ! $this->transaction instanceof EE_Transaction && absint( $this->transaction ) !== 0 ) { |
|
1227 | + if ( ! $this->transaction instanceof EE_Transaction && absint($this->transaction) !== 0) { |
|
1228 | 1228 | // $this->transaction is actually just an ID, so use it to get the object from the db |
1229 | - $this->transaction = EEM_Transaction::instance()->get_one_by_ID( $this->transaction ); |
|
1229 | + $this->transaction = EEM_Transaction::instance()->get_one_by_ID($this->transaction); |
|
1230 | 1230 | } |
1231 | - foreach ( $this->reg_steps as $reg_step ) { |
|
1231 | + foreach ($this->reg_steps as $reg_step) { |
|
1232 | 1232 | $reg_step->checkout = $this; |
1233 | 1233 | } |
1234 | 1234 | } |
@@ -1245,12 +1245,12 @@ discard block |
||
1245 | 1245 | * @param bool $display_request |
1246 | 1246 | * @throws \EE_Error |
1247 | 1247 | */ |
1248 | - public function log( $class = '', $func = '', $line = '', $info = array(), $display_request = false ) { |
|
1248 | + public function log($class = '', $func = '', $line = '', $info = array(), $display_request = false) { |
|
1249 | 1249 | $disabled = true; |
1250 | - if ( WP_DEBUG && ! $disabled ) { |
|
1251 | - $debug_data = get_option( 'EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array() ); |
|
1250 | + if (WP_DEBUG && ! $disabled) { |
|
1251 | + $debug_data = get_option('EE_DEBUG_SPCO_'.EE_Session::instance()->id(), array()); |
|
1252 | 1252 | $default_data = array( |
1253 | - $class => $func . '() : ' . $line, |
|
1253 | + $class => $func.'() : '.$line, |
|
1254 | 1254 | 'request->step' => $this->step, |
1255 | 1255 | 'request->action' => $this->action, |
1256 | 1256 | 'current_step->slug' => $this->current_step instanceof EE_SPCO_Reg_Step ? |
@@ -1262,24 +1262,24 @@ discard block |
||
1262 | 1262 | 'reg_url_link' => $this->reg_url_link, |
1263 | 1263 | 'REQ' => $display_request ? $_REQUEST : '', |
1264 | 1264 | ); |
1265 | - if ( $this->transaction instanceof EE_Transaction ) { |
|
1266 | - $default_data[ 'TXN_status' ] = $this->transaction->status_ID(); |
|
1267 | - $default_data[ 'TXN_reg_steps' ] = $this->transaction->reg_steps(); |
|
1268 | - foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $REG_ID => $registration ) { |
|
1269 | - $default_data[ 'registrations' ][ $REG_ID ] = $registration->status_ID(); |
|
1265 | + if ($this->transaction instanceof EE_Transaction) { |
|
1266 | + $default_data['TXN_status'] = $this->transaction->status_ID(); |
|
1267 | + $default_data['TXN_reg_steps'] = $this->transaction->reg_steps(); |
|
1268 | + foreach ($this->transaction->registrations($this->reg_cache_where_params) as $REG_ID => $registration) { |
|
1269 | + $default_data['registrations'][$REG_ID] = $registration->status_ID(); |
|
1270 | 1270 | } |
1271 | - if ( $this->transaction->ID() ) { |
|
1272 | - $TXN_ID = 'EE_Transaction: ' . $this->transaction->ID(); |
|
1271 | + if ($this->transaction->ID()) { |
|
1272 | + $TXN_ID = 'EE_Transaction: '.$this->transaction->ID(); |
|
1273 | 1273 | // don't serialize objects |
1274 | - $info = $this->_strip_objects( $info ); |
|
1275 | - if ( ! isset( $debug_data[ $TXN_ID ] ) ) { |
|
1276 | - $debug_data[ $TXN_ID ] = array(); |
|
1274 | + $info = $this->_strip_objects($info); |
|
1275 | + if ( ! isset($debug_data[$TXN_ID])) { |
|
1276 | + $debug_data[$TXN_ID] = array(); |
|
1277 | 1277 | } |
1278 | - $debug_data[ $TXN_ID ][ microtime() ] = array_merge( |
|
1278 | + $debug_data[$TXN_ID][microtime()] = array_merge( |
|
1279 | 1279 | $default_data, |
1280 | 1280 | $info |
1281 | 1281 | ); |
1282 | - update_option( 'EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data ); |
|
1282 | + update_option('EE_DEBUG_SPCO_'.EE_Session::instance()->id(), $debug_data); |
|
1283 | 1283 | } |
1284 | 1284 | } |
1285 | 1285 | } |
@@ -1292,23 +1292,23 @@ discard block |
||
1292 | 1292 | * @param array $info |
1293 | 1293 | * @return array |
1294 | 1294 | */ |
1295 | - public function _strip_objects( $info = array() ) { |
|
1296 | - foreach ( (array)$info as $key => $value ) { |
|
1297 | - if ( is_array( $value )) { |
|
1298 | - $info[ $key ] = $this->_strip_objects( $value ); |
|
1299 | - } else if ( is_object( $value ) ) { |
|
1300 | - $object_class = get_class( $value ); |
|
1301 | - $info[ $object_class ] = array(); |
|
1302 | - $info[ $object_class ][ 'ID' ] = method_exists( $value, 'ID' ) ? $value->ID() : 0; |
|
1303 | - if ( method_exists( $value, 'status' ) ) { |
|
1304 | - $info[ $object_class ][ 'status' ] = $value->status(); |
|
1305 | - } else if ( method_exists( $value, 'status_ID' ) ) { |
|
1306 | - $info[ $object_class ][ 'status' ] = $value->status_ID(); |
|
1295 | + public function _strip_objects($info = array()) { |
|
1296 | + foreach ((array) $info as $key => $value) { |
|
1297 | + if (is_array($value)) { |
|
1298 | + $info[$key] = $this->_strip_objects($value); |
|
1299 | + } else if (is_object($value)) { |
|
1300 | + $object_class = get_class($value); |
|
1301 | + $info[$object_class] = array(); |
|
1302 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0; |
|
1303 | + if (method_exists($value, 'status')) { |
|
1304 | + $info[$object_class]['status'] = $value->status(); |
|
1305 | + } else if (method_exists($value, 'status_ID')) { |
|
1306 | + $info[$object_class]['status'] = $value->status_ID(); |
|
1307 | 1307 | } |
1308 | - unset( $info[ $key ] ); |
|
1308 | + unset($info[$key]); |
|
1309 | 1309 | } |
1310 | 1310 | } |
1311 | - return (array)$info; |
|
1311 | + return (array) $info; |
|
1312 | 1312 | } |
1313 | 1313 | |
1314 | 1314 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\domain\services\DomainService; |
5 | 5 | |
6 | 6 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -20,25 +20,25 @@ discard block |
||
20 | 20 | class UpdateRegistrationService extends DomainService |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @param \EE_Registration $registration |
|
25 | - * @return bool |
|
26 | - */ |
|
27 | - public function updateRegistrationAndTransaction(\EE_Registration $registration) |
|
28 | - { |
|
29 | - $transaction = $registration->transaction(); |
|
30 | - // reset transaction status back to incomplete |
|
31 | - $transaction->set_status(\EEM_Transaction::incomplete_status_code); |
|
32 | - // update transaction and all line item totals and subtotals |
|
33 | - $transaction->total_line_item()->recalculate_total_including_taxes(); |
|
34 | - // maybe update status, but don't save transaction just yet |
|
35 | - $transaction->update_status_based_on_total_paid(); |
|
36 | - /** @type \EE_Registration_Processor $registration_processor */ |
|
37 | - $registration_processor = \EE_Registry::instance()->load_class('Registration_Processor'); |
|
38 | - $registration_processor->update_registration_final_prices($transaction); |
|
39 | - $registration_processor->update_registration_status_and_trigger_notifications($registration); |
|
40 | - return true; |
|
41 | - } |
|
23 | + /** |
|
24 | + * @param \EE_Registration $registration |
|
25 | + * @return bool |
|
26 | + */ |
|
27 | + public function updateRegistrationAndTransaction(\EE_Registration $registration) |
|
28 | + { |
|
29 | + $transaction = $registration->transaction(); |
|
30 | + // reset transaction status back to incomplete |
|
31 | + $transaction->set_status(\EEM_Transaction::incomplete_status_code); |
|
32 | + // update transaction and all line item totals and subtotals |
|
33 | + $transaction->total_line_item()->recalculate_total_including_taxes(); |
|
34 | + // maybe update status, but don't save transaction just yet |
|
35 | + $transaction->update_status_based_on_total_paid(); |
|
36 | + /** @type \EE_Registration_Processor $registration_processor */ |
|
37 | + $registration_processor = \EE_Registry::instance()->load_class('Registration_Processor'); |
|
38 | + $registration_processor->update_registration_final_prices($transaction); |
|
39 | + $registration_processor->update_registration_status_and_trigger_notifications($registration); |
|
40 | + return true; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | } |
44 | 44 | // End of file UpdateRegistrationService.php |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -19,1073 +19,1073 @@ discard block |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * possibly truncated version of the EE core version string |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected static $_core_version = ''; |
|
22 | + /** |
|
23 | + * possibly truncated version of the EE core version string |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected static $_core_version = ''; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Holds values for registered addons |
|
31 | - * |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - protected static $_settings = array(); |
|
29 | + /** |
|
30 | + * Holds values for registered addons |
|
31 | + * |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + protected static $_settings = array(); |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
38 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
39 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
40 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
41 | - * EE core with knowledge of ALL the addons out there. |
|
42 | - * If you want NO versions of an addon to run with a certain version of core, |
|
43 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
44 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
45 | - * minimum plugin version. |
|
46 | - * @access protected |
|
47 | - */ |
|
48 | - protected static $_incompatible_addons = array( |
|
49 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
50 | - 'Promotions' => '1.0.0.rc.084', |
|
51 | - ); |
|
36 | + /** |
|
37 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
38 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
39 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
40 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
41 | + * EE core with knowledge of ALL the addons out there. |
|
42 | + * If you want NO versions of an addon to run with a certain version of core, |
|
43 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
44 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
45 | + * minimum plugin version. |
|
46 | + * @access protected |
|
47 | + */ |
|
48 | + protected static $_incompatible_addons = array( |
|
49 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
50 | + 'Promotions' => '1.0.0.rc.084', |
|
51 | + ); |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
56 | - * not just '4.3.0'. |
|
57 | - * So if the addon developer doesn't provide that full version string, |
|
58 | - * fill in the blanks for them |
|
59 | - * |
|
60 | - * @param string $min_core_version |
|
61 | - * @return string always like '4.3.0.rc.000' |
|
62 | - */ |
|
63 | - protected static function _effective_version($min_core_version) |
|
64 | - { |
|
65 | - // versions: 4 . 3 . 1 . p . 123 |
|
66 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
67 | - $version_parts = explode('.', $min_core_version); |
|
68 | - //check they specified the micro version (after 2nd period) |
|
69 | - if (! isset($version_parts[2])) { |
|
70 | - $version_parts[2] = '0'; |
|
71 | - } |
|
72 | - //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
73 | - //soon we can assume that's 'rc', but this current version is 'alpha' |
|
74 | - if (! isset($version_parts[3])) { |
|
75 | - $version_parts[3] = 'dev'; |
|
76 | - } |
|
77 | - if (! isset($version_parts[4])) { |
|
78 | - $version_parts[4] = '000'; |
|
79 | - } |
|
80 | - return implode('.', $version_parts); |
|
81 | - } |
|
54 | + /** |
|
55 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
56 | + * not just '4.3.0'. |
|
57 | + * So if the addon developer doesn't provide that full version string, |
|
58 | + * fill in the blanks for them |
|
59 | + * |
|
60 | + * @param string $min_core_version |
|
61 | + * @return string always like '4.3.0.rc.000' |
|
62 | + */ |
|
63 | + protected static function _effective_version($min_core_version) |
|
64 | + { |
|
65 | + // versions: 4 . 3 . 1 . p . 123 |
|
66 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
67 | + $version_parts = explode('.', $min_core_version); |
|
68 | + //check they specified the micro version (after 2nd period) |
|
69 | + if (! isset($version_parts[2])) { |
|
70 | + $version_parts[2] = '0'; |
|
71 | + } |
|
72 | + //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
73 | + //soon we can assume that's 'rc', but this current version is 'alpha' |
|
74 | + if (! isset($version_parts[3])) { |
|
75 | + $version_parts[3] = 'dev'; |
|
76 | + } |
|
77 | + if (! isset($version_parts[4])) { |
|
78 | + $version_parts[4] = '000'; |
|
79 | + } |
|
80 | + return implode('.', $version_parts); |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * Returns whether or not the min core version requirement of the addon is met |
|
86 | - * |
|
87 | - * @param string $min_core_version the minimum core version required by the addon |
|
88 | - * @param string $actual_core_version the actual core version, optional |
|
89 | - * @return boolean |
|
90 | - */ |
|
91 | - public static function _meets_min_core_version_requirement( |
|
92 | - $min_core_version, |
|
93 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
94 | - ) { |
|
95 | - return version_compare( |
|
96 | - self::_effective_version($actual_core_version), |
|
97 | - self::_effective_version($min_core_version), |
|
98 | - '>=' |
|
99 | - ); |
|
100 | - } |
|
84 | + /** |
|
85 | + * Returns whether or not the min core version requirement of the addon is met |
|
86 | + * |
|
87 | + * @param string $min_core_version the minimum core version required by the addon |
|
88 | + * @param string $actual_core_version the actual core version, optional |
|
89 | + * @return boolean |
|
90 | + */ |
|
91 | + public static function _meets_min_core_version_requirement( |
|
92 | + $min_core_version, |
|
93 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
94 | + ) { |
|
95 | + return version_compare( |
|
96 | + self::_effective_version($actual_core_version), |
|
97 | + self::_effective_version($min_core_version), |
|
98 | + '>=' |
|
99 | + ); |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * Method for registering new EE_Addons. |
|
105 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
106 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
107 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
108 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
109 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
110 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
111 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
112 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
113 | - * |
|
114 | - * @since 4.3.0 |
|
115 | - * @param string $addon_name the EE_Addon's name. Required. |
|
116 | - * @param array $setup_args { An |
|
117 | - * array of arguments provided for registering |
|
118 | - * the message type. |
|
119 | - * @type string $class_name the addon's main file name. |
|
120 | - * If left blank, generated from the addon |
|
121 | - * name, changes something like "calendar" to |
|
122 | - * "EE_Calendar" |
|
123 | - * @type string $min_core_version the minimum version of EE Core that the |
|
124 | - * addon will work with. eg "4.8.1.rc.084" |
|
125 | - * @type string $version the "software" version for the addon. eg |
|
126 | - * "1.0.0.p" for a first stable release, or "1.0.0.rc.043" for a version in progress |
|
127 | - * @type string $main_file_path the full server path to the main file |
|
128 | - * loaded |
|
129 | - * directly by WP |
|
130 | - * @type string $admin_path full server path to the folder where the |
|
131 | - * addon\'s admin files reside |
|
132 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
133 | - * first invoked, can be used for hooking into any admin page |
|
134 | - * @type string $config_section the section name for this addon's |
|
135 | - * configuration settings section (defaults to "addons") |
|
136 | - * @type string $config_class the class name for this addon's |
|
137 | - * configuration settings object |
|
138 | - * @type string $config_name the class name for this addon's |
|
139 | - * configuration settings object |
|
140 | - * @type string $autoloader_paths an array of class names and the full server |
|
141 | - * paths to those files. Required. |
|
142 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
143 | - * folders containing classes that might be invoked by the addon |
|
144 | - * @type string $dms_paths an array of full server paths to folders |
|
145 | - * that contain data migration scripts. Required. |
|
146 | - * @type string $module_paths an array of full server paths to any |
|
147 | - * EED_Modules used by the addon |
|
148 | - * @type string $shortcode_paths an array of full server paths to folders |
|
149 | - * that contain EES_Shortcodes |
|
150 | - * @type string $widget_paths an array of full server paths to folders |
|
151 | - * that contain WP_Widgets |
|
152 | - * @type string $pue_options |
|
153 | - * @type array $capabilities an array indexed by role name |
|
154 | - * (i.e administrator,author ) and the values |
|
155 | - * are an array of caps to add to the role. |
|
156 | - * 'administrator' => array( |
|
157 | - * 'read_addon', 'edit_addon', etc. |
|
158 | - * ). |
|
159 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
160 | - * for any addons that need to register any special meta mapped capabilities. Should be indexed where the |
|
161 | - * key is the EE_Meta_Capability_Map class name and the values are the arguments sent to the class. |
|
162 | - * @type array $model_paths array of folders containing DB models |
|
163 | - * @see EE_Register_Model |
|
164 | - * @type array $class_paths array of folders containing DB classes |
|
165 | - * @see EE_Register_Model |
|
166 | - * @type array $model_extension_paths array of folders containing DB model |
|
167 | - * extensions |
|
168 | - * @see EE_Register_Model_Extension |
|
169 | - * @type array $class_extension_paths array of folders containing DB class |
|
170 | - * extensions |
|
171 | - * @see EE_Register_Model_Extension |
|
172 | - * @type array message_types { |
|
173 | - * An array of message types with the key as |
|
174 | - * the message type name and the values as |
|
175 | - * below: |
|
176 | - * @type string $mtfilename The filename of the message type being |
|
177 | - * registered. This will be the main EE_{Messagetype_Name}_message_type class. |
|
178 | - * (eg. |
|
179 | - * EE_Declined_Registration_message_type.class.php) |
|
180 | - * Required. |
|
181 | - * @type array $autoloadpaths An array of paths to add to the messages |
|
182 | - * autoloader for the new message type. |
|
183 | - * Required. |
|
184 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
185 | - * type should activate with. Each value in |
|
186 | - * the |
|
187 | - * array |
|
188 | - * should match the name property of a |
|
189 | - * EE_messenger. Optional. |
|
190 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
191 | - * type should validate with. Each value in |
|
192 | - * the |
|
193 | - * array |
|
194 | - * should match the name property of an |
|
195 | - * EE_messenger. |
|
196 | - * Optional. |
|
197 | - * } |
|
198 | - * @type array $custom_post_types |
|
199 | - * @type array $custom_taxonomies |
|
200 | - * @type array $payment_method_paths each element is the folder containing the |
|
201 | - * EE_PMT_Base child class |
|
202 | - * (eg, |
|
203 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
204 | - * which contains the files |
|
205 | - * EE_PMT_Payomatic.pm.php) |
|
206 | - * @type array $default_terms |
|
207 | - * @type array $namespace { |
|
208 | - * An array with two items for registering the |
|
209 | - * addon's namespace. (If, for some reason, |
|
210 | - * you |
|
211 | - * require additional namespaces, use |
|
212 | - * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
213 | - * directly) |
|
214 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
215 | - * @type string $FQNS the namespace prefix |
|
216 | - * @type string $DIR a base directory for class files in the |
|
217 | - * namespace. |
|
218 | - * } |
|
219 | - * } |
|
220 | - * @throws EE_Error |
|
221 | - * @return void |
|
222 | - */ |
|
223 | - public static function register($addon_name = '', $setup_args = array()) |
|
224 | - { |
|
225 | - // required fields MUST be present, so let's make sure they are. |
|
226 | - \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
227 | - // get class name for addon |
|
228 | - $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
229 | - //setup $_settings array from incoming values. |
|
230 | - $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
231 | - // setup PUE |
|
232 | - \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
233 | - // does this addon work with this version of core or WordPress ? |
|
234 | - if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
235 | - return; |
|
236 | - } |
|
237 | - // register namespaces |
|
238 | - \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
239 | - // check if this is an activation request |
|
240 | - if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
241 | - // dont bother setting up the rest of the addon atm |
|
242 | - return; |
|
243 | - } |
|
244 | - // we need cars |
|
245 | - \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
246 | - // register new models and extensions |
|
247 | - \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
248 | - // setup DMS |
|
249 | - \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
250 | - // if config_class is present let's register config. |
|
251 | - \EE_Register_Addon::_register_config($addon_name); |
|
252 | - // register admin pages |
|
253 | - \EE_Register_Addon::_register_admin_pages($addon_name); |
|
254 | - // add to list of modules to be registered |
|
255 | - \EE_Register_Addon::_register_modules($addon_name); |
|
256 | - // add to list of shortcodes to be registered |
|
257 | - \EE_Register_Addon::_register_shortcodes($addon_name); |
|
258 | - // add to list of widgets to be registered |
|
259 | - \EE_Register_Addon::_register_widgets($addon_name); |
|
260 | - // register capability related stuff. |
|
261 | - \EE_Register_Addon::_register_capabilities($addon_name); |
|
262 | - // any message type to register? |
|
263 | - \EE_Register_Addon::_register_message_types($addon_name); |
|
264 | - // any custom post type/ custom capabilities or default terms to register |
|
265 | - \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
266 | - // and any payment methods |
|
267 | - \EE_Register_Addon::_register_payment_methods($addon_name); |
|
268 | - // load and instantiate main addon class |
|
269 | - $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
103 | + /** |
|
104 | + * Method for registering new EE_Addons. |
|
105 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
106 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
107 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
108 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
109 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
110 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
111 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
112 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
113 | + * |
|
114 | + * @since 4.3.0 |
|
115 | + * @param string $addon_name the EE_Addon's name. Required. |
|
116 | + * @param array $setup_args { An |
|
117 | + * array of arguments provided for registering |
|
118 | + * the message type. |
|
119 | + * @type string $class_name the addon's main file name. |
|
120 | + * If left blank, generated from the addon |
|
121 | + * name, changes something like "calendar" to |
|
122 | + * "EE_Calendar" |
|
123 | + * @type string $min_core_version the minimum version of EE Core that the |
|
124 | + * addon will work with. eg "4.8.1.rc.084" |
|
125 | + * @type string $version the "software" version for the addon. eg |
|
126 | + * "1.0.0.p" for a first stable release, or "1.0.0.rc.043" for a version in progress |
|
127 | + * @type string $main_file_path the full server path to the main file |
|
128 | + * loaded |
|
129 | + * directly by WP |
|
130 | + * @type string $admin_path full server path to the folder where the |
|
131 | + * addon\'s admin files reside |
|
132 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
133 | + * first invoked, can be used for hooking into any admin page |
|
134 | + * @type string $config_section the section name for this addon's |
|
135 | + * configuration settings section (defaults to "addons") |
|
136 | + * @type string $config_class the class name for this addon's |
|
137 | + * configuration settings object |
|
138 | + * @type string $config_name the class name for this addon's |
|
139 | + * configuration settings object |
|
140 | + * @type string $autoloader_paths an array of class names and the full server |
|
141 | + * paths to those files. Required. |
|
142 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
143 | + * folders containing classes that might be invoked by the addon |
|
144 | + * @type string $dms_paths an array of full server paths to folders |
|
145 | + * that contain data migration scripts. Required. |
|
146 | + * @type string $module_paths an array of full server paths to any |
|
147 | + * EED_Modules used by the addon |
|
148 | + * @type string $shortcode_paths an array of full server paths to folders |
|
149 | + * that contain EES_Shortcodes |
|
150 | + * @type string $widget_paths an array of full server paths to folders |
|
151 | + * that contain WP_Widgets |
|
152 | + * @type string $pue_options |
|
153 | + * @type array $capabilities an array indexed by role name |
|
154 | + * (i.e administrator,author ) and the values |
|
155 | + * are an array of caps to add to the role. |
|
156 | + * 'administrator' => array( |
|
157 | + * 'read_addon', 'edit_addon', etc. |
|
158 | + * ). |
|
159 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
160 | + * for any addons that need to register any special meta mapped capabilities. Should be indexed where the |
|
161 | + * key is the EE_Meta_Capability_Map class name and the values are the arguments sent to the class. |
|
162 | + * @type array $model_paths array of folders containing DB models |
|
163 | + * @see EE_Register_Model |
|
164 | + * @type array $class_paths array of folders containing DB classes |
|
165 | + * @see EE_Register_Model |
|
166 | + * @type array $model_extension_paths array of folders containing DB model |
|
167 | + * extensions |
|
168 | + * @see EE_Register_Model_Extension |
|
169 | + * @type array $class_extension_paths array of folders containing DB class |
|
170 | + * extensions |
|
171 | + * @see EE_Register_Model_Extension |
|
172 | + * @type array message_types { |
|
173 | + * An array of message types with the key as |
|
174 | + * the message type name and the values as |
|
175 | + * below: |
|
176 | + * @type string $mtfilename The filename of the message type being |
|
177 | + * registered. This will be the main EE_{Messagetype_Name}_message_type class. |
|
178 | + * (eg. |
|
179 | + * EE_Declined_Registration_message_type.class.php) |
|
180 | + * Required. |
|
181 | + * @type array $autoloadpaths An array of paths to add to the messages |
|
182 | + * autoloader for the new message type. |
|
183 | + * Required. |
|
184 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
185 | + * type should activate with. Each value in |
|
186 | + * the |
|
187 | + * array |
|
188 | + * should match the name property of a |
|
189 | + * EE_messenger. Optional. |
|
190 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
191 | + * type should validate with. Each value in |
|
192 | + * the |
|
193 | + * array |
|
194 | + * should match the name property of an |
|
195 | + * EE_messenger. |
|
196 | + * Optional. |
|
197 | + * } |
|
198 | + * @type array $custom_post_types |
|
199 | + * @type array $custom_taxonomies |
|
200 | + * @type array $payment_method_paths each element is the folder containing the |
|
201 | + * EE_PMT_Base child class |
|
202 | + * (eg, |
|
203 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
204 | + * which contains the files |
|
205 | + * EE_PMT_Payomatic.pm.php) |
|
206 | + * @type array $default_terms |
|
207 | + * @type array $namespace { |
|
208 | + * An array with two items for registering the |
|
209 | + * addon's namespace. (If, for some reason, |
|
210 | + * you |
|
211 | + * require additional namespaces, use |
|
212 | + * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
213 | + * directly) |
|
214 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
215 | + * @type string $FQNS the namespace prefix |
|
216 | + * @type string $DIR a base directory for class files in the |
|
217 | + * namespace. |
|
218 | + * } |
|
219 | + * } |
|
220 | + * @throws EE_Error |
|
221 | + * @return void |
|
222 | + */ |
|
223 | + public static function register($addon_name = '', $setup_args = array()) |
|
224 | + { |
|
225 | + // required fields MUST be present, so let's make sure they are. |
|
226 | + \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
227 | + // get class name for addon |
|
228 | + $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
229 | + //setup $_settings array from incoming values. |
|
230 | + $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
231 | + // setup PUE |
|
232 | + \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
233 | + // does this addon work with this version of core or WordPress ? |
|
234 | + if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
235 | + return; |
|
236 | + } |
|
237 | + // register namespaces |
|
238 | + \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
239 | + // check if this is an activation request |
|
240 | + if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
241 | + // dont bother setting up the rest of the addon atm |
|
242 | + return; |
|
243 | + } |
|
244 | + // we need cars |
|
245 | + \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
246 | + // register new models and extensions |
|
247 | + \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
248 | + // setup DMS |
|
249 | + \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
250 | + // if config_class is present let's register config. |
|
251 | + \EE_Register_Addon::_register_config($addon_name); |
|
252 | + // register admin pages |
|
253 | + \EE_Register_Addon::_register_admin_pages($addon_name); |
|
254 | + // add to list of modules to be registered |
|
255 | + \EE_Register_Addon::_register_modules($addon_name); |
|
256 | + // add to list of shortcodes to be registered |
|
257 | + \EE_Register_Addon::_register_shortcodes($addon_name); |
|
258 | + // add to list of widgets to be registered |
|
259 | + \EE_Register_Addon::_register_widgets($addon_name); |
|
260 | + // register capability related stuff. |
|
261 | + \EE_Register_Addon::_register_capabilities($addon_name); |
|
262 | + // any message type to register? |
|
263 | + \EE_Register_Addon::_register_message_types($addon_name); |
|
264 | + // any custom post type/ custom capabilities or default terms to register |
|
265 | + \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
266 | + // and any payment methods |
|
267 | + \EE_Register_Addon::_register_payment_methods($addon_name); |
|
268 | + // load and instantiate main addon class |
|
269 | + $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
270 | 270 | |
271 | - //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
272 | - add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
273 | - } |
|
271 | + //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
272 | + add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
273 | + } |
|
274 | 274 | |
275 | 275 | |
276 | - /** |
|
277 | - * @param string $addon_name |
|
278 | - * @param array $setup_args |
|
279 | - * @return void |
|
280 | - * @throws \EE_Error |
|
281 | - */ |
|
282 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
283 | - { |
|
284 | - // required fields MUST be present, so let's make sure they are. |
|
285 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
286 | - throw new EE_Error( |
|
287 | - __( |
|
288 | - '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.', |
|
289 | - 'event_espresso' |
|
290 | - ) |
|
291 | - ); |
|
292 | - } |
|
293 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
294 | - throw new EE_Error( |
|
295 | - sprintf( |
|
296 | - __( |
|
297 | - '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', |
|
298 | - 'event_espresso' |
|
299 | - ), |
|
300 | - implode(',', array_keys($setup_args)) |
|
301 | - ) |
|
302 | - ); |
|
303 | - } |
|
304 | - // check that addon has not already been registered with that name |
|
305 | - if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
306 | - throw new EE_Error( |
|
307 | - sprintf( |
|
308 | - __( |
|
309 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
310 | - 'event_espresso' |
|
311 | - ), |
|
312 | - $addon_name |
|
313 | - ) |
|
314 | - ); |
|
315 | - } |
|
316 | - } |
|
276 | + /** |
|
277 | + * @param string $addon_name |
|
278 | + * @param array $setup_args |
|
279 | + * @return void |
|
280 | + * @throws \EE_Error |
|
281 | + */ |
|
282 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
283 | + { |
|
284 | + // required fields MUST be present, so let's make sure they are. |
|
285 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
286 | + throw new EE_Error( |
|
287 | + __( |
|
288 | + '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.', |
|
289 | + 'event_espresso' |
|
290 | + ) |
|
291 | + ); |
|
292 | + } |
|
293 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
294 | + throw new EE_Error( |
|
295 | + sprintf( |
|
296 | + __( |
|
297 | + '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', |
|
298 | + 'event_espresso' |
|
299 | + ), |
|
300 | + implode(',', array_keys($setup_args)) |
|
301 | + ) |
|
302 | + ); |
|
303 | + } |
|
304 | + // check that addon has not already been registered with that name |
|
305 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
306 | + throw new EE_Error( |
|
307 | + sprintf( |
|
308 | + __( |
|
309 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
310 | + 'event_espresso' |
|
311 | + ), |
|
312 | + $addon_name |
|
313 | + ) |
|
314 | + ); |
|
315 | + } |
|
316 | + } |
|
317 | 317 | |
318 | 318 | |
319 | - /** |
|
320 | - * @param string $addon_name |
|
321 | - * @param array $setup_args |
|
322 | - * @return string |
|
323 | - */ |
|
324 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
325 | - { |
|
326 | - if (empty($setup_args['class_name'])) { |
|
327 | - // generate one by first separating name with spaces |
|
328 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
329 | - //capitalize, then replace spaces with underscores |
|
330 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
331 | - } else { |
|
332 | - $class_name = $setup_args['class_name']; |
|
333 | - } |
|
334 | - return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
335 | - } |
|
319 | + /** |
|
320 | + * @param string $addon_name |
|
321 | + * @param array $setup_args |
|
322 | + * @return string |
|
323 | + */ |
|
324 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
325 | + { |
|
326 | + if (empty($setup_args['class_name'])) { |
|
327 | + // generate one by first separating name with spaces |
|
328 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
329 | + //capitalize, then replace spaces with underscores |
|
330 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
331 | + } else { |
|
332 | + $class_name = $setup_args['class_name']; |
|
333 | + } |
|
334 | + return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
335 | + } |
|
336 | 336 | |
337 | 337 | |
338 | - /** |
|
339 | - * @param string $class_name |
|
340 | - * @param array $setup_args |
|
341 | - * @return array |
|
342 | - */ |
|
343 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
344 | - { |
|
345 | - //setup $_settings array from incoming values. |
|
346 | - $addon_settings = array( |
|
347 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
348 | - 'class_name' => $class_name, |
|
349 | - // the addon slug for use in URLs, etc |
|
350 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
351 | - ? (string)$setup_args['plugin_slug'] |
|
352 | - : '', |
|
353 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
354 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
355 | - ? (string)$setup_args['plugin_action_slug'] |
|
356 | - : '', |
|
357 | - // the "software" version for the addon |
|
358 | - 'version' => isset($setup_args['version']) |
|
359 | - ? (string)$setup_args['version'] |
|
360 | - : '', |
|
361 | - // the minimum version of EE Core that the addon will work with |
|
362 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
363 | - ? (string)$setup_args['min_core_version'] |
|
364 | - : '', |
|
365 | - // the minimum version of WordPress that the addon will work with |
|
366 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
367 | - ? (string)$setup_args['min_wp_version'] |
|
368 | - : EE_MIN_WP_VER_REQUIRED, |
|
369 | - // full server path to main file (file loaded directly by WP) |
|
370 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
371 | - ? (string)$setup_args['main_file_path'] |
|
372 | - : '', |
|
373 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
374 | - 'admin_path' => isset($setup_args['admin_path']) |
|
375 | - ? (string)$setup_args['admin_path'] : '', |
|
376 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
377 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
378 | - ? (string)$setup_args['admin_callback'] |
|
379 | - : '', |
|
380 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
381 | - 'config_section' => isset($setup_args['config_section']) |
|
382 | - ? (string)$setup_args['config_section'] |
|
383 | - : 'addons', |
|
384 | - // the class name for this addon's configuration settings object |
|
385 | - 'config_class' => isset($setup_args['config_class']) |
|
386 | - ? (string)$setup_args['config_class'] : '', |
|
387 | - //the name given to the config for this addons' configuration settings object (optional) |
|
388 | - 'config_name' => isset($setup_args['config_name']) |
|
389 | - ? (string)$setup_args['config_name'] : '', |
|
390 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
391 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
392 | - ? (array)$setup_args['autoloader_paths'] |
|
393 | - : array(), |
|
394 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
395 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
396 | - ? (array)$setup_args['autoloader_folders'] |
|
397 | - : array(), |
|
398 | - // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
399 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
400 | - ? (array)$setup_args['dms_paths'] |
|
401 | - : array(), |
|
402 | - // array of full server paths to any EED_Modules used by the addon |
|
403 | - 'module_paths' => isset($setup_args['module_paths']) |
|
404 | - ? (array)$setup_args['module_paths'] |
|
405 | - : array(), |
|
406 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
407 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
408 | - ? (array)$setup_args['shortcode_paths'] |
|
409 | - : array(), |
|
410 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
411 | - ? (array) $setup_args['shortcode_fqcns'] |
|
412 | - : array(), |
|
413 | - // array of full server paths to any WP_Widgets used by the addon |
|
414 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
415 | - ? (array)$setup_args['widget_paths'] |
|
416 | - : array(), |
|
417 | - // array of PUE options used by the addon |
|
418 | - 'pue_options' => isset($setup_args['pue_options']) |
|
419 | - ? (array)$setup_args['pue_options'] |
|
420 | - : array(), |
|
421 | - 'message_types' => isset($setup_args['message_types']) |
|
422 | - ? (array)$setup_args['message_types'] |
|
423 | - : array(), |
|
424 | - 'capabilities' => isset($setup_args['capabilities']) |
|
425 | - ? (array)$setup_args['capabilities'] |
|
426 | - : array(), |
|
427 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
428 | - ? (array)$setup_args['capability_maps'] |
|
429 | - : array(), |
|
430 | - 'model_paths' => isset($setup_args['model_paths']) |
|
431 | - ? (array)$setup_args['model_paths'] |
|
432 | - : array(), |
|
433 | - 'class_paths' => isset($setup_args['class_paths']) |
|
434 | - ? (array)$setup_args['class_paths'] |
|
435 | - : array(), |
|
436 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
437 | - ? (array)$setup_args['model_extension_paths'] |
|
438 | - : array(), |
|
439 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
440 | - ? (array)$setup_args['class_extension_paths'] |
|
441 | - : array(), |
|
442 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
443 | - ? (array)$setup_args['custom_post_types'] |
|
444 | - : array(), |
|
445 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
446 | - ? (array)$setup_args['custom_taxonomies'] |
|
447 | - : array(), |
|
448 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
449 | - ? (array)$setup_args['payment_method_paths'] |
|
450 | - : array(), |
|
451 | - 'default_terms' => isset($setup_args['default_terms']) |
|
452 | - ? (array)$setup_args['default_terms'] |
|
453 | - : array(), |
|
454 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
455 | - // that can be used for adding upgrading/marketing info |
|
456 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
457 | - ? $setup_args['plugins_page_row'] |
|
458 | - : '', |
|
459 | - 'namespace' => isset( |
|
460 | - $setup_args['namespace'], |
|
461 | - $setup_args['namespace']['FQNS'], |
|
462 | - $setup_args['namespace']['DIR'] |
|
463 | - ) |
|
464 | - ? (array)$setup_args['namespace'] |
|
465 | - : array(), |
|
466 | - ); |
|
467 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
468 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
469 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
470 | - && ! empty($addon_settings['admin_path']) |
|
471 | - ? $addon_settings['plugin_slug'] |
|
472 | - : $addon_settings['plugin_action_slug']; |
|
473 | - // full server path to main file (file loaded directly by WP) |
|
474 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
475 | - return $addon_settings; |
|
476 | - } |
|
338 | + /** |
|
339 | + * @param string $class_name |
|
340 | + * @param array $setup_args |
|
341 | + * @return array |
|
342 | + */ |
|
343 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
344 | + { |
|
345 | + //setup $_settings array from incoming values. |
|
346 | + $addon_settings = array( |
|
347 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
348 | + 'class_name' => $class_name, |
|
349 | + // the addon slug for use in URLs, etc |
|
350 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
351 | + ? (string)$setup_args['plugin_slug'] |
|
352 | + : '', |
|
353 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
354 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
355 | + ? (string)$setup_args['plugin_action_slug'] |
|
356 | + : '', |
|
357 | + // the "software" version for the addon |
|
358 | + 'version' => isset($setup_args['version']) |
|
359 | + ? (string)$setup_args['version'] |
|
360 | + : '', |
|
361 | + // the minimum version of EE Core that the addon will work with |
|
362 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
363 | + ? (string)$setup_args['min_core_version'] |
|
364 | + : '', |
|
365 | + // the minimum version of WordPress that the addon will work with |
|
366 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
367 | + ? (string)$setup_args['min_wp_version'] |
|
368 | + : EE_MIN_WP_VER_REQUIRED, |
|
369 | + // full server path to main file (file loaded directly by WP) |
|
370 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
371 | + ? (string)$setup_args['main_file_path'] |
|
372 | + : '', |
|
373 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
374 | + 'admin_path' => isset($setup_args['admin_path']) |
|
375 | + ? (string)$setup_args['admin_path'] : '', |
|
376 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
377 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
378 | + ? (string)$setup_args['admin_callback'] |
|
379 | + : '', |
|
380 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
381 | + 'config_section' => isset($setup_args['config_section']) |
|
382 | + ? (string)$setup_args['config_section'] |
|
383 | + : 'addons', |
|
384 | + // the class name for this addon's configuration settings object |
|
385 | + 'config_class' => isset($setup_args['config_class']) |
|
386 | + ? (string)$setup_args['config_class'] : '', |
|
387 | + //the name given to the config for this addons' configuration settings object (optional) |
|
388 | + 'config_name' => isset($setup_args['config_name']) |
|
389 | + ? (string)$setup_args['config_name'] : '', |
|
390 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
391 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
392 | + ? (array)$setup_args['autoloader_paths'] |
|
393 | + : array(), |
|
394 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
395 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
396 | + ? (array)$setup_args['autoloader_folders'] |
|
397 | + : array(), |
|
398 | + // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
399 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
400 | + ? (array)$setup_args['dms_paths'] |
|
401 | + : array(), |
|
402 | + // array of full server paths to any EED_Modules used by the addon |
|
403 | + 'module_paths' => isset($setup_args['module_paths']) |
|
404 | + ? (array)$setup_args['module_paths'] |
|
405 | + : array(), |
|
406 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
407 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
408 | + ? (array)$setup_args['shortcode_paths'] |
|
409 | + : array(), |
|
410 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
411 | + ? (array) $setup_args['shortcode_fqcns'] |
|
412 | + : array(), |
|
413 | + // array of full server paths to any WP_Widgets used by the addon |
|
414 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
415 | + ? (array)$setup_args['widget_paths'] |
|
416 | + : array(), |
|
417 | + // array of PUE options used by the addon |
|
418 | + 'pue_options' => isset($setup_args['pue_options']) |
|
419 | + ? (array)$setup_args['pue_options'] |
|
420 | + : array(), |
|
421 | + 'message_types' => isset($setup_args['message_types']) |
|
422 | + ? (array)$setup_args['message_types'] |
|
423 | + : array(), |
|
424 | + 'capabilities' => isset($setup_args['capabilities']) |
|
425 | + ? (array)$setup_args['capabilities'] |
|
426 | + : array(), |
|
427 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
428 | + ? (array)$setup_args['capability_maps'] |
|
429 | + : array(), |
|
430 | + 'model_paths' => isset($setup_args['model_paths']) |
|
431 | + ? (array)$setup_args['model_paths'] |
|
432 | + : array(), |
|
433 | + 'class_paths' => isset($setup_args['class_paths']) |
|
434 | + ? (array)$setup_args['class_paths'] |
|
435 | + : array(), |
|
436 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
437 | + ? (array)$setup_args['model_extension_paths'] |
|
438 | + : array(), |
|
439 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
440 | + ? (array)$setup_args['class_extension_paths'] |
|
441 | + : array(), |
|
442 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
443 | + ? (array)$setup_args['custom_post_types'] |
|
444 | + : array(), |
|
445 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
446 | + ? (array)$setup_args['custom_taxonomies'] |
|
447 | + : array(), |
|
448 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
449 | + ? (array)$setup_args['payment_method_paths'] |
|
450 | + : array(), |
|
451 | + 'default_terms' => isset($setup_args['default_terms']) |
|
452 | + ? (array)$setup_args['default_terms'] |
|
453 | + : array(), |
|
454 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
455 | + // that can be used for adding upgrading/marketing info |
|
456 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
457 | + ? $setup_args['plugins_page_row'] |
|
458 | + : '', |
|
459 | + 'namespace' => isset( |
|
460 | + $setup_args['namespace'], |
|
461 | + $setup_args['namespace']['FQNS'], |
|
462 | + $setup_args['namespace']['DIR'] |
|
463 | + ) |
|
464 | + ? (array)$setup_args['namespace'] |
|
465 | + : array(), |
|
466 | + ); |
|
467 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
468 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
469 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
470 | + && ! empty($addon_settings['admin_path']) |
|
471 | + ? $addon_settings['plugin_slug'] |
|
472 | + : $addon_settings['plugin_action_slug']; |
|
473 | + // full server path to main file (file loaded directly by WP) |
|
474 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
475 | + return $addon_settings; |
|
476 | + } |
|
477 | 477 | |
478 | 478 | |
479 | - /** |
|
480 | - * @param string $addon_name |
|
481 | - * @param array $addon_settings |
|
482 | - * @return boolean |
|
483 | - */ |
|
484 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
485 | - { |
|
486 | - global $wp_version; |
|
487 | - $incompatibility_message = ''; |
|
488 | - //check whether this addon version is compatible with EE core |
|
489 | - if ( |
|
490 | - isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
491 | - && ! self::_meets_min_core_version_requirement( |
|
492 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
493 | - $addon_settings['version'] |
|
494 | - ) |
|
495 | - ) { |
|
496 | - $incompatibility_message = sprintf( |
|
497 | - __( |
|
498 | - '%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.' |
|
499 | - ), |
|
500 | - $addon_name, |
|
501 | - '<br />', |
|
502 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
503 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
504 | - '</span><br />' |
|
505 | - ); |
|
506 | - } else if ( |
|
507 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
508 | - ) { |
|
509 | - $incompatibility_message = sprintf( |
|
510 | - __( |
|
511 | - '%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".', |
|
512 | - 'event_espresso' |
|
513 | - ), |
|
514 | - $addon_name, |
|
515 | - self::_effective_version($addon_settings['min_core_version']), |
|
516 | - self::_effective_version(espresso_version()), |
|
517 | - '<br />', |
|
518 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
519 | - '</span><br />' |
|
520 | - ); |
|
521 | - } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
522 | - $incompatibility_message = sprintf( |
|
523 | - __( |
|
524 | - '%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.', |
|
525 | - 'event_espresso' |
|
526 | - ), |
|
527 | - $addon_name, |
|
528 | - $addon_settings['min_wp_version'], |
|
529 | - '<br />', |
|
530 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
531 | - '</span><br />' |
|
532 | - ); |
|
533 | - } |
|
534 | - if (! empty($incompatibility_message)) { |
|
535 | - // remove 'activate' from the REQUEST |
|
536 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
537 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
538 | - if (current_user_can('activate_plugins')) { |
|
539 | - // show an error message indicating the plugin didn't activate properly |
|
540 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
541 | - } |
|
542 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
543 | - return false; |
|
544 | - } |
|
545 | - // addon IS compatible |
|
546 | - return true; |
|
547 | - } |
|
479 | + /** |
|
480 | + * @param string $addon_name |
|
481 | + * @param array $addon_settings |
|
482 | + * @return boolean |
|
483 | + */ |
|
484 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
485 | + { |
|
486 | + global $wp_version; |
|
487 | + $incompatibility_message = ''; |
|
488 | + //check whether this addon version is compatible with EE core |
|
489 | + if ( |
|
490 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
491 | + && ! self::_meets_min_core_version_requirement( |
|
492 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
493 | + $addon_settings['version'] |
|
494 | + ) |
|
495 | + ) { |
|
496 | + $incompatibility_message = sprintf( |
|
497 | + __( |
|
498 | + '%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.' |
|
499 | + ), |
|
500 | + $addon_name, |
|
501 | + '<br />', |
|
502 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
503 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
504 | + '</span><br />' |
|
505 | + ); |
|
506 | + } else if ( |
|
507 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
508 | + ) { |
|
509 | + $incompatibility_message = sprintf( |
|
510 | + __( |
|
511 | + '%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".', |
|
512 | + 'event_espresso' |
|
513 | + ), |
|
514 | + $addon_name, |
|
515 | + self::_effective_version($addon_settings['min_core_version']), |
|
516 | + self::_effective_version(espresso_version()), |
|
517 | + '<br />', |
|
518 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
519 | + '</span><br />' |
|
520 | + ); |
|
521 | + } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
522 | + $incompatibility_message = sprintf( |
|
523 | + __( |
|
524 | + '%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.', |
|
525 | + 'event_espresso' |
|
526 | + ), |
|
527 | + $addon_name, |
|
528 | + $addon_settings['min_wp_version'], |
|
529 | + '<br />', |
|
530 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
531 | + '</span><br />' |
|
532 | + ); |
|
533 | + } |
|
534 | + if (! empty($incompatibility_message)) { |
|
535 | + // remove 'activate' from the REQUEST |
|
536 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
537 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
538 | + if (current_user_can('activate_plugins')) { |
|
539 | + // show an error message indicating the plugin didn't activate properly |
|
540 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
541 | + } |
|
542 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
543 | + return false; |
|
544 | + } |
|
545 | + // addon IS compatible |
|
546 | + return true; |
|
547 | + } |
|
548 | 548 | |
549 | 549 | |
550 | - /** |
|
551 | - * if plugin update engine is being used for auto-updates, |
|
552 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
553 | - * (not needed if PUE is not being used) |
|
554 | - * |
|
555 | - * @param string $addon_name |
|
556 | - * @param string $class_name |
|
557 | - * @param array $setup_args |
|
558 | - * @return void |
|
559 | - */ |
|
560 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
561 | - { |
|
562 | - if (! empty($setup_args['pue_options'])) { |
|
563 | - self::$_settings[$addon_name]['pue_options'] = array( |
|
564 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
565 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
566 | - : 'espresso_' . strtolower($class_name), |
|
567 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
568 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
569 | - : plugin_basename($setup_args['main_file_path']), |
|
570 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
571 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
572 | - : '24', |
|
573 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
574 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
575 | - : false, |
|
576 | - ); |
|
577 | - add_action( |
|
578 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
579 | - array('EE_Register_Addon', 'load_pue_update') |
|
580 | - ); |
|
581 | - } |
|
582 | - } |
|
550 | + /** |
|
551 | + * if plugin update engine is being used for auto-updates, |
|
552 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
553 | + * (not needed if PUE is not being used) |
|
554 | + * |
|
555 | + * @param string $addon_name |
|
556 | + * @param string $class_name |
|
557 | + * @param array $setup_args |
|
558 | + * @return void |
|
559 | + */ |
|
560 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
561 | + { |
|
562 | + if (! empty($setup_args['pue_options'])) { |
|
563 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
564 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
565 | + ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
566 | + : 'espresso_' . strtolower($class_name), |
|
567 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
568 | + ? (string)$setup_args['pue_options']['plugin_basename'] |
|
569 | + : plugin_basename($setup_args['main_file_path']), |
|
570 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
571 | + ? (string)$setup_args['pue_options']['checkPeriod'] |
|
572 | + : '24', |
|
573 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
574 | + ? (string)$setup_args['pue_options']['use_wp_update'] |
|
575 | + : false, |
|
576 | + ); |
|
577 | + add_action( |
|
578 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
579 | + array('EE_Register_Addon', 'load_pue_update') |
|
580 | + ); |
|
581 | + } |
|
582 | + } |
|
583 | 583 | |
584 | 584 | |
585 | - /** |
|
586 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
587 | - * |
|
588 | - * @param array $addon_settings |
|
589 | - * @return void |
|
590 | - */ |
|
591 | - private static function _setup_namespaces(array $addon_settings) |
|
592 | - { |
|
593 | - // |
|
594 | - if ( |
|
595 | - isset( |
|
596 | - $addon_settings['namespace'], |
|
597 | - $addon_settings['namespace']['FQNS'], |
|
598 | - $addon_settings['namespace']['DIR'] |
|
599 | - ) |
|
600 | - ) { |
|
601 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
602 | - $addon_settings['namespace']['FQNS'], |
|
603 | - $addon_settings['namespace']['DIR'] |
|
604 | - ); |
|
605 | - } |
|
606 | - } |
|
585 | + /** |
|
586 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
587 | + * |
|
588 | + * @param array $addon_settings |
|
589 | + * @return void |
|
590 | + */ |
|
591 | + private static function _setup_namespaces(array $addon_settings) |
|
592 | + { |
|
593 | + // |
|
594 | + if ( |
|
595 | + isset( |
|
596 | + $addon_settings['namespace'], |
|
597 | + $addon_settings['namespace']['FQNS'], |
|
598 | + $addon_settings['namespace']['DIR'] |
|
599 | + ) |
|
600 | + ) { |
|
601 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
602 | + $addon_settings['namespace']['FQNS'], |
|
603 | + $addon_settings['namespace']['DIR'] |
|
604 | + ); |
|
605 | + } |
|
606 | + } |
|
607 | 607 | |
608 | 608 | |
609 | - /** |
|
610 | - * @param string $addon_name |
|
611 | - * @param array $addon_settings |
|
612 | - * @return bool |
|
613 | - */ |
|
614 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
615 | - { |
|
616 | - // this is an activation request |
|
617 | - if (did_action('activate_plugin')) { |
|
618 | - //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
619 | - //(as the newly-activated addon wasn't around the first time addons were registered). |
|
620 | - //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
621 | - //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
622 | - if (! isset(self::$_settings[$addon_name]) |
|
623 | - || (isset(self::$_settings[$addon_name]) |
|
624 | - && ! isset(self::$_settings[$addon_name]['class_name']) |
|
625 | - ) |
|
626 | - ) { |
|
627 | - self::$_settings[$addon_name] = $addon_settings; |
|
628 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
629 | - $addon->set_activation_indicator_option(); |
|
630 | - // dont bother setting up the rest of the addon. |
|
631 | - // we know it was just activated and the request will end soon |
|
632 | - } |
|
633 | - return true; |
|
634 | - } |
|
635 | - // make sure this was called in the right place! |
|
636 | - if ( |
|
637 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
638 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
639 | - ) { |
|
640 | - EE_Error::doing_it_wrong( |
|
641 | - __METHOD__, |
|
642 | - sprintf( |
|
643 | - __( |
|
644 | - '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.', |
|
645 | - 'event_espresso' |
|
646 | - ), |
|
647 | - $addon_name |
|
648 | - ), |
|
649 | - '4.3.0' |
|
650 | - ); |
|
651 | - } |
|
652 | - // make sure addon settings are set correctly without overwriting anything existing |
|
653 | - if (isset(self::$_settings[$addon_name])) { |
|
654 | - self::$_settings[$addon_name] += $addon_settings; |
|
655 | - } else { |
|
656 | - self::$_settings[$addon_name] = $addon_settings; |
|
657 | - } |
|
658 | - return false; |
|
659 | - } |
|
609 | + /** |
|
610 | + * @param string $addon_name |
|
611 | + * @param array $addon_settings |
|
612 | + * @return bool |
|
613 | + */ |
|
614 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
615 | + { |
|
616 | + // this is an activation request |
|
617 | + if (did_action('activate_plugin')) { |
|
618 | + //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
619 | + //(as the newly-activated addon wasn't around the first time addons were registered). |
|
620 | + //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
621 | + //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
622 | + if (! isset(self::$_settings[$addon_name]) |
|
623 | + || (isset(self::$_settings[$addon_name]) |
|
624 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
625 | + ) |
|
626 | + ) { |
|
627 | + self::$_settings[$addon_name] = $addon_settings; |
|
628 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
629 | + $addon->set_activation_indicator_option(); |
|
630 | + // dont bother setting up the rest of the addon. |
|
631 | + // we know it was just activated and the request will end soon |
|
632 | + } |
|
633 | + return true; |
|
634 | + } |
|
635 | + // make sure this was called in the right place! |
|
636 | + if ( |
|
637 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
638 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
639 | + ) { |
|
640 | + EE_Error::doing_it_wrong( |
|
641 | + __METHOD__, |
|
642 | + sprintf( |
|
643 | + __( |
|
644 | + '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.', |
|
645 | + 'event_espresso' |
|
646 | + ), |
|
647 | + $addon_name |
|
648 | + ), |
|
649 | + '4.3.0' |
|
650 | + ); |
|
651 | + } |
|
652 | + // make sure addon settings are set correctly without overwriting anything existing |
|
653 | + if (isset(self::$_settings[$addon_name])) { |
|
654 | + self::$_settings[$addon_name] += $addon_settings; |
|
655 | + } else { |
|
656 | + self::$_settings[$addon_name] = $addon_settings; |
|
657 | + } |
|
658 | + return false; |
|
659 | + } |
|
660 | 660 | |
661 | 661 | |
662 | - /** |
|
663 | - * @param string $addon_name |
|
664 | - * @return void |
|
665 | - * @throws \EE_Error |
|
666 | - */ |
|
667 | - private static function _setup_autoloaders($addon_name) |
|
668 | - { |
|
669 | - if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
670 | - // setup autoloader for single file |
|
671 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
672 | - } |
|
673 | - // setup autoloaders for folders |
|
674 | - if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
675 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
676 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
677 | - } |
|
678 | - } |
|
679 | - } |
|
662 | + /** |
|
663 | + * @param string $addon_name |
|
664 | + * @return void |
|
665 | + * @throws \EE_Error |
|
666 | + */ |
|
667 | + private static function _setup_autoloaders($addon_name) |
|
668 | + { |
|
669 | + if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
670 | + // setup autoloader for single file |
|
671 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
672 | + } |
|
673 | + // setup autoloaders for folders |
|
674 | + if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
675 | + foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
676 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
677 | + } |
|
678 | + } |
|
679 | + } |
|
680 | 680 | |
681 | 681 | |
682 | - /** |
|
683 | - * register new models and extensions |
|
684 | - * |
|
685 | - * @param string $addon_name |
|
686 | - * @return void |
|
687 | - * @throws \EE_Error |
|
688 | - */ |
|
689 | - private static function _register_models_and_extensions($addon_name) |
|
690 | - { |
|
691 | - // register new models |
|
692 | - if ( |
|
693 | - ! empty(self::$_settings[$addon_name]['model_paths']) |
|
694 | - || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
695 | - ) { |
|
696 | - EE_Register_Model::register( |
|
697 | - $addon_name, |
|
698 | - array( |
|
699 | - 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
700 | - 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
701 | - ) |
|
702 | - ); |
|
703 | - } |
|
704 | - // register model extensions |
|
705 | - if ( |
|
706 | - ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
707 | - || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
708 | - ) { |
|
709 | - EE_Register_Model_Extensions::register( |
|
710 | - $addon_name, |
|
711 | - array( |
|
712 | - 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
713 | - 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
714 | - ) |
|
715 | - ); |
|
716 | - } |
|
717 | - } |
|
682 | + /** |
|
683 | + * register new models and extensions |
|
684 | + * |
|
685 | + * @param string $addon_name |
|
686 | + * @return void |
|
687 | + * @throws \EE_Error |
|
688 | + */ |
|
689 | + private static function _register_models_and_extensions($addon_name) |
|
690 | + { |
|
691 | + // register new models |
|
692 | + if ( |
|
693 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
694 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
695 | + ) { |
|
696 | + EE_Register_Model::register( |
|
697 | + $addon_name, |
|
698 | + array( |
|
699 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
700 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
701 | + ) |
|
702 | + ); |
|
703 | + } |
|
704 | + // register model extensions |
|
705 | + if ( |
|
706 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
707 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
708 | + ) { |
|
709 | + EE_Register_Model_Extensions::register( |
|
710 | + $addon_name, |
|
711 | + array( |
|
712 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
713 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
714 | + ) |
|
715 | + ); |
|
716 | + } |
|
717 | + } |
|
718 | 718 | |
719 | 719 | |
720 | - /** |
|
721 | - * @param string $addon_name |
|
722 | - * @return void |
|
723 | - * @throws \EE_Error |
|
724 | - */ |
|
725 | - private static function _register_data_migration_scripts($addon_name) |
|
726 | - { |
|
727 | - // setup DMS |
|
728 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
729 | - EE_Register_Data_Migration_Scripts::register( |
|
730 | - $addon_name, |
|
731 | - array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
732 | - ); |
|
733 | - } |
|
734 | - } |
|
720 | + /** |
|
721 | + * @param string $addon_name |
|
722 | + * @return void |
|
723 | + * @throws \EE_Error |
|
724 | + */ |
|
725 | + private static function _register_data_migration_scripts($addon_name) |
|
726 | + { |
|
727 | + // setup DMS |
|
728 | + if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
729 | + EE_Register_Data_Migration_Scripts::register( |
|
730 | + $addon_name, |
|
731 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
732 | + ); |
|
733 | + } |
|
734 | + } |
|
735 | 735 | |
736 | 736 | |
737 | - /** |
|
738 | - * @param string $addon_name |
|
739 | - * @return void |
|
740 | - * @throws \EE_Error |
|
741 | - */ |
|
742 | - private static function _register_config($addon_name) |
|
743 | - { |
|
744 | - // if config_class is present let's register config. |
|
745 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
746 | - EE_Register_Config::register( |
|
747 | - self::$_settings[$addon_name]['config_class'], |
|
748 | - array( |
|
749 | - 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
750 | - 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
751 | - ) |
|
752 | - ); |
|
753 | - } |
|
754 | - } |
|
737 | + /** |
|
738 | + * @param string $addon_name |
|
739 | + * @return void |
|
740 | + * @throws \EE_Error |
|
741 | + */ |
|
742 | + private static function _register_config($addon_name) |
|
743 | + { |
|
744 | + // if config_class is present let's register config. |
|
745 | + if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
746 | + EE_Register_Config::register( |
|
747 | + self::$_settings[$addon_name]['config_class'], |
|
748 | + array( |
|
749 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
750 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
751 | + ) |
|
752 | + ); |
|
753 | + } |
|
754 | + } |
|
755 | 755 | |
756 | 756 | |
757 | - /** |
|
758 | - * @param string $addon_name |
|
759 | - * @return void |
|
760 | - * @throws \EE_Error |
|
761 | - */ |
|
762 | - private static function _register_admin_pages($addon_name) |
|
763 | - { |
|
764 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
765 | - EE_Register_Admin_Page::register( |
|
766 | - $addon_name, |
|
767 | - array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
768 | - ); |
|
769 | - } |
|
770 | - } |
|
757 | + /** |
|
758 | + * @param string $addon_name |
|
759 | + * @return void |
|
760 | + * @throws \EE_Error |
|
761 | + */ |
|
762 | + private static function _register_admin_pages($addon_name) |
|
763 | + { |
|
764 | + if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
765 | + EE_Register_Admin_Page::register( |
|
766 | + $addon_name, |
|
767 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
768 | + ); |
|
769 | + } |
|
770 | + } |
|
771 | 771 | |
772 | 772 | |
773 | - /** |
|
774 | - * @param string $addon_name |
|
775 | - * @return void |
|
776 | - * @throws \EE_Error |
|
777 | - */ |
|
778 | - private static function _register_modules($addon_name) |
|
779 | - { |
|
780 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
781 | - EE_Register_Module::register( |
|
782 | - $addon_name, |
|
783 | - array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
784 | - ); |
|
785 | - } |
|
786 | - } |
|
773 | + /** |
|
774 | + * @param string $addon_name |
|
775 | + * @return void |
|
776 | + * @throws \EE_Error |
|
777 | + */ |
|
778 | + private static function _register_modules($addon_name) |
|
779 | + { |
|
780 | + if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
781 | + EE_Register_Module::register( |
|
782 | + $addon_name, |
|
783 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
784 | + ); |
|
785 | + } |
|
786 | + } |
|
787 | 787 | |
788 | 788 | |
789 | - /** |
|
790 | - * @param string $addon_name |
|
791 | - * @return void |
|
792 | - * @throws \EE_Error |
|
793 | - */ |
|
794 | - private static function _register_shortcodes($addon_name) |
|
795 | - { |
|
796 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
797 | - || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
798 | - ) { |
|
799 | - EE_Register_Shortcode::register( |
|
800 | - $addon_name, |
|
801 | - array( |
|
802 | - 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
803 | - ? self::$_settings[$addon_name]['shortcode_paths'] |
|
804 | - : array(), |
|
805 | - 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
806 | - ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
807 | - : array() |
|
808 | - ) |
|
809 | - ); |
|
810 | - } |
|
811 | - } |
|
789 | + /** |
|
790 | + * @param string $addon_name |
|
791 | + * @return void |
|
792 | + * @throws \EE_Error |
|
793 | + */ |
|
794 | + private static function _register_shortcodes($addon_name) |
|
795 | + { |
|
796 | + if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
797 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
798 | + ) { |
|
799 | + EE_Register_Shortcode::register( |
|
800 | + $addon_name, |
|
801 | + array( |
|
802 | + 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
803 | + ? self::$_settings[$addon_name]['shortcode_paths'] |
|
804 | + : array(), |
|
805 | + 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
806 | + ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
807 | + : array() |
|
808 | + ) |
|
809 | + ); |
|
810 | + } |
|
811 | + } |
|
812 | 812 | |
813 | 813 | |
814 | - /** |
|
815 | - * @param string $addon_name |
|
816 | - * @return void |
|
817 | - * @throws \EE_Error |
|
818 | - */ |
|
819 | - private static function _register_widgets($addon_name) |
|
820 | - { |
|
821 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
822 | - EE_Register_Widget::register( |
|
823 | - $addon_name, |
|
824 | - array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
825 | - ); |
|
826 | - } |
|
827 | - } |
|
814 | + /** |
|
815 | + * @param string $addon_name |
|
816 | + * @return void |
|
817 | + * @throws \EE_Error |
|
818 | + */ |
|
819 | + private static function _register_widgets($addon_name) |
|
820 | + { |
|
821 | + if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
822 | + EE_Register_Widget::register( |
|
823 | + $addon_name, |
|
824 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
825 | + ); |
|
826 | + } |
|
827 | + } |
|
828 | 828 | |
829 | 829 | |
830 | - /** |
|
831 | - * @param string $addon_name |
|
832 | - * @return void |
|
833 | - * @throws \EE_Error |
|
834 | - */ |
|
835 | - private static function _register_capabilities($addon_name) |
|
836 | - { |
|
837 | - if (! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
838 | - EE_Register_Capabilities::register( |
|
839 | - $addon_name, |
|
840 | - array( |
|
841 | - 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
842 | - 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
843 | - ) |
|
844 | - ); |
|
845 | - } |
|
846 | - } |
|
830 | + /** |
|
831 | + * @param string $addon_name |
|
832 | + * @return void |
|
833 | + * @throws \EE_Error |
|
834 | + */ |
|
835 | + private static function _register_capabilities($addon_name) |
|
836 | + { |
|
837 | + if (! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
838 | + EE_Register_Capabilities::register( |
|
839 | + $addon_name, |
|
840 | + array( |
|
841 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
842 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
843 | + ) |
|
844 | + ); |
|
845 | + } |
|
846 | + } |
|
847 | 847 | |
848 | 848 | |
849 | - /** |
|
850 | - * @param string $addon_name |
|
851 | - * @return void |
|
852 | - * @throws \EE_Error |
|
853 | - */ |
|
854 | - private static function _register_message_types($addon_name) |
|
855 | - { |
|
856 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
857 | - add_action( |
|
858 | - 'EE_Brewing_Regular___messages_caf', |
|
859 | - array('EE_Register_Addon', 'register_message_types') |
|
860 | - ); |
|
861 | - } |
|
862 | - } |
|
849 | + /** |
|
850 | + * @param string $addon_name |
|
851 | + * @return void |
|
852 | + * @throws \EE_Error |
|
853 | + */ |
|
854 | + private static function _register_message_types($addon_name) |
|
855 | + { |
|
856 | + if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
857 | + add_action( |
|
858 | + 'EE_Brewing_Regular___messages_caf', |
|
859 | + array('EE_Register_Addon', 'register_message_types') |
|
860 | + ); |
|
861 | + } |
|
862 | + } |
|
863 | 863 | |
864 | 864 | |
865 | - /** |
|
866 | - * @param string $addon_name |
|
867 | - * @return void |
|
868 | - * @throws \EE_Error |
|
869 | - */ |
|
870 | - private static function _register_custom_post_types($addon_name) |
|
871 | - { |
|
872 | - if ( |
|
873 | - ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
874 | - || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
875 | - ) { |
|
876 | - EE_Register_CPT::register( |
|
877 | - $addon_name, |
|
878 | - array( |
|
879 | - 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
880 | - 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
881 | - 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
882 | - ) |
|
883 | - ); |
|
884 | - } |
|
885 | - } |
|
865 | + /** |
|
866 | + * @param string $addon_name |
|
867 | + * @return void |
|
868 | + * @throws \EE_Error |
|
869 | + */ |
|
870 | + private static function _register_custom_post_types($addon_name) |
|
871 | + { |
|
872 | + if ( |
|
873 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
874 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
875 | + ) { |
|
876 | + EE_Register_CPT::register( |
|
877 | + $addon_name, |
|
878 | + array( |
|
879 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
880 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
881 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
882 | + ) |
|
883 | + ); |
|
884 | + } |
|
885 | + } |
|
886 | 886 | |
887 | 887 | |
888 | - /** |
|
889 | - * @param string $addon_name |
|
890 | - * @return void |
|
891 | - * @throws \EE_Error |
|
892 | - */ |
|
893 | - private static function _register_payment_methods($addon_name) |
|
894 | - { |
|
895 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
896 | - EE_Register_Payment_Method::register( |
|
897 | - $addon_name, |
|
898 | - array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
899 | - ); |
|
900 | - } |
|
901 | - } |
|
888 | + /** |
|
889 | + * @param string $addon_name |
|
890 | + * @return void |
|
891 | + * @throws \EE_Error |
|
892 | + */ |
|
893 | + private static function _register_payment_methods($addon_name) |
|
894 | + { |
|
895 | + if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
896 | + EE_Register_Payment_Method::register( |
|
897 | + $addon_name, |
|
898 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
899 | + ); |
|
900 | + } |
|
901 | + } |
|
902 | 902 | |
903 | 903 | |
904 | - /** |
|
905 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
906 | - * |
|
907 | - * @param string $addon_name |
|
908 | - * @return EE_Addon |
|
909 | - */ |
|
910 | - private static function _load_and_init_addon_class($addon_name) |
|
911 | - { |
|
912 | - $addon = EE_Registry::instance()->load_addon( |
|
913 | - dirname(self::$_settings[$addon_name]['main_file_path']), |
|
914 | - self::$_settings[$addon_name]['class_name'] |
|
915 | - ); |
|
916 | - $addon->set_name($addon_name); |
|
917 | - $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
918 | - $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
919 | - $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
920 | - $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
921 | - $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
922 | - $addon->set_version(self::$_settings[$addon_name]['version']); |
|
923 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
924 | - $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
925 | - $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
926 | - $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
927 | - //unfortunately this can't be hooked in upon construction, because we don't have |
|
928 | - //the plugin mainfile's path upon construction. |
|
929 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
930 | - // call any additional admin_callback functions during load_admin_controller hook |
|
931 | - if (! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
932 | - add_action( |
|
933 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
934 | - array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
935 | - ); |
|
936 | - } |
|
937 | - return $addon; |
|
938 | - } |
|
904 | + /** |
|
905 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
906 | + * |
|
907 | + * @param string $addon_name |
|
908 | + * @return EE_Addon |
|
909 | + */ |
|
910 | + private static function _load_and_init_addon_class($addon_name) |
|
911 | + { |
|
912 | + $addon = EE_Registry::instance()->load_addon( |
|
913 | + dirname(self::$_settings[$addon_name]['main_file_path']), |
|
914 | + self::$_settings[$addon_name]['class_name'] |
|
915 | + ); |
|
916 | + $addon->set_name($addon_name); |
|
917 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
918 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
919 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
920 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
921 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
922 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
923 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
924 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
925 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
926 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
927 | + //unfortunately this can't be hooked in upon construction, because we don't have |
|
928 | + //the plugin mainfile's path upon construction. |
|
929 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
930 | + // call any additional admin_callback functions during load_admin_controller hook |
|
931 | + if (! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
932 | + add_action( |
|
933 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
934 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
935 | + ); |
|
936 | + } |
|
937 | + return $addon; |
|
938 | + } |
|
939 | 939 | |
940 | 940 | |
941 | - /** |
|
942 | - * load_pue_update - Update notifications |
|
943 | - * |
|
944 | - * @return void |
|
945 | - */ |
|
946 | - public static function load_pue_update() |
|
947 | - { |
|
948 | - // load PUE client |
|
949 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
950 | - // cycle thru settings |
|
951 | - foreach (self::$_settings as $settings) { |
|
952 | - if (! empty($settings['pue_options'])) { |
|
953 | - // initiate the class and start the plugin update engine! |
|
954 | - new PluginUpdateEngineChecker( |
|
955 | - // host file URL |
|
956 | - 'https://eventespresso.com', |
|
957 | - // plugin slug(s) |
|
958 | - array( |
|
959 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
960 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
961 | - ), |
|
962 | - // options |
|
963 | - array( |
|
964 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
965 | - 'lang_domain' => 'event_espresso', |
|
966 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
967 | - 'option_key' => 'site_license_key', |
|
968 | - 'options_page_slug' => 'event_espresso', |
|
969 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
970 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
971 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
972 | - ) |
|
973 | - ); |
|
974 | - } |
|
975 | - } |
|
976 | - } |
|
941 | + /** |
|
942 | + * load_pue_update - Update notifications |
|
943 | + * |
|
944 | + * @return void |
|
945 | + */ |
|
946 | + public static function load_pue_update() |
|
947 | + { |
|
948 | + // load PUE client |
|
949 | + require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
950 | + // cycle thru settings |
|
951 | + foreach (self::$_settings as $settings) { |
|
952 | + if (! empty($settings['pue_options'])) { |
|
953 | + // initiate the class and start the plugin update engine! |
|
954 | + new PluginUpdateEngineChecker( |
|
955 | + // host file URL |
|
956 | + 'https://eventespresso.com', |
|
957 | + // plugin slug(s) |
|
958 | + array( |
|
959 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
960 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
961 | + ), |
|
962 | + // options |
|
963 | + array( |
|
964 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
965 | + 'lang_domain' => 'event_espresso', |
|
966 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
967 | + 'option_key' => 'site_license_key', |
|
968 | + 'options_page_slug' => 'event_espresso', |
|
969 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
970 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
971 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
972 | + ) |
|
973 | + ); |
|
974 | + } |
|
975 | + } |
|
976 | + } |
|
977 | 977 | |
978 | 978 | |
979 | - /** |
|
980 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
981 | - * |
|
982 | - * @since 4.4.0 |
|
983 | - * @return void |
|
984 | - * @throws \EE_Error |
|
985 | - */ |
|
986 | - public static function register_message_types() |
|
987 | - { |
|
988 | - foreach (self::$_settings as $addon_name => $settings) { |
|
989 | - if (! empty($settings['message_types'])) { |
|
990 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
991 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
992 | - } |
|
993 | - } |
|
994 | - } |
|
995 | - } |
|
979 | + /** |
|
980 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
981 | + * |
|
982 | + * @since 4.4.0 |
|
983 | + * @return void |
|
984 | + * @throws \EE_Error |
|
985 | + */ |
|
986 | + public static function register_message_types() |
|
987 | + { |
|
988 | + foreach (self::$_settings as $addon_name => $settings) { |
|
989 | + if (! empty($settings['message_types'])) { |
|
990 | + foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
991 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
992 | + } |
|
993 | + } |
|
994 | + } |
|
995 | + } |
|
996 | 996 | |
997 | 997 | |
998 | - /** |
|
999 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
1000 | - * |
|
1001 | - * @since 4.3.0 |
|
1002 | - * @param string $addon_name the name for the addon that was previously registered |
|
1003 | - * @throws EE_Error |
|
1004 | - * @return void |
|
1005 | - */ |
|
1006 | - public static function deregister($addon_name = null) |
|
1007 | - { |
|
1008 | - if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) { |
|
1009 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1010 | - $class_name = self::$_settings[$addon_name]['class_name']; |
|
1011 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
1012 | - // setup DMS |
|
1013 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1014 | - } |
|
1015 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
1016 | - // register admin page |
|
1017 | - EE_Register_Admin_Page::deregister($addon_name); |
|
1018 | - } |
|
1019 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
1020 | - // add to list of modules to be registered |
|
1021 | - EE_Register_Module::deregister($addon_name); |
|
1022 | - } |
|
1023 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
1024 | - || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
1025 | - ) { |
|
1026 | - // add to list of shortcodes to be registered |
|
1027 | - EE_Register_Shortcode::deregister($addon_name); |
|
1028 | - } |
|
1029 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1030 | - // if config_class present let's register config. |
|
1031 | - EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
1032 | - } |
|
1033 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1034 | - // add to list of widgets to be registered |
|
1035 | - EE_Register_Widget::deregister($addon_name); |
|
1036 | - } |
|
1037 | - if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
1038 | - || |
|
1039 | - ! empty(self::$_settings[$addon_name]['class_paths']) |
|
1040 | - ) { |
|
1041 | - // add to list of shortcodes to be registered |
|
1042 | - EE_Register_Model::deregister($addon_name); |
|
1043 | - } |
|
1044 | - if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1045 | - || |
|
1046 | - ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
1047 | - ) { |
|
1048 | - // add to list of shortcodes to be registered |
|
1049 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
1050 | - } |
|
1051 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1052 | - foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
1053 | - EE_Register_Message_Type::deregister($message_type); |
|
1054 | - } |
|
1055 | - } |
|
1056 | - //deregister capabilities for addon |
|
1057 | - if ( |
|
1058 | - ! empty(self::$_settings[$addon_name]['capabilities']) |
|
1059 | - || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
1060 | - ) { |
|
1061 | - EE_Register_Capabilities::deregister($addon_name); |
|
1062 | - } |
|
1063 | - //deregister custom_post_types for addon |
|
1064 | - if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1065 | - EE_Register_CPT::deregister($addon_name); |
|
1066 | - } |
|
1067 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
1068 | - EE_Register_Payment_Method::deregister($addon_name); |
|
1069 | - } |
|
1070 | - remove_action( |
|
1071 | - 'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
1072 | - array(EE_Registry::instance()->addons->{$class_name}, 'deactivation') |
|
1073 | - ); |
|
1074 | - remove_action( |
|
1075 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1076 | - array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required') |
|
1077 | - ); |
|
1078 | - //remove `after_registration` call |
|
1079 | - remove_action( |
|
1080 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
1081 | - array(EE_Registry::instance()->addons->{$class_name}, 'after_registration'), |
|
1082 | - 999 |
|
1083 | - ); |
|
1084 | - unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]); |
|
998 | + /** |
|
999 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
1000 | + * |
|
1001 | + * @since 4.3.0 |
|
1002 | + * @param string $addon_name the name for the addon that was previously registered |
|
1003 | + * @throws EE_Error |
|
1004 | + * @return void |
|
1005 | + */ |
|
1006 | + public static function deregister($addon_name = null) |
|
1007 | + { |
|
1008 | + if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) { |
|
1009 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1010 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
1011 | + if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
1012 | + // setup DMS |
|
1013 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1014 | + } |
|
1015 | + if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
1016 | + // register admin page |
|
1017 | + EE_Register_Admin_Page::deregister($addon_name); |
|
1018 | + } |
|
1019 | + if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
1020 | + // add to list of modules to be registered |
|
1021 | + EE_Register_Module::deregister($addon_name); |
|
1022 | + } |
|
1023 | + if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
1024 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
1025 | + ) { |
|
1026 | + // add to list of shortcodes to be registered |
|
1027 | + EE_Register_Shortcode::deregister($addon_name); |
|
1028 | + } |
|
1029 | + if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1030 | + // if config_class present let's register config. |
|
1031 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
1032 | + } |
|
1033 | + if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1034 | + // add to list of widgets to be registered |
|
1035 | + EE_Register_Widget::deregister($addon_name); |
|
1036 | + } |
|
1037 | + if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
1038 | + || |
|
1039 | + ! empty(self::$_settings[$addon_name]['class_paths']) |
|
1040 | + ) { |
|
1041 | + // add to list of shortcodes to be registered |
|
1042 | + EE_Register_Model::deregister($addon_name); |
|
1043 | + } |
|
1044 | + if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1045 | + || |
|
1046 | + ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
1047 | + ) { |
|
1048 | + // add to list of shortcodes to be registered |
|
1049 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
1050 | + } |
|
1051 | + if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1052 | + foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
1053 | + EE_Register_Message_Type::deregister($message_type); |
|
1054 | + } |
|
1055 | + } |
|
1056 | + //deregister capabilities for addon |
|
1057 | + if ( |
|
1058 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
1059 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
1060 | + ) { |
|
1061 | + EE_Register_Capabilities::deregister($addon_name); |
|
1062 | + } |
|
1063 | + //deregister custom_post_types for addon |
|
1064 | + if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1065 | + EE_Register_CPT::deregister($addon_name); |
|
1066 | + } |
|
1067 | + if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
1068 | + EE_Register_Payment_Method::deregister($addon_name); |
|
1069 | + } |
|
1070 | + remove_action( |
|
1071 | + 'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
1072 | + array(EE_Registry::instance()->addons->{$class_name}, 'deactivation') |
|
1073 | + ); |
|
1074 | + remove_action( |
|
1075 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1076 | + array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required') |
|
1077 | + ); |
|
1078 | + //remove `after_registration` call |
|
1079 | + remove_action( |
|
1080 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
1081 | + array(EE_Registry::instance()->addons->{$class_name}, 'after_registration'), |
|
1082 | + 999 |
|
1083 | + ); |
|
1084 | + unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]); |
|
1085 | 1085 | |
1086 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1087 | - } |
|
1088 | - } |
|
1086 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1087 | + } |
|
1088 | + } |
|
1089 | 1089 | |
1090 | 1090 | |
1091 | 1091 | } |
@@ -14,732 +14,732 @@ discard block |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * prefix to be added onto an addon's plugin slug to make a wp option name |
|
19 | - * which will be used to store the plugin's activation history |
|
20 | - */ |
|
21 | - const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var $_version |
|
25 | - * @type string |
|
26 | - */ |
|
27 | - protected $_version = ''; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var $_min_core_version |
|
31 | - * @type string |
|
32 | - */ |
|
33 | - protected $_min_core_version = ''; |
|
34 | - |
|
35 | - /** |
|
36 | - * derived from plugin 'main_file_path using plugin_basename() |
|
37 | - * |
|
38 | - * @type string $_plugin_basename |
|
39 | - */ |
|
40 | - protected $_plugin_basename = ''; |
|
41 | - |
|
42 | - /** |
|
43 | - * A non-internationalized name to identify this addon for use in URLs, etc |
|
44 | - * |
|
45 | - * @type string $_plugin_slug |
|
46 | - */ |
|
47 | - protected $_plugin_slug = ''; |
|
48 | - |
|
49 | - /** |
|
50 | - * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
|
51 | - * |
|
52 | - * @type string _addon_name |
|
53 | - */ |
|
54 | - protected $_addon_name = ''; |
|
55 | - |
|
56 | - /** |
|
57 | - * one of the EE_System::req_type_* constants |
|
58 | - * |
|
59 | - * @type int $_req_type |
|
60 | - */ |
|
61 | - protected $_req_type; |
|
62 | - |
|
63 | - /** |
|
64 | - * page slug to be used when generating the "Settings" link on the WP plugin page |
|
65 | - * |
|
66 | - * @type string $_plugin_action_slug |
|
67 | - */ |
|
68 | - protected $_plugin_action_slug = ''; |
|
69 | - |
|
70 | - /** |
|
71 | - * if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
72 | - * that can be used for adding upgrading/marketing info |
|
73 | - * |
|
74 | - * @type array $_plugins_page_row |
|
75 | - */ |
|
76 | - protected $_plugins_page_row = array(); |
|
77 | - |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc. |
|
82 | - * |
|
83 | - * @type string |
|
84 | - */ |
|
85 | - protected $_main_plugin_file; |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * class constructor |
|
90 | - */ |
|
91 | - public function __construct() |
|
92 | - { |
|
93 | - add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init')); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @param mixed $version |
|
99 | - */ |
|
100 | - public function set_version($version = null) |
|
101 | - { |
|
102 | - $this->_version = $version; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * get__version |
|
108 | - * |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public function version() |
|
112 | - { |
|
113 | - return $this->_version; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @param mixed $min_core_version |
|
119 | - */ |
|
120 | - public function set_min_core_version($min_core_version = null) |
|
121 | - { |
|
122 | - $this->_min_core_version = $min_core_version; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * get__min_core_version |
|
128 | - * |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function min_core_version() |
|
132 | - { |
|
133 | - return $this->_min_core_version; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * Sets addon_name |
|
139 | - * |
|
140 | - * @param string $addon_name |
|
141 | - * @return boolean |
|
142 | - */ |
|
143 | - public function set_name($addon_name) |
|
144 | - { |
|
145 | - return $this->_addon_name = $addon_name; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * Gets addon_name |
|
151 | - * |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - public function name() |
|
155 | - { |
|
156 | - return $this->_addon_name; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @return string |
|
162 | - */ |
|
163 | - public function plugin_basename() |
|
164 | - { |
|
165 | - |
|
166 | - return $this->_plugin_basename; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @param string $plugin_basename |
|
172 | - */ |
|
173 | - public function set_plugin_basename($plugin_basename) |
|
174 | - { |
|
175 | - |
|
176 | - $this->_plugin_basename = $plugin_basename; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * @return string |
|
182 | - */ |
|
183 | - public function plugin_slug() |
|
184 | - { |
|
185 | - |
|
186 | - return $this->_plugin_slug; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * @param string $plugin_slug |
|
192 | - */ |
|
193 | - public function set_plugin_slug($plugin_slug) |
|
194 | - { |
|
195 | - |
|
196 | - $this->_plugin_slug = $plugin_slug; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @return string |
|
202 | - */ |
|
203 | - public function plugin_action_slug() |
|
204 | - { |
|
205 | - |
|
206 | - return $this->_plugin_action_slug; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * @param string $plugin_action_slug |
|
212 | - */ |
|
213 | - public function set_plugin_action_slug($plugin_action_slug) |
|
214 | - { |
|
215 | - |
|
216 | - $this->_plugin_action_slug = $plugin_action_slug; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * @return array |
|
222 | - */ |
|
223 | - public function get_plugins_page_row() |
|
224 | - { |
|
225 | - |
|
226 | - return $this->_plugins_page_row; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * @param array $plugins_page_row |
|
232 | - */ |
|
233 | - public function set_plugins_page_row($plugins_page_row = array()) |
|
234 | - { |
|
235 | - // sigh.... check for example content that I stupidly merged to master and remove it if found |
|
236 | - if (! is_array($plugins_page_row) |
|
237 | - && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
|
238 | - ) { |
|
239 | - $plugins_page_row = array(); |
|
240 | - } |
|
241 | - $this->_plugins_page_row = (array) $plugins_page_row; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * Called when EE core detects this addon has been activated for the first time. |
|
247 | - * If the site isn't in maintenance mode, should setup the addon's database |
|
248 | - * |
|
249 | - * @return void |
|
250 | - */ |
|
251 | - public function new_install() |
|
252 | - { |
|
253 | - $classname = get_class($this); |
|
254 | - do_action("AHEE__{$classname}__new_install"); |
|
255 | - do_action('AHEE__EE_Addon__new_install', $this); |
|
256 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
257 | - add_action( |
|
258 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
259 | - array($this, 'initialize_db_if_no_migrations_required') |
|
260 | - ); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * Called when EE core detects this addon has been reactivated. When this happens, |
|
266 | - * it's good to just check that your data is still intact |
|
267 | - * |
|
268 | - * @return void |
|
269 | - */ |
|
270 | - public function reactivation() |
|
271 | - { |
|
272 | - $classname = get_class($this); |
|
273 | - do_action("AHEE__{$classname}__reactivation"); |
|
274 | - do_action('AHEE__EE_Addon__reactivation', $this); |
|
275 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
276 | - add_action( |
|
277 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
278 | - array($this, 'initialize_db_if_no_migrations_required') |
|
279 | - ); |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * Called when the registered deactivation hook for this addon fires. |
|
285 | - * @throws EE_Error |
|
286 | - */ |
|
287 | - public function deactivation() |
|
288 | - { |
|
289 | - $classname = get_class($this); |
|
290 | - do_action("AHEE__{$classname}__deactivation"); |
|
291 | - do_action('AHEE__EE_Addon__deactivation', $this); |
|
292 | - //check if the site no longer needs to be in maintenance mode |
|
293 | - EE_Register_Addon::deregister($this->name()); |
|
294 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * Takes care of double-checking that we're not in maintenance mode, and then |
|
300 | - * initializing this addon's necessary initial data. This is called by default on new activations |
|
301 | - * and reactivations. |
|
302 | - * |
|
303 | - * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data. |
|
304 | - * This is a resource-intensive job so we prefer to only do it when necessary |
|
305 | - * @return void |
|
306 | - * @throws \EE_Error |
|
307 | - */ |
|
308 | - public function initialize_db_if_no_migrations_required($verify_schema = true) |
|
309 | - { |
|
310 | - if ($verify_schema === '') { |
|
311 | - //wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name |
|
312 | - //(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it |
|
313 | - //calls them with an argument of an empty string (ie ""), which evaluates to false |
|
314 | - //so we need to treat the empty string as if nothing had been passed, and should instead use the default |
|
315 | - $verify_schema = true; |
|
316 | - } |
|
317 | - if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
318 | - if ($verify_schema) { |
|
319 | - $this->initialize_db(); |
|
320 | - } |
|
321 | - $this->initialize_default_data(); |
|
322 | - //@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe |
|
323 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
324 | - array( |
|
325 | - 'slug' => $this->name(), |
|
326 | - 'version' => $this->version(), |
|
327 | - ) |
|
328 | - ); |
|
329 | - /* make sure core's data is a-ok |
|
17 | + /** |
|
18 | + * prefix to be added onto an addon's plugin slug to make a wp option name |
|
19 | + * which will be used to store the plugin's activation history |
|
20 | + */ |
|
21 | + const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var $_version |
|
25 | + * @type string |
|
26 | + */ |
|
27 | + protected $_version = ''; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var $_min_core_version |
|
31 | + * @type string |
|
32 | + */ |
|
33 | + protected $_min_core_version = ''; |
|
34 | + |
|
35 | + /** |
|
36 | + * derived from plugin 'main_file_path using plugin_basename() |
|
37 | + * |
|
38 | + * @type string $_plugin_basename |
|
39 | + */ |
|
40 | + protected $_plugin_basename = ''; |
|
41 | + |
|
42 | + /** |
|
43 | + * A non-internationalized name to identify this addon for use in URLs, etc |
|
44 | + * |
|
45 | + * @type string $_plugin_slug |
|
46 | + */ |
|
47 | + protected $_plugin_slug = ''; |
|
48 | + |
|
49 | + /** |
|
50 | + * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
|
51 | + * |
|
52 | + * @type string _addon_name |
|
53 | + */ |
|
54 | + protected $_addon_name = ''; |
|
55 | + |
|
56 | + /** |
|
57 | + * one of the EE_System::req_type_* constants |
|
58 | + * |
|
59 | + * @type int $_req_type |
|
60 | + */ |
|
61 | + protected $_req_type; |
|
62 | + |
|
63 | + /** |
|
64 | + * page slug to be used when generating the "Settings" link on the WP plugin page |
|
65 | + * |
|
66 | + * @type string $_plugin_action_slug |
|
67 | + */ |
|
68 | + protected $_plugin_action_slug = ''; |
|
69 | + |
|
70 | + /** |
|
71 | + * if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
72 | + * that can be used for adding upgrading/marketing info |
|
73 | + * |
|
74 | + * @type array $_plugins_page_row |
|
75 | + */ |
|
76 | + protected $_plugins_page_row = array(); |
|
77 | + |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc. |
|
82 | + * |
|
83 | + * @type string |
|
84 | + */ |
|
85 | + protected $_main_plugin_file; |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * class constructor |
|
90 | + */ |
|
91 | + public function __construct() |
|
92 | + { |
|
93 | + add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init')); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @param mixed $version |
|
99 | + */ |
|
100 | + public function set_version($version = null) |
|
101 | + { |
|
102 | + $this->_version = $version; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * get__version |
|
108 | + * |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public function version() |
|
112 | + { |
|
113 | + return $this->_version; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @param mixed $min_core_version |
|
119 | + */ |
|
120 | + public function set_min_core_version($min_core_version = null) |
|
121 | + { |
|
122 | + $this->_min_core_version = $min_core_version; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * get__min_core_version |
|
128 | + * |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function min_core_version() |
|
132 | + { |
|
133 | + return $this->_min_core_version; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * Sets addon_name |
|
139 | + * |
|
140 | + * @param string $addon_name |
|
141 | + * @return boolean |
|
142 | + */ |
|
143 | + public function set_name($addon_name) |
|
144 | + { |
|
145 | + return $this->_addon_name = $addon_name; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * Gets addon_name |
|
151 | + * |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + public function name() |
|
155 | + { |
|
156 | + return $this->_addon_name; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @return string |
|
162 | + */ |
|
163 | + public function plugin_basename() |
|
164 | + { |
|
165 | + |
|
166 | + return $this->_plugin_basename; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @param string $plugin_basename |
|
172 | + */ |
|
173 | + public function set_plugin_basename($plugin_basename) |
|
174 | + { |
|
175 | + |
|
176 | + $this->_plugin_basename = $plugin_basename; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * @return string |
|
182 | + */ |
|
183 | + public function plugin_slug() |
|
184 | + { |
|
185 | + |
|
186 | + return $this->_plugin_slug; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * @param string $plugin_slug |
|
192 | + */ |
|
193 | + public function set_plugin_slug($plugin_slug) |
|
194 | + { |
|
195 | + |
|
196 | + $this->_plugin_slug = $plugin_slug; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @return string |
|
202 | + */ |
|
203 | + public function plugin_action_slug() |
|
204 | + { |
|
205 | + |
|
206 | + return $this->_plugin_action_slug; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * @param string $plugin_action_slug |
|
212 | + */ |
|
213 | + public function set_plugin_action_slug($plugin_action_slug) |
|
214 | + { |
|
215 | + |
|
216 | + $this->_plugin_action_slug = $plugin_action_slug; |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * @return array |
|
222 | + */ |
|
223 | + public function get_plugins_page_row() |
|
224 | + { |
|
225 | + |
|
226 | + return $this->_plugins_page_row; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * @param array $plugins_page_row |
|
232 | + */ |
|
233 | + public function set_plugins_page_row($plugins_page_row = array()) |
|
234 | + { |
|
235 | + // sigh.... check for example content that I stupidly merged to master and remove it if found |
|
236 | + if (! is_array($plugins_page_row) |
|
237 | + && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
|
238 | + ) { |
|
239 | + $plugins_page_row = array(); |
|
240 | + } |
|
241 | + $this->_plugins_page_row = (array) $plugins_page_row; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * Called when EE core detects this addon has been activated for the first time. |
|
247 | + * If the site isn't in maintenance mode, should setup the addon's database |
|
248 | + * |
|
249 | + * @return void |
|
250 | + */ |
|
251 | + public function new_install() |
|
252 | + { |
|
253 | + $classname = get_class($this); |
|
254 | + do_action("AHEE__{$classname}__new_install"); |
|
255 | + do_action('AHEE__EE_Addon__new_install', $this); |
|
256 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
257 | + add_action( |
|
258 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
259 | + array($this, 'initialize_db_if_no_migrations_required') |
|
260 | + ); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * Called when EE core detects this addon has been reactivated. When this happens, |
|
266 | + * it's good to just check that your data is still intact |
|
267 | + * |
|
268 | + * @return void |
|
269 | + */ |
|
270 | + public function reactivation() |
|
271 | + { |
|
272 | + $classname = get_class($this); |
|
273 | + do_action("AHEE__{$classname}__reactivation"); |
|
274 | + do_action('AHEE__EE_Addon__reactivation', $this); |
|
275 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
276 | + add_action( |
|
277 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
278 | + array($this, 'initialize_db_if_no_migrations_required') |
|
279 | + ); |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * Called when the registered deactivation hook for this addon fires. |
|
285 | + * @throws EE_Error |
|
286 | + */ |
|
287 | + public function deactivation() |
|
288 | + { |
|
289 | + $classname = get_class($this); |
|
290 | + do_action("AHEE__{$classname}__deactivation"); |
|
291 | + do_action('AHEE__EE_Addon__deactivation', $this); |
|
292 | + //check if the site no longer needs to be in maintenance mode |
|
293 | + EE_Register_Addon::deregister($this->name()); |
|
294 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * Takes care of double-checking that we're not in maintenance mode, and then |
|
300 | + * initializing this addon's necessary initial data. This is called by default on new activations |
|
301 | + * and reactivations. |
|
302 | + * |
|
303 | + * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data. |
|
304 | + * This is a resource-intensive job so we prefer to only do it when necessary |
|
305 | + * @return void |
|
306 | + * @throws \EE_Error |
|
307 | + */ |
|
308 | + public function initialize_db_if_no_migrations_required($verify_schema = true) |
|
309 | + { |
|
310 | + if ($verify_schema === '') { |
|
311 | + //wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name |
|
312 | + //(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it |
|
313 | + //calls them with an argument of an empty string (ie ""), which evaluates to false |
|
314 | + //so we need to treat the empty string as if nothing had been passed, and should instead use the default |
|
315 | + $verify_schema = true; |
|
316 | + } |
|
317 | + if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
318 | + if ($verify_schema) { |
|
319 | + $this->initialize_db(); |
|
320 | + } |
|
321 | + $this->initialize_default_data(); |
|
322 | + //@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe |
|
323 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
324 | + array( |
|
325 | + 'slug' => $this->name(), |
|
326 | + 'version' => $this->version(), |
|
327 | + ) |
|
328 | + ); |
|
329 | + /* make sure core's data is a-ok |
|
330 | 330 | * (at the time of writing, we especially want to verify all the caps are present |
331 | 331 | * because payment method type capabilities are added dynamically, and it's |
332 | 332 | * possible this addon added a payment method. But it's also possible |
333 | 333 | * other data needs to be verified) |
334 | 334 | */ |
335 | - EEH_Activation::initialize_db_content(); |
|
336 | - update_option('ee_flush_rewrite_rules', true); |
|
337 | - //in case there are lots of addons being activated at once, let's force garbage collection |
|
338 | - //to help avoid memory limit errors |
|
339 | - //EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true ); |
|
340 | - gc_collect_cycles(); |
|
341 | - } else { |
|
342 | - //ask the data migration manager to init this addon's data |
|
343 | - //when migrations are finished because we can't do it now |
|
344 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name()); |
|
345 | - } |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * Used to setup this addon's database tables, but not necessarily any default |
|
351 | - * data in them. The default is to actually use the most up-to-date data migration script |
|
352 | - * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration() |
|
353 | - * methods to setup the db. |
|
354 | - */ |
|
355 | - public function initialize_db() |
|
356 | - { |
|
357 | - //find the migration script that sets the database to be compatible with the code |
|
358 | - $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name()); |
|
359 | - if ($current_dms_name) { |
|
360 | - $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name); |
|
361 | - $current_data_migration_script->set_migrating(false); |
|
362 | - $current_data_migration_script->schema_changes_before_migration(); |
|
363 | - $current_data_migration_script->schema_changes_after_migration(); |
|
364 | - if ($current_data_migration_script->get_errors()) { |
|
365 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
366 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
367 | - } |
|
368 | - } |
|
369 | - } |
|
370 | - //if not DMS was found that should be ok. This addon just doesn't require any database changes |
|
371 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
372 | - array( |
|
373 | - 'slug' => $this->name(), |
|
374 | - 'version' => $this->version(), |
|
375 | - ) |
|
376 | - ); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * If you want to setup default data for the addon, override this method, and call |
|
382 | - * parent::initialize_default_data() from within it. This is normally called |
|
383 | - * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db() |
|
384 | - * and should verify default data is present (but this is also called |
|
385 | - * on reactivations and just after migrations, so please verify you actually want |
|
386 | - * to ADD default data, because it may already be present). |
|
387 | - * However, please call this parent (currently it just fires a hook which other |
|
388 | - * addons may be depending on) |
|
389 | - */ |
|
390 | - public function initialize_default_data() |
|
391 | - { |
|
392 | - /** |
|
393 | - * Called when an addon is ensuring its default data is set (possibly called |
|
394 | - * on a reactivation, so first check for the absence of other data before setting |
|
395 | - * default data) |
|
396 | - * |
|
397 | - * @param EE_Addon $addon the addon that called this |
|
398 | - */ |
|
399 | - do_action('AHEE__EE_Addon__initialize_default_data__begin', $this); |
|
400 | - //override to insert default data. It is safe to use the models here |
|
401 | - //because the site should not be in maintenance mode |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * EE Core detected that this addon has been upgraded. We should check if there |
|
407 | - * are any new migration scripts, and if so put the site into maintenance mode until |
|
408 | - * they're ran |
|
409 | - * |
|
410 | - * @return void |
|
411 | - */ |
|
412 | - public function upgrade() |
|
413 | - { |
|
414 | - $classname = get_class($this); |
|
415 | - do_action("AHEE__{$classname}__upgrade"); |
|
416 | - do_action('AHEE__EE_Addon__upgrade', $this); |
|
417 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
418 | - //also it's possible there is new default data that needs to be added |
|
419 | - add_action( |
|
420 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
421 | - array($this, 'initialize_db_if_no_migrations_required') |
|
422 | - ); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * If Core detects this addon has been downgraded, you may want to invoke some special logic here. |
|
428 | - */ |
|
429 | - public function downgrade() |
|
430 | - { |
|
431 | - $classname = get_class($this); |
|
432 | - do_action("AHEE__{$classname}__downgrade"); |
|
433 | - do_action('AHEE__EE_Addon__downgrade', $this); |
|
434 | - //it's possible there's old default data that needs to be double-checked |
|
435 | - add_action( |
|
436 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
437 | - array($this, 'initialize_db_if_no_migrations_required') |
|
438 | - ); |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * set_db_update_option_name |
|
444 | - * Until we do something better, we'll just check for migration scripts upon |
|
445 | - * plugin activation only. In the future, we'll want to do it on plugin updates too |
|
446 | - * |
|
447 | - * @return bool |
|
448 | - */ |
|
449 | - public function set_db_update_option_name() |
|
450 | - { |
|
451 | - EE_Error::doing_it_wrong( |
|
452 | - __FUNCTION__, |
|
453 | - esc_html__( |
|
454 | - 'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', |
|
455 | - 'event_espresso' |
|
456 | - ), |
|
457 | - '4.3.0.alpha.016' |
|
458 | - ); |
|
459 | - //let's just handle this on the next request, ok? right now we're just not really ready |
|
460 | - return $this->set_activation_indicator_option(); |
|
461 | - } |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * Returns the name of the activation indicator option |
|
466 | - * (an option which is set temporarily to indicate that this addon was just activated) |
|
467 | - * |
|
468 | - * @deprecated since version 4.3.0.alpha.016 |
|
469 | - * @return string |
|
470 | - */ |
|
471 | - public function get_db_update_option_name() |
|
472 | - { |
|
473 | - EE_Error::doing_it_wrong( |
|
474 | - __FUNCTION__, |
|
475 | - esc_html__( |
|
476 | - 'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', |
|
477 | - 'event_espresso' |
|
478 | - ), |
|
479 | - '4.3.0.alpha.016' |
|
480 | - ); |
|
481 | - return $this->get_activation_indicator_option_name(); |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * When the addon is activated, this should be called to set a wordpress option that |
|
487 | - * indicates it was activated. This is especially useful for detecting reactivations. |
|
488 | - * |
|
489 | - * @return bool |
|
490 | - */ |
|
491 | - public function set_activation_indicator_option() |
|
492 | - { |
|
493 | - // let's just handle this on the next request, ok? right now we're just not really ready |
|
494 | - return update_option($this->get_activation_indicator_option_name(), true); |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * Gets the name of the wp option which is used to temporarily indicate that this addon was activated |
|
500 | - * |
|
501 | - * @return string |
|
502 | - */ |
|
503 | - public function get_activation_indicator_option_name() |
|
504 | - { |
|
505 | - return 'ee_activation_' . $this->name(); |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * Used by EE_System to set the request type of this addon. Should not be used by addon developers |
|
511 | - * |
|
512 | - * @param int $req_type |
|
513 | - */ |
|
514 | - public function set_req_type($req_type) |
|
515 | - { |
|
516 | - $this->_req_type = $req_type; |
|
517 | - } |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation, |
|
522 | - * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by |
|
523 | - * EE_System when it is checking for new install or upgrades of addons |
|
524 | - */ |
|
525 | - public function detect_req_type() |
|
526 | - { |
|
527 | - if (! $this->_req_type) { |
|
528 | - $this->detect_activation_or_upgrade(); |
|
529 | - } |
|
530 | - return $this->_req_type; |
|
531 | - } |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.) |
|
536 | - * Should only be called once per request |
|
537 | - * |
|
538 | - * @return void |
|
539 | - */ |
|
540 | - public function detect_activation_or_upgrade() |
|
541 | - { |
|
542 | - $activation_history_for_addon = $this->get_activation_history(); |
|
335 | + EEH_Activation::initialize_db_content(); |
|
336 | + update_option('ee_flush_rewrite_rules', true); |
|
337 | + //in case there are lots of addons being activated at once, let's force garbage collection |
|
338 | + //to help avoid memory limit errors |
|
339 | + //EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true ); |
|
340 | + gc_collect_cycles(); |
|
341 | + } else { |
|
342 | + //ask the data migration manager to init this addon's data |
|
343 | + //when migrations are finished because we can't do it now |
|
344 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name()); |
|
345 | + } |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * Used to setup this addon's database tables, but not necessarily any default |
|
351 | + * data in them. The default is to actually use the most up-to-date data migration script |
|
352 | + * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration() |
|
353 | + * methods to setup the db. |
|
354 | + */ |
|
355 | + public function initialize_db() |
|
356 | + { |
|
357 | + //find the migration script that sets the database to be compatible with the code |
|
358 | + $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name()); |
|
359 | + if ($current_dms_name) { |
|
360 | + $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name); |
|
361 | + $current_data_migration_script->set_migrating(false); |
|
362 | + $current_data_migration_script->schema_changes_before_migration(); |
|
363 | + $current_data_migration_script->schema_changes_after_migration(); |
|
364 | + if ($current_data_migration_script->get_errors()) { |
|
365 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
366 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
367 | + } |
|
368 | + } |
|
369 | + } |
|
370 | + //if not DMS was found that should be ok. This addon just doesn't require any database changes |
|
371 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
372 | + array( |
|
373 | + 'slug' => $this->name(), |
|
374 | + 'version' => $this->version(), |
|
375 | + ) |
|
376 | + ); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * If you want to setup default data for the addon, override this method, and call |
|
382 | + * parent::initialize_default_data() from within it. This is normally called |
|
383 | + * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db() |
|
384 | + * and should verify default data is present (but this is also called |
|
385 | + * on reactivations and just after migrations, so please verify you actually want |
|
386 | + * to ADD default data, because it may already be present). |
|
387 | + * However, please call this parent (currently it just fires a hook which other |
|
388 | + * addons may be depending on) |
|
389 | + */ |
|
390 | + public function initialize_default_data() |
|
391 | + { |
|
392 | + /** |
|
393 | + * Called when an addon is ensuring its default data is set (possibly called |
|
394 | + * on a reactivation, so first check for the absence of other data before setting |
|
395 | + * default data) |
|
396 | + * |
|
397 | + * @param EE_Addon $addon the addon that called this |
|
398 | + */ |
|
399 | + do_action('AHEE__EE_Addon__initialize_default_data__begin', $this); |
|
400 | + //override to insert default data. It is safe to use the models here |
|
401 | + //because the site should not be in maintenance mode |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * EE Core detected that this addon has been upgraded. We should check if there |
|
407 | + * are any new migration scripts, and if so put the site into maintenance mode until |
|
408 | + * they're ran |
|
409 | + * |
|
410 | + * @return void |
|
411 | + */ |
|
412 | + public function upgrade() |
|
413 | + { |
|
414 | + $classname = get_class($this); |
|
415 | + do_action("AHEE__{$classname}__upgrade"); |
|
416 | + do_action('AHEE__EE_Addon__upgrade', $this); |
|
417 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
418 | + //also it's possible there is new default data that needs to be added |
|
419 | + add_action( |
|
420 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
421 | + array($this, 'initialize_db_if_no_migrations_required') |
|
422 | + ); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * If Core detects this addon has been downgraded, you may want to invoke some special logic here. |
|
428 | + */ |
|
429 | + public function downgrade() |
|
430 | + { |
|
431 | + $classname = get_class($this); |
|
432 | + do_action("AHEE__{$classname}__downgrade"); |
|
433 | + do_action('AHEE__EE_Addon__downgrade', $this); |
|
434 | + //it's possible there's old default data that needs to be double-checked |
|
435 | + add_action( |
|
436 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
437 | + array($this, 'initialize_db_if_no_migrations_required') |
|
438 | + ); |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * set_db_update_option_name |
|
444 | + * Until we do something better, we'll just check for migration scripts upon |
|
445 | + * plugin activation only. In the future, we'll want to do it on plugin updates too |
|
446 | + * |
|
447 | + * @return bool |
|
448 | + */ |
|
449 | + public function set_db_update_option_name() |
|
450 | + { |
|
451 | + EE_Error::doing_it_wrong( |
|
452 | + __FUNCTION__, |
|
453 | + esc_html__( |
|
454 | + 'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', |
|
455 | + 'event_espresso' |
|
456 | + ), |
|
457 | + '4.3.0.alpha.016' |
|
458 | + ); |
|
459 | + //let's just handle this on the next request, ok? right now we're just not really ready |
|
460 | + return $this->set_activation_indicator_option(); |
|
461 | + } |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * Returns the name of the activation indicator option |
|
466 | + * (an option which is set temporarily to indicate that this addon was just activated) |
|
467 | + * |
|
468 | + * @deprecated since version 4.3.0.alpha.016 |
|
469 | + * @return string |
|
470 | + */ |
|
471 | + public function get_db_update_option_name() |
|
472 | + { |
|
473 | + EE_Error::doing_it_wrong( |
|
474 | + __FUNCTION__, |
|
475 | + esc_html__( |
|
476 | + 'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', |
|
477 | + 'event_espresso' |
|
478 | + ), |
|
479 | + '4.3.0.alpha.016' |
|
480 | + ); |
|
481 | + return $this->get_activation_indicator_option_name(); |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * When the addon is activated, this should be called to set a wordpress option that |
|
487 | + * indicates it was activated. This is especially useful for detecting reactivations. |
|
488 | + * |
|
489 | + * @return bool |
|
490 | + */ |
|
491 | + public function set_activation_indicator_option() |
|
492 | + { |
|
493 | + // let's just handle this on the next request, ok? right now we're just not really ready |
|
494 | + return update_option($this->get_activation_indicator_option_name(), true); |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * Gets the name of the wp option which is used to temporarily indicate that this addon was activated |
|
500 | + * |
|
501 | + * @return string |
|
502 | + */ |
|
503 | + public function get_activation_indicator_option_name() |
|
504 | + { |
|
505 | + return 'ee_activation_' . $this->name(); |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * Used by EE_System to set the request type of this addon. Should not be used by addon developers |
|
511 | + * |
|
512 | + * @param int $req_type |
|
513 | + */ |
|
514 | + public function set_req_type($req_type) |
|
515 | + { |
|
516 | + $this->_req_type = $req_type; |
|
517 | + } |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation, |
|
522 | + * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by |
|
523 | + * EE_System when it is checking for new install or upgrades of addons |
|
524 | + */ |
|
525 | + public function detect_req_type() |
|
526 | + { |
|
527 | + if (! $this->_req_type) { |
|
528 | + $this->detect_activation_or_upgrade(); |
|
529 | + } |
|
530 | + return $this->_req_type; |
|
531 | + } |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.) |
|
536 | + * Should only be called once per request |
|
537 | + * |
|
538 | + * @return void |
|
539 | + */ |
|
540 | + public function detect_activation_or_upgrade() |
|
541 | + { |
|
542 | + $activation_history_for_addon = $this->get_activation_history(); |
|
543 | 543 | // d($activation_history_for_addon); |
544 | - $request_type = EE_System::detect_req_type_given_activation_history( |
|
545 | - $activation_history_for_addon, |
|
546 | - $this->get_activation_indicator_option_name(), |
|
547 | - $this->version() |
|
548 | - ); |
|
549 | - $this->set_req_type($request_type); |
|
550 | - $classname = get_class($this); |
|
551 | - switch ($request_type) { |
|
552 | - case EE_System::req_type_new_activation: |
|
553 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation"); |
|
554 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this); |
|
555 | - $this->new_install(); |
|
556 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
557 | - break; |
|
558 | - case EE_System::req_type_reactivation: |
|
559 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation"); |
|
560 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this); |
|
561 | - $this->reactivation(); |
|
562 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
563 | - break; |
|
564 | - case EE_System::req_type_upgrade: |
|
565 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade"); |
|
566 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this); |
|
567 | - $this->upgrade(); |
|
568 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
569 | - break; |
|
570 | - case EE_System::req_type_downgrade: |
|
571 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade"); |
|
572 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this); |
|
573 | - $this->downgrade(); |
|
574 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
575 | - break; |
|
576 | - case EE_System::req_type_normal: |
|
577 | - default: |
|
544 | + $request_type = EE_System::detect_req_type_given_activation_history( |
|
545 | + $activation_history_for_addon, |
|
546 | + $this->get_activation_indicator_option_name(), |
|
547 | + $this->version() |
|
548 | + ); |
|
549 | + $this->set_req_type($request_type); |
|
550 | + $classname = get_class($this); |
|
551 | + switch ($request_type) { |
|
552 | + case EE_System::req_type_new_activation: |
|
553 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation"); |
|
554 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this); |
|
555 | + $this->new_install(); |
|
556 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
557 | + break; |
|
558 | + case EE_System::req_type_reactivation: |
|
559 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation"); |
|
560 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this); |
|
561 | + $this->reactivation(); |
|
562 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
563 | + break; |
|
564 | + case EE_System::req_type_upgrade: |
|
565 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade"); |
|
566 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this); |
|
567 | + $this->upgrade(); |
|
568 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
569 | + break; |
|
570 | + case EE_System::req_type_downgrade: |
|
571 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade"); |
|
572 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this); |
|
573 | + $this->downgrade(); |
|
574 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
575 | + break; |
|
576 | + case EE_System::req_type_normal: |
|
577 | + default: |
|
578 | 578 | // $this->_maybe_redirect_to_ee_about(); |
579 | - break; |
|
580 | - } |
|
581 | - |
|
582 | - do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete"); |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * Updates the version history for this addon |
|
587 | - * |
|
588 | - * @param array $version_history |
|
589 | - * @param string $current_version_to_add |
|
590 | - * @return boolean success |
|
591 | - */ |
|
592 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
593 | - { |
|
594 | - if (! $version_history) { |
|
595 | - $version_history = $this->get_activation_history(); |
|
596 | - } |
|
597 | - if ($current_version_to_add === null) { |
|
598 | - $current_version_to_add = $this->version(); |
|
599 | - } |
|
600 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
601 | - // resave |
|
579 | + break; |
|
580 | + } |
|
581 | + |
|
582 | + do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete"); |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * Updates the version history for this addon |
|
587 | + * |
|
588 | + * @param array $version_history |
|
589 | + * @param string $current_version_to_add |
|
590 | + * @return boolean success |
|
591 | + */ |
|
592 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
593 | + { |
|
594 | + if (! $version_history) { |
|
595 | + $version_history = $this->get_activation_history(); |
|
596 | + } |
|
597 | + if ($current_version_to_add === null) { |
|
598 | + $current_version_to_add = $this->version(); |
|
599 | + } |
|
600 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
601 | + // resave |
|
602 | 602 | // echo "updating list of installed versions:".$this->get_activation_history_option_name();d($version_history); |
603 | - return update_option($this->get_activation_history_option_name(), $version_history); |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * Gets the name of the wp option that stores the activation history |
|
608 | - * of this addon |
|
609 | - * |
|
610 | - * @return string |
|
611 | - */ |
|
612 | - public function get_activation_history_option_name() |
|
613 | - { |
|
614 | - return self::ee_addon_version_history_option_prefix . $this->name(); |
|
615 | - } |
|
616 | - |
|
617 | - |
|
618 | - /** |
|
619 | - * Gets the wp option which stores the activation history for this addon |
|
620 | - * |
|
621 | - * @return array |
|
622 | - */ |
|
623 | - public function get_activation_history() |
|
624 | - { |
|
625 | - return get_option($this->get_activation_history_option_name(), null); |
|
626 | - } |
|
627 | - |
|
628 | - |
|
629 | - /** |
|
630 | - * @param string $config_section |
|
631 | - */ |
|
632 | - public function set_config_section($config_section = '') |
|
633 | - { |
|
634 | - $this->_config_section = ! empty($config_section) ? $config_section : 'addons'; |
|
635 | - } |
|
636 | - |
|
637 | - /** |
|
638 | - * Sets the filepath to the main plugin file |
|
639 | - * |
|
640 | - * @param string $filepath |
|
641 | - */ |
|
642 | - public function set_main_plugin_file($filepath) |
|
643 | - { |
|
644 | - $this->_main_plugin_file = $filepath; |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * gets the filepath to teh main file |
|
649 | - * |
|
650 | - * @return string |
|
651 | - */ |
|
652 | - public function get_main_plugin_file() |
|
653 | - { |
|
654 | - return $this->_main_plugin_file; |
|
655 | - } |
|
656 | - |
|
657 | - /** |
|
658 | - * Gets the filename (no path) of the main file (the main file loaded |
|
659 | - * by WP) |
|
660 | - * |
|
661 | - * @return string |
|
662 | - */ |
|
663 | - public function get_main_plugin_file_basename() |
|
664 | - { |
|
665 | - return plugin_basename($this->get_main_plugin_file()); |
|
666 | - } |
|
667 | - |
|
668 | - /** |
|
669 | - * Gets the folder name which contains the main plugin file |
|
670 | - * |
|
671 | - * @return string |
|
672 | - */ |
|
673 | - public function get_main_plugin_file_dirname() |
|
674 | - { |
|
675 | - return dirname($this->get_main_plugin_file()); |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - /** |
|
680 | - * sets hooks used in the admin |
|
681 | - * |
|
682 | - * @return void |
|
683 | - */ |
|
684 | - public function admin_init() |
|
685 | - { |
|
686 | - // is admin and not in M-Mode ? |
|
687 | - if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
688 | - add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
|
689 | - add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
690 | - } |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * plugin_actions |
|
696 | - * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
|
697 | - * |
|
698 | - * @param $links |
|
699 | - * @param $file |
|
700 | - * @return array |
|
701 | - */ |
|
702 | - public function plugin_action_links($links, $file) |
|
703 | - { |
|
704 | - if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
705 | - // before other links |
|
706 | - array_unshift( |
|
707 | - $links, |
|
708 | - '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
709 | - . esc_html__('Settings', 'event_espresso') |
|
710 | - . '</a>' |
|
711 | - ); |
|
712 | - } |
|
713 | - return $links; |
|
714 | - } |
|
715 | - |
|
716 | - |
|
717 | - /** |
|
718 | - * after_plugin_row |
|
719 | - * Add additional content to the plugins page plugin row |
|
720 | - * Inserts another row |
|
721 | - * |
|
722 | - * @param $plugin_file |
|
723 | - * @param $plugin_data |
|
724 | - * @param $status |
|
725 | - * @return void |
|
726 | - */ |
|
727 | - public function after_plugin_row($plugin_file, $plugin_data, $status) |
|
728 | - { |
|
729 | - $after_plugin_row = ''; |
|
730 | - $plugins_page_row = $this->get_plugins_page_row(); |
|
731 | - if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
732 | - $class = $status ? 'active' : 'inactive'; |
|
733 | - $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
|
734 | - $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
|
735 | - $description = isset($plugins_page_row['description']) |
|
736 | - ? $plugins_page_row['description'] |
|
737 | - : ''; |
|
738 | - if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
739 | - $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
740 | - $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
|
741 | - $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
|
742 | - $after_plugin_row .= '<style> |
|
603 | + return update_option($this->get_activation_history_option_name(), $version_history); |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * Gets the name of the wp option that stores the activation history |
|
608 | + * of this addon |
|
609 | + * |
|
610 | + * @return string |
|
611 | + */ |
|
612 | + public function get_activation_history_option_name() |
|
613 | + { |
|
614 | + return self::ee_addon_version_history_option_prefix . $this->name(); |
|
615 | + } |
|
616 | + |
|
617 | + |
|
618 | + /** |
|
619 | + * Gets the wp option which stores the activation history for this addon |
|
620 | + * |
|
621 | + * @return array |
|
622 | + */ |
|
623 | + public function get_activation_history() |
|
624 | + { |
|
625 | + return get_option($this->get_activation_history_option_name(), null); |
|
626 | + } |
|
627 | + |
|
628 | + |
|
629 | + /** |
|
630 | + * @param string $config_section |
|
631 | + */ |
|
632 | + public function set_config_section($config_section = '') |
|
633 | + { |
|
634 | + $this->_config_section = ! empty($config_section) ? $config_section : 'addons'; |
|
635 | + } |
|
636 | + |
|
637 | + /** |
|
638 | + * Sets the filepath to the main plugin file |
|
639 | + * |
|
640 | + * @param string $filepath |
|
641 | + */ |
|
642 | + public function set_main_plugin_file($filepath) |
|
643 | + { |
|
644 | + $this->_main_plugin_file = $filepath; |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * gets the filepath to teh main file |
|
649 | + * |
|
650 | + * @return string |
|
651 | + */ |
|
652 | + public function get_main_plugin_file() |
|
653 | + { |
|
654 | + return $this->_main_plugin_file; |
|
655 | + } |
|
656 | + |
|
657 | + /** |
|
658 | + * Gets the filename (no path) of the main file (the main file loaded |
|
659 | + * by WP) |
|
660 | + * |
|
661 | + * @return string |
|
662 | + */ |
|
663 | + public function get_main_plugin_file_basename() |
|
664 | + { |
|
665 | + return plugin_basename($this->get_main_plugin_file()); |
|
666 | + } |
|
667 | + |
|
668 | + /** |
|
669 | + * Gets the folder name which contains the main plugin file |
|
670 | + * |
|
671 | + * @return string |
|
672 | + */ |
|
673 | + public function get_main_plugin_file_dirname() |
|
674 | + { |
|
675 | + return dirname($this->get_main_plugin_file()); |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + /** |
|
680 | + * sets hooks used in the admin |
|
681 | + * |
|
682 | + * @return void |
|
683 | + */ |
|
684 | + public function admin_init() |
|
685 | + { |
|
686 | + // is admin and not in M-Mode ? |
|
687 | + if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
688 | + add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
|
689 | + add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
690 | + } |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * plugin_actions |
|
696 | + * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
|
697 | + * |
|
698 | + * @param $links |
|
699 | + * @param $file |
|
700 | + * @return array |
|
701 | + */ |
|
702 | + public function plugin_action_links($links, $file) |
|
703 | + { |
|
704 | + if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
705 | + // before other links |
|
706 | + array_unshift( |
|
707 | + $links, |
|
708 | + '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
709 | + . esc_html__('Settings', 'event_espresso') |
|
710 | + . '</a>' |
|
711 | + ); |
|
712 | + } |
|
713 | + return $links; |
|
714 | + } |
|
715 | + |
|
716 | + |
|
717 | + /** |
|
718 | + * after_plugin_row |
|
719 | + * Add additional content to the plugins page plugin row |
|
720 | + * Inserts another row |
|
721 | + * |
|
722 | + * @param $plugin_file |
|
723 | + * @param $plugin_data |
|
724 | + * @param $status |
|
725 | + * @return void |
|
726 | + */ |
|
727 | + public function after_plugin_row($plugin_file, $plugin_data, $status) |
|
728 | + { |
|
729 | + $after_plugin_row = ''; |
|
730 | + $plugins_page_row = $this->get_plugins_page_row(); |
|
731 | + if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
732 | + $class = $status ? 'active' : 'inactive'; |
|
733 | + $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
|
734 | + $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
|
735 | + $description = isset($plugins_page_row['description']) |
|
736 | + ? $plugins_page_row['description'] |
|
737 | + : ''; |
|
738 | + if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
739 | + $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
740 | + $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
|
741 | + $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
|
742 | + $after_plugin_row .= '<style> |
|
743 | 743 | .ee-button, |
744 | 744 | .ee-button:active, |
745 | 745 | .ee-button:visited { |
@@ -776,49 +776,49 @@ discard block |
||
776 | 776 | } |
777 | 777 | .ee-button:active { top:0; } |
778 | 778 | </style>'; |
779 | - $after_plugin_row .= ' |
|
779 | + $after_plugin_row .= ' |
|
780 | 780 | <p class="ee-addon-upsell-info-dv"> |
781 | 781 | <a class="ee-button" href="' . $link_url . '">' |
782 | - . $link_text |
|
783 | - . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
|
784 | - . '</a> |
|
782 | + . $link_text |
|
783 | + . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
|
784 | + . '</a> |
|
785 | 785 | </p>'; |
786 | - $after_plugin_row .= '</td>'; |
|
787 | - $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
|
788 | - $after_plugin_row .= $description; |
|
789 | - $after_plugin_row .= '</td>'; |
|
790 | - $after_plugin_row .= '</tr>'; |
|
791 | - } else { |
|
792 | - $after_plugin_row .= $description; |
|
793 | - } |
|
794 | - } |
|
795 | - |
|
796 | - echo $after_plugin_row; |
|
797 | - } |
|
798 | - |
|
799 | - |
|
800 | - /** |
|
801 | - * A safe space for addons to add additional logic like setting hooks that need to be set early in the request. |
|
802 | - * Child classes that have logic like that to run can override this method declaration. This was not made abstract |
|
803 | - * for back compat reasons. |
|
804 | - * |
|
805 | - * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999. |
|
806 | - * |
|
807 | - * It is recommended, if client code is `de-registering` an add-on, then do it on the |
|
808 | - * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this |
|
809 | - * callback does not get run/set in that request. |
|
810 | - * |
|
811 | - * Also, keep in mind that if a registered add-on happens to be deactivated via |
|
812 | - * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method |
|
813 | - * (including setting hooks etc) will have executed before the plugin was deactivated. If you use |
|
814 | - * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's |
|
815 | - * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there. Just remember |
|
816 | - * to call `parent::deactivation`. |
|
817 | - * |
|
818 | - * @since 4.9.26 |
|
819 | - */ |
|
820 | - public function after_registration() |
|
821 | - { |
|
822 | - // cricket chirp... cricket chirp... |
|
823 | - } |
|
786 | + $after_plugin_row .= '</td>'; |
|
787 | + $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
|
788 | + $after_plugin_row .= $description; |
|
789 | + $after_plugin_row .= '</td>'; |
|
790 | + $after_plugin_row .= '</tr>'; |
|
791 | + } else { |
|
792 | + $after_plugin_row .= $description; |
|
793 | + } |
|
794 | + } |
|
795 | + |
|
796 | + echo $after_plugin_row; |
|
797 | + } |
|
798 | + |
|
799 | + |
|
800 | + /** |
|
801 | + * A safe space for addons to add additional logic like setting hooks that need to be set early in the request. |
|
802 | + * Child classes that have logic like that to run can override this method declaration. This was not made abstract |
|
803 | + * for back compat reasons. |
|
804 | + * |
|
805 | + * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999. |
|
806 | + * |
|
807 | + * It is recommended, if client code is `de-registering` an add-on, then do it on the |
|
808 | + * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this |
|
809 | + * callback does not get run/set in that request. |
|
810 | + * |
|
811 | + * Also, keep in mind that if a registered add-on happens to be deactivated via |
|
812 | + * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method |
|
813 | + * (including setting hooks etc) will have executed before the plugin was deactivated. If you use |
|
814 | + * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's |
|
815 | + * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there. Just remember |
|
816 | + * to call `parent::deactivation`. |
|
817 | + * |
|
818 | + * @since 4.9.26 |
|
819 | + */ |
|
820 | + public function after_registration() |
|
821 | + { |
|
822 | + // cricket chirp... cricket chirp... |
|
823 | + } |
|
824 | 824 | } |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | public function set_plugins_page_row($plugins_page_row = array()) |
234 | 234 | { |
235 | 235 | // sigh.... check for example content that I stupidly merged to master and remove it if found |
236 | - if (! is_array($plugins_page_row) |
|
236 | + if ( ! is_array($plugins_page_row) |
|
237 | 237 | && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
238 | 238 | ) { |
239 | 239 | $plugins_page_row = array(); |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | */ |
503 | 503 | public function get_activation_indicator_option_name() |
504 | 504 | { |
505 | - return 'ee_activation_' . $this->name(); |
|
505 | + return 'ee_activation_'.$this->name(); |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | */ |
525 | 525 | public function detect_req_type() |
526 | 526 | { |
527 | - if (! $this->_req_type) { |
|
527 | + if ( ! $this->_req_type) { |
|
528 | 528 | $this->detect_activation_or_upgrade(); |
529 | 529 | } |
530 | 530 | return $this->_req_type; |
@@ -591,7 +591,7 @@ discard block |
||
591 | 591 | */ |
592 | 592 | public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
593 | 593 | { |
594 | - if (! $version_history) { |
|
594 | + if ( ! $version_history) { |
|
595 | 595 | $version_history = $this->get_activation_history(); |
596 | 596 | } |
597 | 597 | if ($current_version_to_add === null) { |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | */ |
612 | 612 | public function get_activation_history_option_name() |
613 | 613 | { |
614 | - return self::ee_addon_version_history_option_prefix . $this->name(); |
|
614 | + return self::ee_addon_version_history_option_prefix.$this->name(); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | // is admin and not in M-Mode ? |
687 | 687 | if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
688 | 688 | add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
689 | - add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
689 | + add_filter('after_plugin_row_'.$this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
690 | 690 | } |
691 | 691 | } |
692 | 692 | |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | // before other links |
706 | 706 | array_unshift( |
707 | 707 | $links, |
708 | - '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
708 | + '<a href="admin.php?page='.$this->plugin_action_slug().'">' |
|
709 | 709 | . esc_html__('Settings', 'event_espresso') |
710 | 710 | . '</a>' |
711 | 711 | ); |
@@ -728,15 +728,15 @@ discard block |
||
728 | 728 | { |
729 | 729 | $after_plugin_row = ''; |
730 | 730 | $plugins_page_row = $this->get_plugins_page_row(); |
731 | - if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
731 | + if ( ! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
732 | 732 | $class = $status ? 'active' : 'inactive'; |
733 | 733 | $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
734 | 734 | $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
735 | 735 | $description = isset($plugins_page_row['description']) |
736 | 736 | ? $plugins_page_row['description'] |
737 | 737 | : ''; |
738 | - if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
739 | - $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
738 | + if ( ! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
739 | + $after_plugin_row .= '<tr id="'.sanitize_title($plugin_file).'-ee-addon" class="'.$class.'">'; |
|
740 | 740 | $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
741 | 741 | $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
742 | 742 | $after_plugin_row .= '<style> |
@@ -778,7 +778,7 @@ discard block |
||
778 | 778 | </style>'; |
779 | 779 | $after_plugin_row .= ' |
780 | 780 | <p class="ee-addon-upsell-info-dv"> |
781 | - <a class="ee-button" href="' . $link_url . '">' |
|
781 | + <a class="ee-button" href="' . $link_url.'">' |
|
782 | 782 | . $link_text |
783 | 783 | . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
784 | 784 | . '</a> |