@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | ?> |
4 | -<h1><?php esc_html_e("You must upgrade your Event Espresso Add-ons before Migrating", "event_espresso");?></h1> |
|
5 | -<p><?php printf(esc_html__("Please %s visit the plugins page%s and update all Event Espresso addon plugins before updating your database.", "event_espresso"), "<a href='".admin_url('/plugins.php')."'>","</a>");?></p> |
|
6 | -<p><?php esc_html_e("You can also deactivate the addons, but all of their data will be lost when your database is migrated", "event_espresso");?></p> |
|
7 | 4 | \ No newline at end of file |
5 | +<h1><?php esc_html_e("You must upgrade your Event Espresso Add-ons before Migrating", "event_espresso"); ?></h1> |
|
6 | +<p><?php printf(esc_html__("Please %s visit the plugins page%s and update all Event Espresso addon plugins before updating your database.", "event_espresso"), "<a href='".admin_url('/plugins.php')."'>", "</a>"); ?></p> |
|
7 | +<p><?php esc_html_e("You can also deactivate the addons, but all of their data will be lost when your database is migrated", "event_espresso"); ?></p> |
|
8 | 8 | \ No newline at end of file |
@@ -28,29 +28,29 @@ discard block |
||
28 | 28 | <h3 class="espresso-header"> |
29 | 29 | <span class="dashicons dashicons-flag ee-icon-size-22"></span> |
30 | 30 | <?php |
31 | - echo apply_filters( |
|
32 | - 'FHEE__ee_migration_page__header', |
|
33 | - sprintf( |
|
34 | - esc_html__("Your Event Espresso data needs to be updated.", "event_espresso"), |
|
35 | - $current_db_state, |
|
36 | - $next_db_state |
|
37 | - ), |
|
38 | - $current_db_state, |
|
39 | - $next_db_state |
|
40 | - ); |
|
41 | - ?> |
|
31 | + echo apply_filters( |
|
32 | + 'FHEE__ee_migration_page__header', |
|
33 | + sprintf( |
|
34 | + esc_html__("Your Event Espresso data needs to be updated.", "event_espresso"), |
|
35 | + $current_db_state, |
|
36 | + $next_db_state |
|
37 | + ), |
|
38 | + $current_db_state, |
|
39 | + $next_db_state |
|
40 | + ); |
|
41 | + ?> |
|
42 | 42 | </h3> |
43 | 43 | <?php } elseif ($show_most_recent_migration) { ?> |
44 | 44 | <h3 class="espresso-header"> |
45 | 45 | <span class="dashicons dashicons-awards ee-icon-size-22"></span> |
46 | 46 | <?php echo apply_filters('FHEE__ee_migration_page__done_migration_header', |
47 | - sprintf(esc_html__('Congratulations! Your database is "up-to-date" and you are ready to begin using %s', |
|
48 | - "event_espresso"), $ultimate_db_state)); ?> |
|
47 | + sprintf(esc_html__('Congratulations! Your database is "up-to-date" and you are ready to begin using %s', |
|
48 | + "event_espresso"), $ultimate_db_state)); ?> |
|
49 | 49 | </h3> |
50 | 50 | <p> |
51 | 51 | <?php echo apply_filters('FHEE__ee_migration_page__p_after_done_migration_header', |
52 | - sprintf(esc_html__("Time to find out about all the great new features %s has to offer.", |
|
53 | - "event_espresso"), $ultimate_db_state)); ?> |
|
52 | + sprintf(esc_html__("Time to find out about all the great new features %s has to offer.", |
|
53 | + "event_espresso"), $ultimate_db_state)); ?> |
|
54 | 54 | <b><a id="get-started-after-migrate" class="button-primary" |
55 | 55 | href="<?php echo add_query_arg(array('page' => 'espresso_about'), admin_url('admin.php')); ?>"> |
56 | 56 | <?php esc_html_e("Let's Get Started", "event_espresso"); ?> <span |
@@ -61,34 +61,34 @@ discard block |
||
61 | 61 | |
62 | 62 | |
63 | 63 | <?php if ($show_backup_db_text) { |
64 | - echo $migration_options_html; |
|
65 | - } ?> |
|
64 | + echo $migration_options_html; |
|
65 | + } ?> |
|
66 | 66 | |
67 | 67 | <?php |
68 | - if ($show_most_recent_migration) { |
|
69 | - if ($most_recent_migration && $most_recent_migration instanceof EE_Data_Migration_Script_Base) { |
|
70 | - if ($most_recent_migration->can_continue()) { |
|
71 | - //tell the user they should continue their migration because it appears to be unfinished... well, assuming there were no errors ?> |
|
68 | + if ($show_most_recent_migration) { |
|
69 | + if ($most_recent_migration && $most_recent_migration instanceof EE_Data_Migration_Script_Base) { |
|
70 | + if ($most_recent_migration->can_continue()) { |
|
71 | + //tell the user they should continue their migration because it appears to be unfinished... well, assuming there were no errors ?> |
|
72 | 72 | <h3 class="espresso-header"> |
73 | 73 | <span class="dashicons dashicons-star-half ee-icon-size-22"></span> |
74 | 74 | <?php printf(esc_html__("It appears that your previous Database Update (%s) is incomplete, and should be resumed", |
75 | - "event_espresso"), $most_recent_migration->pretty_name()); ?> |
|
75 | + "event_espresso"), $most_recent_migration->pretty_name()); ?> |
|
76 | 76 | </h3> |
77 | 77 | <?php } elseif ($most_recent_migration->is_broken()) { |
78 | - //tell the user the migration failed and they should notify EE?> |
|
78 | + //tell the user the migration failed and they should notify EE?> |
|
79 | 79 | <h3 class="espresso-header"> |
80 | 80 | <span class="dashicons dashicons-no ee-icon-size-22"></span> |
81 | 81 | <?php echo $most_recent_migration->get_feedback_message() ?> |
82 | 82 | </h3> |
83 | 83 | <?php } |
84 | - //display errors or not of the most recent migration ran |
|
85 | - if ($most_recent_migration->get_errors()) { ?> |
|
84 | + //display errors or not of the most recent migration ran |
|
85 | + if ($most_recent_migration->get_errors()) { ?> |
|
86 | 86 | <div class="ee-attention"> |
87 | 87 | <strong><?php printf(esc_html__("Warnings occurred during your last Database Update (%s):", |
88 | - 'event_espresso'), |
|
89 | - $most_recent_migration->pretty_name()) ?></strong> |
|
88 | + 'event_espresso'), |
|
89 | + $most_recent_migration->pretty_name()) ?></strong> |
|
90 | 90 | <a id="show-hide-migration-warnings" class="display-the-hidden"><?php esc_html_e("Show Warnings", |
91 | - 'event_espresso'); ?></a> |
|
91 | + 'event_espresso'); ?></a> |
|
92 | 92 | <ul class="migration-warnings" style="display:none"> |
93 | 93 | <?php foreach ($most_recent_migration->get_errors() as $error) { ?> |
94 | 94 | <li><?php echo htmlentities($error) ?></li> |
@@ -96,15 +96,15 @@ discard block |
||
96 | 96 | </ul> |
97 | 97 | </div> |
98 | 98 | <?php } else { |
99 | - //there were no errors during the last migration, just say so?> |
|
99 | + //there were no errors during the last migration, just say so?> |
|
100 | 100 | <h2><?php printf(esc_html__("The last Database Update (%s) ran successfully without errors.", |
101 | - "event_espresso"), $most_recent_migration->pretty_name()) ?></h2> |
|
101 | + "event_espresso"), $most_recent_migration->pretty_name()) ?></h2> |
|
102 | 102 | <?php } |
103 | - } else { |
|
104 | - } |
|
105 | - } |
|
106 | - // end of: if ( $show_most_recent_migration ) |
|
107 | - ?> |
|
103 | + } else { |
|
104 | + } |
|
105 | + } |
|
106 | + // end of: if ( $show_most_recent_migration ) |
|
107 | + ?> |
|
108 | 108 | |
109 | 109 | </div> |
110 | 110 | <!--end of #migration-prep--> |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | <div id='progress-area'> |
125 | 125 | <h3 class="espresso-header"> |
126 | 126 | <?php |
127 | - echo sprintf(_n( |
|
128 | - "The following task needs to be performed:", |
|
129 | - "The following %s tasks need to be performed:", |
|
130 | - count($script_names), |
|
131 | - "event_espresso" |
|
132 | - ), count($script_names)); ?> |
|
127 | + echo sprintf(_n( |
|
128 | + "The following task needs to be performed:", |
|
129 | + "The following %s tasks need to be performed:", |
|
130 | + count($script_names), |
|
131 | + "event_espresso" |
|
132 | + ), count($script_names)); ?> |
|
133 | 133 | </h3> |
134 | 134 | <ul style="list-style: inside;"> |
135 | 135 | <?php foreach ($script_names as $script_name) { ?> |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | <br/> |
140 | 140 | <?php if (count($script_names) > 1) { ?> |
141 | 141 | <p><?php esc_html_e("Please note: after each task is completed you will need to continue the Database Update, or report an error to Event Espresso.", |
142 | - "event_espresso"); ?></p> |
|
142 | + "event_espresso"); ?></p> |
|
143 | 143 | <?php } ?> |
144 | 144 | |
145 | 145 | <div class="ee-attention"> |
@@ -149,11 +149,11 @@ discard block |
||
149 | 149 | </span> |
150 | 150 | <br/> |
151 | 151 | <?php esc_html_e("Depending on the number of events and the complexity of the information in your database, this could take a few minutes.", |
152 | - "event_espresso"); ?> |
|
152 | + "event_espresso"); ?> |
|
153 | 153 | </p> |
154 | 154 | <p> |
155 | 155 | <?php printf(esc_html__("%sPlease be patient and do NOT navigate away from this page once the migration has begun%s. If any issues arise due to existing malformed data, an itemized report will be made available to you after the migration has completed.", |
156 | - "event_espresso"), '<strong>', '</strong>'); ?> |
|
156 | + "event_espresso"), '<strong>', '</strong>'); ?> |
|
157 | 157 | </p> |
158 | 158 | <p> |
159 | 159 | <?php esc_html_e("Click the button below to begin the migration process.", "event_espresso") ?> |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | |
170 | 170 | <button id='start-migration' class='button-primary'> |
171 | 171 | <?php echo $show_continue_current_migration_script ? esc_html__("Continue Database Update", |
172 | - "event_espresso") |
|
173 | - : esc_html__("Begin Database Update", "event_espresso"); ?> |
|
172 | + "event_espresso") |
|
173 | + : esc_html__("Begin Database Update", "event_espresso"); ?> |
|
174 | 174 | </button> |
175 | 175 | <br class="clear"/> |
176 | 176 | |
@@ -186,10 +186,10 @@ discard block |
||
186 | 186 | </div> |
187 | 187 | |
188 | 188 | <?php } |
189 | - if ($show_maintenance_switch) { |
|
190 | - ?> |
|
189 | + if ($show_maintenance_switch) { |
|
190 | + ?> |
|
191 | 191 | <h2><span class="dashicons dashicons-admin-tools"></span><?php esc_html_e('Set Event Espresso Maintenance Mode', |
192 | - 'event_espresso'); ?></h2> |
|
192 | + 'event_espresso'); ?></h2> |
|
193 | 193 | <form method='post' action='<?php echo $update_migration_script_page_link ?>'> |
194 | 194 | <div class="ee-table-wrap"> |
195 | 195 | <table> |
@@ -197,15 +197,15 @@ discard block |
||
197 | 197 | <td width="40px" align="center"> |
198 | 198 | <input type="radio" id="maintenance_mode_level_off" name="maintenance_mode_level" |
199 | 199 | value="0" <?php echo EE_Maintenance_Mode::instance()->level() |
200 | - == EE_Maintenance_Mode::level_0_not_in_maintenance |
|
201 | - ? 'checked="checked"' : '' ?>> |
|
200 | + == EE_Maintenance_Mode::level_0_not_in_maintenance |
|
201 | + ? 'checked="checked"' : '' ?>> |
|
202 | 202 | </td> |
203 | 203 | <th align="left"> |
204 | 204 | <label for="maintenance_mode_level_off"><?php esc_html_e('Maintenance Mode OFF', |
205 | - 'event_espresso'); ?></label> |
|
205 | + 'event_espresso'); ?></label> |
|
206 | 206 | <p class='description' style="font-weight: normal;"> |
207 | 207 | <?php esc_html_e("This is the normal operating mode for Event Espresso and allows all functionality to be viewed by all site visitors.", |
208 | - "event_espresso"); ?> |
|
208 | + "event_espresso"); ?> |
|
209 | 209 | </p> |
210 | 210 | </th> |
211 | 211 | </tr> |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | <td width="40px" align="center"> |
214 | 214 | <input type="radio" id="maintenance_mode_level_on" name="maintenance_mode_level" |
215 | 215 | value="1" <?php echo EE_Maintenance_Mode::instance()->level() |
216 | - == EE_Maintenance_Mode::level_1_frontend_only_maintenance |
|
217 | - ? 'checked="checked"' : '' ?>> |
|
216 | + == EE_Maintenance_Mode::level_1_frontend_only_maintenance |
|
217 | + ? 'checked="checked"' : '' ?>> |
|
218 | 218 | </td> |
219 | 219 | <th align="left"> |
220 | 220 | <label for="maintenance_mode_level_on"> |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | </label> |
223 | 223 | <p class='description' style="font-weight: normal;"> |
224 | 224 | <?php esc_html_e("This disables Event Espresso frontend functionality for all site visitors that are not administrators, and allows you to configure and/or test things on the frontend of your website before others can see.", |
225 | - "event_espresso"); ?> |
|
225 | + "event_espresso"); ?> |
|
226 | 226 | </p> |
227 | 227 | </th> |
228 | 228 | </tr> |
@@ -234,6 +234,6 @@ discard block |
||
234 | 234 | </p> |
235 | 235 | </form> |
236 | 236 | <?php |
237 | - } ?> |
|
237 | + } ?> |
|
238 | 238 | |
239 | 239 | </div> |
@@ -1,26 +1,26 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | ?> |
4 | -<h1><?php esc_html_e("Data Migration Error", "event_espresso");?></h1> |
|
5 | -<p class='error'><?php printf(esc_html__("Your last Database Update had a %s FATAL ERROR, and CANNOT be continued%s.", "event_espresso"),"<b>","</b>");?></p> |
|
6 | -<a id="show-hide-migration-warnings" class="display-the-hidden"><?php esc_html_e("Show Errors", 'event_espresso');?></a> |
|
4 | +<h1><?php esc_html_e("Data Migration Error", "event_espresso"); ?></h1> |
|
5 | +<p class='error'><?php printf(esc_html__("Your last Database Update had a %s FATAL ERROR, and CANNOT be continued%s.", "event_espresso"), "<b>", "</b>"); ?></p> |
|
6 | +<a id="show-hide-migration-warnings" class="display-the-hidden"><?php esc_html_e("Show Errors", 'event_espresso'); ?></a> |
|
7 | 7 | <ul class="migration-warnings" style="display:none"> |
8 | -<?php foreach($most_recent_migration->get_errors() as $error){ ?> |
|
8 | +<?php foreach ($most_recent_migration->get_errors() as $error) { ?> |
|
9 | 9 | <li style="overflow-y:auto;max-height:100px"><?php echo esc_html($error)?></li> |
10 | 10 | <?php }?> |
11 | 11 | </ul> |
12 | -<h2><?php esc_html_e("Fill out the below form to automatically Send Event Espresso a Crash Report", "event_espresso");?></h2> |
|
13 | -<form action='<?php echo EE_Admin_Page::add_query_args_and_nonce(array('action'=>'send_migration_crash_report'), EE_MAINTENANCE_ADMIN_URL);?>' method='post'> |
|
12 | +<h2><?php esc_html_e("Fill out the below form to automatically Send Event Espresso a Crash Report", "event_espresso"); ?></h2> |
|
13 | +<form action='<?php echo EE_Admin_Page::add_query_args_and_nonce(array('action'=>'send_migration_crash_report'), EE_MAINTENANCE_ADMIN_URL); ?>' method='post'> |
|
14 | 14 | <table class='widefat'> |
15 | - <tr><td><label for='from'><?php esc_html_e("From/Reply-To:", "event_espresso");?></label></td><td><input name='from' id='from' type='text' style="width:200px"value='<?php echo get_bloginfo('admin_email','display'); ?>'></td></tr> |
|
16 | - <tr><td><label for='from_name'><?php esc_html_e("Your Name", "event_espresso");?></label></td><td><input name='from_name' id='from_name' type='text' style="width:200px"value='<?php printf(esc_html__("Admin of %s", "event_espresso"),get_bloginfo('name','display'));?>'></td></tr> |
|
17 | - <tr><td><label for='body'><?php esc_html_e("Comments", "event_espresso");?></label></td><td><textarea name="body" id="body" class='system_status_info'><?php esc_html_e("Enter any comments about why you think the error may have occurred", "event_espresso");?></textarea> |
|
18 | - <p class='description'><?php esc_html_e("Note: the System Information report will also be added to the email's body, which contains information about your Event Espresso, Wordpress, and PHP settings which can be helpful in debugging the problem.", "event_espresso");?></p></td></tr> |
|
19 | - <tr><td colspan="2"><input type="submit" value="<?php esc_html_e("Mail Crash Report to Event Espresso", "event_espresso");?>"/></td></tr> |
|
15 | + <tr><td><label for='from'><?php esc_html_e("From/Reply-To:", "event_espresso"); ?></label></td><td><input name='from' id='from' type='text' style="width:200px"value='<?php echo get_bloginfo('admin_email', 'display'); ?>'></td></tr> |
|
16 | + <tr><td><label for='from_name'><?php esc_html_e("Your Name", "event_espresso"); ?></label></td><td><input name='from_name' id='from_name' type='text' style="width:200px"value='<?php printf(esc_html__("Admin of %s", "event_espresso"), get_bloginfo('name', 'display')); ?>'></td></tr> |
|
17 | + <tr><td><label for='body'><?php esc_html_e("Comments", "event_espresso"); ?></label></td><td><textarea name="body" id="body" class='system_status_info'><?php esc_html_e("Enter any comments about why you think the error may have occurred", "event_espresso"); ?></textarea> |
|
18 | + <p class='description'><?php esc_html_e("Note: the System Information report will also be added to the email's body, which contains information about your Event Espresso, Wordpress, and PHP settings which can be helpful in debugging the problem.", "event_espresso"); ?></p></td></tr> |
|
19 | + <tr><td colspan="2"><input type="submit" value="<?php esc_html_e("Mail Crash Report to Event Espresso", "event_espresso"); ?>"/></td></tr> |
|
20 | 20 | </table> |
21 | 21 | </form> |
22 | 22 | <br> |
23 | -<p><?php printf(esc_html__('...or copy-and-paste the below information to %1$s %2$s %3$s', "event_espresso"),'<a href="mailto:'.EE_SUPPORT_EMAIL.'">',EE_SUPPORT_EMAIL,"</a>");?></p> |
|
24 | -<textarea class="system_status_info"><?php print_r( EEM_System_Status::instance()->get_system_stati())?></textarea> |
|
25 | -<p><?php printf( esc_html__( '%1$sNext Step%2$s', 'event_espresso' ), "<a href='$next_url'>","</a>");?></p> |
|
26 | -<p><?php printf( esc_html__( '...or %1$sDON\'T send crash report%2$s.', 'event_espresso' ), "<a href='$next_url'>","</a>");?></p> |
|
23 | +<p><?php printf(esc_html__('...or copy-and-paste the below information to %1$s %2$s %3$s', "event_espresso"), '<a href="mailto:'.EE_SUPPORT_EMAIL.'">', EE_SUPPORT_EMAIL, "</a>"); ?></p> |
|
24 | +<textarea class="system_status_info"><?php print_r(EEM_System_Status::instance()->get_system_stati())?></textarea> |
|
25 | +<p><?php printf(esc_html__('%1$sNext Step%2$s', 'event_espresso'), "<a href='$next_url'>", "</a>"); ?></p> |
|
26 | +<p><?php printf(esc_html__('...or %1$sDON\'T send crash report%2$s.', 'event_espresso'), "<a href='$next_url'>", "</a>"); ?></p> |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | * _get_transaction_and_cart_for_previous_visit |
782 | 782 | * |
783 | 783 | * @access private |
784 | - * @return mixed EE_Transaction|NULL |
|
784 | + * @return EE_Transaction|null EE_Transaction|NULL |
|
785 | 785 | */ |
786 | 786 | private function _get_transaction_and_cart_for_previous_visit() |
787 | 787 | { |
@@ -863,7 +863,7 @@ discard block |
||
863 | 863 | * generates a new EE_Transaction object and adds it to the $_transaction property. |
864 | 864 | * |
865 | 865 | * @access private |
866 | - * @return mixed EE_Transaction|NULL |
|
866 | + * @return EE_Transaction|null EE_Transaction|NULL |
|
867 | 867 | */ |
868 | 868 | private function _initialize_transaction() |
869 | 869 | { |
@@ -218,19 +218,19 @@ discard block |
||
218 | 218 | */ |
219 | 219 | public static function set_definitions() |
220 | 220 | { |
221 | - if(defined('SPCO_BASE_PATH')) { |
|
221 | + if (defined('SPCO_BASE_PATH')) { |
|
222 | 222 | return; |
223 | 223 | } |
224 | 224 | define( |
225 | 225 | 'SPCO_BASE_PATH', |
226 | - rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
226 | + rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS |
|
227 | 227 | ); |
228 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
229 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
230 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
231 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
232 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
233 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
228 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS); |
|
229 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS); |
|
230 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS); |
|
231 | + define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS); |
|
232 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS); |
|
233 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS); |
|
234 | 234 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
235 | 235 | EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(); |
236 | 236 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | return; |
252 | 252 | } |
253 | 253 | // filter list of reg_steps |
254 | - $reg_steps_to_load = (array)apply_filters( |
|
254 | + $reg_steps_to_load = (array) apply_filters( |
|
255 | 255 | 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
256 | 256 | EED_Single_Page_Checkout::get_reg_steps() |
257 | 257 | ); |
@@ -303,25 +303,25 @@ discard block |
||
303 | 303 | if (empty($reg_steps)) { |
304 | 304 | $reg_steps = array( |
305 | 305 | 10 => array( |
306 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
306 | + 'file_path' => SPCO_REG_STEPS_PATH.'attendee_information', |
|
307 | 307 | 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
308 | 308 | 'slug' => 'attendee_information', |
309 | 309 | 'has_hooks' => false, |
310 | 310 | ), |
311 | 311 | 20 => array( |
312 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
312 | + 'file_path' => SPCO_REG_STEPS_PATH.'registration_confirmation', |
|
313 | 313 | 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
314 | 314 | 'slug' => 'registration_confirmation', |
315 | 315 | 'has_hooks' => false, |
316 | 316 | ), |
317 | 317 | 30 => array( |
318 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
318 | + 'file_path' => SPCO_REG_STEPS_PATH.'payment_options', |
|
319 | 319 | 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
320 | 320 | 'slug' => 'payment_options', |
321 | 321 | 'has_hooks' => true, |
322 | 322 | ), |
323 | 323 | 999 => array( |
324 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
324 | + 'file_path' => SPCO_REG_STEPS_PATH.'finalize_registration', |
|
325 | 325 | 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
326 | 326 | 'slug' => 'finalize_registration', |
327 | 327 | 'has_hooks' => false, |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | // DEBUG LOG |
506 | 506 | //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
507 | 507 | // get reg form |
508 | - if( ! $this->_check_form_submission()) { |
|
508 | + if ( ! $this->_check_form_submission()) { |
|
509 | 509 | EED_Single_Page_Checkout::$_initialized = true; |
510 | 510 | return; |
511 | 511 | } |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | ); |
547 | 547 | // is session still valid ? |
548 | 548 | if ($clear_session_requested |
549 | - || ( EE_Registry::instance()->SSN->expired() |
|
549 | + || (EE_Registry::instance()->SSN->expired() |
|
550 | 550 | && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
551 | 551 | ) |
552 | 552 | ) { |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | // EE_Registry::instance()->SSN->reset_cart(); |
556 | 556 | // EE_Registry::instance()->SSN->reset_checkout(); |
557 | 557 | // EE_Registry::instance()->SSN->reset_transaction(); |
558 | - if (! $clear_session_requested) { |
|
558 | + if ( ! $clear_session_requested) { |
|
559 | 559 | EE_Error::add_attention( |
560 | 560 | EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
561 | 561 | __FILE__, __FUNCTION__, __LINE__ |
@@ -1114,7 +1114,7 @@ discard block |
||
1114 | 1114 | if ( ! $registration instanceof EE_Registration) { |
1115 | 1115 | throw new InvalidEntityException($registration, 'EE_Registration'); |
1116 | 1116 | } |
1117 | - $registrations[ $registration->ID() ] = $registration; |
|
1117 | + $registrations[$registration->ID()] = $registration; |
|
1118 | 1118 | } |
1119 | 1119 | } |
1120 | 1120 | $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
@@ -1375,7 +1375,7 @@ discard block |
||
1375 | 1375 | ) { |
1376 | 1376 | EE_Error::add_success( |
1377 | 1377 | $this->checkout->current_step->success_message() |
1378 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
1378 | + . '<br />'.$this->checkout->next_step->_instructions() |
|
1379 | 1379 | ); |
1380 | 1380 | } |
1381 | 1381 | // pack it up, pack it in... |
@@ -1519,7 +1519,7 @@ discard block |
||
1519 | 1519 | // load css |
1520 | 1520 | wp_register_style( |
1521 | 1521 | 'single_page_checkout', |
1522 | - SPCO_CSS_URL . 'single_page_checkout.css', |
|
1522 | + SPCO_CSS_URL.'single_page_checkout.css', |
|
1523 | 1523 | array('espresso_default'), |
1524 | 1524 | EVENT_ESPRESSO_VERSION |
1525 | 1525 | ); |
@@ -1527,21 +1527,21 @@ discard block |
||
1527 | 1527 | // load JS |
1528 | 1528 | wp_register_script( |
1529 | 1529 | 'jquery_plugin', |
1530 | - EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
1530 | + EE_THIRD_PARTY_URL.'jquery .plugin.min.js', |
|
1531 | 1531 | array('jquery'), |
1532 | 1532 | '1.0.1', |
1533 | 1533 | true |
1534 | 1534 | ); |
1535 | 1535 | wp_register_script( |
1536 | 1536 | 'jquery_countdown', |
1537 | - EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
1537 | + EE_THIRD_PARTY_URL.'jquery .countdown.min.js', |
|
1538 | 1538 | array('jquery_plugin'), |
1539 | 1539 | '2.0.2', |
1540 | 1540 | true |
1541 | 1541 | ); |
1542 | 1542 | wp_register_script( |
1543 | 1543 | 'single_page_checkout', |
1544 | - SPCO_JS_URL . 'single_page_checkout.js', |
|
1544 | + SPCO_JS_URL.'single_page_checkout.js', |
|
1545 | 1545 | array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), |
1546 | 1546 | EVENT_ESPRESSO_VERSION, |
1547 | 1547 | true |
@@ -1564,7 +1564,7 @@ discard block |
||
1564 | 1564 | * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
1565 | 1565 | */ |
1566 | 1566 | do_action( |
1567 | - 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
1567 | + 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(), |
|
1568 | 1568 | $this |
1569 | 1569 | ); |
1570 | 1570 | } |
@@ -1618,7 +1618,7 @@ discard block |
||
1618 | 1618 | 'layout_strategy' => |
1619 | 1619 | new EE_Template_Layout( |
1620 | 1620 | array( |
1621 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1621 | + 'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php', |
|
1622 | 1622 | 'template_args' => array( |
1623 | 1623 | 'empty_cart' => $empty_cart, |
1624 | 1624 | 'revisit' => $this->checkout->revisit, |
@@ -1692,7 +1692,7 @@ discard block |
||
1692 | 1692 | ) { |
1693 | 1693 | add_filter( |
1694 | 1694 | 'FHEE__EEH_Template__powered_by_event_espresso__url', |
1695 | - function ($url) { |
|
1695 | + function($url) { |
|
1696 | 1696 | return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
1697 | 1697 | } |
1698 | 1698 | ); |
@@ -1871,7 +1871,7 @@ discard block |
||
1871 | 1871 | '</h4>', |
1872 | 1872 | '<br />', |
1873 | 1873 | '<p>', |
1874 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1874 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
1875 | 1875 | '">', |
1876 | 1876 | '</a>', |
1877 | 1877 | '</p>' |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | use EventEspresso\core\exceptions\InvalidEntityException; |
6 | 6 | |
7 | 7 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
8 | - exit('No direct script access allowed'); |
|
8 | + exit('No direct script access allowed'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | |
@@ -20,1849 +20,1849 @@ discard block |
||
20 | 20 | class EED_Single_Page_Checkout extends EED_Module |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * $_initialized - has the SPCO controller already been initialized ? |
|
25 | - * |
|
26 | - * @access private |
|
27 | - * @var bool $_initialized |
|
28 | - */ |
|
29 | - private static $_initialized = false; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
34 | - * |
|
35 | - * @access private |
|
36 | - * @var bool $_valid_checkout |
|
37 | - */ |
|
38 | - private static $_checkout_verified = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * $_reg_steps_array - holds initial array of reg steps |
|
42 | - * |
|
43 | - * @access private |
|
44 | - * @var array $_reg_steps_array |
|
45 | - */ |
|
46 | - private static $_reg_steps_array = array(); |
|
47 | - |
|
48 | - /** |
|
49 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
50 | - * |
|
51 | - * @access public |
|
52 | - * @var EE_Checkout $checkout |
|
53 | - */ |
|
54 | - public $checkout; |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @return EED_Module|EED_Single_Page_Checkout |
|
60 | - */ |
|
61 | - public static function instance() |
|
62 | - { |
|
63 | - add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
64 | - return parent::get_instance(__CLASS__); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @return EE_CART |
|
71 | - */ |
|
72 | - public function cart() |
|
73 | - { |
|
74 | - return $this->checkout->cart; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @return EE_Transaction |
|
81 | - */ |
|
82 | - public function transaction() |
|
83 | - { |
|
84 | - return $this->checkout->transaction; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
91 | - * |
|
92 | - * @access public |
|
93 | - * @return void |
|
94 | - * @throws EE_Error |
|
95 | - */ |
|
96 | - public static function set_hooks() |
|
97 | - { |
|
98 | - EED_Single_Page_Checkout::set_definitions(); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
105 | - * |
|
106 | - * @access public |
|
107 | - * @return void |
|
108 | - * @throws EE_Error |
|
109 | - */ |
|
110 | - public static function set_hooks_admin() |
|
111 | - { |
|
112 | - EED_Single_Page_Checkout::set_definitions(); |
|
113 | - if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
114 | - return; |
|
115 | - } |
|
116 | - // going to start an output buffer in case anything gets accidentally output |
|
117 | - // that might disrupt our JSON response |
|
118 | - ob_start(); |
|
119 | - EED_Single_Page_Checkout::load_request_handler(); |
|
120 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
121 | - // set ajax hooks |
|
122 | - add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
123 | - add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
124 | - add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
125 | - add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
126 | - add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
127 | - add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * process ajax request |
|
134 | - * |
|
135 | - * @param string $ajax_action |
|
136 | - * @throws EE_Error |
|
137 | - */ |
|
138 | - public static function process_ajax_request($ajax_action) |
|
139 | - { |
|
140 | - EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
141 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * ajax display registration step |
|
148 | - * |
|
149 | - * @throws EE_Error |
|
150 | - */ |
|
151 | - public static function display_reg_step() |
|
152 | - { |
|
153 | - EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * ajax process registration step |
|
160 | - * |
|
161 | - * @throws EE_Error |
|
162 | - */ |
|
163 | - public static function process_reg_step() |
|
164 | - { |
|
165 | - EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * ajax process registration step |
|
172 | - * |
|
173 | - * @throws EE_Error |
|
174 | - */ |
|
175 | - public static function update_reg_step() |
|
176 | - { |
|
177 | - EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * update_checkout |
|
184 | - * |
|
185 | - * @access public |
|
186 | - * @return void |
|
187 | - * @throws EE_Error |
|
188 | - */ |
|
189 | - public static function update_checkout() |
|
190 | - { |
|
191 | - EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * load_request_handler |
|
198 | - * |
|
199 | - * @access public |
|
200 | - * @return void |
|
201 | - */ |
|
202 | - public static function load_request_handler() |
|
203 | - { |
|
204 | - // load core Request_Handler class |
|
205 | - if (EE_Registry::instance()->REQ !== null) { |
|
206 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * set_definitions |
|
214 | - * |
|
215 | - * @access public |
|
216 | - * @return void |
|
217 | - * @throws EE_Error |
|
218 | - */ |
|
219 | - public static function set_definitions() |
|
220 | - { |
|
221 | - if(defined('SPCO_BASE_PATH')) { |
|
222 | - return; |
|
223 | - } |
|
224 | - define( |
|
225 | - 'SPCO_BASE_PATH', |
|
226 | - rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
227 | - ); |
|
228 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
229 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
230 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
231 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
232 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
233 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
235 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * load_reg_steps |
|
242 | - * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
243 | - * |
|
244 | - * @access private |
|
245 | - * @throws EE_Error |
|
246 | - */ |
|
247 | - public static function load_reg_steps() |
|
248 | - { |
|
249 | - static $reg_steps_loaded = false; |
|
250 | - if ($reg_steps_loaded) { |
|
251 | - return; |
|
252 | - } |
|
253 | - // filter list of reg_steps |
|
254 | - $reg_steps_to_load = (array)apply_filters( |
|
255 | - 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
256 | - EED_Single_Page_Checkout::get_reg_steps() |
|
257 | - ); |
|
258 | - // sort by key (order) |
|
259 | - ksort($reg_steps_to_load); |
|
260 | - // loop through folders |
|
261 | - foreach ($reg_steps_to_load as $order => $reg_step) { |
|
262 | - // we need a |
|
263 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
264 | - // copy over to the reg_steps_array |
|
265 | - EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
266 | - // register custom key route for each reg step |
|
267 | - // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
268 | - EE_Config::register_route( |
|
269 | - $reg_step['slug'], |
|
270 | - 'EED_Single_Page_Checkout', |
|
271 | - 'run', |
|
272 | - 'step' |
|
273 | - ); |
|
274 | - // add AJAX or other hooks |
|
275 | - if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
276 | - // setup autoloaders if necessary |
|
277 | - if ( ! class_exists($reg_step['class_name'])) { |
|
278 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
|
279 | - $reg_step['file_path'], |
|
280 | - true |
|
281 | - ); |
|
282 | - } |
|
283 | - if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
284 | - call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
285 | - } |
|
286 | - } |
|
287 | - } |
|
288 | - } |
|
289 | - $reg_steps_loaded = true; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * get_reg_steps |
|
296 | - * |
|
297 | - * @access public |
|
298 | - * @return array |
|
299 | - */ |
|
300 | - public static function get_reg_steps() |
|
301 | - { |
|
302 | - $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
303 | - if (empty($reg_steps)) { |
|
304 | - $reg_steps = array( |
|
305 | - 10 => array( |
|
306 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
307 | - 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
308 | - 'slug' => 'attendee_information', |
|
309 | - 'has_hooks' => false, |
|
310 | - ), |
|
311 | - 20 => array( |
|
312 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
313 | - 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
314 | - 'slug' => 'registration_confirmation', |
|
315 | - 'has_hooks' => false, |
|
316 | - ), |
|
317 | - 30 => array( |
|
318 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
319 | - 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
320 | - 'slug' => 'payment_options', |
|
321 | - 'has_hooks' => true, |
|
322 | - ), |
|
323 | - 999 => array( |
|
324 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
325 | - 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
326 | - 'slug' => 'finalize_registration', |
|
327 | - 'has_hooks' => false, |
|
328 | - ), |
|
329 | - ); |
|
330 | - } |
|
331 | - return $reg_steps; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * registration_checkout_for_admin |
|
338 | - * |
|
339 | - * @access public |
|
340 | - * @return string |
|
341 | - * @throws EE_Error |
|
342 | - */ |
|
343 | - public static function registration_checkout_for_admin() |
|
344 | - { |
|
345 | - EED_Single_Page_Checkout::load_request_handler(); |
|
346 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
347 | - EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
348 | - EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
349 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
350 | - EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
351 | - return EE_Registry::instance()->REQ->get_output(); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * process_registration_from_admin |
|
358 | - * |
|
359 | - * @access public |
|
360 | - * @return \EE_Transaction |
|
361 | - * @throws EE_Error |
|
362 | - */ |
|
363 | - public static function process_registration_from_admin() |
|
364 | - { |
|
365 | - EED_Single_Page_Checkout::load_request_handler(); |
|
366 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
367 | - EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
368 | - EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
369 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
370 | - if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
371 | - $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
372 | - if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
373 | - EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
374 | - if ($final_reg_step->process_reg_step()) { |
|
375 | - $final_reg_step->set_completed(); |
|
376 | - EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
377 | - return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
378 | - } |
|
379 | - } |
|
380 | - } |
|
381 | - return null; |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * run |
|
388 | - * |
|
389 | - * @access public |
|
390 | - * @param WP_Query $WP_Query |
|
391 | - * @return void |
|
392 | - * @throws EE_Error |
|
393 | - */ |
|
394 | - public function run($WP_Query) |
|
395 | - { |
|
396 | - if ( |
|
397 | - $WP_Query instanceof WP_Query |
|
398 | - && $WP_Query->is_main_query() |
|
399 | - && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
400 | - && $this->_is_reg_checkout() |
|
401 | - ) { |
|
402 | - $this->_initialize(); |
|
403 | - } |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * determines whether current url matches reg page url |
|
410 | - * |
|
411 | - * @return bool |
|
412 | - */ |
|
413 | - protected function _is_reg_checkout() |
|
414 | - { |
|
415 | - // get current permalink for reg page without any extra query args |
|
416 | - $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
417 | - // get request URI for current request, but without the scheme or host |
|
418 | - $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
419 | - $current_request_uri = html_entity_decode($current_request_uri); |
|
420 | - // get array of query args from the current request URI |
|
421 | - $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
422 | - // grab page id if it is set |
|
423 | - $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
424 | - // and remove the page id from the query args (we will re-add it later) |
|
425 | - unset($query_args['page_id']); |
|
426 | - // now strip all query args from current request URI |
|
427 | - $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
428 | - // and re-add the page id if it was set |
|
429 | - if ($page_id) { |
|
430 | - $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
431 | - } |
|
432 | - // remove slashes and ? |
|
433 | - $current_request_uri = trim($current_request_uri, '?/'); |
|
434 | - // is current request URI part of the known full reg page URL ? |
|
435 | - return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * @param WP_Query $wp_query |
|
442 | - * @return void |
|
443 | - * @throws EE_Error |
|
444 | - */ |
|
445 | - public static function init($wp_query) |
|
446 | - { |
|
447 | - EED_Single_Page_Checkout::instance()->run($wp_query); |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * _initialize - initial module setup |
|
454 | - * |
|
455 | - * @access private |
|
456 | - * @throws EE_Error |
|
457 | - * @return void |
|
458 | - */ |
|
459 | - private function _initialize() |
|
460 | - { |
|
461 | - // ensure SPCO doesn't run twice |
|
462 | - if (EED_Single_Page_Checkout::$_initialized) { |
|
463 | - return; |
|
464 | - } |
|
465 | - try { |
|
466 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
467 | - $this->_verify_session(); |
|
468 | - // setup the EE_Checkout object |
|
469 | - $this->checkout = $this->_initialize_checkout(); |
|
470 | - // filter checkout |
|
471 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
472 | - // get the $_GET |
|
473 | - $this->_get_request_vars(); |
|
474 | - if ($this->_block_bots()) { |
|
475 | - return; |
|
476 | - } |
|
477 | - // filter continue_reg |
|
478 | - $this->checkout->continue_reg = apply_filters( |
|
479 | - 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
480 | - true, |
|
481 | - $this->checkout |
|
482 | - ); |
|
483 | - // load the reg steps array |
|
484 | - if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
485 | - EED_Single_Page_Checkout::$_initialized = true; |
|
486 | - return; |
|
487 | - } |
|
488 | - // set the current step |
|
489 | - $this->checkout->set_current_step($this->checkout->step); |
|
490 | - // and the next step |
|
491 | - $this->checkout->set_next_step(); |
|
492 | - // verify that everything has been setup correctly |
|
493 | - if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
494 | - EED_Single_Page_Checkout::$_initialized = true; |
|
495 | - return; |
|
496 | - } |
|
497 | - // lock the transaction |
|
498 | - $this->checkout->transaction->lock(); |
|
499 | - // make sure all of our cached objects are added to their respective model entity mappers |
|
500 | - $this->checkout->refresh_all_entities(); |
|
501 | - // set amount owing |
|
502 | - $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
503 | - // initialize each reg step, which gives them the chance to potentially alter the process |
|
504 | - $this->_initialize_reg_steps(); |
|
505 | - // DEBUG LOG |
|
506 | - //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
507 | - // get reg form |
|
508 | - if( ! $this->_check_form_submission()) { |
|
509 | - EED_Single_Page_Checkout::$_initialized = true; |
|
510 | - return; |
|
511 | - } |
|
512 | - // checkout the action!!! |
|
513 | - $this->_process_form_action(); |
|
514 | - // add some style and make it dance |
|
515 | - $this->add_styles_and_scripts(); |
|
516 | - // kk... SPCO has successfully run |
|
517 | - EED_Single_Page_Checkout::$_initialized = true; |
|
518 | - // set no cache headers and constants |
|
519 | - EE_System::do_not_cache(); |
|
520 | - // add anchor |
|
521 | - add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
522 | - // remove transaction lock |
|
523 | - add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
524 | - } catch (Exception $e) { |
|
525 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
526 | - } |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - |
|
531 | - /** |
|
532 | - * _verify_session |
|
533 | - * checks that the session is valid and not expired |
|
534 | - * |
|
535 | - * @access private |
|
536 | - * @throws EE_Error |
|
537 | - */ |
|
538 | - private function _verify_session() |
|
539 | - { |
|
540 | - if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
541 | - throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
542 | - } |
|
543 | - $clear_session_requested = filter_var( |
|
544 | - EE_Registry::instance()->REQ->get('clear_session', false), |
|
545 | - FILTER_VALIDATE_BOOLEAN |
|
546 | - ); |
|
547 | - // is session still valid ? |
|
548 | - if ($clear_session_requested |
|
549 | - || ( EE_Registry::instance()->SSN->expired() |
|
550 | - && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
|
551 | - ) |
|
552 | - ) { |
|
553 | - $this->checkout = new EE_Checkout(); |
|
554 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
555 | - // EE_Registry::instance()->SSN->reset_cart(); |
|
556 | - // EE_Registry::instance()->SSN->reset_checkout(); |
|
557 | - // EE_Registry::instance()->SSN->reset_transaction(); |
|
558 | - if (! $clear_session_requested) { |
|
559 | - EE_Error::add_attention( |
|
560 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
|
561 | - __FILE__, __FUNCTION__, __LINE__ |
|
562 | - ); |
|
563 | - } |
|
564 | - // EE_Registry::instance()->SSN->reset_expired(); |
|
565 | - } |
|
566 | - } |
|
567 | - |
|
568 | - |
|
569 | - |
|
570 | - /** |
|
571 | - * _initialize_checkout |
|
572 | - * loads and instantiates EE_Checkout |
|
573 | - * |
|
574 | - * @access private |
|
575 | - * @throws EE_Error |
|
576 | - * @return EE_Checkout |
|
577 | - */ |
|
578 | - private function _initialize_checkout() |
|
579 | - { |
|
580 | - // look in session for existing checkout |
|
581 | - /** @type EE_Checkout $checkout */ |
|
582 | - $checkout = EE_Registry::instance()->SSN->checkout(); |
|
583 | - // verify |
|
584 | - if ( ! $checkout instanceof EE_Checkout) { |
|
585 | - // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
586 | - $checkout = EE_Registry::instance()->load_file( |
|
587 | - SPCO_INC_PATH, |
|
588 | - 'EE_Checkout', |
|
589 | - 'class', array(), |
|
590 | - false |
|
591 | - ); |
|
592 | - } else { |
|
593 | - if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
594 | - $this->unlock_transaction(); |
|
595 | - wp_safe_redirect($checkout->redirect_url); |
|
596 | - exit(); |
|
597 | - } |
|
598 | - } |
|
599 | - $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
600 | - // verify again |
|
601 | - if ( ! $checkout instanceof EE_Checkout) { |
|
602 | - throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
603 | - } |
|
604 | - // reset anything that needs a clean slate for each request |
|
605 | - $checkout->reset_for_current_request(); |
|
606 | - return $checkout; |
|
607 | - } |
|
608 | - |
|
609 | - |
|
610 | - |
|
611 | - /** |
|
612 | - * _get_request_vars |
|
613 | - * |
|
614 | - * @access private |
|
615 | - * @return void |
|
616 | - * @throws EE_Error |
|
617 | - */ |
|
618 | - private function _get_request_vars() |
|
619 | - { |
|
620 | - // load classes |
|
621 | - EED_Single_Page_Checkout::load_request_handler(); |
|
622 | - //make sure this request is marked as belonging to EE |
|
623 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
624 | - // which step is being requested ? |
|
625 | - $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
626 | - // which step is being edited ? |
|
627 | - $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
628 | - // and what we're doing on the current step |
|
629 | - $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
630 | - // timestamp |
|
631 | - $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
632 | - // returning to edit ? |
|
633 | - $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
634 | - // add reg url link to registration query params |
|
635 | - if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) { |
|
636 | - $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link; |
|
637 | - } |
|
638 | - // or some other kind of revisit ? |
|
639 | - $this->checkout->revisit = filter_var( |
|
640 | - EE_Registry::instance()->REQ->get('revisit', false), |
|
641 | - FILTER_VALIDATE_BOOLEAN |
|
642 | - ); |
|
643 | - // and whether or not to generate a reg form for this request |
|
644 | - $this->checkout->generate_reg_form = filter_var( |
|
645 | - EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
646 | - FILTER_VALIDATE_BOOLEAN |
|
647 | - ); |
|
648 | - // and whether or not to process a reg form submission for this request |
|
649 | - $this->checkout->process_form_submission = filter_var( |
|
650 | - EE_Registry::instance()->REQ->get( |
|
651 | - 'process_form_submission', |
|
652 | - $this->checkout->action === 'process_reg_step' |
|
653 | - ), |
|
654 | - FILTER_VALIDATE_BOOLEAN |
|
655 | - ); |
|
656 | - $this->checkout->process_form_submission = filter_var( |
|
657 | - $this->checkout->action !== 'display_spco_reg_step' |
|
658 | - ? $this->checkout->process_form_submission |
|
659 | - : false, |
|
660 | - FILTER_VALIDATE_BOOLEAN |
|
661 | - ); |
|
662 | - // $this->_display_request_vars(); |
|
663 | - } |
|
664 | - |
|
665 | - |
|
666 | - |
|
667 | - /** |
|
668 | - * _display_request_vars |
|
669 | - * |
|
670 | - * @access protected |
|
671 | - * @return void |
|
672 | - */ |
|
673 | - protected function _display_request_vars() |
|
674 | - { |
|
675 | - if ( ! WP_DEBUG) { |
|
676 | - return; |
|
677 | - } |
|
678 | - EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
679 | - EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
680 | - EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
681 | - EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
682 | - EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
683 | - EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
684 | - EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
685 | - EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
686 | - } |
|
687 | - |
|
688 | - |
|
689 | - |
|
690 | - /** |
|
691 | - * _block_bots |
|
692 | - * checks that the incoming request has either of the following set: |
|
693 | - * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
694 | - * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
695 | - * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
696 | - * then where you coming from man? |
|
697 | - * |
|
698 | - * @return boolean |
|
699 | - */ |
|
700 | - private function _block_bots() |
|
701 | - { |
|
702 | - $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
703 | - if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
704 | - return true; |
|
705 | - } |
|
706 | - return false; |
|
707 | - } |
|
708 | - |
|
709 | - |
|
710 | - |
|
711 | - /** |
|
712 | - * _get_first_step |
|
713 | - * gets slug for first step in $_reg_steps_array |
|
714 | - * |
|
715 | - * @access private |
|
716 | - * @throws EE_Error |
|
717 | - * @return string |
|
718 | - */ |
|
719 | - private function _get_first_step() |
|
720 | - { |
|
721 | - $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
722 | - return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
723 | - } |
|
724 | - |
|
725 | - |
|
726 | - |
|
727 | - /** |
|
728 | - * _load_and_instantiate_reg_steps |
|
729 | - * instantiates each reg step based on the loaded reg_steps array |
|
730 | - * |
|
731 | - * @access private |
|
732 | - * @throws EE_Error |
|
733 | - * @return bool |
|
734 | - */ |
|
735 | - private function _load_and_instantiate_reg_steps() |
|
736 | - { |
|
737 | - do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
738 | - // have reg_steps already been instantiated ? |
|
739 | - if ( |
|
740 | - empty($this->checkout->reg_steps) |
|
741 | - || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
742 | - ) { |
|
743 | - // if not, then loop through raw reg steps array |
|
744 | - foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
745 | - if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
746 | - return false; |
|
747 | - } |
|
748 | - } |
|
749 | - EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
750 | - EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
751 | - // skip the registration_confirmation page ? |
|
752 | - if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
753 | - // just remove it from the reg steps array |
|
754 | - $this->checkout->remove_reg_step('registration_confirmation', false); |
|
755 | - } else if ( |
|
756 | - isset($this->checkout->reg_steps['registration_confirmation']) |
|
757 | - && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
758 | - ) { |
|
759 | - // set the order to something big like 100 |
|
760 | - $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
761 | - } |
|
762 | - // filter the array for good luck |
|
763 | - $this->checkout->reg_steps = apply_filters( |
|
764 | - 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
765 | - $this->checkout->reg_steps |
|
766 | - ); |
|
767 | - // finally re-sort based on the reg step class order properties |
|
768 | - $this->checkout->sort_reg_steps(); |
|
769 | - } else { |
|
770 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
771 | - // set all current step stati to FALSE |
|
772 | - $reg_step->set_is_current_step(false); |
|
773 | - } |
|
774 | - } |
|
775 | - if (empty($this->checkout->reg_steps)) { |
|
776 | - EE_Error::add_error( |
|
777 | - __('No Reg Steps were loaded..', 'event_espresso'), |
|
778 | - __FILE__, __FUNCTION__, __LINE__ |
|
779 | - ); |
|
780 | - return false; |
|
781 | - } |
|
782 | - // make reg step details available to JS |
|
783 | - $this->checkout->set_reg_step_JSON_info(); |
|
784 | - return true; |
|
785 | - } |
|
786 | - |
|
787 | - |
|
788 | - |
|
789 | - /** |
|
790 | - * _load_and_instantiate_reg_step |
|
791 | - * |
|
792 | - * @access private |
|
793 | - * @param array $reg_step |
|
794 | - * @param int $order |
|
795 | - * @return bool |
|
796 | - */ |
|
797 | - private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
798 | - { |
|
799 | - // we need a file_path, class_name, and slug to add a reg step |
|
800 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
801 | - // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
802 | - if ( |
|
803 | - $this->checkout->reg_url_link |
|
804 | - && $this->checkout->step !== $reg_step['slug'] |
|
805 | - && $reg_step['slug'] !== 'finalize_registration' |
|
806 | - // normally at this point we would NOT load the reg step, but this filter can change that |
|
807 | - && apply_filters( |
|
808 | - 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
809 | - true, |
|
810 | - $reg_step, |
|
811 | - $this->checkout |
|
812 | - ) |
|
813 | - ) { |
|
814 | - return true; |
|
815 | - } |
|
816 | - // instantiate step class using file path and class name |
|
817 | - $reg_step_obj = EE_Registry::instance()->load_file( |
|
818 | - $reg_step['file_path'], |
|
819 | - $reg_step['class_name'], |
|
820 | - 'class', |
|
821 | - $this->checkout, |
|
822 | - false |
|
823 | - ); |
|
824 | - // did we gets the goods ? |
|
825 | - if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
826 | - // set reg step order based on config |
|
827 | - $reg_step_obj->set_order($order); |
|
828 | - // add instantiated reg step object to the master reg steps array |
|
829 | - $this->checkout->add_reg_step($reg_step_obj); |
|
830 | - } else { |
|
831 | - EE_Error::add_error( |
|
832 | - __('The current step could not be set.', 'event_espresso'), |
|
833 | - __FILE__, __FUNCTION__, __LINE__ |
|
834 | - ); |
|
835 | - return false; |
|
836 | - } |
|
837 | - } else { |
|
838 | - if (WP_DEBUG) { |
|
839 | - EE_Error::add_error( |
|
840 | - sprintf( |
|
841 | - __( |
|
842 | - 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', |
|
843 | - 'event_espresso' |
|
844 | - ), |
|
845 | - isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
846 | - isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
847 | - isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
848 | - '<ul>', |
|
849 | - '<li>', |
|
850 | - '</li>', |
|
851 | - '</ul>' |
|
852 | - ), |
|
853 | - __FILE__, __FUNCTION__, __LINE__ |
|
854 | - ); |
|
855 | - } |
|
856 | - return false; |
|
857 | - } |
|
858 | - return true; |
|
859 | - } |
|
860 | - |
|
861 | - |
|
862 | - /** |
|
863 | - * _verify_transaction_and_get_registrations |
|
864 | - * |
|
865 | - * @access private |
|
866 | - * @return bool |
|
867 | - * @throws InvalidDataTypeException |
|
868 | - * @throws InvalidEntityException |
|
869 | - * @throws EE_Error |
|
870 | - */ |
|
871 | - private function _verify_transaction_and_get_registrations() |
|
872 | - { |
|
873 | - // was there already a valid transaction in the checkout from the session ? |
|
874 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
875 | - // get transaction from db or session |
|
876 | - $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
877 | - ? $this->_get_transaction_and_cart_for_previous_visit() |
|
878 | - : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
879 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
880 | - EE_Error::add_error( |
|
881 | - __('Your Registration and Transaction information could not be retrieved from the db.', |
|
882 | - 'event_espresso'), |
|
883 | - __FILE__, __FUNCTION__, __LINE__ |
|
884 | - ); |
|
885 | - $this->checkout->transaction = EE_Transaction::new_instance(); |
|
886 | - // add some style and make it dance |
|
887 | - $this->add_styles_and_scripts(); |
|
888 | - EED_Single_Page_Checkout::$_initialized = true; |
|
889 | - return false; |
|
890 | - } |
|
891 | - // and the registrations for the transaction |
|
892 | - $this->_get_registrations($this->checkout->transaction); |
|
893 | - } |
|
894 | - return true; |
|
895 | - } |
|
896 | - |
|
897 | - |
|
898 | - |
|
899 | - /** |
|
900 | - * _get_transaction_and_cart_for_previous_visit |
|
901 | - * |
|
902 | - * @access private |
|
903 | - * @return mixed EE_Transaction|NULL |
|
904 | - */ |
|
905 | - private function _get_transaction_and_cart_for_previous_visit() |
|
906 | - { |
|
907 | - /** @var $TXN_model EEM_Transaction */ |
|
908 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
909 | - // because the reg_url_link is present in the request, |
|
910 | - // this is a return visit to SPCO, so we'll get the transaction data from the db |
|
911 | - $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
912 | - // verify transaction |
|
913 | - if ($transaction instanceof EE_Transaction) { |
|
914 | - // and get the cart that was used for that transaction |
|
915 | - $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
916 | - return $transaction; |
|
917 | - } |
|
918 | - EE_Error::add_error( |
|
919 | - __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
920 | - __FILE__, __FUNCTION__, __LINE__ |
|
921 | - ); |
|
922 | - return null; |
|
923 | - |
|
924 | - } |
|
925 | - |
|
926 | - |
|
927 | - |
|
928 | - /** |
|
929 | - * _get_cart_for_transaction |
|
930 | - * |
|
931 | - * @access private |
|
932 | - * @param EE_Transaction $transaction |
|
933 | - * @return EE_Cart |
|
934 | - */ |
|
935 | - private function _get_cart_for_transaction($transaction) |
|
936 | - { |
|
937 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
938 | - } |
|
939 | - |
|
940 | - |
|
941 | - |
|
942 | - /** |
|
943 | - * get_cart_for_transaction |
|
944 | - * |
|
945 | - * @access public |
|
946 | - * @param EE_Transaction $transaction |
|
947 | - * @return EE_Cart |
|
948 | - */ |
|
949 | - public function get_cart_for_transaction(EE_Transaction $transaction) |
|
950 | - { |
|
951 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
952 | - } |
|
953 | - |
|
954 | - |
|
955 | - |
|
956 | - /** |
|
957 | - * _get_transaction_and_cart_for_current_session |
|
958 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
959 | - * |
|
960 | - * @access private |
|
961 | - * @return EE_Transaction |
|
962 | - * @throws EE_Error |
|
963 | - */ |
|
964 | - private function _get_cart_for_current_session_and_setup_new_transaction() |
|
965 | - { |
|
966 | - // if there's no transaction, then this is the FIRST visit to SPCO |
|
967 | - // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
968 | - $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
969 | - // and then create a new transaction |
|
970 | - $transaction = $this->_initialize_transaction(); |
|
971 | - // verify transaction |
|
972 | - if ($transaction instanceof EE_Transaction) { |
|
973 | - // save it so that we have an ID for other objects to use |
|
974 | - $transaction->save(); |
|
975 | - // and save TXN data to the cart |
|
976 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
977 | - } else { |
|
978 | - EE_Error::add_error( |
|
979 | - __('A Valid Transaction could not be initialized.', 'event_espresso'), |
|
980 | - __FILE__, __FUNCTION__, __LINE__ |
|
981 | - ); |
|
982 | - } |
|
983 | - return $transaction; |
|
984 | - } |
|
985 | - |
|
986 | - |
|
987 | - |
|
988 | - /** |
|
989 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
990 | - * |
|
991 | - * @access private |
|
992 | - * @return mixed EE_Transaction|NULL |
|
993 | - */ |
|
994 | - private function _initialize_transaction() |
|
995 | - { |
|
996 | - try { |
|
997 | - // ensure cart totals have been calculated |
|
998 | - $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
999 | - // grab the cart grand total |
|
1000 | - $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
1001 | - // create new TXN |
|
1002 | - $transaction = EE_Transaction::new_instance( |
|
1003 | - array( |
|
1004 | - 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
1005 | - 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
1006 | - 'TXN_paid' => 0, |
|
1007 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
1008 | - ) |
|
1009 | - ); |
|
1010 | - // save it so that we have an ID for other objects to use |
|
1011 | - $transaction->save(); |
|
1012 | - // set cron job for following up on TXNs after their session has expired |
|
1013 | - EE_Cron_Tasks::schedule_expired_transaction_check( |
|
1014 | - EE_Registry::instance()->SSN->expiration() + 1, |
|
1015 | - $transaction->ID() |
|
1016 | - ); |
|
1017 | - return $transaction; |
|
1018 | - } catch (Exception $e) { |
|
1019 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1020 | - } |
|
1021 | - return null; |
|
1022 | - } |
|
1023 | - |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * _get_registrations |
|
1027 | - * |
|
1028 | - * @access private |
|
1029 | - * @param EE_Transaction $transaction |
|
1030 | - * @return void |
|
1031 | - * @throws InvalidDataTypeException |
|
1032 | - * @throws InvalidEntityException |
|
1033 | - * @throws EE_Error |
|
1034 | - */ |
|
1035 | - private function _get_registrations(EE_Transaction $transaction) |
|
1036 | - { |
|
1037 | - // first step: grab the registrants { : o |
|
1038 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1039 | - $this->checkout->total_ticket_count = count($registrations); |
|
1040 | - // verify registrations have been set |
|
1041 | - if (empty($registrations)) { |
|
1042 | - // if no cached registrations, then check the db |
|
1043 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1044 | - // still nothing ? well as long as this isn't a revisit |
|
1045 | - if (empty($registrations) && ! $this->checkout->revisit) { |
|
1046 | - // generate new registrations from scratch |
|
1047 | - $registrations = $this->_initialize_registrations($transaction); |
|
1048 | - } |
|
1049 | - } |
|
1050 | - // sort by their original registration order |
|
1051 | - usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
1052 | - // then loop thru the array |
|
1053 | - foreach ($registrations as $registration) { |
|
1054 | - // verify each registration |
|
1055 | - if ($registration instanceof EE_Registration) { |
|
1056 | - // we display all attendee info for the primary registrant |
|
1057 | - if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
1058 | - && $registration->is_primary_registrant() |
|
1059 | - ) { |
|
1060 | - $this->checkout->primary_revisit = true; |
|
1061 | - break; |
|
1062 | - } |
|
1063 | - if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) { |
|
1064 | - // but hide info if it doesn't belong to you |
|
1065 | - $transaction->clear_cache('Registration', $registration->ID()); |
|
1066 | - $this->checkout->total_ticket_count--; |
|
1067 | - } |
|
1068 | - $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
1069 | - } |
|
1070 | - } |
|
1071 | - } |
|
1072 | - |
|
1073 | - |
|
1074 | - /** |
|
1075 | - * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
1076 | - * |
|
1077 | - * @access private |
|
1078 | - * @param EE_Transaction $transaction |
|
1079 | - * @return array |
|
1080 | - * @throws InvalidDataTypeException |
|
1081 | - * @throws InvalidEntityException |
|
1082 | - * @throws EE_Error |
|
1083 | - */ |
|
1084 | - private function _initialize_registrations(EE_Transaction $transaction) |
|
1085 | - { |
|
1086 | - $att_nmbr = 0; |
|
1087 | - $registrations = array(); |
|
1088 | - if ($transaction instanceof EE_Transaction) { |
|
1089 | - /** @type EE_Registration_Processor $registration_processor */ |
|
1090 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1091 | - $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
1092 | - // now let's add the cart items to the $transaction |
|
1093 | - foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
1094 | - //do the following for each ticket of this type they selected |
|
1095 | - for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
1096 | - $att_nmbr++; |
|
1097 | - /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
1098 | - $CreateRegistrationCommand = EE_Registry::instance()->create( |
|
1099 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1100 | - array( |
|
1101 | - $transaction, |
|
1102 | - $line_item, |
|
1103 | - $att_nmbr, |
|
1104 | - $this->checkout->total_ticket_count, |
|
1105 | - ) |
|
1106 | - ); |
|
1107 | - // override capabilities for frontend registrations |
|
1108 | - if ( ! is_admin()) { |
|
1109 | - $CreateRegistrationCommand->setCapCheck( |
|
1110 | - new PublicCapabilities('', 'create_new_registration') |
|
1111 | - ); |
|
1112 | - } |
|
1113 | - $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
1114 | - if ( ! $registration instanceof EE_Registration) { |
|
1115 | - throw new InvalidEntityException($registration, 'EE_Registration'); |
|
1116 | - } |
|
1117 | - $registrations[ $registration->ID() ] = $registration; |
|
1118 | - } |
|
1119 | - } |
|
1120 | - $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
1121 | - } |
|
1122 | - return $registrations; |
|
1123 | - } |
|
1124 | - |
|
1125 | - |
|
1126 | - |
|
1127 | - /** |
|
1128 | - * sorts registrations by REG_count |
|
1129 | - * |
|
1130 | - * @access public |
|
1131 | - * @param EE_Registration $reg_A |
|
1132 | - * @param EE_Registration $reg_B |
|
1133 | - * @return int |
|
1134 | - */ |
|
1135 | - public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
1136 | - { |
|
1137 | - // this shouldn't ever happen within the same TXN, but oh well |
|
1138 | - if ($reg_A->count() === $reg_B->count()) { |
|
1139 | - return 0; |
|
1140 | - } |
|
1141 | - return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
1142 | - } |
|
1143 | - |
|
1144 | - |
|
1145 | - |
|
1146 | - /** |
|
1147 | - * _final_verifications |
|
1148 | - * just makes sure that everything is set up correctly before proceeding |
|
1149 | - * |
|
1150 | - * @access private |
|
1151 | - * @return bool |
|
1152 | - * @throws EE_Error |
|
1153 | - */ |
|
1154 | - private function _final_verifications() |
|
1155 | - { |
|
1156 | - // filter checkout |
|
1157 | - $this->checkout = apply_filters( |
|
1158 | - 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', |
|
1159 | - $this->checkout |
|
1160 | - ); |
|
1161 | - //verify that current step is still set correctly |
|
1162 | - if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1163 | - EE_Error::add_error( |
|
1164 | - __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1165 | - __FILE__, |
|
1166 | - __FUNCTION__, |
|
1167 | - __LINE__ |
|
1168 | - ); |
|
1169 | - return false; |
|
1170 | - } |
|
1171 | - // if returning to SPCO, then verify that primary registrant is set |
|
1172 | - if ( ! empty($this->checkout->reg_url_link)) { |
|
1173 | - $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
1174 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
1175 | - EE_Error::add_error( |
|
1176 | - __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1177 | - __FILE__, |
|
1178 | - __FUNCTION__, |
|
1179 | - __LINE__ |
|
1180 | - ); |
|
1181 | - return false; |
|
1182 | - } |
|
1183 | - $valid_registrant = null; |
|
1184 | - foreach ( |
|
1185 | - $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration |
|
1186 | - ) { |
|
1187 | - if ( |
|
1188 | - $registration instanceof EE_Registration |
|
1189 | - && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
1190 | - ) { |
|
1191 | - $valid_registrant = $registration; |
|
1192 | - } |
|
1193 | - } |
|
1194 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
1195 | - // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
1196 | - if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
1197 | - // clear the session, mark the checkout as unverified, and try again |
|
1198 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
1199 | - EED_Single_Page_Checkout::$_initialized = false; |
|
1200 | - EED_Single_Page_Checkout::$_checkout_verified = false; |
|
1201 | - $this->_initialize(); |
|
1202 | - EE_Error::reset_notices(); |
|
1203 | - return false; |
|
1204 | - } |
|
1205 | - EE_Error::add_error( |
|
1206 | - __( |
|
1207 | - 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', |
|
1208 | - 'event_espresso' |
|
1209 | - ), |
|
1210 | - __FILE__, |
|
1211 | - __FUNCTION__, |
|
1212 | - __LINE__ |
|
1213 | - ); |
|
1214 | - return false; |
|
1215 | - } |
|
1216 | - } |
|
1217 | - // now that things have been kinda sufficiently verified, |
|
1218 | - // let's add the checkout to the session so that it's available to other systems |
|
1219 | - EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
1220 | - return true; |
|
1221 | - } |
|
1222 | - |
|
1223 | - |
|
1224 | - |
|
1225 | - /** |
|
1226 | - * _initialize_reg_steps |
|
1227 | - * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
1228 | - * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
1229 | - * |
|
1230 | - * @access private |
|
1231 | - * @param bool $reinitializing |
|
1232 | - * @throws EE_Error |
|
1233 | - */ |
|
1234 | - private function _initialize_reg_steps($reinitializing = false) |
|
1235 | - { |
|
1236 | - $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
1237 | - // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
1238 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
1239 | - if ( ! $reg_step->initialize_reg_step()) { |
|
1240 | - // if not initialized then maybe this step is being removed... |
|
1241 | - if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
1242 | - // if it was the current step, then we need to start over here |
|
1243 | - $this->_initialize_reg_steps(true); |
|
1244 | - return; |
|
1245 | - } |
|
1246 | - continue; |
|
1247 | - } |
|
1248 | - // add css and JS for current step |
|
1249 | - $reg_step->enqueue_styles_and_scripts(); |
|
1250 | - // i18n |
|
1251 | - $reg_step->translate_js_strings(); |
|
1252 | - if ($reg_step->is_current_step()) { |
|
1253 | - // the text that appears on the reg step form submit button |
|
1254 | - $reg_step->set_submit_button_text(); |
|
1255 | - } |
|
1256 | - } |
|
1257 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
1258 | - do_action( |
|
1259 | - "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", |
|
1260 | - $this->checkout->current_step |
|
1261 | - ); |
|
1262 | - } |
|
1263 | - |
|
1264 | - |
|
1265 | - |
|
1266 | - /** |
|
1267 | - * _check_form_submission |
|
1268 | - * |
|
1269 | - * @access private |
|
1270 | - * @return boolean |
|
1271 | - */ |
|
1272 | - private function _check_form_submission() |
|
1273 | - { |
|
1274 | - //does this request require the reg form to be generated ? |
|
1275 | - if ($this->checkout->generate_reg_form) { |
|
1276 | - // ever heard that song by Blue Rodeo ? |
|
1277 | - try { |
|
1278 | - $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
1279 | - // if not displaying a form, then check for form submission |
|
1280 | - if ( |
|
1281 | - $this->checkout->process_form_submission |
|
1282 | - && $this->checkout->current_step->reg_form->was_submitted() |
|
1283 | - ) { |
|
1284 | - // clear out any old data in case this step is being run again |
|
1285 | - $this->checkout->current_step->set_valid_data(array()); |
|
1286 | - // capture submitted form data |
|
1287 | - $this->checkout->current_step->reg_form->receive_form_submission( |
|
1288 | - apply_filters( |
|
1289 | - 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
1290 | - EE_Registry::instance()->REQ->params(), |
|
1291 | - $this->checkout |
|
1292 | - ) |
|
1293 | - ); |
|
1294 | - // validate submitted form data |
|
1295 | - if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1296 | - // thou shall not pass !!! |
|
1297 | - $this->checkout->continue_reg = false; |
|
1298 | - // any form validation errors? |
|
1299 | - if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
1300 | - EE_Error::add_error( |
|
1301 | - $this->checkout->current_step->reg_form->submission_error_message(), |
|
1302 | - __FILE__, __FUNCTION__, __LINE__ |
|
1303 | - ); |
|
1304 | - } |
|
1305 | - // well not really... what will happen is |
|
1306 | - // we'll just get redirected back to redo the current step |
|
1307 | - $this->go_to_next_step(); |
|
1308 | - return false; |
|
1309 | - } |
|
1310 | - } |
|
1311 | - } catch (EE_Error $e) { |
|
1312 | - $e->get_error(); |
|
1313 | - } |
|
1314 | - } |
|
1315 | - return true; |
|
1316 | - } |
|
1317 | - |
|
1318 | - |
|
1319 | - |
|
1320 | - /** |
|
1321 | - * _process_action |
|
1322 | - * |
|
1323 | - * @access private |
|
1324 | - * @return void |
|
1325 | - * @throws EE_Error |
|
1326 | - */ |
|
1327 | - private function _process_form_action() |
|
1328 | - { |
|
1329 | - // what cha wanna do? |
|
1330 | - switch ($this->checkout->action) { |
|
1331 | - // AJAX next step reg form |
|
1332 | - case 'display_spco_reg_step' : |
|
1333 | - $this->checkout->redirect = false; |
|
1334 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1335 | - $this->checkout->json_response->set_reg_step_html( |
|
1336 | - $this->checkout->current_step->display_reg_form() |
|
1337 | - ); |
|
1338 | - } |
|
1339 | - break; |
|
1340 | - default : |
|
1341 | - // meh... do one of those other steps first |
|
1342 | - if ( |
|
1343 | - ! empty($this->checkout->action) |
|
1344 | - && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
|
1345 | - ) { |
|
1346 | - // dynamically creates hook point like: |
|
1347 | - // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
1348 | - do_action( |
|
1349 | - "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1350 | - $this->checkout->current_step |
|
1351 | - ); |
|
1352 | - // call action on current step |
|
1353 | - if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1354 | - // good registrant, you get to proceed |
|
1355 | - if ( |
|
1356 | - $this->checkout->current_step->success_message() !== '' |
|
1357 | - && apply_filters( |
|
1358 | - 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
1359 | - false |
|
1360 | - ) |
|
1361 | - ) { |
|
1362 | - EE_Error::add_success( |
|
1363 | - $this->checkout->current_step->success_message() |
|
1364 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
1365 | - ); |
|
1366 | - } |
|
1367 | - // pack it up, pack it in... |
|
1368 | - $this->_setup_redirect(); |
|
1369 | - } |
|
1370 | - // dynamically creates hook point like: |
|
1371 | - // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
1372 | - do_action( |
|
1373 | - "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1374 | - $this->checkout->current_step |
|
1375 | - ); |
|
1376 | - } else { |
|
1377 | - EE_Error::add_error( |
|
1378 | - sprintf( |
|
1379 | - __( |
|
1380 | - 'The requested form action "%s" does not exist for the current "%s" registration step.', |
|
1381 | - 'event_espresso' |
|
1382 | - ), |
|
1383 | - $this->checkout->action, |
|
1384 | - $this->checkout->current_step->name() |
|
1385 | - ), |
|
1386 | - __FILE__, |
|
1387 | - __FUNCTION__, |
|
1388 | - __LINE__ |
|
1389 | - ); |
|
1390 | - } |
|
1391 | - // end default |
|
1392 | - } |
|
1393 | - // store our progress so far |
|
1394 | - $this->checkout->stash_transaction_and_checkout(); |
|
1395 | - // advance to the next step! If you pass GO, collect $200 |
|
1396 | - $this->go_to_next_step(); |
|
1397 | - } |
|
1398 | - |
|
1399 | - |
|
1400 | - |
|
1401 | - /** |
|
1402 | - * add_styles_and_scripts |
|
1403 | - * |
|
1404 | - * @access public |
|
1405 | - * @return void |
|
1406 | - */ |
|
1407 | - public function add_styles_and_scripts() |
|
1408 | - { |
|
1409 | - // i18n |
|
1410 | - $this->translate_js_strings(); |
|
1411 | - if ($this->checkout->admin_request) { |
|
1412 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1413 | - } else { |
|
1414 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1415 | - } |
|
1416 | - } |
|
1417 | - |
|
1418 | - |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * translate_js_strings |
|
1422 | - * |
|
1423 | - * @access public |
|
1424 | - * @return void |
|
1425 | - */ |
|
1426 | - public function translate_js_strings() |
|
1427 | - { |
|
1428 | - EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
1429 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
1430 | - EE_Registry::$i18n_js_strings['server_error'] = __( |
|
1431 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1432 | - 'event_espresso' |
|
1433 | - ); |
|
1434 | - EE_Registry::$i18n_js_strings['invalid_json_response'] = __( |
|
1435 | - 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1436 | - 'event_espresso' |
|
1437 | - ); |
|
1438 | - EE_Registry::$i18n_js_strings['validation_error'] = __( |
|
1439 | - 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', |
|
1440 | - 'event_espresso' |
|
1441 | - ); |
|
1442 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( |
|
1443 | - 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', |
|
1444 | - 'event_espresso' |
|
1445 | - ); |
|
1446 | - EE_Registry::$i18n_js_strings['reg_step_error'] = __( |
|
1447 | - 'This registration step could not be completed. Please refresh the page and try again.', |
|
1448 | - 'event_espresso' |
|
1449 | - ); |
|
1450 | - EE_Registry::$i18n_js_strings['invalid_coupon'] = __( |
|
1451 | - 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', |
|
1452 | - 'event_espresso' |
|
1453 | - ); |
|
1454 | - EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
1455 | - __( |
|
1456 | - 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', |
|
1457 | - 'event_espresso' |
|
1458 | - ), |
|
1459 | - '<br/>', |
|
1460 | - '<br/>' |
|
1461 | - ); |
|
1462 | - EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1463 | - EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
1464 | - EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
1465 | - EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
1466 | - EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1467 | - EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1468 | - EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1469 | - EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1470 | - EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1471 | - EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1472 | - EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1473 | - EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1474 | - EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1475 | - EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1476 | - EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1477 | - EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1478 | - EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1479 | - EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1480 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(); |
|
1481 | - EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( |
|
1482 | - 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
1483 | - true |
|
1484 | - ); |
|
1485 | - EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
1486 | - apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
1487 | - ); |
|
1488 | - EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
1489 | - 'M d, Y H:i:s', |
|
1490 | - EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1491 | - ); |
|
1492 | - } |
|
1493 | - |
|
1494 | - |
|
1495 | - |
|
1496 | - /** |
|
1497 | - * enqueue_styles_and_scripts |
|
1498 | - * |
|
1499 | - * @access public |
|
1500 | - * @return void |
|
1501 | - * @throws EE_Error |
|
1502 | - */ |
|
1503 | - public function enqueue_styles_and_scripts() |
|
1504 | - { |
|
1505 | - // load css |
|
1506 | - wp_register_style( |
|
1507 | - 'single_page_checkout', |
|
1508 | - SPCO_CSS_URL . 'single_page_checkout.css', |
|
1509 | - array('espresso_default'), |
|
1510 | - EVENT_ESPRESSO_VERSION |
|
1511 | - ); |
|
1512 | - wp_enqueue_style('single_page_checkout'); |
|
1513 | - // load JS |
|
1514 | - wp_register_script( |
|
1515 | - 'jquery_plugin', |
|
1516 | - EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
1517 | - array('jquery'), |
|
1518 | - '1.0.1', |
|
1519 | - true |
|
1520 | - ); |
|
1521 | - wp_register_script( |
|
1522 | - 'jquery_countdown', |
|
1523 | - EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
1524 | - array('jquery_plugin'), |
|
1525 | - '2.0.2', |
|
1526 | - true |
|
1527 | - ); |
|
1528 | - wp_register_script( |
|
1529 | - 'single_page_checkout', |
|
1530 | - SPCO_JS_URL . 'single_page_checkout.js', |
|
1531 | - array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), |
|
1532 | - EVENT_ESPRESSO_VERSION, |
|
1533 | - true |
|
1534 | - ); |
|
1535 | - if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
1536 | - $this->checkout->registration_form->enqueue_js(); |
|
1537 | - } |
|
1538 | - if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
1539 | - $this->checkout->current_step->reg_form->enqueue_js(); |
|
1540 | - } |
|
1541 | - wp_enqueue_script('single_page_checkout'); |
|
1542 | - /** |
|
1543 | - * global action hook for enqueueing styles and scripts with |
|
1544 | - * spco calls. |
|
1545 | - */ |
|
1546 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1547 | - /** |
|
1548 | - * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
1549 | - * The hook will end up being something like: |
|
1550 | - * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
1551 | - */ |
|
1552 | - do_action( |
|
1553 | - 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
1554 | - $this |
|
1555 | - ); |
|
1556 | - } |
|
1557 | - |
|
1558 | - |
|
1559 | - |
|
1560 | - /** |
|
1561 | - * display the Registration Single Page Checkout Form |
|
1562 | - * |
|
1563 | - * @access private |
|
1564 | - * @return void |
|
1565 | - * @throws EE_Error |
|
1566 | - */ |
|
1567 | - private function _display_spco_reg_form() |
|
1568 | - { |
|
1569 | - // if registering via the admin, just display the reg form for the current step |
|
1570 | - if ($this->checkout->admin_request) { |
|
1571 | - EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1572 | - } else { |
|
1573 | - // add powered by EE msg |
|
1574 | - add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1575 | - $empty_cart = count( |
|
1576 | - $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) |
|
1577 | - ) < 1; |
|
1578 | - EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
1579 | - $cookies_not_set_msg = ''; |
|
1580 | - if ($empty_cart) { |
|
1581 | - $cookies_not_set_msg = apply_filters( |
|
1582 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
1583 | - sprintf( |
|
1584 | - __( |
|
1585 | - '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
1586 | - 'event_espresso' |
|
1587 | - ), |
|
1588 | - '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">', |
|
1589 | - '</div>', |
|
1590 | - '<h6 class="important-notice">', |
|
1591 | - '</h6>', |
|
1592 | - '<p>', |
|
1593 | - '</p>', |
|
1594 | - '<br />', |
|
1595 | - '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
1596 | - '</a>' |
|
1597 | - ) |
|
1598 | - ); |
|
1599 | - } |
|
1600 | - $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
1601 | - array( |
|
1602 | - 'name' => 'single-page-checkout', |
|
1603 | - 'html_id' => 'ee-single-page-checkout-dv', |
|
1604 | - 'layout_strategy' => |
|
1605 | - new EE_Template_Layout( |
|
1606 | - array( |
|
1607 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1608 | - 'template_args' => array( |
|
1609 | - 'empty_cart' => $empty_cart, |
|
1610 | - 'revisit' => $this->checkout->revisit, |
|
1611 | - 'reg_steps' => $this->checkout->reg_steps, |
|
1612 | - 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
1613 | - ? $this->checkout->next_step->slug() |
|
1614 | - : '', |
|
1615 | - 'empty_msg' => apply_filters( |
|
1616 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
1617 | - sprintf( |
|
1618 | - __( |
|
1619 | - 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
1620 | - 'event_espresso' |
|
1621 | - ), |
|
1622 | - '<a href="' |
|
1623 | - . get_post_type_archive_link('espresso_events') |
|
1624 | - . '" title="', |
|
1625 | - '">', |
|
1626 | - '</a>' |
|
1627 | - ) |
|
1628 | - ), |
|
1629 | - 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
1630 | - 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
1631 | - 'session_expiration' => gmdate( |
|
1632 | - 'M d, Y H:i:s', |
|
1633 | - EE_Registry::instance()->SSN->expiration() |
|
1634 | - + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1635 | - ), |
|
1636 | - ), |
|
1637 | - ) |
|
1638 | - ), |
|
1639 | - ) |
|
1640 | - ); |
|
1641 | - // load template and add to output sent that gets filtered into the_content() |
|
1642 | - EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
1643 | - } |
|
1644 | - } |
|
1645 | - |
|
1646 | - |
|
1647 | - |
|
1648 | - /** |
|
1649 | - * add_extra_finalize_registration_inputs |
|
1650 | - * |
|
1651 | - * @access public |
|
1652 | - * @param $next_step |
|
1653 | - * @internal param string $label |
|
1654 | - * @return void |
|
1655 | - */ |
|
1656 | - public function add_extra_finalize_registration_inputs($next_step) |
|
1657 | - { |
|
1658 | - if ($next_step === 'finalize_registration') { |
|
1659 | - echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
1660 | - } |
|
1661 | - } |
|
1662 | - |
|
1663 | - |
|
1664 | - |
|
1665 | - /** |
|
1666 | - * display_registration_footer |
|
1667 | - * |
|
1668 | - * @access public |
|
1669 | - * @return string |
|
1670 | - */ |
|
1671 | - public static function display_registration_footer() |
|
1672 | - { |
|
1673 | - if ( |
|
1674 | - apply_filters( |
|
1675 | - 'FHEE__EE_Front__Controller__show_reg_footer', |
|
1676 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
1677 | - ) |
|
1678 | - ) { |
|
1679 | - add_filter( |
|
1680 | - 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
1681 | - function ($url) { |
|
1682 | - return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1683 | - } |
|
1684 | - ); |
|
1685 | - echo apply_filters( |
|
1686 | - 'FHEE__EE_Front_Controller__display_registration_footer', |
|
1687 | - \EEH_Template::powered_by_event_espresso( |
|
1688 | - '', |
|
1689 | - 'espresso-registration-footer-dv', |
|
1690 | - array('utm_content' => 'registration_checkout') |
|
1691 | - ) |
|
1692 | - ); |
|
1693 | - } |
|
1694 | - return ''; |
|
1695 | - } |
|
1696 | - |
|
1697 | - |
|
1698 | - |
|
1699 | - /** |
|
1700 | - * unlock_transaction |
|
1701 | - * |
|
1702 | - * @access public |
|
1703 | - * @return void |
|
1704 | - * @throws EE_Error |
|
1705 | - */ |
|
1706 | - public function unlock_transaction() |
|
1707 | - { |
|
1708 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
1709 | - $this->checkout->transaction->unlock(); |
|
1710 | - } |
|
1711 | - } |
|
1712 | - |
|
1713 | - |
|
1714 | - |
|
1715 | - /** |
|
1716 | - * _setup_redirect |
|
1717 | - * |
|
1718 | - * @access private |
|
1719 | - * @return void |
|
1720 | - */ |
|
1721 | - private function _setup_redirect() |
|
1722 | - { |
|
1723 | - if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1724 | - $this->checkout->redirect = true; |
|
1725 | - if (empty($this->checkout->redirect_url)) { |
|
1726 | - $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
1727 | - } |
|
1728 | - $this->checkout->redirect_url = apply_filters( |
|
1729 | - 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
1730 | - $this->checkout->redirect_url, |
|
1731 | - $this->checkout |
|
1732 | - ); |
|
1733 | - } |
|
1734 | - } |
|
1735 | - |
|
1736 | - |
|
1737 | - |
|
1738 | - /** |
|
1739 | - * handle ajax message responses and redirects |
|
1740 | - * |
|
1741 | - * @access public |
|
1742 | - * @return void |
|
1743 | - * @throws EE_Error |
|
1744 | - */ |
|
1745 | - public function go_to_next_step() |
|
1746 | - { |
|
1747 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1748 | - // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
1749 | - $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1750 | - } |
|
1751 | - $this->unlock_transaction(); |
|
1752 | - // just return for these conditions |
|
1753 | - if ( |
|
1754 | - $this->checkout->admin_request |
|
1755 | - || $this->checkout->action === 'redirect_form' |
|
1756 | - || $this->checkout->action === 'update_checkout' |
|
1757 | - ) { |
|
1758 | - return; |
|
1759 | - } |
|
1760 | - // AJAX response |
|
1761 | - $this->_handle_json_response(); |
|
1762 | - // redirect to next step or the Thank You page |
|
1763 | - $this->_handle_html_redirects(); |
|
1764 | - // hmmm... must be something wrong, so let's just display the form again ! |
|
1765 | - $this->_display_spco_reg_form(); |
|
1766 | - } |
|
1767 | - |
|
1768 | - |
|
1769 | - |
|
1770 | - /** |
|
1771 | - * _handle_json_response |
|
1772 | - * |
|
1773 | - * @access protected |
|
1774 | - * @return void |
|
1775 | - */ |
|
1776 | - protected function _handle_json_response() |
|
1777 | - { |
|
1778 | - // if this is an ajax request |
|
1779 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1780 | - // DEBUG LOG |
|
1781 | - //$this->checkout->log( |
|
1782 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
1783 | - // array( |
|
1784 | - // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
1785 | - // 'redirect' => $this->checkout->redirect, |
|
1786 | - // 'continue_reg' => $this->checkout->continue_reg, |
|
1787 | - // ) |
|
1788 | - //); |
|
1789 | - $this->checkout->json_response->set_registration_time_limit( |
|
1790 | - $this->checkout->get_registration_time_limit() |
|
1791 | - ); |
|
1792 | - $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1793 | - // just send the ajax ( |
|
1794 | - $json_response = apply_filters( |
|
1795 | - 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
1796 | - $this->checkout->json_response |
|
1797 | - ); |
|
1798 | - echo $json_response; |
|
1799 | - exit(); |
|
1800 | - } |
|
1801 | - } |
|
1802 | - |
|
1803 | - |
|
1804 | - |
|
1805 | - /** |
|
1806 | - * _handle_redirects |
|
1807 | - * |
|
1808 | - * @access protected |
|
1809 | - * @return void |
|
1810 | - */ |
|
1811 | - protected function _handle_html_redirects() |
|
1812 | - { |
|
1813 | - // going somewhere ? |
|
1814 | - if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1815 | - // store notices in a transient |
|
1816 | - EE_Error::get_notices(false, true, true); |
|
1817 | - // DEBUG LOG |
|
1818 | - //$this->checkout->log( |
|
1819 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
1820 | - // array( |
|
1821 | - // 'headers_sent' => headers_sent(), |
|
1822 | - // 'redirect_url' => $this->checkout->redirect_url, |
|
1823 | - // 'headers_list' => headers_list(), |
|
1824 | - // ) |
|
1825 | - //); |
|
1826 | - wp_safe_redirect($this->checkout->redirect_url); |
|
1827 | - exit(); |
|
1828 | - } |
|
1829 | - } |
|
1830 | - |
|
1831 | - |
|
1832 | - |
|
1833 | - /** |
|
1834 | - * set_checkout_anchor |
|
1835 | - * |
|
1836 | - * @access public |
|
1837 | - * @return void |
|
1838 | - */ |
|
1839 | - public function set_checkout_anchor() |
|
1840 | - { |
|
1841 | - echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
1842 | - } |
|
1843 | - |
|
1844 | - /** |
|
1845 | - * getRegistrationExpirationNotice |
|
1846 | - * |
|
1847 | - * @since $VID:$ |
|
1848 | - * @access public |
|
1849 | - * @return string |
|
1850 | - */ |
|
1851 | - public static function getRegistrationExpirationNotice() |
|
1852 | - { |
|
1853 | - return sprintf( |
|
1854 | - __('%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s', |
|
1855 | - 'event_espresso'), |
|
1856 | - '<h4 class="important-notice">', |
|
1857 | - '</h4>', |
|
1858 | - '<br />', |
|
1859 | - '<p>', |
|
1860 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1861 | - '">', |
|
1862 | - '</a>', |
|
1863 | - '</p>' |
|
1864 | - ); |
|
1865 | - } |
|
23 | + /** |
|
24 | + * $_initialized - has the SPCO controller already been initialized ? |
|
25 | + * |
|
26 | + * @access private |
|
27 | + * @var bool $_initialized |
|
28 | + */ |
|
29 | + private static $_initialized = false; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
34 | + * |
|
35 | + * @access private |
|
36 | + * @var bool $_valid_checkout |
|
37 | + */ |
|
38 | + private static $_checkout_verified = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * $_reg_steps_array - holds initial array of reg steps |
|
42 | + * |
|
43 | + * @access private |
|
44 | + * @var array $_reg_steps_array |
|
45 | + */ |
|
46 | + private static $_reg_steps_array = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
50 | + * |
|
51 | + * @access public |
|
52 | + * @var EE_Checkout $checkout |
|
53 | + */ |
|
54 | + public $checkout; |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @return EED_Module|EED_Single_Page_Checkout |
|
60 | + */ |
|
61 | + public static function instance() |
|
62 | + { |
|
63 | + add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
64 | + return parent::get_instance(__CLASS__); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @return EE_CART |
|
71 | + */ |
|
72 | + public function cart() |
|
73 | + { |
|
74 | + return $this->checkout->cart; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @return EE_Transaction |
|
81 | + */ |
|
82 | + public function transaction() |
|
83 | + { |
|
84 | + return $this->checkout->transaction; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
91 | + * |
|
92 | + * @access public |
|
93 | + * @return void |
|
94 | + * @throws EE_Error |
|
95 | + */ |
|
96 | + public static function set_hooks() |
|
97 | + { |
|
98 | + EED_Single_Page_Checkout::set_definitions(); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
105 | + * |
|
106 | + * @access public |
|
107 | + * @return void |
|
108 | + * @throws EE_Error |
|
109 | + */ |
|
110 | + public static function set_hooks_admin() |
|
111 | + { |
|
112 | + EED_Single_Page_Checkout::set_definitions(); |
|
113 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
114 | + return; |
|
115 | + } |
|
116 | + // going to start an output buffer in case anything gets accidentally output |
|
117 | + // that might disrupt our JSON response |
|
118 | + ob_start(); |
|
119 | + EED_Single_Page_Checkout::load_request_handler(); |
|
120 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
121 | + // set ajax hooks |
|
122 | + add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
123 | + add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
124 | + add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
125 | + add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
126 | + add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
127 | + add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * process ajax request |
|
134 | + * |
|
135 | + * @param string $ajax_action |
|
136 | + * @throws EE_Error |
|
137 | + */ |
|
138 | + public static function process_ajax_request($ajax_action) |
|
139 | + { |
|
140 | + EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
141 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * ajax display registration step |
|
148 | + * |
|
149 | + * @throws EE_Error |
|
150 | + */ |
|
151 | + public static function display_reg_step() |
|
152 | + { |
|
153 | + EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * ajax process registration step |
|
160 | + * |
|
161 | + * @throws EE_Error |
|
162 | + */ |
|
163 | + public static function process_reg_step() |
|
164 | + { |
|
165 | + EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * ajax process registration step |
|
172 | + * |
|
173 | + * @throws EE_Error |
|
174 | + */ |
|
175 | + public static function update_reg_step() |
|
176 | + { |
|
177 | + EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * update_checkout |
|
184 | + * |
|
185 | + * @access public |
|
186 | + * @return void |
|
187 | + * @throws EE_Error |
|
188 | + */ |
|
189 | + public static function update_checkout() |
|
190 | + { |
|
191 | + EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * load_request_handler |
|
198 | + * |
|
199 | + * @access public |
|
200 | + * @return void |
|
201 | + */ |
|
202 | + public static function load_request_handler() |
|
203 | + { |
|
204 | + // load core Request_Handler class |
|
205 | + if (EE_Registry::instance()->REQ !== null) { |
|
206 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * set_definitions |
|
214 | + * |
|
215 | + * @access public |
|
216 | + * @return void |
|
217 | + * @throws EE_Error |
|
218 | + */ |
|
219 | + public static function set_definitions() |
|
220 | + { |
|
221 | + if(defined('SPCO_BASE_PATH')) { |
|
222 | + return; |
|
223 | + } |
|
224 | + define( |
|
225 | + 'SPCO_BASE_PATH', |
|
226 | + rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
227 | + ); |
|
228 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
229 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
230 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
231 | + define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
232 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
233 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
235 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * load_reg_steps |
|
242 | + * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
243 | + * |
|
244 | + * @access private |
|
245 | + * @throws EE_Error |
|
246 | + */ |
|
247 | + public static function load_reg_steps() |
|
248 | + { |
|
249 | + static $reg_steps_loaded = false; |
|
250 | + if ($reg_steps_loaded) { |
|
251 | + return; |
|
252 | + } |
|
253 | + // filter list of reg_steps |
|
254 | + $reg_steps_to_load = (array)apply_filters( |
|
255 | + 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
256 | + EED_Single_Page_Checkout::get_reg_steps() |
|
257 | + ); |
|
258 | + // sort by key (order) |
|
259 | + ksort($reg_steps_to_load); |
|
260 | + // loop through folders |
|
261 | + foreach ($reg_steps_to_load as $order => $reg_step) { |
|
262 | + // we need a |
|
263 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
264 | + // copy over to the reg_steps_array |
|
265 | + EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
266 | + // register custom key route for each reg step |
|
267 | + // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
268 | + EE_Config::register_route( |
|
269 | + $reg_step['slug'], |
|
270 | + 'EED_Single_Page_Checkout', |
|
271 | + 'run', |
|
272 | + 'step' |
|
273 | + ); |
|
274 | + // add AJAX or other hooks |
|
275 | + if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
276 | + // setup autoloaders if necessary |
|
277 | + if ( ! class_exists($reg_step['class_name'])) { |
|
278 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
|
279 | + $reg_step['file_path'], |
|
280 | + true |
|
281 | + ); |
|
282 | + } |
|
283 | + if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
284 | + call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
285 | + } |
|
286 | + } |
|
287 | + } |
|
288 | + } |
|
289 | + $reg_steps_loaded = true; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * get_reg_steps |
|
296 | + * |
|
297 | + * @access public |
|
298 | + * @return array |
|
299 | + */ |
|
300 | + public static function get_reg_steps() |
|
301 | + { |
|
302 | + $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
303 | + if (empty($reg_steps)) { |
|
304 | + $reg_steps = array( |
|
305 | + 10 => array( |
|
306 | + 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
307 | + 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
308 | + 'slug' => 'attendee_information', |
|
309 | + 'has_hooks' => false, |
|
310 | + ), |
|
311 | + 20 => array( |
|
312 | + 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
313 | + 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
314 | + 'slug' => 'registration_confirmation', |
|
315 | + 'has_hooks' => false, |
|
316 | + ), |
|
317 | + 30 => array( |
|
318 | + 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
319 | + 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
320 | + 'slug' => 'payment_options', |
|
321 | + 'has_hooks' => true, |
|
322 | + ), |
|
323 | + 999 => array( |
|
324 | + 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
325 | + 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
326 | + 'slug' => 'finalize_registration', |
|
327 | + 'has_hooks' => false, |
|
328 | + ), |
|
329 | + ); |
|
330 | + } |
|
331 | + return $reg_steps; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * registration_checkout_for_admin |
|
338 | + * |
|
339 | + * @access public |
|
340 | + * @return string |
|
341 | + * @throws EE_Error |
|
342 | + */ |
|
343 | + public static function registration_checkout_for_admin() |
|
344 | + { |
|
345 | + EED_Single_Page_Checkout::load_request_handler(); |
|
346 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
347 | + EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
348 | + EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
349 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
350 | + EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
351 | + return EE_Registry::instance()->REQ->get_output(); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * process_registration_from_admin |
|
358 | + * |
|
359 | + * @access public |
|
360 | + * @return \EE_Transaction |
|
361 | + * @throws EE_Error |
|
362 | + */ |
|
363 | + public static function process_registration_from_admin() |
|
364 | + { |
|
365 | + EED_Single_Page_Checkout::load_request_handler(); |
|
366 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
367 | + EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
368 | + EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
369 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
370 | + if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
371 | + $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
372 | + if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
373 | + EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
374 | + if ($final_reg_step->process_reg_step()) { |
|
375 | + $final_reg_step->set_completed(); |
|
376 | + EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
377 | + return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
378 | + } |
|
379 | + } |
|
380 | + } |
|
381 | + return null; |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * run |
|
388 | + * |
|
389 | + * @access public |
|
390 | + * @param WP_Query $WP_Query |
|
391 | + * @return void |
|
392 | + * @throws EE_Error |
|
393 | + */ |
|
394 | + public function run($WP_Query) |
|
395 | + { |
|
396 | + if ( |
|
397 | + $WP_Query instanceof WP_Query |
|
398 | + && $WP_Query->is_main_query() |
|
399 | + && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
400 | + && $this->_is_reg_checkout() |
|
401 | + ) { |
|
402 | + $this->_initialize(); |
|
403 | + } |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * determines whether current url matches reg page url |
|
410 | + * |
|
411 | + * @return bool |
|
412 | + */ |
|
413 | + protected function _is_reg_checkout() |
|
414 | + { |
|
415 | + // get current permalink for reg page without any extra query args |
|
416 | + $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
417 | + // get request URI for current request, but without the scheme or host |
|
418 | + $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
419 | + $current_request_uri = html_entity_decode($current_request_uri); |
|
420 | + // get array of query args from the current request URI |
|
421 | + $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
422 | + // grab page id if it is set |
|
423 | + $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
424 | + // and remove the page id from the query args (we will re-add it later) |
|
425 | + unset($query_args['page_id']); |
|
426 | + // now strip all query args from current request URI |
|
427 | + $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
428 | + // and re-add the page id if it was set |
|
429 | + if ($page_id) { |
|
430 | + $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
431 | + } |
|
432 | + // remove slashes and ? |
|
433 | + $current_request_uri = trim($current_request_uri, '?/'); |
|
434 | + // is current request URI part of the known full reg page URL ? |
|
435 | + return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * @param WP_Query $wp_query |
|
442 | + * @return void |
|
443 | + * @throws EE_Error |
|
444 | + */ |
|
445 | + public static function init($wp_query) |
|
446 | + { |
|
447 | + EED_Single_Page_Checkout::instance()->run($wp_query); |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * _initialize - initial module setup |
|
454 | + * |
|
455 | + * @access private |
|
456 | + * @throws EE_Error |
|
457 | + * @return void |
|
458 | + */ |
|
459 | + private function _initialize() |
|
460 | + { |
|
461 | + // ensure SPCO doesn't run twice |
|
462 | + if (EED_Single_Page_Checkout::$_initialized) { |
|
463 | + return; |
|
464 | + } |
|
465 | + try { |
|
466 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
467 | + $this->_verify_session(); |
|
468 | + // setup the EE_Checkout object |
|
469 | + $this->checkout = $this->_initialize_checkout(); |
|
470 | + // filter checkout |
|
471 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
472 | + // get the $_GET |
|
473 | + $this->_get_request_vars(); |
|
474 | + if ($this->_block_bots()) { |
|
475 | + return; |
|
476 | + } |
|
477 | + // filter continue_reg |
|
478 | + $this->checkout->continue_reg = apply_filters( |
|
479 | + 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
480 | + true, |
|
481 | + $this->checkout |
|
482 | + ); |
|
483 | + // load the reg steps array |
|
484 | + if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
485 | + EED_Single_Page_Checkout::$_initialized = true; |
|
486 | + return; |
|
487 | + } |
|
488 | + // set the current step |
|
489 | + $this->checkout->set_current_step($this->checkout->step); |
|
490 | + // and the next step |
|
491 | + $this->checkout->set_next_step(); |
|
492 | + // verify that everything has been setup correctly |
|
493 | + if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
494 | + EED_Single_Page_Checkout::$_initialized = true; |
|
495 | + return; |
|
496 | + } |
|
497 | + // lock the transaction |
|
498 | + $this->checkout->transaction->lock(); |
|
499 | + // make sure all of our cached objects are added to their respective model entity mappers |
|
500 | + $this->checkout->refresh_all_entities(); |
|
501 | + // set amount owing |
|
502 | + $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
503 | + // initialize each reg step, which gives them the chance to potentially alter the process |
|
504 | + $this->_initialize_reg_steps(); |
|
505 | + // DEBUG LOG |
|
506 | + //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
507 | + // get reg form |
|
508 | + if( ! $this->_check_form_submission()) { |
|
509 | + EED_Single_Page_Checkout::$_initialized = true; |
|
510 | + return; |
|
511 | + } |
|
512 | + // checkout the action!!! |
|
513 | + $this->_process_form_action(); |
|
514 | + // add some style and make it dance |
|
515 | + $this->add_styles_and_scripts(); |
|
516 | + // kk... SPCO has successfully run |
|
517 | + EED_Single_Page_Checkout::$_initialized = true; |
|
518 | + // set no cache headers and constants |
|
519 | + EE_System::do_not_cache(); |
|
520 | + // add anchor |
|
521 | + add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
522 | + // remove transaction lock |
|
523 | + add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
524 | + } catch (Exception $e) { |
|
525 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
526 | + } |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + |
|
531 | + /** |
|
532 | + * _verify_session |
|
533 | + * checks that the session is valid and not expired |
|
534 | + * |
|
535 | + * @access private |
|
536 | + * @throws EE_Error |
|
537 | + */ |
|
538 | + private function _verify_session() |
|
539 | + { |
|
540 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
541 | + throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
542 | + } |
|
543 | + $clear_session_requested = filter_var( |
|
544 | + EE_Registry::instance()->REQ->get('clear_session', false), |
|
545 | + FILTER_VALIDATE_BOOLEAN |
|
546 | + ); |
|
547 | + // is session still valid ? |
|
548 | + if ($clear_session_requested |
|
549 | + || ( EE_Registry::instance()->SSN->expired() |
|
550 | + && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
|
551 | + ) |
|
552 | + ) { |
|
553 | + $this->checkout = new EE_Checkout(); |
|
554 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
555 | + // EE_Registry::instance()->SSN->reset_cart(); |
|
556 | + // EE_Registry::instance()->SSN->reset_checkout(); |
|
557 | + // EE_Registry::instance()->SSN->reset_transaction(); |
|
558 | + if (! $clear_session_requested) { |
|
559 | + EE_Error::add_attention( |
|
560 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
|
561 | + __FILE__, __FUNCTION__, __LINE__ |
|
562 | + ); |
|
563 | + } |
|
564 | + // EE_Registry::instance()->SSN->reset_expired(); |
|
565 | + } |
|
566 | + } |
|
567 | + |
|
568 | + |
|
569 | + |
|
570 | + /** |
|
571 | + * _initialize_checkout |
|
572 | + * loads and instantiates EE_Checkout |
|
573 | + * |
|
574 | + * @access private |
|
575 | + * @throws EE_Error |
|
576 | + * @return EE_Checkout |
|
577 | + */ |
|
578 | + private function _initialize_checkout() |
|
579 | + { |
|
580 | + // look in session for existing checkout |
|
581 | + /** @type EE_Checkout $checkout */ |
|
582 | + $checkout = EE_Registry::instance()->SSN->checkout(); |
|
583 | + // verify |
|
584 | + if ( ! $checkout instanceof EE_Checkout) { |
|
585 | + // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
586 | + $checkout = EE_Registry::instance()->load_file( |
|
587 | + SPCO_INC_PATH, |
|
588 | + 'EE_Checkout', |
|
589 | + 'class', array(), |
|
590 | + false |
|
591 | + ); |
|
592 | + } else { |
|
593 | + if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
594 | + $this->unlock_transaction(); |
|
595 | + wp_safe_redirect($checkout->redirect_url); |
|
596 | + exit(); |
|
597 | + } |
|
598 | + } |
|
599 | + $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
600 | + // verify again |
|
601 | + if ( ! $checkout instanceof EE_Checkout) { |
|
602 | + throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
603 | + } |
|
604 | + // reset anything that needs a clean slate for each request |
|
605 | + $checkout->reset_for_current_request(); |
|
606 | + return $checkout; |
|
607 | + } |
|
608 | + |
|
609 | + |
|
610 | + |
|
611 | + /** |
|
612 | + * _get_request_vars |
|
613 | + * |
|
614 | + * @access private |
|
615 | + * @return void |
|
616 | + * @throws EE_Error |
|
617 | + */ |
|
618 | + private function _get_request_vars() |
|
619 | + { |
|
620 | + // load classes |
|
621 | + EED_Single_Page_Checkout::load_request_handler(); |
|
622 | + //make sure this request is marked as belonging to EE |
|
623 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
624 | + // which step is being requested ? |
|
625 | + $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
626 | + // which step is being edited ? |
|
627 | + $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
628 | + // and what we're doing on the current step |
|
629 | + $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
630 | + // timestamp |
|
631 | + $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
632 | + // returning to edit ? |
|
633 | + $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
634 | + // add reg url link to registration query params |
|
635 | + if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) { |
|
636 | + $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link; |
|
637 | + } |
|
638 | + // or some other kind of revisit ? |
|
639 | + $this->checkout->revisit = filter_var( |
|
640 | + EE_Registry::instance()->REQ->get('revisit', false), |
|
641 | + FILTER_VALIDATE_BOOLEAN |
|
642 | + ); |
|
643 | + // and whether or not to generate a reg form for this request |
|
644 | + $this->checkout->generate_reg_form = filter_var( |
|
645 | + EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
646 | + FILTER_VALIDATE_BOOLEAN |
|
647 | + ); |
|
648 | + // and whether or not to process a reg form submission for this request |
|
649 | + $this->checkout->process_form_submission = filter_var( |
|
650 | + EE_Registry::instance()->REQ->get( |
|
651 | + 'process_form_submission', |
|
652 | + $this->checkout->action === 'process_reg_step' |
|
653 | + ), |
|
654 | + FILTER_VALIDATE_BOOLEAN |
|
655 | + ); |
|
656 | + $this->checkout->process_form_submission = filter_var( |
|
657 | + $this->checkout->action !== 'display_spco_reg_step' |
|
658 | + ? $this->checkout->process_form_submission |
|
659 | + : false, |
|
660 | + FILTER_VALIDATE_BOOLEAN |
|
661 | + ); |
|
662 | + // $this->_display_request_vars(); |
|
663 | + } |
|
664 | + |
|
665 | + |
|
666 | + |
|
667 | + /** |
|
668 | + * _display_request_vars |
|
669 | + * |
|
670 | + * @access protected |
|
671 | + * @return void |
|
672 | + */ |
|
673 | + protected function _display_request_vars() |
|
674 | + { |
|
675 | + if ( ! WP_DEBUG) { |
|
676 | + return; |
|
677 | + } |
|
678 | + EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
679 | + EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
680 | + EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
681 | + EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
682 | + EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
683 | + EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
684 | + EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
685 | + EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
686 | + } |
|
687 | + |
|
688 | + |
|
689 | + |
|
690 | + /** |
|
691 | + * _block_bots |
|
692 | + * checks that the incoming request has either of the following set: |
|
693 | + * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
694 | + * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
695 | + * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
696 | + * then where you coming from man? |
|
697 | + * |
|
698 | + * @return boolean |
|
699 | + */ |
|
700 | + private function _block_bots() |
|
701 | + { |
|
702 | + $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
703 | + if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
704 | + return true; |
|
705 | + } |
|
706 | + return false; |
|
707 | + } |
|
708 | + |
|
709 | + |
|
710 | + |
|
711 | + /** |
|
712 | + * _get_first_step |
|
713 | + * gets slug for first step in $_reg_steps_array |
|
714 | + * |
|
715 | + * @access private |
|
716 | + * @throws EE_Error |
|
717 | + * @return string |
|
718 | + */ |
|
719 | + private function _get_first_step() |
|
720 | + { |
|
721 | + $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
722 | + return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
723 | + } |
|
724 | + |
|
725 | + |
|
726 | + |
|
727 | + /** |
|
728 | + * _load_and_instantiate_reg_steps |
|
729 | + * instantiates each reg step based on the loaded reg_steps array |
|
730 | + * |
|
731 | + * @access private |
|
732 | + * @throws EE_Error |
|
733 | + * @return bool |
|
734 | + */ |
|
735 | + private function _load_and_instantiate_reg_steps() |
|
736 | + { |
|
737 | + do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
738 | + // have reg_steps already been instantiated ? |
|
739 | + if ( |
|
740 | + empty($this->checkout->reg_steps) |
|
741 | + || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
742 | + ) { |
|
743 | + // if not, then loop through raw reg steps array |
|
744 | + foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
745 | + if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
746 | + return false; |
|
747 | + } |
|
748 | + } |
|
749 | + EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
750 | + EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
751 | + // skip the registration_confirmation page ? |
|
752 | + if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
753 | + // just remove it from the reg steps array |
|
754 | + $this->checkout->remove_reg_step('registration_confirmation', false); |
|
755 | + } else if ( |
|
756 | + isset($this->checkout->reg_steps['registration_confirmation']) |
|
757 | + && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
758 | + ) { |
|
759 | + // set the order to something big like 100 |
|
760 | + $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
761 | + } |
|
762 | + // filter the array for good luck |
|
763 | + $this->checkout->reg_steps = apply_filters( |
|
764 | + 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
765 | + $this->checkout->reg_steps |
|
766 | + ); |
|
767 | + // finally re-sort based on the reg step class order properties |
|
768 | + $this->checkout->sort_reg_steps(); |
|
769 | + } else { |
|
770 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
771 | + // set all current step stati to FALSE |
|
772 | + $reg_step->set_is_current_step(false); |
|
773 | + } |
|
774 | + } |
|
775 | + if (empty($this->checkout->reg_steps)) { |
|
776 | + EE_Error::add_error( |
|
777 | + __('No Reg Steps were loaded..', 'event_espresso'), |
|
778 | + __FILE__, __FUNCTION__, __LINE__ |
|
779 | + ); |
|
780 | + return false; |
|
781 | + } |
|
782 | + // make reg step details available to JS |
|
783 | + $this->checkout->set_reg_step_JSON_info(); |
|
784 | + return true; |
|
785 | + } |
|
786 | + |
|
787 | + |
|
788 | + |
|
789 | + /** |
|
790 | + * _load_and_instantiate_reg_step |
|
791 | + * |
|
792 | + * @access private |
|
793 | + * @param array $reg_step |
|
794 | + * @param int $order |
|
795 | + * @return bool |
|
796 | + */ |
|
797 | + private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
798 | + { |
|
799 | + // we need a file_path, class_name, and slug to add a reg step |
|
800 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
801 | + // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
802 | + if ( |
|
803 | + $this->checkout->reg_url_link |
|
804 | + && $this->checkout->step !== $reg_step['slug'] |
|
805 | + && $reg_step['slug'] !== 'finalize_registration' |
|
806 | + // normally at this point we would NOT load the reg step, but this filter can change that |
|
807 | + && apply_filters( |
|
808 | + 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
809 | + true, |
|
810 | + $reg_step, |
|
811 | + $this->checkout |
|
812 | + ) |
|
813 | + ) { |
|
814 | + return true; |
|
815 | + } |
|
816 | + // instantiate step class using file path and class name |
|
817 | + $reg_step_obj = EE_Registry::instance()->load_file( |
|
818 | + $reg_step['file_path'], |
|
819 | + $reg_step['class_name'], |
|
820 | + 'class', |
|
821 | + $this->checkout, |
|
822 | + false |
|
823 | + ); |
|
824 | + // did we gets the goods ? |
|
825 | + if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
826 | + // set reg step order based on config |
|
827 | + $reg_step_obj->set_order($order); |
|
828 | + // add instantiated reg step object to the master reg steps array |
|
829 | + $this->checkout->add_reg_step($reg_step_obj); |
|
830 | + } else { |
|
831 | + EE_Error::add_error( |
|
832 | + __('The current step could not be set.', 'event_espresso'), |
|
833 | + __FILE__, __FUNCTION__, __LINE__ |
|
834 | + ); |
|
835 | + return false; |
|
836 | + } |
|
837 | + } else { |
|
838 | + if (WP_DEBUG) { |
|
839 | + EE_Error::add_error( |
|
840 | + sprintf( |
|
841 | + __( |
|
842 | + 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', |
|
843 | + 'event_espresso' |
|
844 | + ), |
|
845 | + isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
846 | + isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
847 | + isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
848 | + '<ul>', |
|
849 | + '<li>', |
|
850 | + '</li>', |
|
851 | + '</ul>' |
|
852 | + ), |
|
853 | + __FILE__, __FUNCTION__, __LINE__ |
|
854 | + ); |
|
855 | + } |
|
856 | + return false; |
|
857 | + } |
|
858 | + return true; |
|
859 | + } |
|
860 | + |
|
861 | + |
|
862 | + /** |
|
863 | + * _verify_transaction_and_get_registrations |
|
864 | + * |
|
865 | + * @access private |
|
866 | + * @return bool |
|
867 | + * @throws InvalidDataTypeException |
|
868 | + * @throws InvalidEntityException |
|
869 | + * @throws EE_Error |
|
870 | + */ |
|
871 | + private function _verify_transaction_and_get_registrations() |
|
872 | + { |
|
873 | + // was there already a valid transaction in the checkout from the session ? |
|
874 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
875 | + // get transaction from db or session |
|
876 | + $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
877 | + ? $this->_get_transaction_and_cart_for_previous_visit() |
|
878 | + : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
879 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
880 | + EE_Error::add_error( |
|
881 | + __('Your Registration and Transaction information could not be retrieved from the db.', |
|
882 | + 'event_espresso'), |
|
883 | + __FILE__, __FUNCTION__, __LINE__ |
|
884 | + ); |
|
885 | + $this->checkout->transaction = EE_Transaction::new_instance(); |
|
886 | + // add some style and make it dance |
|
887 | + $this->add_styles_and_scripts(); |
|
888 | + EED_Single_Page_Checkout::$_initialized = true; |
|
889 | + return false; |
|
890 | + } |
|
891 | + // and the registrations for the transaction |
|
892 | + $this->_get_registrations($this->checkout->transaction); |
|
893 | + } |
|
894 | + return true; |
|
895 | + } |
|
896 | + |
|
897 | + |
|
898 | + |
|
899 | + /** |
|
900 | + * _get_transaction_and_cart_for_previous_visit |
|
901 | + * |
|
902 | + * @access private |
|
903 | + * @return mixed EE_Transaction|NULL |
|
904 | + */ |
|
905 | + private function _get_transaction_and_cart_for_previous_visit() |
|
906 | + { |
|
907 | + /** @var $TXN_model EEM_Transaction */ |
|
908 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
909 | + // because the reg_url_link is present in the request, |
|
910 | + // this is a return visit to SPCO, so we'll get the transaction data from the db |
|
911 | + $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
912 | + // verify transaction |
|
913 | + if ($transaction instanceof EE_Transaction) { |
|
914 | + // and get the cart that was used for that transaction |
|
915 | + $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
916 | + return $transaction; |
|
917 | + } |
|
918 | + EE_Error::add_error( |
|
919 | + __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
920 | + __FILE__, __FUNCTION__, __LINE__ |
|
921 | + ); |
|
922 | + return null; |
|
923 | + |
|
924 | + } |
|
925 | + |
|
926 | + |
|
927 | + |
|
928 | + /** |
|
929 | + * _get_cart_for_transaction |
|
930 | + * |
|
931 | + * @access private |
|
932 | + * @param EE_Transaction $transaction |
|
933 | + * @return EE_Cart |
|
934 | + */ |
|
935 | + private function _get_cart_for_transaction($transaction) |
|
936 | + { |
|
937 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
938 | + } |
|
939 | + |
|
940 | + |
|
941 | + |
|
942 | + /** |
|
943 | + * get_cart_for_transaction |
|
944 | + * |
|
945 | + * @access public |
|
946 | + * @param EE_Transaction $transaction |
|
947 | + * @return EE_Cart |
|
948 | + */ |
|
949 | + public function get_cart_for_transaction(EE_Transaction $transaction) |
|
950 | + { |
|
951 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
952 | + } |
|
953 | + |
|
954 | + |
|
955 | + |
|
956 | + /** |
|
957 | + * _get_transaction_and_cart_for_current_session |
|
958 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
959 | + * |
|
960 | + * @access private |
|
961 | + * @return EE_Transaction |
|
962 | + * @throws EE_Error |
|
963 | + */ |
|
964 | + private function _get_cart_for_current_session_and_setup_new_transaction() |
|
965 | + { |
|
966 | + // if there's no transaction, then this is the FIRST visit to SPCO |
|
967 | + // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
968 | + $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
969 | + // and then create a new transaction |
|
970 | + $transaction = $this->_initialize_transaction(); |
|
971 | + // verify transaction |
|
972 | + if ($transaction instanceof EE_Transaction) { |
|
973 | + // save it so that we have an ID for other objects to use |
|
974 | + $transaction->save(); |
|
975 | + // and save TXN data to the cart |
|
976 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
977 | + } else { |
|
978 | + EE_Error::add_error( |
|
979 | + __('A Valid Transaction could not be initialized.', 'event_espresso'), |
|
980 | + __FILE__, __FUNCTION__, __LINE__ |
|
981 | + ); |
|
982 | + } |
|
983 | + return $transaction; |
|
984 | + } |
|
985 | + |
|
986 | + |
|
987 | + |
|
988 | + /** |
|
989 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
990 | + * |
|
991 | + * @access private |
|
992 | + * @return mixed EE_Transaction|NULL |
|
993 | + */ |
|
994 | + private function _initialize_transaction() |
|
995 | + { |
|
996 | + try { |
|
997 | + // ensure cart totals have been calculated |
|
998 | + $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
999 | + // grab the cart grand total |
|
1000 | + $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
1001 | + // create new TXN |
|
1002 | + $transaction = EE_Transaction::new_instance( |
|
1003 | + array( |
|
1004 | + 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
1005 | + 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
1006 | + 'TXN_paid' => 0, |
|
1007 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
1008 | + ) |
|
1009 | + ); |
|
1010 | + // save it so that we have an ID for other objects to use |
|
1011 | + $transaction->save(); |
|
1012 | + // set cron job for following up on TXNs after their session has expired |
|
1013 | + EE_Cron_Tasks::schedule_expired_transaction_check( |
|
1014 | + EE_Registry::instance()->SSN->expiration() + 1, |
|
1015 | + $transaction->ID() |
|
1016 | + ); |
|
1017 | + return $transaction; |
|
1018 | + } catch (Exception $e) { |
|
1019 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1020 | + } |
|
1021 | + return null; |
|
1022 | + } |
|
1023 | + |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * _get_registrations |
|
1027 | + * |
|
1028 | + * @access private |
|
1029 | + * @param EE_Transaction $transaction |
|
1030 | + * @return void |
|
1031 | + * @throws InvalidDataTypeException |
|
1032 | + * @throws InvalidEntityException |
|
1033 | + * @throws EE_Error |
|
1034 | + */ |
|
1035 | + private function _get_registrations(EE_Transaction $transaction) |
|
1036 | + { |
|
1037 | + // first step: grab the registrants { : o |
|
1038 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1039 | + $this->checkout->total_ticket_count = count($registrations); |
|
1040 | + // verify registrations have been set |
|
1041 | + if (empty($registrations)) { |
|
1042 | + // if no cached registrations, then check the db |
|
1043 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1044 | + // still nothing ? well as long as this isn't a revisit |
|
1045 | + if (empty($registrations) && ! $this->checkout->revisit) { |
|
1046 | + // generate new registrations from scratch |
|
1047 | + $registrations = $this->_initialize_registrations($transaction); |
|
1048 | + } |
|
1049 | + } |
|
1050 | + // sort by their original registration order |
|
1051 | + usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
1052 | + // then loop thru the array |
|
1053 | + foreach ($registrations as $registration) { |
|
1054 | + // verify each registration |
|
1055 | + if ($registration instanceof EE_Registration) { |
|
1056 | + // we display all attendee info for the primary registrant |
|
1057 | + if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
1058 | + && $registration->is_primary_registrant() |
|
1059 | + ) { |
|
1060 | + $this->checkout->primary_revisit = true; |
|
1061 | + break; |
|
1062 | + } |
|
1063 | + if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) { |
|
1064 | + // but hide info if it doesn't belong to you |
|
1065 | + $transaction->clear_cache('Registration', $registration->ID()); |
|
1066 | + $this->checkout->total_ticket_count--; |
|
1067 | + } |
|
1068 | + $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
1069 | + } |
|
1070 | + } |
|
1071 | + } |
|
1072 | + |
|
1073 | + |
|
1074 | + /** |
|
1075 | + * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
1076 | + * |
|
1077 | + * @access private |
|
1078 | + * @param EE_Transaction $transaction |
|
1079 | + * @return array |
|
1080 | + * @throws InvalidDataTypeException |
|
1081 | + * @throws InvalidEntityException |
|
1082 | + * @throws EE_Error |
|
1083 | + */ |
|
1084 | + private function _initialize_registrations(EE_Transaction $transaction) |
|
1085 | + { |
|
1086 | + $att_nmbr = 0; |
|
1087 | + $registrations = array(); |
|
1088 | + if ($transaction instanceof EE_Transaction) { |
|
1089 | + /** @type EE_Registration_Processor $registration_processor */ |
|
1090 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1091 | + $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
1092 | + // now let's add the cart items to the $transaction |
|
1093 | + foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
1094 | + //do the following for each ticket of this type they selected |
|
1095 | + for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
1096 | + $att_nmbr++; |
|
1097 | + /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
1098 | + $CreateRegistrationCommand = EE_Registry::instance()->create( |
|
1099 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1100 | + array( |
|
1101 | + $transaction, |
|
1102 | + $line_item, |
|
1103 | + $att_nmbr, |
|
1104 | + $this->checkout->total_ticket_count, |
|
1105 | + ) |
|
1106 | + ); |
|
1107 | + // override capabilities for frontend registrations |
|
1108 | + if ( ! is_admin()) { |
|
1109 | + $CreateRegistrationCommand->setCapCheck( |
|
1110 | + new PublicCapabilities('', 'create_new_registration') |
|
1111 | + ); |
|
1112 | + } |
|
1113 | + $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
1114 | + if ( ! $registration instanceof EE_Registration) { |
|
1115 | + throw new InvalidEntityException($registration, 'EE_Registration'); |
|
1116 | + } |
|
1117 | + $registrations[ $registration->ID() ] = $registration; |
|
1118 | + } |
|
1119 | + } |
|
1120 | + $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
1121 | + } |
|
1122 | + return $registrations; |
|
1123 | + } |
|
1124 | + |
|
1125 | + |
|
1126 | + |
|
1127 | + /** |
|
1128 | + * sorts registrations by REG_count |
|
1129 | + * |
|
1130 | + * @access public |
|
1131 | + * @param EE_Registration $reg_A |
|
1132 | + * @param EE_Registration $reg_B |
|
1133 | + * @return int |
|
1134 | + */ |
|
1135 | + public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
1136 | + { |
|
1137 | + // this shouldn't ever happen within the same TXN, but oh well |
|
1138 | + if ($reg_A->count() === $reg_B->count()) { |
|
1139 | + return 0; |
|
1140 | + } |
|
1141 | + return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
1142 | + } |
|
1143 | + |
|
1144 | + |
|
1145 | + |
|
1146 | + /** |
|
1147 | + * _final_verifications |
|
1148 | + * just makes sure that everything is set up correctly before proceeding |
|
1149 | + * |
|
1150 | + * @access private |
|
1151 | + * @return bool |
|
1152 | + * @throws EE_Error |
|
1153 | + */ |
|
1154 | + private function _final_verifications() |
|
1155 | + { |
|
1156 | + // filter checkout |
|
1157 | + $this->checkout = apply_filters( |
|
1158 | + 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', |
|
1159 | + $this->checkout |
|
1160 | + ); |
|
1161 | + //verify that current step is still set correctly |
|
1162 | + if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1163 | + EE_Error::add_error( |
|
1164 | + __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1165 | + __FILE__, |
|
1166 | + __FUNCTION__, |
|
1167 | + __LINE__ |
|
1168 | + ); |
|
1169 | + return false; |
|
1170 | + } |
|
1171 | + // if returning to SPCO, then verify that primary registrant is set |
|
1172 | + if ( ! empty($this->checkout->reg_url_link)) { |
|
1173 | + $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
1174 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
1175 | + EE_Error::add_error( |
|
1176 | + __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1177 | + __FILE__, |
|
1178 | + __FUNCTION__, |
|
1179 | + __LINE__ |
|
1180 | + ); |
|
1181 | + return false; |
|
1182 | + } |
|
1183 | + $valid_registrant = null; |
|
1184 | + foreach ( |
|
1185 | + $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration |
|
1186 | + ) { |
|
1187 | + if ( |
|
1188 | + $registration instanceof EE_Registration |
|
1189 | + && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
1190 | + ) { |
|
1191 | + $valid_registrant = $registration; |
|
1192 | + } |
|
1193 | + } |
|
1194 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
1195 | + // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
1196 | + if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
1197 | + // clear the session, mark the checkout as unverified, and try again |
|
1198 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
1199 | + EED_Single_Page_Checkout::$_initialized = false; |
|
1200 | + EED_Single_Page_Checkout::$_checkout_verified = false; |
|
1201 | + $this->_initialize(); |
|
1202 | + EE_Error::reset_notices(); |
|
1203 | + return false; |
|
1204 | + } |
|
1205 | + EE_Error::add_error( |
|
1206 | + __( |
|
1207 | + 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', |
|
1208 | + 'event_espresso' |
|
1209 | + ), |
|
1210 | + __FILE__, |
|
1211 | + __FUNCTION__, |
|
1212 | + __LINE__ |
|
1213 | + ); |
|
1214 | + return false; |
|
1215 | + } |
|
1216 | + } |
|
1217 | + // now that things have been kinda sufficiently verified, |
|
1218 | + // let's add the checkout to the session so that it's available to other systems |
|
1219 | + EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
1220 | + return true; |
|
1221 | + } |
|
1222 | + |
|
1223 | + |
|
1224 | + |
|
1225 | + /** |
|
1226 | + * _initialize_reg_steps |
|
1227 | + * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
1228 | + * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
1229 | + * |
|
1230 | + * @access private |
|
1231 | + * @param bool $reinitializing |
|
1232 | + * @throws EE_Error |
|
1233 | + */ |
|
1234 | + private function _initialize_reg_steps($reinitializing = false) |
|
1235 | + { |
|
1236 | + $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
1237 | + // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
1238 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
1239 | + if ( ! $reg_step->initialize_reg_step()) { |
|
1240 | + // if not initialized then maybe this step is being removed... |
|
1241 | + if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
1242 | + // if it was the current step, then we need to start over here |
|
1243 | + $this->_initialize_reg_steps(true); |
|
1244 | + return; |
|
1245 | + } |
|
1246 | + continue; |
|
1247 | + } |
|
1248 | + // add css and JS for current step |
|
1249 | + $reg_step->enqueue_styles_and_scripts(); |
|
1250 | + // i18n |
|
1251 | + $reg_step->translate_js_strings(); |
|
1252 | + if ($reg_step->is_current_step()) { |
|
1253 | + // the text that appears on the reg step form submit button |
|
1254 | + $reg_step->set_submit_button_text(); |
|
1255 | + } |
|
1256 | + } |
|
1257 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
1258 | + do_action( |
|
1259 | + "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", |
|
1260 | + $this->checkout->current_step |
|
1261 | + ); |
|
1262 | + } |
|
1263 | + |
|
1264 | + |
|
1265 | + |
|
1266 | + /** |
|
1267 | + * _check_form_submission |
|
1268 | + * |
|
1269 | + * @access private |
|
1270 | + * @return boolean |
|
1271 | + */ |
|
1272 | + private function _check_form_submission() |
|
1273 | + { |
|
1274 | + //does this request require the reg form to be generated ? |
|
1275 | + if ($this->checkout->generate_reg_form) { |
|
1276 | + // ever heard that song by Blue Rodeo ? |
|
1277 | + try { |
|
1278 | + $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
1279 | + // if not displaying a form, then check for form submission |
|
1280 | + if ( |
|
1281 | + $this->checkout->process_form_submission |
|
1282 | + && $this->checkout->current_step->reg_form->was_submitted() |
|
1283 | + ) { |
|
1284 | + // clear out any old data in case this step is being run again |
|
1285 | + $this->checkout->current_step->set_valid_data(array()); |
|
1286 | + // capture submitted form data |
|
1287 | + $this->checkout->current_step->reg_form->receive_form_submission( |
|
1288 | + apply_filters( |
|
1289 | + 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
1290 | + EE_Registry::instance()->REQ->params(), |
|
1291 | + $this->checkout |
|
1292 | + ) |
|
1293 | + ); |
|
1294 | + // validate submitted form data |
|
1295 | + if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1296 | + // thou shall not pass !!! |
|
1297 | + $this->checkout->continue_reg = false; |
|
1298 | + // any form validation errors? |
|
1299 | + if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
1300 | + EE_Error::add_error( |
|
1301 | + $this->checkout->current_step->reg_form->submission_error_message(), |
|
1302 | + __FILE__, __FUNCTION__, __LINE__ |
|
1303 | + ); |
|
1304 | + } |
|
1305 | + // well not really... what will happen is |
|
1306 | + // we'll just get redirected back to redo the current step |
|
1307 | + $this->go_to_next_step(); |
|
1308 | + return false; |
|
1309 | + } |
|
1310 | + } |
|
1311 | + } catch (EE_Error $e) { |
|
1312 | + $e->get_error(); |
|
1313 | + } |
|
1314 | + } |
|
1315 | + return true; |
|
1316 | + } |
|
1317 | + |
|
1318 | + |
|
1319 | + |
|
1320 | + /** |
|
1321 | + * _process_action |
|
1322 | + * |
|
1323 | + * @access private |
|
1324 | + * @return void |
|
1325 | + * @throws EE_Error |
|
1326 | + */ |
|
1327 | + private function _process_form_action() |
|
1328 | + { |
|
1329 | + // what cha wanna do? |
|
1330 | + switch ($this->checkout->action) { |
|
1331 | + // AJAX next step reg form |
|
1332 | + case 'display_spco_reg_step' : |
|
1333 | + $this->checkout->redirect = false; |
|
1334 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1335 | + $this->checkout->json_response->set_reg_step_html( |
|
1336 | + $this->checkout->current_step->display_reg_form() |
|
1337 | + ); |
|
1338 | + } |
|
1339 | + break; |
|
1340 | + default : |
|
1341 | + // meh... do one of those other steps first |
|
1342 | + if ( |
|
1343 | + ! empty($this->checkout->action) |
|
1344 | + && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
|
1345 | + ) { |
|
1346 | + // dynamically creates hook point like: |
|
1347 | + // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
1348 | + do_action( |
|
1349 | + "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1350 | + $this->checkout->current_step |
|
1351 | + ); |
|
1352 | + // call action on current step |
|
1353 | + if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1354 | + // good registrant, you get to proceed |
|
1355 | + if ( |
|
1356 | + $this->checkout->current_step->success_message() !== '' |
|
1357 | + && apply_filters( |
|
1358 | + 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
1359 | + false |
|
1360 | + ) |
|
1361 | + ) { |
|
1362 | + EE_Error::add_success( |
|
1363 | + $this->checkout->current_step->success_message() |
|
1364 | + . '<br />' . $this->checkout->next_step->_instructions() |
|
1365 | + ); |
|
1366 | + } |
|
1367 | + // pack it up, pack it in... |
|
1368 | + $this->_setup_redirect(); |
|
1369 | + } |
|
1370 | + // dynamically creates hook point like: |
|
1371 | + // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
1372 | + do_action( |
|
1373 | + "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1374 | + $this->checkout->current_step |
|
1375 | + ); |
|
1376 | + } else { |
|
1377 | + EE_Error::add_error( |
|
1378 | + sprintf( |
|
1379 | + __( |
|
1380 | + 'The requested form action "%s" does not exist for the current "%s" registration step.', |
|
1381 | + 'event_espresso' |
|
1382 | + ), |
|
1383 | + $this->checkout->action, |
|
1384 | + $this->checkout->current_step->name() |
|
1385 | + ), |
|
1386 | + __FILE__, |
|
1387 | + __FUNCTION__, |
|
1388 | + __LINE__ |
|
1389 | + ); |
|
1390 | + } |
|
1391 | + // end default |
|
1392 | + } |
|
1393 | + // store our progress so far |
|
1394 | + $this->checkout->stash_transaction_and_checkout(); |
|
1395 | + // advance to the next step! If you pass GO, collect $200 |
|
1396 | + $this->go_to_next_step(); |
|
1397 | + } |
|
1398 | + |
|
1399 | + |
|
1400 | + |
|
1401 | + /** |
|
1402 | + * add_styles_and_scripts |
|
1403 | + * |
|
1404 | + * @access public |
|
1405 | + * @return void |
|
1406 | + */ |
|
1407 | + public function add_styles_and_scripts() |
|
1408 | + { |
|
1409 | + // i18n |
|
1410 | + $this->translate_js_strings(); |
|
1411 | + if ($this->checkout->admin_request) { |
|
1412 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1413 | + } else { |
|
1414 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1415 | + } |
|
1416 | + } |
|
1417 | + |
|
1418 | + |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * translate_js_strings |
|
1422 | + * |
|
1423 | + * @access public |
|
1424 | + * @return void |
|
1425 | + */ |
|
1426 | + public function translate_js_strings() |
|
1427 | + { |
|
1428 | + EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
1429 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
1430 | + EE_Registry::$i18n_js_strings['server_error'] = __( |
|
1431 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1432 | + 'event_espresso' |
|
1433 | + ); |
|
1434 | + EE_Registry::$i18n_js_strings['invalid_json_response'] = __( |
|
1435 | + 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1436 | + 'event_espresso' |
|
1437 | + ); |
|
1438 | + EE_Registry::$i18n_js_strings['validation_error'] = __( |
|
1439 | + 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', |
|
1440 | + 'event_espresso' |
|
1441 | + ); |
|
1442 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( |
|
1443 | + 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', |
|
1444 | + 'event_espresso' |
|
1445 | + ); |
|
1446 | + EE_Registry::$i18n_js_strings['reg_step_error'] = __( |
|
1447 | + 'This registration step could not be completed. Please refresh the page and try again.', |
|
1448 | + 'event_espresso' |
|
1449 | + ); |
|
1450 | + EE_Registry::$i18n_js_strings['invalid_coupon'] = __( |
|
1451 | + 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', |
|
1452 | + 'event_espresso' |
|
1453 | + ); |
|
1454 | + EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
1455 | + __( |
|
1456 | + 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', |
|
1457 | + 'event_espresso' |
|
1458 | + ), |
|
1459 | + '<br/>', |
|
1460 | + '<br/>' |
|
1461 | + ); |
|
1462 | + EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1463 | + EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
1464 | + EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
1465 | + EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
1466 | + EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1467 | + EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1468 | + EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1469 | + EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1470 | + EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1471 | + EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1472 | + EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1473 | + EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1474 | + EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1475 | + EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1476 | + EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1477 | + EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1478 | + EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1479 | + EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1480 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(); |
|
1481 | + EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( |
|
1482 | + 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
1483 | + true |
|
1484 | + ); |
|
1485 | + EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
1486 | + apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
1487 | + ); |
|
1488 | + EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
1489 | + 'M d, Y H:i:s', |
|
1490 | + EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1491 | + ); |
|
1492 | + } |
|
1493 | + |
|
1494 | + |
|
1495 | + |
|
1496 | + /** |
|
1497 | + * enqueue_styles_and_scripts |
|
1498 | + * |
|
1499 | + * @access public |
|
1500 | + * @return void |
|
1501 | + * @throws EE_Error |
|
1502 | + */ |
|
1503 | + public function enqueue_styles_and_scripts() |
|
1504 | + { |
|
1505 | + // load css |
|
1506 | + wp_register_style( |
|
1507 | + 'single_page_checkout', |
|
1508 | + SPCO_CSS_URL . 'single_page_checkout.css', |
|
1509 | + array('espresso_default'), |
|
1510 | + EVENT_ESPRESSO_VERSION |
|
1511 | + ); |
|
1512 | + wp_enqueue_style('single_page_checkout'); |
|
1513 | + // load JS |
|
1514 | + wp_register_script( |
|
1515 | + 'jquery_plugin', |
|
1516 | + EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
1517 | + array('jquery'), |
|
1518 | + '1.0.1', |
|
1519 | + true |
|
1520 | + ); |
|
1521 | + wp_register_script( |
|
1522 | + 'jquery_countdown', |
|
1523 | + EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
1524 | + array('jquery_plugin'), |
|
1525 | + '2.0.2', |
|
1526 | + true |
|
1527 | + ); |
|
1528 | + wp_register_script( |
|
1529 | + 'single_page_checkout', |
|
1530 | + SPCO_JS_URL . 'single_page_checkout.js', |
|
1531 | + array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), |
|
1532 | + EVENT_ESPRESSO_VERSION, |
|
1533 | + true |
|
1534 | + ); |
|
1535 | + if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
1536 | + $this->checkout->registration_form->enqueue_js(); |
|
1537 | + } |
|
1538 | + if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
1539 | + $this->checkout->current_step->reg_form->enqueue_js(); |
|
1540 | + } |
|
1541 | + wp_enqueue_script('single_page_checkout'); |
|
1542 | + /** |
|
1543 | + * global action hook for enqueueing styles and scripts with |
|
1544 | + * spco calls. |
|
1545 | + */ |
|
1546 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1547 | + /** |
|
1548 | + * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
1549 | + * The hook will end up being something like: |
|
1550 | + * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
1551 | + */ |
|
1552 | + do_action( |
|
1553 | + 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
1554 | + $this |
|
1555 | + ); |
|
1556 | + } |
|
1557 | + |
|
1558 | + |
|
1559 | + |
|
1560 | + /** |
|
1561 | + * display the Registration Single Page Checkout Form |
|
1562 | + * |
|
1563 | + * @access private |
|
1564 | + * @return void |
|
1565 | + * @throws EE_Error |
|
1566 | + */ |
|
1567 | + private function _display_spco_reg_form() |
|
1568 | + { |
|
1569 | + // if registering via the admin, just display the reg form for the current step |
|
1570 | + if ($this->checkout->admin_request) { |
|
1571 | + EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1572 | + } else { |
|
1573 | + // add powered by EE msg |
|
1574 | + add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1575 | + $empty_cart = count( |
|
1576 | + $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) |
|
1577 | + ) < 1; |
|
1578 | + EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
1579 | + $cookies_not_set_msg = ''; |
|
1580 | + if ($empty_cart) { |
|
1581 | + $cookies_not_set_msg = apply_filters( |
|
1582 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
1583 | + sprintf( |
|
1584 | + __( |
|
1585 | + '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
1586 | + 'event_espresso' |
|
1587 | + ), |
|
1588 | + '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">', |
|
1589 | + '</div>', |
|
1590 | + '<h6 class="important-notice">', |
|
1591 | + '</h6>', |
|
1592 | + '<p>', |
|
1593 | + '</p>', |
|
1594 | + '<br />', |
|
1595 | + '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
1596 | + '</a>' |
|
1597 | + ) |
|
1598 | + ); |
|
1599 | + } |
|
1600 | + $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
1601 | + array( |
|
1602 | + 'name' => 'single-page-checkout', |
|
1603 | + 'html_id' => 'ee-single-page-checkout-dv', |
|
1604 | + 'layout_strategy' => |
|
1605 | + new EE_Template_Layout( |
|
1606 | + array( |
|
1607 | + 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1608 | + 'template_args' => array( |
|
1609 | + 'empty_cart' => $empty_cart, |
|
1610 | + 'revisit' => $this->checkout->revisit, |
|
1611 | + 'reg_steps' => $this->checkout->reg_steps, |
|
1612 | + 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
1613 | + ? $this->checkout->next_step->slug() |
|
1614 | + : '', |
|
1615 | + 'empty_msg' => apply_filters( |
|
1616 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
1617 | + sprintf( |
|
1618 | + __( |
|
1619 | + 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
1620 | + 'event_espresso' |
|
1621 | + ), |
|
1622 | + '<a href="' |
|
1623 | + . get_post_type_archive_link('espresso_events') |
|
1624 | + . '" title="', |
|
1625 | + '">', |
|
1626 | + '</a>' |
|
1627 | + ) |
|
1628 | + ), |
|
1629 | + 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
1630 | + 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
1631 | + 'session_expiration' => gmdate( |
|
1632 | + 'M d, Y H:i:s', |
|
1633 | + EE_Registry::instance()->SSN->expiration() |
|
1634 | + + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1635 | + ), |
|
1636 | + ), |
|
1637 | + ) |
|
1638 | + ), |
|
1639 | + ) |
|
1640 | + ); |
|
1641 | + // load template and add to output sent that gets filtered into the_content() |
|
1642 | + EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
1643 | + } |
|
1644 | + } |
|
1645 | + |
|
1646 | + |
|
1647 | + |
|
1648 | + /** |
|
1649 | + * add_extra_finalize_registration_inputs |
|
1650 | + * |
|
1651 | + * @access public |
|
1652 | + * @param $next_step |
|
1653 | + * @internal param string $label |
|
1654 | + * @return void |
|
1655 | + */ |
|
1656 | + public function add_extra_finalize_registration_inputs($next_step) |
|
1657 | + { |
|
1658 | + if ($next_step === 'finalize_registration') { |
|
1659 | + echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
1660 | + } |
|
1661 | + } |
|
1662 | + |
|
1663 | + |
|
1664 | + |
|
1665 | + /** |
|
1666 | + * display_registration_footer |
|
1667 | + * |
|
1668 | + * @access public |
|
1669 | + * @return string |
|
1670 | + */ |
|
1671 | + public static function display_registration_footer() |
|
1672 | + { |
|
1673 | + if ( |
|
1674 | + apply_filters( |
|
1675 | + 'FHEE__EE_Front__Controller__show_reg_footer', |
|
1676 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
1677 | + ) |
|
1678 | + ) { |
|
1679 | + add_filter( |
|
1680 | + 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
1681 | + function ($url) { |
|
1682 | + return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1683 | + } |
|
1684 | + ); |
|
1685 | + echo apply_filters( |
|
1686 | + 'FHEE__EE_Front_Controller__display_registration_footer', |
|
1687 | + \EEH_Template::powered_by_event_espresso( |
|
1688 | + '', |
|
1689 | + 'espresso-registration-footer-dv', |
|
1690 | + array('utm_content' => 'registration_checkout') |
|
1691 | + ) |
|
1692 | + ); |
|
1693 | + } |
|
1694 | + return ''; |
|
1695 | + } |
|
1696 | + |
|
1697 | + |
|
1698 | + |
|
1699 | + /** |
|
1700 | + * unlock_transaction |
|
1701 | + * |
|
1702 | + * @access public |
|
1703 | + * @return void |
|
1704 | + * @throws EE_Error |
|
1705 | + */ |
|
1706 | + public function unlock_transaction() |
|
1707 | + { |
|
1708 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
1709 | + $this->checkout->transaction->unlock(); |
|
1710 | + } |
|
1711 | + } |
|
1712 | + |
|
1713 | + |
|
1714 | + |
|
1715 | + /** |
|
1716 | + * _setup_redirect |
|
1717 | + * |
|
1718 | + * @access private |
|
1719 | + * @return void |
|
1720 | + */ |
|
1721 | + private function _setup_redirect() |
|
1722 | + { |
|
1723 | + if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1724 | + $this->checkout->redirect = true; |
|
1725 | + if (empty($this->checkout->redirect_url)) { |
|
1726 | + $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
1727 | + } |
|
1728 | + $this->checkout->redirect_url = apply_filters( |
|
1729 | + 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
1730 | + $this->checkout->redirect_url, |
|
1731 | + $this->checkout |
|
1732 | + ); |
|
1733 | + } |
|
1734 | + } |
|
1735 | + |
|
1736 | + |
|
1737 | + |
|
1738 | + /** |
|
1739 | + * handle ajax message responses and redirects |
|
1740 | + * |
|
1741 | + * @access public |
|
1742 | + * @return void |
|
1743 | + * @throws EE_Error |
|
1744 | + */ |
|
1745 | + public function go_to_next_step() |
|
1746 | + { |
|
1747 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1748 | + // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
1749 | + $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1750 | + } |
|
1751 | + $this->unlock_transaction(); |
|
1752 | + // just return for these conditions |
|
1753 | + if ( |
|
1754 | + $this->checkout->admin_request |
|
1755 | + || $this->checkout->action === 'redirect_form' |
|
1756 | + || $this->checkout->action === 'update_checkout' |
|
1757 | + ) { |
|
1758 | + return; |
|
1759 | + } |
|
1760 | + // AJAX response |
|
1761 | + $this->_handle_json_response(); |
|
1762 | + // redirect to next step or the Thank You page |
|
1763 | + $this->_handle_html_redirects(); |
|
1764 | + // hmmm... must be something wrong, so let's just display the form again ! |
|
1765 | + $this->_display_spco_reg_form(); |
|
1766 | + } |
|
1767 | + |
|
1768 | + |
|
1769 | + |
|
1770 | + /** |
|
1771 | + * _handle_json_response |
|
1772 | + * |
|
1773 | + * @access protected |
|
1774 | + * @return void |
|
1775 | + */ |
|
1776 | + protected function _handle_json_response() |
|
1777 | + { |
|
1778 | + // if this is an ajax request |
|
1779 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1780 | + // DEBUG LOG |
|
1781 | + //$this->checkout->log( |
|
1782 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
1783 | + // array( |
|
1784 | + // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
1785 | + // 'redirect' => $this->checkout->redirect, |
|
1786 | + // 'continue_reg' => $this->checkout->continue_reg, |
|
1787 | + // ) |
|
1788 | + //); |
|
1789 | + $this->checkout->json_response->set_registration_time_limit( |
|
1790 | + $this->checkout->get_registration_time_limit() |
|
1791 | + ); |
|
1792 | + $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1793 | + // just send the ajax ( |
|
1794 | + $json_response = apply_filters( |
|
1795 | + 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
1796 | + $this->checkout->json_response |
|
1797 | + ); |
|
1798 | + echo $json_response; |
|
1799 | + exit(); |
|
1800 | + } |
|
1801 | + } |
|
1802 | + |
|
1803 | + |
|
1804 | + |
|
1805 | + /** |
|
1806 | + * _handle_redirects |
|
1807 | + * |
|
1808 | + * @access protected |
|
1809 | + * @return void |
|
1810 | + */ |
|
1811 | + protected function _handle_html_redirects() |
|
1812 | + { |
|
1813 | + // going somewhere ? |
|
1814 | + if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1815 | + // store notices in a transient |
|
1816 | + EE_Error::get_notices(false, true, true); |
|
1817 | + // DEBUG LOG |
|
1818 | + //$this->checkout->log( |
|
1819 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
1820 | + // array( |
|
1821 | + // 'headers_sent' => headers_sent(), |
|
1822 | + // 'redirect_url' => $this->checkout->redirect_url, |
|
1823 | + // 'headers_list' => headers_list(), |
|
1824 | + // ) |
|
1825 | + //); |
|
1826 | + wp_safe_redirect($this->checkout->redirect_url); |
|
1827 | + exit(); |
|
1828 | + } |
|
1829 | + } |
|
1830 | + |
|
1831 | + |
|
1832 | + |
|
1833 | + /** |
|
1834 | + * set_checkout_anchor |
|
1835 | + * |
|
1836 | + * @access public |
|
1837 | + * @return void |
|
1838 | + */ |
|
1839 | + public function set_checkout_anchor() |
|
1840 | + { |
|
1841 | + echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
1842 | + } |
|
1843 | + |
|
1844 | + /** |
|
1845 | + * getRegistrationExpirationNotice |
|
1846 | + * |
|
1847 | + * @since $VID:$ |
|
1848 | + * @access public |
|
1849 | + * @return string |
|
1850 | + */ |
|
1851 | + public static function getRegistrationExpirationNotice() |
|
1852 | + { |
|
1853 | + return sprintf( |
|
1854 | + __('%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s', |
|
1855 | + 'event_espresso'), |
|
1856 | + '<h4 class="important-notice">', |
|
1857 | + '</h4>', |
|
1858 | + '<br />', |
|
1859 | + '<p>', |
|
1860 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1861 | + '">', |
|
1862 | + '</a>', |
|
1863 | + '</p>' |
|
1864 | + ); |
|
1865 | + } |
|
1866 | 1866 | |
1867 | 1867 | } |
1868 | 1868 | // End of file EED_Single_Page_Checkout.module.php |
@@ -68,7 +68,7 @@ |
||
68 | 68 | </div> |
69 | 69 | <p><?php esc_html_e('Don\'t want to keep your old Event Espresso data? Alternatively, you can delete it all and start fresh.', |
70 | 70 | 'event_espresso'); ?> <a |
71 | - href="<?php echo $data_reset_page;?>"><?php esc_html_e('Visit the Maintenance Page and Reset Your Event Espresso Data', |
|
71 | + href="<?php echo $data_reset_page; ?>"><?php esc_html_e('Visit the Maintenance Page and Reset Your Event Espresso Data', |
|
72 | 72 | 'event_espresso'); ?></a></p> |
73 | 73 | <?php do_action('AHEE__ee_migration_page__after_migration_options_table'); ?> |
74 | 74 | </div> |
75 | 75 | \ No newline at end of file |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | <tr> |
26 | 26 | <td> |
27 | 27 | <?php |
28 | - echo apply_filters( |
|
29 | - 'FHEE__ee_migration_page__option_1_main', |
|
30 | - esc_html__('Before updating your database, you should first create a database backup', |
|
31 | - "event_espresso"), |
|
32 | - $current_db_state, |
|
33 | - $next_db_state |
|
34 | - ); |
|
35 | - ?> |
|
28 | + echo apply_filters( |
|
29 | + 'FHEE__ee_migration_page__option_1_main', |
|
30 | + esc_html__('Before updating your database, you should first create a database backup', |
|
31 | + "event_espresso"), |
|
32 | + $current_db_state, |
|
33 | + $next_db_state |
|
34 | + ); |
|
35 | + ?> |
|
36 | 36 | <a id="display-migration-details" |
37 | 37 | class="display-the-hidden lt-grey-text smaller-text hide-if-no-js" |
38 | 38 | rel="migration-details"><?php esc_html_e('How Do I Make a Database Backup?', "event_espresso"); ?> |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | <td> |
42 | 42 | <a id="db-backed-up" |
43 | 43 | class="toggle-migration-monitor button-primary"><?php echo apply_filters('FHEE__ee_migration_page__option_1_button_text', |
44 | - sprintf(esc_html__("My Database Is Backed Up, Continue", "event_espresso"), $current_db_state, |
|
45 | - $next_db_state), $current_db_state, $next_db_state); ?></a> |
|
44 | + sprintf(esc_html__("My Database Is Backed Up, Continue", "event_espresso"), $current_db_state, |
|
45 | + $next_db_state), $current_db_state, $next_db_state); ?></a> |
|
46 | 46 | </td> |
47 | 47 | </tr> |
48 | 48 | <tr> |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | <div id="migration-details-dv" style="display: none; padding: 1em;"> |
51 | 51 | <p> |
52 | 52 | <?php |
53 | - printf( |
|
54 | - esc_html__('%1$sClick Here to Learn How To Backup your Database Yourself%2$s. Or have one of our dedicated support technicians help you by %3$spurchasing a Priority Support Token.%2$s', |
|
55 | - "event_espresso"), |
|
56 | - '<a target="_blank" href="http://eventespresso.com/wiki/how-to-back-up-your-site/">', |
|
57 | - "</a>", |
|
58 | - "<a target=\"_blank\" href='http://eventespresso.com/product/priority-support-tokens/'>" |
|
59 | - ); |
|
60 | - ?> |
|
53 | + printf( |
|
54 | + esc_html__('%1$sClick Here to Learn How To Backup your Database Yourself%2$s. Or have one of our dedicated support technicians help you by %3$spurchasing a Priority Support Token.%2$s', |
|
55 | + "event_espresso"), |
|
56 | + '<a target="_blank" href="http://eventespresso.com/wiki/how-to-back-up-your-site/">', |
|
57 | + "</a>", |
|
58 | + "<a target=\"_blank\" href='http://eventespresso.com/product/priority-support-tokens/'>" |
|
59 | + ); |
|
60 | + ?> |
|
61 | 61 | </p> |
62 | 62 | <?php do_action('AHEE__ee_migration_page__option_1_extra_details'); ?> |
63 | 63 | </div> |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | </table> |
68 | 68 | </div> |
69 | 69 | <p><?php esc_html_e('Don\'t want to keep your old Event Espresso data? Alternatively, you can delete it all and start fresh.', |
70 | - 'event_espresso'); ?> <a |
|
70 | + 'event_espresso'); ?> <a |
|
71 | 71 | href="<?php echo $data_reset_page;?>"><?php esc_html_e('Visit the Maintenance Page and Reset Your Event Espresso Data', |
72 | - 'event_espresso'); ?></a></p> |
|
72 | + 'event_espresso'); ?></a></p> |
|
73 | 73 | <?php do_action('AHEE__ee_migration_page__after_migration_options_table'); ?> |
74 | 74 | </div> |
75 | 75 | \ No newline at end of file |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @access public |
261 | 261 | * @param EE_Ticket $ticket |
262 | 262 | * @param int $qty |
263 | - * @return TRUE on success, FALSE on fail |
|
263 | + * @return boolean on success, FALSE on fail |
|
264 | 264 | * @throws \EE_Error |
265 | 265 | */ |
266 | 266 | public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | * @save cart to session |
386 | 386 | * @access public |
387 | 387 | * @param bool $apply_taxes |
388 | - * @return TRUE on success, FALSE on fail |
|
388 | + * @return boolean on success, FALSE on fail |
|
389 | 389 | * @throws \EE_Error |
390 | 390 | */ |
391 | 391 | public function save_cart($apply_taxes = true) |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | |
420 | 420 | |
421 | 421 | /** |
422 | - * @return array |
|
422 | + * @return string[] |
|
423 | 423 | */ |
424 | 424 | public function __sleep() |
425 | 425 | { |
@@ -203,7 +203,7 @@ |
||
203 | 203 | */ |
204 | 204 | public function get_tickets() |
205 | 205 | { |
206 | - if ($this->_grand_total === null ) { |
|
206 | + if ($this->_grand_total === null) { |
|
207 | 207 | return array(); |
208 | 208 | } |
209 | 209 | return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\interfaces\ResettableInterface; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
8 | 8 | |
@@ -23,421 +23,421 @@ discard block |
||
23 | 23 | class EE_Cart implements ResettableInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * instance of the EE_Cart object |
|
28 | - * |
|
29 | - * @access private |
|
30 | - * @var EE_Cart $_instance |
|
31 | - */ |
|
32 | - private static $_instance; |
|
33 | - |
|
34 | - /** |
|
35 | - * instance of the EE_Session object |
|
36 | - * |
|
37 | - * @access protected |
|
38 | - * @var EE_Session $_session |
|
39 | - */ |
|
40 | - protected $_session; |
|
41 | - |
|
42 | - /** |
|
43 | - * The total Line item which comprises all the children line-item subtotals, |
|
44 | - * which in turn each have their line items. |
|
45 | - * Typically, the line item structure will look like: |
|
46 | - * grand total |
|
47 | - * -tickets-sub-total |
|
48 | - * --ticket1 |
|
49 | - * --ticket2 |
|
50 | - * --... |
|
51 | - * -taxes-sub-total |
|
52 | - * --tax1 |
|
53 | - * --tax2 |
|
54 | - * |
|
55 | - * @var EE_Line_Item |
|
56 | - */ |
|
57 | - private $_grand_total; |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @singleton method used to instantiate class object |
|
63 | - * @access public |
|
64 | - * @param EE_Line_Item $grand_total |
|
65 | - * @param EE_Session $session |
|
66 | - * @return \EE_Cart |
|
67 | - * @throws \EE_Error |
|
68 | - */ |
|
69 | - public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
70 | - { |
|
71 | - if ( ! empty($grand_total)) { |
|
72 | - self::$_instance = new self($grand_total, $session); |
|
73 | - } |
|
74 | - // or maybe retrieve an existing one ? |
|
75 | - if ( ! self::$_instance instanceof EE_Cart) { |
|
76 | - // try getting the cart out of the session |
|
77 | - $saved_cart = $session instanceof EE_Session ? $session->cart() : null; |
|
78 | - self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session); |
|
79 | - unset($saved_cart); |
|
80 | - } |
|
81 | - // verify that cart is ok and grand total line item exists |
|
82 | - if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) { |
|
83 | - self::$_instance = new self($grand_total, $session); |
|
84 | - } |
|
85 | - self::$_instance->get_grand_total(); |
|
86 | - // once everything is all said and done, save the cart to the EE_Session |
|
87 | - add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
88 | - return self::$_instance; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * private constructor to prevent direct creation |
|
95 | - * |
|
96 | - * @Constructor |
|
97 | - * @access private |
|
98 | - * @param EE_Line_Item $grand_total |
|
99 | - * @param EE_Session $session |
|
100 | - */ |
|
101 | - private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
102 | - { |
|
103 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
104 | - $this->set_session($session); |
|
105 | - if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) { |
|
106 | - $this->set_grand_total_line_item($grand_total); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Resets the cart completely (whereas empty_cart |
|
114 | - * |
|
115 | - * @param EE_Line_Item $grand_total |
|
116 | - * @param EE_Session $session |
|
117 | - * @return EE_Cart |
|
118 | - * @throws \EE_Error |
|
119 | - */ |
|
120 | - public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
121 | - { |
|
122 | - remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
123 | - if ($session instanceof EE_Session) { |
|
124 | - $session->reset_cart(); |
|
125 | - } |
|
126 | - self::$_instance = null; |
|
127 | - return self::instance($grand_total, $session); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return \EE_Session |
|
134 | - */ |
|
135 | - public function session() |
|
136 | - { |
|
137 | - if ( ! $this->_session instanceof EE_Session) { |
|
138 | - $this->set_session(); |
|
139 | - } |
|
140 | - return $this->_session; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param EE_Session $session |
|
147 | - */ |
|
148 | - public function set_session(EE_Session $session = null) |
|
149 | - { |
|
150 | - $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session'); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * Sets the cart to match the line item. Especially handy for loading an old cart where you |
|
157 | - * know the grand total line item on it |
|
158 | - * |
|
159 | - * @param EE_Line_Item $line_item |
|
160 | - */ |
|
161 | - public function set_grand_total_line_item(EE_Line_Item $line_item) |
|
162 | - { |
|
163 | - $this->_grand_total = $line_item; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * get_cart_from_reg_url_link |
|
170 | - * |
|
171 | - * @access public |
|
172 | - * @param EE_Transaction $transaction |
|
173 | - * @param EE_Session $session |
|
174 | - * @return \EE_Cart |
|
175 | - * @throws \EE_Error |
|
176 | - */ |
|
177 | - public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) |
|
178 | - { |
|
179 | - $grand_total = $transaction->total_line_item(); |
|
180 | - $grand_total->get_items(); |
|
181 | - $grand_total->tax_descendants(); |
|
182 | - return EE_Cart::instance($grand_total, $session); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
|
189 | - * |
|
190 | - * @return EE_Line_Item |
|
191 | - * @throws \EE_Error |
|
192 | - */ |
|
193 | - private function _create_grand_total() |
|
194 | - { |
|
195 | - $this->_grand_total = EEH_Line_Item::create_total_line_item(); |
|
196 | - return $this->_grand_total; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Gets all the line items of object type Ticket |
|
203 | - * |
|
204 | - * @access public |
|
205 | - * @return \EE_Line_Item[] |
|
206 | - */ |
|
207 | - public function get_tickets() |
|
208 | - { |
|
209 | - if ($this->_grand_total === null ) { |
|
210 | - return array(); |
|
211 | - } |
|
212 | - return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * returns the total quantity of tickets in the cart |
|
219 | - * |
|
220 | - * @access public |
|
221 | - * @return int |
|
222 | - * @throws \EE_Error |
|
223 | - */ |
|
224 | - public function all_ticket_quantity_count() |
|
225 | - { |
|
226 | - $tickets = $this->get_tickets(); |
|
227 | - if (empty($tickets)) { |
|
228 | - return 0; |
|
229 | - } |
|
230 | - $count = 0; |
|
231 | - foreach ($tickets as $ticket) { |
|
232 | - $count += $ticket->get('LIN_quantity'); |
|
233 | - } |
|
234 | - return $count; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Gets all the tax line items |
|
241 | - * |
|
242 | - * @return \EE_Line_Item[] |
|
243 | - * @throws \EE_Error |
|
244 | - */ |
|
245 | - public function get_taxes() |
|
246 | - { |
|
247 | - return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * Gets the total line item (which is a parent of all other line items) on this cart |
|
254 | - * |
|
255 | - * @return EE_Line_Item |
|
256 | - * @throws \EE_Error |
|
257 | - */ |
|
258 | - public function get_grand_total() |
|
259 | - { |
|
260 | - return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @process items for adding to cart |
|
267 | - * @access public |
|
268 | - * @param EE_Ticket $ticket |
|
269 | - * @param int $qty |
|
270 | - * @return TRUE on success, FALSE on fail |
|
271 | - * @throws \EE_Error |
|
272 | - */ |
|
273 | - public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
|
274 | - { |
|
275 | - EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty); |
|
276 | - return $this->save_cart() ? true : false; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * get_cart_total_before_tax |
|
283 | - * |
|
284 | - * @access public |
|
285 | - * @return float |
|
286 | - * @throws \EE_Error |
|
287 | - */ |
|
288 | - public function get_cart_total_before_tax() |
|
289 | - { |
|
290 | - return $this->get_grand_total()->recalculate_pre_tax_total(); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * gets the total amount of tax paid for items in this cart |
|
297 | - * |
|
298 | - * @access public |
|
299 | - * @return float |
|
300 | - * @throws \EE_Error |
|
301 | - */ |
|
302 | - public function get_applied_taxes() |
|
303 | - { |
|
304 | - return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
311 | - * |
|
312 | - * @access public |
|
313 | - * @return float |
|
314 | - * @throws \EE_Error |
|
315 | - */ |
|
316 | - public function get_cart_grand_total() |
|
317 | - { |
|
318 | - EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
319 | - return $this->get_grand_total()->total(); |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
326 | - * |
|
327 | - * @access public |
|
328 | - * @return float |
|
329 | - * @throws \EE_Error |
|
330 | - */ |
|
331 | - public function recalculate_all_cart_totals() |
|
332 | - { |
|
333 | - $pre_tax_total = $this->get_cart_total_before_tax(); |
|
334 | - $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
335 | - $this->_grand_total->set_total($pre_tax_total + $taxes_total); |
|
336 | - $this->_grand_total->save_this_and_descendants_to_txn(); |
|
337 | - return $this->get_grand_total()->total(); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * deletes an item from the cart |
|
344 | - * |
|
345 | - * @access public |
|
346 | - * @param array|bool|string $line_item_codes |
|
347 | - * @return int on success, FALSE on fail |
|
348 | - * @throws \EE_Error |
|
349 | - */ |
|
350 | - public function delete_items($line_item_codes = false) |
|
351 | - { |
|
352 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
353 | - return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * @remove ALL items from cart and zero ALL totals |
|
360 | - * @access public |
|
361 | - * @return bool |
|
362 | - * @throws \EE_Error |
|
363 | - */ |
|
364 | - public function empty_cart() |
|
365 | - { |
|
366 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
367 | - $this->_grand_total = $this->_create_grand_total(); |
|
368 | - return $this->save_cart(true); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * @remove ALL items from cart and delete total as well |
|
375 | - * @access public |
|
376 | - * @return bool |
|
377 | - * @throws \EE_Error |
|
378 | - */ |
|
379 | - public function delete_cart() |
|
380 | - { |
|
381 | - if ($this->_grand_total instanceof EE_Line_Item) { |
|
382 | - $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total); |
|
383 | - if ($deleted) { |
|
384 | - $deleted += $this->_grand_total->delete(); |
|
385 | - $this->_grand_total = null; |
|
386 | - return true; |
|
387 | - } |
|
388 | - } |
|
389 | - return false; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * @save cart to session |
|
396 | - * @access public |
|
397 | - * @param bool $apply_taxes |
|
398 | - * @return TRUE on success, FALSE on fail |
|
399 | - * @throws \EE_Error |
|
400 | - */ |
|
401 | - public function save_cart($apply_taxes = true) |
|
402 | - { |
|
403 | - if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) { |
|
404 | - EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
405 | - //make sure we don't cache the transaction because it can get stale |
|
406 | - if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction |
|
407 | - && $this->_grand_total->get_one_from_cache('Transaction')->ID() |
|
408 | - ) { |
|
409 | - $this->_grand_total->clear_cache('Transaction', null, true); |
|
410 | - } |
|
411 | - } |
|
412 | - if ($this->session() instanceof EE_Session) { |
|
413 | - return $this->session()->set_cart($this); |
|
414 | - } else { |
|
415 | - return false; |
|
416 | - } |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - |
|
421 | - public function __wakeup() |
|
422 | - { |
|
423 | - if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) { |
|
424 | - // $this->_grand_total is actually just an ID, so use it to get the object from the db |
|
425 | - $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total); |
|
426 | - } |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * @return array |
|
433 | - */ |
|
434 | - public function __sleep() |
|
435 | - { |
|
436 | - if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) { |
|
437 | - $this->_grand_total = $this->_grand_total->ID(); |
|
438 | - } |
|
439 | - return array('_grand_total'); |
|
440 | - } |
|
26 | + /** |
|
27 | + * instance of the EE_Cart object |
|
28 | + * |
|
29 | + * @access private |
|
30 | + * @var EE_Cart $_instance |
|
31 | + */ |
|
32 | + private static $_instance; |
|
33 | + |
|
34 | + /** |
|
35 | + * instance of the EE_Session object |
|
36 | + * |
|
37 | + * @access protected |
|
38 | + * @var EE_Session $_session |
|
39 | + */ |
|
40 | + protected $_session; |
|
41 | + |
|
42 | + /** |
|
43 | + * The total Line item which comprises all the children line-item subtotals, |
|
44 | + * which in turn each have their line items. |
|
45 | + * Typically, the line item structure will look like: |
|
46 | + * grand total |
|
47 | + * -tickets-sub-total |
|
48 | + * --ticket1 |
|
49 | + * --ticket2 |
|
50 | + * --... |
|
51 | + * -taxes-sub-total |
|
52 | + * --tax1 |
|
53 | + * --tax2 |
|
54 | + * |
|
55 | + * @var EE_Line_Item |
|
56 | + */ |
|
57 | + private $_grand_total; |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @singleton method used to instantiate class object |
|
63 | + * @access public |
|
64 | + * @param EE_Line_Item $grand_total |
|
65 | + * @param EE_Session $session |
|
66 | + * @return \EE_Cart |
|
67 | + * @throws \EE_Error |
|
68 | + */ |
|
69 | + public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
70 | + { |
|
71 | + if ( ! empty($grand_total)) { |
|
72 | + self::$_instance = new self($grand_total, $session); |
|
73 | + } |
|
74 | + // or maybe retrieve an existing one ? |
|
75 | + if ( ! self::$_instance instanceof EE_Cart) { |
|
76 | + // try getting the cart out of the session |
|
77 | + $saved_cart = $session instanceof EE_Session ? $session->cart() : null; |
|
78 | + self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session); |
|
79 | + unset($saved_cart); |
|
80 | + } |
|
81 | + // verify that cart is ok and grand total line item exists |
|
82 | + if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) { |
|
83 | + self::$_instance = new self($grand_total, $session); |
|
84 | + } |
|
85 | + self::$_instance->get_grand_total(); |
|
86 | + // once everything is all said and done, save the cart to the EE_Session |
|
87 | + add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
88 | + return self::$_instance; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * private constructor to prevent direct creation |
|
95 | + * |
|
96 | + * @Constructor |
|
97 | + * @access private |
|
98 | + * @param EE_Line_Item $grand_total |
|
99 | + * @param EE_Session $session |
|
100 | + */ |
|
101 | + private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
102 | + { |
|
103 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
104 | + $this->set_session($session); |
|
105 | + if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) { |
|
106 | + $this->set_grand_total_line_item($grand_total); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Resets the cart completely (whereas empty_cart |
|
114 | + * |
|
115 | + * @param EE_Line_Item $grand_total |
|
116 | + * @param EE_Session $session |
|
117 | + * @return EE_Cart |
|
118 | + * @throws \EE_Error |
|
119 | + */ |
|
120 | + public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
121 | + { |
|
122 | + remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
123 | + if ($session instanceof EE_Session) { |
|
124 | + $session->reset_cart(); |
|
125 | + } |
|
126 | + self::$_instance = null; |
|
127 | + return self::instance($grand_total, $session); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return \EE_Session |
|
134 | + */ |
|
135 | + public function session() |
|
136 | + { |
|
137 | + if ( ! $this->_session instanceof EE_Session) { |
|
138 | + $this->set_session(); |
|
139 | + } |
|
140 | + return $this->_session; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param EE_Session $session |
|
147 | + */ |
|
148 | + public function set_session(EE_Session $session = null) |
|
149 | + { |
|
150 | + $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session'); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * Sets the cart to match the line item. Especially handy for loading an old cart where you |
|
157 | + * know the grand total line item on it |
|
158 | + * |
|
159 | + * @param EE_Line_Item $line_item |
|
160 | + */ |
|
161 | + public function set_grand_total_line_item(EE_Line_Item $line_item) |
|
162 | + { |
|
163 | + $this->_grand_total = $line_item; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * get_cart_from_reg_url_link |
|
170 | + * |
|
171 | + * @access public |
|
172 | + * @param EE_Transaction $transaction |
|
173 | + * @param EE_Session $session |
|
174 | + * @return \EE_Cart |
|
175 | + * @throws \EE_Error |
|
176 | + */ |
|
177 | + public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) |
|
178 | + { |
|
179 | + $grand_total = $transaction->total_line_item(); |
|
180 | + $grand_total->get_items(); |
|
181 | + $grand_total->tax_descendants(); |
|
182 | + return EE_Cart::instance($grand_total, $session); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
|
189 | + * |
|
190 | + * @return EE_Line_Item |
|
191 | + * @throws \EE_Error |
|
192 | + */ |
|
193 | + private function _create_grand_total() |
|
194 | + { |
|
195 | + $this->_grand_total = EEH_Line_Item::create_total_line_item(); |
|
196 | + return $this->_grand_total; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Gets all the line items of object type Ticket |
|
203 | + * |
|
204 | + * @access public |
|
205 | + * @return \EE_Line_Item[] |
|
206 | + */ |
|
207 | + public function get_tickets() |
|
208 | + { |
|
209 | + if ($this->_grand_total === null ) { |
|
210 | + return array(); |
|
211 | + } |
|
212 | + return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * returns the total quantity of tickets in the cart |
|
219 | + * |
|
220 | + * @access public |
|
221 | + * @return int |
|
222 | + * @throws \EE_Error |
|
223 | + */ |
|
224 | + public function all_ticket_quantity_count() |
|
225 | + { |
|
226 | + $tickets = $this->get_tickets(); |
|
227 | + if (empty($tickets)) { |
|
228 | + return 0; |
|
229 | + } |
|
230 | + $count = 0; |
|
231 | + foreach ($tickets as $ticket) { |
|
232 | + $count += $ticket->get('LIN_quantity'); |
|
233 | + } |
|
234 | + return $count; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Gets all the tax line items |
|
241 | + * |
|
242 | + * @return \EE_Line_Item[] |
|
243 | + * @throws \EE_Error |
|
244 | + */ |
|
245 | + public function get_taxes() |
|
246 | + { |
|
247 | + return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * Gets the total line item (which is a parent of all other line items) on this cart |
|
254 | + * |
|
255 | + * @return EE_Line_Item |
|
256 | + * @throws \EE_Error |
|
257 | + */ |
|
258 | + public function get_grand_total() |
|
259 | + { |
|
260 | + return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @process items for adding to cart |
|
267 | + * @access public |
|
268 | + * @param EE_Ticket $ticket |
|
269 | + * @param int $qty |
|
270 | + * @return TRUE on success, FALSE on fail |
|
271 | + * @throws \EE_Error |
|
272 | + */ |
|
273 | + public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
|
274 | + { |
|
275 | + EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty); |
|
276 | + return $this->save_cart() ? true : false; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * get_cart_total_before_tax |
|
283 | + * |
|
284 | + * @access public |
|
285 | + * @return float |
|
286 | + * @throws \EE_Error |
|
287 | + */ |
|
288 | + public function get_cart_total_before_tax() |
|
289 | + { |
|
290 | + return $this->get_grand_total()->recalculate_pre_tax_total(); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * gets the total amount of tax paid for items in this cart |
|
297 | + * |
|
298 | + * @access public |
|
299 | + * @return float |
|
300 | + * @throws \EE_Error |
|
301 | + */ |
|
302 | + public function get_applied_taxes() |
|
303 | + { |
|
304 | + return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
311 | + * |
|
312 | + * @access public |
|
313 | + * @return float |
|
314 | + * @throws \EE_Error |
|
315 | + */ |
|
316 | + public function get_cart_grand_total() |
|
317 | + { |
|
318 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
319 | + return $this->get_grand_total()->total(); |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
326 | + * |
|
327 | + * @access public |
|
328 | + * @return float |
|
329 | + * @throws \EE_Error |
|
330 | + */ |
|
331 | + public function recalculate_all_cart_totals() |
|
332 | + { |
|
333 | + $pre_tax_total = $this->get_cart_total_before_tax(); |
|
334 | + $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
335 | + $this->_grand_total->set_total($pre_tax_total + $taxes_total); |
|
336 | + $this->_grand_total->save_this_and_descendants_to_txn(); |
|
337 | + return $this->get_grand_total()->total(); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * deletes an item from the cart |
|
344 | + * |
|
345 | + * @access public |
|
346 | + * @param array|bool|string $line_item_codes |
|
347 | + * @return int on success, FALSE on fail |
|
348 | + * @throws \EE_Error |
|
349 | + */ |
|
350 | + public function delete_items($line_item_codes = false) |
|
351 | + { |
|
352 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
353 | + return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * @remove ALL items from cart and zero ALL totals |
|
360 | + * @access public |
|
361 | + * @return bool |
|
362 | + * @throws \EE_Error |
|
363 | + */ |
|
364 | + public function empty_cart() |
|
365 | + { |
|
366 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
367 | + $this->_grand_total = $this->_create_grand_total(); |
|
368 | + return $this->save_cart(true); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * @remove ALL items from cart and delete total as well |
|
375 | + * @access public |
|
376 | + * @return bool |
|
377 | + * @throws \EE_Error |
|
378 | + */ |
|
379 | + public function delete_cart() |
|
380 | + { |
|
381 | + if ($this->_grand_total instanceof EE_Line_Item) { |
|
382 | + $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total); |
|
383 | + if ($deleted) { |
|
384 | + $deleted += $this->_grand_total->delete(); |
|
385 | + $this->_grand_total = null; |
|
386 | + return true; |
|
387 | + } |
|
388 | + } |
|
389 | + return false; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * @save cart to session |
|
396 | + * @access public |
|
397 | + * @param bool $apply_taxes |
|
398 | + * @return TRUE on success, FALSE on fail |
|
399 | + * @throws \EE_Error |
|
400 | + */ |
|
401 | + public function save_cart($apply_taxes = true) |
|
402 | + { |
|
403 | + if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) { |
|
404 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
405 | + //make sure we don't cache the transaction because it can get stale |
|
406 | + if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction |
|
407 | + && $this->_grand_total->get_one_from_cache('Transaction')->ID() |
|
408 | + ) { |
|
409 | + $this->_grand_total->clear_cache('Transaction', null, true); |
|
410 | + } |
|
411 | + } |
|
412 | + if ($this->session() instanceof EE_Session) { |
|
413 | + return $this->session()->set_cart($this); |
|
414 | + } else { |
|
415 | + return false; |
|
416 | + } |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + |
|
421 | + public function __wakeup() |
|
422 | + { |
|
423 | + if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) { |
|
424 | + // $this->_grand_total is actually just an ID, so use it to get the object from the db |
|
425 | + $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total); |
|
426 | + } |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * @return array |
|
433 | + */ |
|
434 | + public function __sleep() |
|
435 | + { |
|
436 | + if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) { |
|
437 | + $this->_grand_total = $this->_grand_total->ID(); |
|
438 | + } |
|
439 | + return array('_grand_total'); |
|
440 | + } |
|
441 | 441 | |
442 | 442 | |
443 | 443 | } |
@@ -613,7 +613,7 @@ discard block |
||
613 | 613 | * |
614 | 614 | * @since 4.6.0 |
615 | 615 | * @global WPDB $wpdb |
616 | - * @return mixed null|int WP_user ID or NULL |
|
616 | + * @return integer|null null|int WP_user ID or NULL |
|
617 | 617 | */ |
618 | 618 | public static function get_default_creator_id() |
619 | 619 | { |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | * @static |
775 | 775 | * @deprecated instead use TableManager::dropTable() |
776 | 776 | * @param string $table_name |
777 | - * @return bool | int |
|
777 | + * @return integer | int |
|
778 | 778 | */ |
779 | 779 | public static function delete_unused_db_table($table_name) |
780 | 780 | { |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | * @deprecated instead use TableManager::dropIndex() |
792 | 792 | * @param string $table_name |
793 | 793 | * @param string $index_name |
794 | - * @return bool | int |
|
794 | + * @return integer | int |
|
795 | 795 | */ |
796 | 796 | public static function drop_index($table_name, $index_name) |
797 | 797 | { |
@@ -18,243 +18,243 @@ discard block |
||
18 | 18 | class EEH_Activation implements ResettableInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * constant used to indicate a cron task is no longer in use |
|
23 | - */ |
|
24 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
25 | - |
|
26 | - /** |
|
27 | - * option name that will indicate whether or not we still |
|
28 | - * need to create EE's folders in the uploads directory |
|
29 | - * (because if EE was installed without file system access, |
|
30 | - * we need to request credentials before we can create them) |
|
31 | - */ |
|
32 | - const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
33 | - |
|
34 | - /** |
|
35 | - * WP_User->ID |
|
36 | - * |
|
37 | - * @var int |
|
38 | - */ |
|
39 | - private static $_default_creator_id; |
|
40 | - |
|
41 | - /** |
|
42 | - * indicates whether or not we've already verified core's default data during this request, |
|
43 | - * because after migrations are done, any addons activated while in maintenance mode |
|
44 | - * will want to setup their own default data, and they might hook into core's default data |
|
45 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
46 | - * This prevents doing that for EVERY single addon. |
|
47 | - * |
|
48 | - * @var boolean |
|
49 | - */ |
|
50 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
54 | - */ |
|
55 | - private static $table_analysis; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
59 | - */ |
|
60 | - private static $table_manager; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @return \EventEspresso\core\services\database\TableAnalysis |
|
65 | - */ |
|
66 | - public static function getTableAnalysis() |
|
67 | - { |
|
68 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
69 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
70 | - } |
|
71 | - return self::$table_analysis; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @return \EventEspresso\core\services\database\TableManager |
|
77 | - */ |
|
78 | - public static function getTableManager() |
|
79 | - { |
|
80 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
81 | - self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
82 | - } |
|
83 | - return self::$table_manager; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * _ensure_table_name_has_prefix |
|
89 | - * |
|
90 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
91 | - * @access public |
|
92 | - * @static |
|
93 | - * @param $table_name |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public static function ensure_table_name_has_prefix($table_name) |
|
97 | - { |
|
98 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * system_initialization |
|
104 | - * ensures the EE configuration settings are loaded with at least default options set |
|
105 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
106 | - * |
|
107 | - * @access public |
|
108 | - * @static |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - public static function system_initialization() |
|
112 | - { |
|
113 | - EEH_Activation::reset_and_update_config(); |
|
114 | - //which is fired BEFORE activation of plugin anyways |
|
115 | - EEH_Activation::verify_default_pages_exist(); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Sets the database schema and creates folders. This should |
|
121 | - * be called on plugin activation and reactivation |
|
122 | - * |
|
123 | - * @return boolean success, whether the database and folders are setup properly |
|
124 | - * @throws \EE_Error |
|
125 | - */ |
|
126 | - public static function initialize_db_and_folders() |
|
127 | - { |
|
128 | - $good_filesystem = EEH_Activation::create_upload_directories(); |
|
129 | - $good_db = EEH_Activation::create_database_tables(); |
|
130 | - return $good_filesystem && $good_db; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * assuming we have an up-to-date database schema, this will populate it |
|
136 | - * with default and initial data. This should be called |
|
137 | - * upon activation of a new plugin, reactivation, and at the end |
|
138 | - * of running migration scripts |
|
139 | - * |
|
140 | - * @throws \EE_Error |
|
141 | - */ |
|
142 | - public static function initialize_db_content() |
|
143 | - { |
|
144 | - //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
145 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
146 | - return; |
|
147 | - } |
|
148 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
149 | - |
|
150 | - EEH_Activation::initialize_system_questions(); |
|
151 | - EEH_Activation::insert_default_status_codes(); |
|
152 | - EEH_Activation::generate_default_message_templates(); |
|
153 | - EEH_Activation::create_no_ticket_prices_array(); |
|
154 | - |
|
155 | - EEH_Activation::validate_messages_system(); |
|
156 | - EEH_Activation::insert_default_payment_methods(); |
|
157 | - //in case we've |
|
158 | - EEH_Activation::remove_cron_tasks(); |
|
159 | - EEH_Activation::create_cron_tasks(); |
|
160 | - // remove all TXN locks since that is being done via extra meta now |
|
161 | - delete_option('ee_locked_transactions'); |
|
162 | - //also, check for CAF default db content |
|
163 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
164 | - //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
165 | - //which users really won't care about on initial activation |
|
166 | - EE_Error::overwrite_success(); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
172 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
173 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
174 | - * (null) |
|
175 | - * |
|
176 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
177 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
178 | - * @return array |
|
179 | - * @throws \EE_Error |
|
180 | - */ |
|
181 | - public static function get_cron_tasks($which_to_include) |
|
182 | - { |
|
183 | - $cron_tasks = apply_filters( |
|
184 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
185 | - array( |
|
186 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
21 | + /** |
|
22 | + * constant used to indicate a cron task is no longer in use |
|
23 | + */ |
|
24 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
25 | + |
|
26 | + /** |
|
27 | + * option name that will indicate whether or not we still |
|
28 | + * need to create EE's folders in the uploads directory |
|
29 | + * (because if EE was installed without file system access, |
|
30 | + * we need to request credentials before we can create them) |
|
31 | + */ |
|
32 | + const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
33 | + |
|
34 | + /** |
|
35 | + * WP_User->ID |
|
36 | + * |
|
37 | + * @var int |
|
38 | + */ |
|
39 | + private static $_default_creator_id; |
|
40 | + |
|
41 | + /** |
|
42 | + * indicates whether or not we've already verified core's default data during this request, |
|
43 | + * because after migrations are done, any addons activated while in maintenance mode |
|
44 | + * will want to setup their own default data, and they might hook into core's default data |
|
45 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
46 | + * This prevents doing that for EVERY single addon. |
|
47 | + * |
|
48 | + * @var boolean |
|
49 | + */ |
|
50 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
54 | + */ |
|
55 | + private static $table_analysis; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
59 | + */ |
|
60 | + private static $table_manager; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @return \EventEspresso\core\services\database\TableAnalysis |
|
65 | + */ |
|
66 | + public static function getTableAnalysis() |
|
67 | + { |
|
68 | + if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
69 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
70 | + } |
|
71 | + return self::$table_analysis; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @return \EventEspresso\core\services\database\TableManager |
|
77 | + */ |
|
78 | + public static function getTableManager() |
|
79 | + { |
|
80 | + if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
81 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
82 | + } |
|
83 | + return self::$table_manager; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * _ensure_table_name_has_prefix |
|
89 | + * |
|
90 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
91 | + * @access public |
|
92 | + * @static |
|
93 | + * @param $table_name |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public static function ensure_table_name_has_prefix($table_name) |
|
97 | + { |
|
98 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * system_initialization |
|
104 | + * ensures the EE configuration settings are loaded with at least default options set |
|
105 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
106 | + * |
|
107 | + * @access public |
|
108 | + * @static |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + public static function system_initialization() |
|
112 | + { |
|
113 | + EEH_Activation::reset_and_update_config(); |
|
114 | + //which is fired BEFORE activation of plugin anyways |
|
115 | + EEH_Activation::verify_default_pages_exist(); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Sets the database schema and creates folders. This should |
|
121 | + * be called on plugin activation and reactivation |
|
122 | + * |
|
123 | + * @return boolean success, whether the database and folders are setup properly |
|
124 | + * @throws \EE_Error |
|
125 | + */ |
|
126 | + public static function initialize_db_and_folders() |
|
127 | + { |
|
128 | + $good_filesystem = EEH_Activation::create_upload_directories(); |
|
129 | + $good_db = EEH_Activation::create_database_tables(); |
|
130 | + return $good_filesystem && $good_db; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * assuming we have an up-to-date database schema, this will populate it |
|
136 | + * with default and initial data. This should be called |
|
137 | + * upon activation of a new plugin, reactivation, and at the end |
|
138 | + * of running migration scripts |
|
139 | + * |
|
140 | + * @throws \EE_Error |
|
141 | + */ |
|
142 | + public static function initialize_db_content() |
|
143 | + { |
|
144 | + //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
145 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
146 | + return; |
|
147 | + } |
|
148 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
149 | + |
|
150 | + EEH_Activation::initialize_system_questions(); |
|
151 | + EEH_Activation::insert_default_status_codes(); |
|
152 | + EEH_Activation::generate_default_message_templates(); |
|
153 | + EEH_Activation::create_no_ticket_prices_array(); |
|
154 | + |
|
155 | + EEH_Activation::validate_messages_system(); |
|
156 | + EEH_Activation::insert_default_payment_methods(); |
|
157 | + //in case we've |
|
158 | + EEH_Activation::remove_cron_tasks(); |
|
159 | + EEH_Activation::create_cron_tasks(); |
|
160 | + // remove all TXN locks since that is being done via extra meta now |
|
161 | + delete_option('ee_locked_transactions'); |
|
162 | + //also, check for CAF default db content |
|
163 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
164 | + //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
165 | + //which users really won't care about on initial activation |
|
166 | + EE_Error::overwrite_success(); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
172 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
173 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
174 | + * (null) |
|
175 | + * |
|
176 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
177 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
178 | + * @return array |
|
179 | + * @throws \EE_Error |
|
180 | + */ |
|
181 | + public static function get_cron_tasks($which_to_include) |
|
182 | + { |
|
183 | + $cron_tasks = apply_filters( |
|
184 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
185 | + array( |
|
186 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
187 | 187 | // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
188 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
189 | - //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
190 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
191 | - ) |
|
192 | - ); |
|
193 | - if ($which_to_include === 'old') { |
|
194 | - $cron_tasks = array_filter( |
|
195 | - $cron_tasks, |
|
196 | - function ($value) { |
|
197 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
198 | - } |
|
199 | - ); |
|
200 | - } elseif ($which_to_include === 'current') { |
|
201 | - $cron_tasks = array_filter($cron_tasks); |
|
202 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
203 | - throw new EE_Error( |
|
204 | - sprintf( |
|
205 | - __( |
|
206 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
207 | - 'event_espresso' |
|
208 | - ), |
|
209 | - $which_to_include |
|
210 | - ) |
|
211 | - ); |
|
212 | - } |
|
213 | - return $cron_tasks; |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
219 | - * |
|
220 | - * @throws \EE_Error |
|
221 | - */ |
|
222 | - public static function create_cron_tasks() |
|
223 | - { |
|
224 | - |
|
225 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
226 | - if (! wp_next_scheduled($hook_name)) { |
|
227 | - /** |
|
228 | - * This allows client code to define the initial start timestamp for this schedule. |
|
229 | - */ |
|
230 | - if (is_array($frequency) |
|
231 | - && count($frequency) === 2 |
|
232 | - && isset($frequency[0], $frequency[1]) |
|
233 | - ) { |
|
234 | - $start_timestamp = $frequency[0]; |
|
235 | - $frequency = $frequency[1]; |
|
236 | - } else { |
|
237 | - $start_timestamp = time(); |
|
238 | - } |
|
239 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * Remove the currently-existing and now-removed cron tasks. |
|
248 | - * |
|
249 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
250 | - * @throws \EE_Error |
|
251 | - */ |
|
252 | - public static function remove_cron_tasks($remove_all = true) |
|
253 | - { |
|
254 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
255 | - $crons = _get_cron_array(); |
|
256 | - $crons = is_array($crons) ? $crons : array(); |
|
257 | - /* reminder of what $crons look like: |
|
188 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
189 | + //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
190 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
191 | + ) |
|
192 | + ); |
|
193 | + if ($which_to_include === 'old') { |
|
194 | + $cron_tasks = array_filter( |
|
195 | + $cron_tasks, |
|
196 | + function ($value) { |
|
197 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
198 | + } |
|
199 | + ); |
|
200 | + } elseif ($which_to_include === 'current') { |
|
201 | + $cron_tasks = array_filter($cron_tasks); |
|
202 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
203 | + throw new EE_Error( |
|
204 | + sprintf( |
|
205 | + __( |
|
206 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
207 | + 'event_espresso' |
|
208 | + ), |
|
209 | + $which_to_include |
|
210 | + ) |
|
211 | + ); |
|
212 | + } |
|
213 | + return $cron_tasks; |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
219 | + * |
|
220 | + * @throws \EE_Error |
|
221 | + */ |
|
222 | + public static function create_cron_tasks() |
|
223 | + { |
|
224 | + |
|
225 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
226 | + if (! wp_next_scheduled($hook_name)) { |
|
227 | + /** |
|
228 | + * This allows client code to define the initial start timestamp for this schedule. |
|
229 | + */ |
|
230 | + if (is_array($frequency) |
|
231 | + && count($frequency) === 2 |
|
232 | + && isset($frequency[0], $frequency[1]) |
|
233 | + ) { |
|
234 | + $start_timestamp = $frequency[0]; |
|
235 | + $frequency = $frequency[1]; |
|
236 | + } else { |
|
237 | + $start_timestamp = time(); |
|
238 | + } |
|
239 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * Remove the currently-existing and now-removed cron tasks. |
|
248 | + * |
|
249 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
250 | + * @throws \EE_Error |
|
251 | + */ |
|
252 | + public static function remove_cron_tasks($remove_all = true) |
|
253 | + { |
|
254 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
255 | + $crons = _get_cron_array(); |
|
256 | + $crons = is_array($crons) ? $crons : array(); |
|
257 | + /* reminder of what $crons look like: |
|
258 | 258 | * Top-level keys are timestamps, and their values are arrays. |
259 | 259 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
260 | 260 | * and their values are arrays. |
@@ -271,911 +271,911 @@ discard block |
||
271 | 271 | * ... |
272 | 272 | * ... |
273 | 273 | */ |
274 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
275 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
276 | - if (is_array($hooks_to_fire_at_time)) { |
|
277 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
278 | - if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
279 | - && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
280 | - ) { |
|
281 | - unset($crons[$timestamp][$hook_name]); |
|
282 | - } |
|
283 | - } |
|
284 | - //also take care of any empty cron timestamps. |
|
285 | - if (empty($hooks_to_fire_at_time)) { |
|
286 | - unset($crons[$timestamp]); |
|
287 | - } |
|
288 | - } |
|
289 | - } |
|
290 | - _set_cron_array($crons); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * CPT_initialization |
|
296 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
297 | - * |
|
298 | - * @access public |
|
299 | - * @static |
|
300 | - * @return void |
|
301 | - */ |
|
302 | - public static function CPT_initialization() |
|
303 | - { |
|
304 | - // register Custom Post Types |
|
305 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
306 | - flush_rewrite_rules(); |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * reset_and_update_config |
|
313 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
314 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
315 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
316 | - * |
|
317 | - * @access public |
|
318 | - * @static |
|
319 | - * @return void |
|
320 | - */ |
|
321 | - public static function reset_and_update_config() |
|
322 | - { |
|
323 | - do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
324 | - add_filter( |
|
325 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
326 | - array('EEH_Activation', 'migrate_old_config_data'), |
|
327 | - 10, |
|
328 | - 3 |
|
329 | - ); |
|
330 | - //EE_Config::reset(); |
|
331 | - if (! EE_Config::logging_enabled()) { |
|
332 | - delete_option(EE_Config::LOG_NAME); |
|
333 | - } |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * load_calendar_config |
|
339 | - * |
|
340 | - * @access public |
|
341 | - * @return void |
|
342 | - */ |
|
343 | - public static function load_calendar_config() |
|
344 | - { |
|
345 | - // grab array of all plugin folders and loop thru it |
|
346 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
347 | - if (empty($plugins)) { |
|
348 | - return; |
|
349 | - } |
|
350 | - foreach ($plugins as $plugin_path) { |
|
351 | - // grab plugin folder name from path |
|
352 | - $plugin = basename($plugin_path); |
|
353 | - // drill down to Espresso plugins |
|
354 | - // then to calendar related plugins |
|
355 | - if ( |
|
356 | - strpos($plugin, 'espresso') !== false |
|
357 | - || strpos($plugin, 'Espresso') !== false |
|
358 | - || strpos($plugin, 'ee4') !== false |
|
359 | - || strpos($plugin, 'EE4') !== false |
|
360 | - || strpos($plugin, 'calendar') !== false |
|
361 | - ) { |
|
362 | - // this is what we are looking for |
|
363 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
364 | - // does it exist in this folder ? |
|
365 | - if (is_readable($calendar_config)) { |
|
366 | - // YEAH! let's load it |
|
367 | - require_once($calendar_config); |
|
368 | - } |
|
369 | - } |
|
370 | - } |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * _migrate_old_config_data |
|
377 | - * |
|
378 | - * @access public |
|
379 | - * @param array|stdClass $settings |
|
380 | - * @param string $config |
|
381 | - * @param \EE_Config $EE_Config |
|
382 | - * @return \stdClass |
|
383 | - */ |
|
384 | - public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
385 | - { |
|
386 | - $convert_from_array = array('addons'); |
|
387 | - // in case old settings were saved as an array |
|
388 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
389 | - // convert existing settings to an object |
|
390 | - $config_array = $settings; |
|
391 | - $settings = new stdClass(); |
|
392 | - foreach ($config_array as $key => $value) { |
|
393 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
394 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
395 | - } else { |
|
396 | - $settings->{$key} = $value; |
|
397 | - } |
|
398 | - } |
|
399 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
400 | - } |
|
401 | - return $settings; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * deactivate_event_espresso |
|
407 | - * |
|
408 | - * @access public |
|
409 | - * @static |
|
410 | - * @return void |
|
411 | - */ |
|
412 | - public static function deactivate_event_espresso() |
|
413 | - { |
|
414 | - // check permissions |
|
415 | - if (current_user_can('activate_plugins')) { |
|
416 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * verify_default_pages_exist |
|
424 | - * |
|
425 | - * @access public |
|
426 | - * @static |
|
427 | - * @return void |
|
428 | - * @throws InvalidDataTypeException |
|
429 | - */ |
|
430 | - public static function verify_default_pages_exist() |
|
431 | - { |
|
432 | - $critical_page_problem = false; |
|
433 | - $critical_pages = array( |
|
434 | - array( |
|
435 | - 'id' => 'reg_page_id', |
|
436 | - 'name' => __('Registration Checkout', 'event_espresso'), |
|
437 | - 'post' => null, |
|
438 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
439 | - ), |
|
440 | - array( |
|
441 | - 'id' => 'txn_page_id', |
|
442 | - 'name' => __('Transactions', 'event_espresso'), |
|
443 | - 'post' => null, |
|
444 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
445 | - ), |
|
446 | - array( |
|
447 | - 'id' => 'thank_you_page_id', |
|
448 | - 'name' => __('Thank You', 'event_espresso'), |
|
449 | - 'post' => null, |
|
450 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
451 | - ), |
|
452 | - array( |
|
453 | - 'id' => 'cancel_page_id', |
|
454 | - 'name' => __('Registration Cancelled', 'event_espresso'), |
|
455 | - 'post' => null, |
|
456 | - 'code' => 'ESPRESSO_CANCELLED', |
|
457 | - ), |
|
458 | - ); |
|
459 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
460 | - foreach ($critical_pages as $critical_page) { |
|
461 | - // is critical page ID set in config ? |
|
462 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
463 | - // attempt to find post by ID |
|
464 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
465 | - } |
|
466 | - // no dice? |
|
467 | - if ($critical_page['post'] === null) { |
|
468 | - // attempt to find post by title |
|
469 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
470 | - // still nothing? |
|
471 | - if ($critical_page['post'] === null) { |
|
472 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
473 | - // REALLY? Still nothing ??!?!? |
|
474 | - if ($critical_page['post'] === null) { |
|
475 | - $msg = __( |
|
476 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
477 | - 'event_espresso' |
|
478 | - ); |
|
479 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
480 | - break; |
|
481 | - } |
|
482 | - } |
|
483 | - } |
|
484 | - // check that Post ID matches critical page ID in config |
|
485 | - if ( |
|
486 | - isset($critical_page['post']->ID) |
|
487 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
488 | - ) { |
|
489 | - //update Config with post ID |
|
490 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
491 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
492 | - $msg = __( |
|
493 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
494 | - 'event_espresso' |
|
495 | - ); |
|
496 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
497 | - } |
|
498 | - } |
|
499 | - $critical_page_problem = |
|
500 | - ! isset($critical_page['post']->post_status) |
|
501 | - || $critical_page['post']->post_status !== 'publish' |
|
502 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
503 | - ? true |
|
504 | - : $critical_page_problem; |
|
505 | - } |
|
506 | - if ($critical_page_problem) { |
|
507 | - new PersistentAdminNotice( |
|
508 | - 'critical_page_problem', |
|
509 | - sprintf( |
|
510 | - esc_html__( |
|
511 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
512 | - 'event_espresso' |
|
513 | - ), |
|
514 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
515 | - . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
516 | - . '</a>' |
|
517 | - ) |
|
518 | - ); |
|
519 | - } |
|
520 | - if (EE_Error::has_notices()) { |
|
521 | - EE_Error::get_notices(false, true, true); |
|
522 | - } |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * Returns the first post which uses the specified shortcode |
|
529 | - * |
|
530 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
531 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
532 | - * "[ESPRESSO_THANK_YOU" |
|
533 | - * (we don't search for the closing shortcode bracket because they might have added |
|
534 | - * parameter to the shortcode |
|
535 | - * @return WP_Post or NULl |
|
536 | - */ |
|
537 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
538 | - { |
|
539 | - global $wpdb; |
|
540 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
541 | - $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
542 | - if ($post_id) { |
|
543 | - return get_post($post_id); |
|
544 | - } else { |
|
545 | - return null; |
|
546 | - } |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * This function generates a post for critical espresso pages |
|
552 | - * |
|
553 | - * @access public |
|
554 | - * @static |
|
555 | - * @param array $critical_page |
|
556 | - * @return array |
|
557 | - */ |
|
558 | - public static function create_critical_page($critical_page) |
|
559 | - { |
|
560 | - |
|
561 | - $post_args = array( |
|
562 | - 'post_title' => $critical_page['name'], |
|
563 | - 'post_status' => 'publish', |
|
564 | - 'post_type' => 'page', |
|
565 | - 'comment_status' => 'closed', |
|
566 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
567 | - ); |
|
568 | - |
|
569 | - $post_id = wp_insert_post($post_args); |
|
570 | - if (! $post_id) { |
|
571 | - $msg = sprintf( |
|
572 | - __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
573 | - $critical_page['name'] |
|
574 | - ); |
|
575 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
576 | - return $critical_page; |
|
577 | - } |
|
578 | - // get newly created post's details |
|
579 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
580 | - $msg = sprintf( |
|
581 | - __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
582 | - $critical_page['name'] |
|
583 | - ); |
|
584 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
585 | - } |
|
586 | - |
|
587 | - return $critical_page; |
|
588 | - |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
596 | - * The role being used to check is filterable. |
|
597 | - * |
|
598 | - * @since 4.6.0 |
|
599 | - * @global WPDB $wpdb |
|
600 | - * @return mixed null|int WP_user ID or NULL |
|
601 | - */ |
|
602 | - public static function get_default_creator_id() |
|
603 | - { |
|
604 | - global $wpdb; |
|
605 | - if ( ! empty(self::$_default_creator_id)) { |
|
606 | - return self::$_default_creator_id; |
|
607 | - }/**/ |
|
608 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
609 | - //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
610 | - $pre_filtered_id = apply_filters( |
|
611 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
612 | - false, |
|
613 | - $role_to_check |
|
614 | - ); |
|
615 | - if ($pre_filtered_id !== false) { |
|
616 | - return (int)$pre_filtered_id; |
|
617 | - } |
|
618 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
619 | - $query = $wpdb->prepare( |
|
620 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
621 | - '%' . $role_to_check . '%' |
|
622 | - ); |
|
623 | - $user_id = $wpdb->get_var($query); |
|
624 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
625 | - if ($user_id && (int)$user_id) { |
|
626 | - self::$_default_creator_id = (int)$user_id; |
|
627 | - return self::$_default_creator_id; |
|
628 | - } else { |
|
629 | - return null; |
|
630 | - } |
|
631 | - } |
|
632 | - |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * used by EE and EE addons during plugin activation to create tables. |
|
637 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
638 | - * but includes extra logic regarding activations. |
|
639 | - * |
|
640 | - * @access public |
|
641 | - * @static |
|
642 | - * @param string $table_name without the $wpdb->prefix |
|
643 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
644 | - * table query) |
|
645 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
646 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
647 | - * and new once this function is done (ie, you really do want to CREATE a |
|
648 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
649 | - * you just want to verify the table exists and matches this definition |
|
650 | - * (and if it HAS data in it you want to leave it be) |
|
651 | - * @return void |
|
652 | - * @throws EE_Error if there are database errors |
|
653 | - */ |
|
654 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
655 | - { |
|
656 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
657 | - return; |
|
658 | - } |
|
659 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
660 | - if ( ! function_exists('dbDelta')) { |
|
661 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
662 | - } |
|
663 | - $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
664 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
665 | - // do we need to first delete an existing version of this table ? |
|
666 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
667 | - // ok, delete the table... but ONLY if it's empty |
|
668 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
669 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
670 | - if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
671 | - \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
672 | - } else if ( ! $deleted_safely) { |
|
673 | - // so we should be more cautious rather than just dropping tables so easily |
|
674 | - error_log( |
|
675 | - sprintf( |
|
676 | - __( |
|
677 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
678 | - 'event_espresso' |
|
679 | - ), |
|
680 | - $wp_table_name, |
|
681 | - '<br/>', |
|
682 | - 'espresso_db_update' |
|
683 | - ) |
|
684 | - ); |
|
685 | - } |
|
686 | - } |
|
687 | - $engine = str_replace('ENGINE=', '', $engine); |
|
688 | - \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * add_column_if_it_doesn't_exist |
|
695 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
696 | - * |
|
697 | - * @access public |
|
698 | - * @static |
|
699 | - * @deprecated instead use TableManager::addColumn() |
|
700 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
701 | - * @param string $column_name |
|
702 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
703 | - * 'VARCHAR(10)' |
|
704 | - * @return bool|int |
|
705 | - */ |
|
706 | - public static function add_column_if_it_doesnt_exist( |
|
707 | - $table_name, |
|
708 | - $column_name, |
|
709 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
710 | - ) { |
|
711 | - return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * get_fields_on_table |
|
717 | - * Gets all the fields on the database table. |
|
718 | - * |
|
719 | - * @access public |
|
720 | - * @deprecated instead use TableManager::getTableColumns() |
|
721 | - * @static |
|
722 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
723 | - * @return array of database column names |
|
724 | - */ |
|
725 | - public static function get_fields_on_table($table_name = null) |
|
726 | - { |
|
727 | - return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - /** |
|
732 | - * db_table_is_empty |
|
733 | - * |
|
734 | - * @access public\ |
|
735 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
736 | - * @static |
|
737 | - * @param string $table_name |
|
738 | - * @return bool |
|
739 | - */ |
|
740 | - public static function db_table_is_empty($table_name) |
|
741 | - { |
|
742 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
743 | - } |
|
744 | - |
|
745 | - |
|
746 | - /** |
|
747 | - * delete_db_table_if_empty |
|
748 | - * |
|
749 | - * @access public |
|
750 | - * @static |
|
751 | - * @param string $table_name |
|
752 | - * @return bool | int |
|
753 | - */ |
|
754 | - public static function delete_db_table_if_empty($table_name) |
|
755 | - { |
|
756 | - if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
757 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
758 | - } |
|
759 | - return false; |
|
760 | - } |
|
761 | - |
|
762 | - |
|
763 | - /** |
|
764 | - * delete_unused_db_table |
|
765 | - * |
|
766 | - * @access public |
|
767 | - * @static |
|
768 | - * @deprecated instead use TableManager::dropTable() |
|
769 | - * @param string $table_name |
|
770 | - * @return bool | int |
|
771 | - */ |
|
772 | - public static function delete_unused_db_table($table_name) |
|
773 | - { |
|
774 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * drop_index |
|
780 | - * |
|
781 | - * @access public |
|
782 | - * @static |
|
783 | - * @deprecated instead use TableManager::dropIndex() |
|
784 | - * @param string $table_name |
|
785 | - * @param string $index_name |
|
786 | - * @return bool | int |
|
787 | - */ |
|
788 | - public static function drop_index($table_name, $index_name) |
|
789 | - { |
|
790 | - return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
791 | - } |
|
792 | - |
|
793 | - |
|
794 | - |
|
795 | - /** |
|
796 | - * create_database_tables |
|
797 | - * |
|
798 | - * @access public |
|
799 | - * @static |
|
800 | - * @throws EE_Error |
|
801 | - * @return boolean success (whether database is setup properly or not) |
|
802 | - */ |
|
803 | - public static function create_database_tables() |
|
804 | - { |
|
805 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
806 | - //find the migration script that sets the database to be compatible with the code |
|
807 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
808 | - if ($dms_name) { |
|
809 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
810 | - $current_data_migration_script->set_migrating(false); |
|
811 | - $current_data_migration_script->schema_changes_before_migration(); |
|
812 | - $current_data_migration_script->schema_changes_after_migration(); |
|
813 | - if ($current_data_migration_script->get_errors()) { |
|
814 | - if (WP_DEBUG) { |
|
815 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
816 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
817 | - } |
|
818 | - } else { |
|
819 | - EE_Error::add_error( |
|
820 | - __( |
|
821 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
274 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
275 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
276 | + if (is_array($hooks_to_fire_at_time)) { |
|
277 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
278 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
279 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
280 | + ) { |
|
281 | + unset($crons[$timestamp][$hook_name]); |
|
282 | + } |
|
283 | + } |
|
284 | + //also take care of any empty cron timestamps. |
|
285 | + if (empty($hooks_to_fire_at_time)) { |
|
286 | + unset($crons[$timestamp]); |
|
287 | + } |
|
288 | + } |
|
289 | + } |
|
290 | + _set_cron_array($crons); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * CPT_initialization |
|
296 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
297 | + * |
|
298 | + * @access public |
|
299 | + * @static |
|
300 | + * @return void |
|
301 | + */ |
|
302 | + public static function CPT_initialization() |
|
303 | + { |
|
304 | + // register Custom Post Types |
|
305 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
306 | + flush_rewrite_rules(); |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * reset_and_update_config |
|
313 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
314 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
315 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
316 | + * |
|
317 | + * @access public |
|
318 | + * @static |
|
319 | + * @return void |
|
320 | + */ |
|
321 | + public static function reset_and_update_config() |
|
322 | + { |
|
323 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
324 | + add_filter( |
|
325 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
326 | + array('EEH_Activation', 'migrate_old_config_data'), |
|
327 | + 10, |
|
328 | + 3 |
|
329 | + ); |
|
330 | + //EE_Config::reset(); |
|
331 | + if (! EE_Config::logging_enabled()) { |
|
332 | + delete_option(EE_Config::LOG_NAME); |
|
333 | + } |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * load_calendar_config |
|
339 | + * |
|
340 | + * @access public |
|
341 | + * @return void |
|
342 | + */ |
|
343 | + public static function load_calendar_config() |
|
344 | + { |
|
345 | + // grab array of all plugin folders and loop thru it |
|
346 | + $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
347 | + if (empty($plugins)) { |
|
348 | + return; |
|
349 | + } |
|
350 | + foreach ($plugins as $plugin_path) { |
|
351 | + // grab plugin folder name from path |
|
352 | + $plugin = basename($plugin_path); |
|
353 | + // drill down to Espresso plugins |
|
354 | + // then to calendar related plugins |
|
355 | + if ( |
|
356 | + strpos($plugin, 'espresso') !== false |
|
357 | + || strpos($plugin, 'Espresso') !== false |
|
358 | + || strpos($plugin, 'ee4') !== false |
|
359 | + || strpos($plugin, 'EE4') !== false |
|
360 | + || strpos($plugin, 'calendar') !== false |
|
361 | + ) { |
|
362 | + // this is what we are looking for |
|
363 | + $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
364 | + // does it exist in this folder ? |
|
365 | + if (is_readable($calendar_config)) { |
|
366 | + // YEAH! let's load it |
|
367 | + require_once($calendar_config); |
|
368 | + } |
|
369 | + } |
|
370 | + } |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * _migrate_old_config_data |
|
377 | + * |
|
378 | + * @access public |
|
379 | + * @param array|stdClass $settings |
|
380 | + * @param string $config |
|
381 | + * @param \EE_Config $EE_Config |
|
382 | + * @return \stdClass |
|
383 | + */ |
|
384 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
385 | + { |
|
386 | + $convert_from_array = array('addons'); |
|
387 | + // in case old settings were saved as an array |
|
388 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
389 | + // convert existing settings to an object |
|
390 | + $config_array = $settings; |
|
391 | + $settings = new stdClass(); |
|
392 | + foreach ($config_array as $key => $value) { |
|
393 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
394 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
395 | + } else { |
|
396 | + $settings->{$key} = $value; |
|
397 | + } |
|
398 | + } |
|
399 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
400 | + } |
|
401 | + return $settings; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * deactivate_event_espresso |
|
407 | + * |
|
408 | + * @access public |
|
409 | + * @static |
|
410 | + * @return void |
|
411 | + */ |
|
412 | + public static function deactivate_event_espresso() |
|
413 | + { |
|
414 | + // check permissions |
|
415 | + if (current_user_can('activate_plugins')) { |
|
416 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * verify_default_pages_exist |
|
424 | + * |
|
425 | + * @access public |
|
426 | + * @static |
|
427 | + * @return void |
|
428 | + * @throws InvalidDataTypeException |
|
429 | + */ |
|
430 | + public static function verify_default_pages_exist() |
|
431 | + { |
|
432 | + $critical_page_problem = false; |
|
433 | + $critical_pages = array( |
|
434 | + array( |
|
435 | + 'id' => 'reg_page_id', |
|
436 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
437 | + 'post' => null, |
|
438 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
439 | + ), |
|
440 | + array( |
|
441 | + 'id' => 'txn_page_id', |
|
442 | + 'name' => __('Transactions', 'event_espresso'), |
|
443 | + 'post' => null, |
|
444 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
445 | + ), |
|
446 | + array( |
|
447 | + 'id' => 'thank_you_page_id', |
|
448 | + 'name' => __('Thank You', 'event_espresso'), |
|
449 | + 'post' => null, |
|
450 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
451 | + ), |
|
452 | + array( |
|
453 | + 'id' => 'cancel_page_id', |
|
454 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
455 | + 'post' => null, |
|
456 | + 'code' => 'ESPRESSO_CANCELLED', |
|
457 | + ), |
|
458 | + ); |
|
459 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
460 | + foreach ($critical_pages as $critical_page) { |
|
461 | + // is critical page ID set in config ? |
|
462 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
463 | + // attempt to find post by ID |
|
464 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
465 | + } |
|
466 | + // no dice? |
|
467 | + if ($critical_page['post'] === null) { |
|
468 | + // attempt to find post by title |
|
469 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
470 | + // still nothing? |
|
471 | + if ($critical_page['post'] === null) { |
|
472 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
473 | + // REALLY? Still nothing ??!?!? |
|
474 | + if ($critical_page['post'] === null) { |
|
475 | + $msg = __( |
|
476 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
477 | + 'event_espresso' |
|
478 | + ); |
|
479 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
480 | + break; |
|
481 | + } |
|
482 | + } |
|
483 | + } |
|
484 | + // check that Post ID matches critical page ID in config |
|
485 | + if ( |
|
486 | + isset($critical_page['post']->ID) |
|
487 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
488 | + ) { |
|
489 | + //update Config with post ID |
|
490 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
491 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
492 | + $msg = __( |
|
493 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
494 | + 'event_espresso' |
|
495 | + ); |
|
496 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
497 | + } |
|
498 | + } |
|
499 | + $critical_page_problem = |
|
500 | + ! isset($critical_page['post']->post_status) |
|
501 | + || $critical_page['post']->post_status !== 'publish' |
|
502 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
503 | + ? true |
|
504 | + : $critical_page_problem; |
|
505 | + } |
|
506 | + if ($critical_page_problem) { |
|
507 | + new PersistentAdminNotice( |
|
508 | + 'critical_page_problem', |
|
509 | + sprintf( |
|
510 | + esc_html__( |
|
511 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
512 | + 'event_espresso' |
|
513 | + ), |
|
514 | + '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
515 | + . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
516 | + . '</a>' |
|
517 | + ) |
|
518 | + ); |
|
519 | + } |
|
520 | + if (EE_Error::has_notices()) { |
|
521 | + EE_Error::get_notices(false, true, true); |
|
522 | + } |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * Returns the first post which uses the specified shortcode |
|
529 | + * |
|
530 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
531 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
532 | + * "[ESPRESSO_THANK_YOU" |
|
533 | + * (we don't search for the closing shortcode bracket because they might have added |
|
534 | + * parameter to the shortcode |
|
535 | + * @return WP_Post or NULl |
|
536 | + */ |
|
537 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
538 | + { |
|
539 | + global $wpdb; |
|
540 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
541 | + $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
542 | + if ($post_id) { |
|
543 | + return get_post($post_id); |
|
544 | + } else { |
|
545 | + return null; |
|
546 | + } |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * This function generates a post for critical espresso pages |
|
552 | + * |
|
553 | + * @access public |
|
554 | + * @static |
|
555 | + * @param array $critical_page |
|
556 | + * @return array |
|
557 | + */ |
|
558 | + public static function create_critical_page($critical_page) |
|
559 | + { |
|
560 | + |
|
561 | + $post_args = array( |
|
562 | + 'post_title' => $critical_page['name'], |
|
563 | + 'post_status' => 'publish', |
|
564 | + 'post_type' => 'page', |
|
565 | + 'comment_status' => 'closed', |
|
566 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
567 | + ); |
|
568 | + |
|
569 | + $post_id = wp_insert_post($post_args); |
|
570 | + if (! $post_id) { |
|
571 | + $msg = sprintf( |
|
572 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
573 | + $critical_page['name'] |
|
574 | + ); |
|
575 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
576 | + return $critical_page; |
|
577 | + } |
|
578 | + // get newly created post's details |
|
579 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
580 | + $msg = sprintf( |
|
581 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
582 | + $critical_page['name'] |
|
583 | + ); |
|
584 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
585 | + } |
|
586 | + |
|
587 | + return $critical_page; |
|
588 | + |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
596 | + * The role being used to check is filterable. |
|
597 | + * |
|
598 | + * @since 4.6.0 |
|
599 | + * @global WPDB $wpdb |
|
600 | + * @return mixed null|int WP_user ID or NULL |
|
601 | + */ |
|
602 | + public static function get_default_creator_id() |
|
603 | + { |
|
604 | + global $wpdb; |
|
605 | + if ( ! empty(self::$_default_creator_id)) { |
|
606 | + return self::$_default_creator_id; |
|
607 | + }/**/ |
|
608 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
609 | + //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
610 | + $pre_filtered_id = apply_filters( |
|
611 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
612 | + false, |
|
613 | + $role_to_check |
|
614 | + ); |
|
615 | + if ($pre_filtered_id !== false) { |
|
616 | + return (int)$pre_filtered_id; |
|
617 | + } |
|
618 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
619 | + $query = $wpdb->prepare( |
|
620 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
621 | + '%' . $role_to_check . '%' |
|
622 | + ); |
|
623 | + $user_id = $wpdb->get_var($query); |
|
624 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
625 | + if ($user_id && (int)$user_id) { |
|
626 | + self::$_default_creator_id = (int)$user_id; |
|
627 | + return self::$_default_creator_id; |
|
628 | + } else { |
|
629 | + return null; |
|
630 | + } |
|
631 | + } |
|
632 | + |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * used by EE and EE addons during plugin activation to create tables. |
|
637 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
638 | + * but includes extra logic regarding activations. |
|
639 | + * |
|
640 | + * @access public |
|
641 | + * @static |
|
642 | + * @param string $table_name without the $wpdb->prefix |
|
643 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
644 | + * table query) |
|
645 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
646 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
647 | + * and new once this function is done (ie, you really do want to CREATE a |
|
648 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
649 | + * you just want to verify the table exists and matches this definition |
|
650 | + * (and if it HAS data in it you want to leave it be) |
|
651 | + * @return void |
|
652 | + * @throws EE_Error if there are database errors |
|
653 | + */ |
|
654 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
655 | + { |
|
656 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
657 | + return; |
|
658 | + } |
|
659 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
660 | + if ( ! function_exists('dbDelta')) { |
|
661 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
662 | + } |
|
663 | + $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
664 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
665 | + // do we need to first delete an existing version of this table ? |
|
666 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
667 | + // ok, delete the table... but ONLY if it's empty |
|
668 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
669 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
670 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
671 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
672 | + } else if ( ! $deleted_safely) { |
|
673 | + // so we should be more cautious rather than just dropping tables so easily |
|
674 | + error_log( |
|
675 | + sprintf( |
|
676 | + __( |
|
677 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
678 | + 'event_espresso' |
|
679 | + ), |
|
680 | + $wp_table_name, |
|
681 | + '<br/>', |
|
682 | + 'espresso_db_update' |
|
683 | + ) |
|
684 | + ); |
|
685 | + } |
|
686 | + } |
|
687 | + $engine = str_replace('ENGINE=', '', $engine); |
|
688 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * add_column_if_it_doesn't_exist |
|
695 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
696 | + * |
|
697 | + * @access public |
|
698 | + * @static |
|
699 | + * @deprecated instead use TableManager::addColumn() |
|
700 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
701 | + * @param string $column_name |
|
702 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
703 | + * 'VARCHAR(10)' |
|
704 | + * @return bool|int |
|
705 | + */ |
|
706 | + public static function add_column_if_it_doesnt_exist( |
|
707 | + $table_name, |
|
708 | + $column_name, |
|
709 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
710 | + ) { |
|
711 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * get_fields_on_table |
|
717 | + * Gets all the fields on the database table. |
|
718 | + * |
|
719 | + * @access public |
|
720 | + * @deprecated instead use TableManager::getTableColumns() |
|
721 | + * @static |
|
722 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
723 | + * @return array of database column names |
|
724 | + */ |
|
725 | + public static function get_fields_on_table($table_name = null) |
|
726 | + { |
|
727 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + /** |
|
732 | + * db_table_is_empty |
|
733 | + * |
|
734 | + * @access public\ |
|
735 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
736 | + * @static |
|
737 | + * @param string $table_name |
|
738 | + * @return bool |
|
739 | + */ |
|
740 | + public static function db_table_is_empty($table_name) |
|
741 | + { |
|
742 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
743 | + } |
|
744 | + |
|
745 | + |
|
746 | + /** |
|
747 | + * delete_db_table_if_empty |
|
748 | + * |
|
749 | + * @access public |
|
750 | + * @static |
|
751 | + * @param string $table_name |
|
752 | + * @return bool | int |
|
753 | + */ |
|
754 | + public static function delete_db_table_if_empty($table_name) |
|
755 | + { |
|
756 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
757 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
758 | + } |
|
759 | + return false; |
|
760 | + } |
|
761 | + |
|
762 | + |
|
763 | + /** |
|
764 | + * delete_unused_db_table |
|
765 | + * |
|
766 | + * @access public |
|
767 | + * @static |
|
768 | + * @deprecated instead use TableManager::dropTable() |
|
769 | + * @param string $table_name |
|
770 | + * @return bool | int |
|
771 | + */ |
|
772 | + public static function delete_unused_db_table($table_name) |
|
773 | + { |
|
774 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * drop_index |
|
780 | + * |
|
781 | + * @access public |
|
782 | + * @static |
|
783 | + * @deprecated instead use TableManager::dropIndex() |
|
784 | + * @param string $table_name |
|
785 | + * @param string $index_name |
|
786 | + * @return bool | int |
|
787 | + */ |
|
788 | + public static function drop_index($table_name, $index_name) |
|
789 | + { |
|
790 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
791 | + } |
|
792 | + |
|
793 | + |
|
794 | + |
|
795 | + /** |
|
796 | + * create_database_tables |
|
797 | + * |
|
798 | + * @access public |
|
799 | + * @static |
|
800 | + * @throws EE_Error |
|
801 | + * @return boolean success (whether database is setup properly or not) |
|
802 | + */ |
|
803 | + public static function create_database_tables() |
|
804 | + { |
|
805 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
806 | + //find the migration script that sets the database to be compatible with the code |
|
807 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
808 | + if ($dms_name) { |
|
809 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
810 | + $current_data_migration_script->set_migrating(false); |
|
811 | + $current_data_migration_script->schema_changes_before_migration(); |
|
812 | + $current_data_migration_script->schema_changes_after_migration(); |
|
813 | + if ($current_data_migration_script->get_errors()) { |
|
814 | + if (WP_DEBUG) { |
|
815 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
816 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
817 | + } |
|
818 | + } else { |
|
819 | + EE_Error::add_error( |
|
820 | + __( |
|
821 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
822 | 822 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
823 | - 'event_espresso' |
|
824 | - ) |
|
825 | - ); |
|
826 | - } |
|
827 | - return false; |
|
828 | - } |
|
829 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
830 | - } else { |
|
831 | - EE_Error::add_error( |
|
832 | - __( |
|
833 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
823 | + 'event_espresso' |
|
824 | + ) |
|
825 | + ); |
|
826 | + } |
|
827 | + return false; |
|
828 | + } |
|
829 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
830 | + } else { |
|
831 | + EE_Error::add_error( |
|
832 | + __( |
|
833 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
834 | 834 | structure. So database is probably not setup properly', |
835 | - 'event_espresso' |
|
836 | - ), |
|
837 | - __FILE__, |
|
838 | - __FUNCTION__, |
|
839 | - __LINE__ |
|
840 | - ); |
|
841 | - return false; |
|
842 | - } |
|
843 | - return true; |
|
844 | - } |
|
845 | - |
|
846 | - |
|
847 | - |
|
848 | - /** |
|
849 | - * initialize_system_questions |
|
850 | - * |
|
851 | - * @access public |
|
852 | - * @static |
|
853 | - * @return void |
|
854 | - */ |
|
855 | - public static function initialize_system_questions() |
|
856 | - { |
|
857 | - // QUESTION GROUPS |
|
858 | - global $wpdb; |
|
859 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
860 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
861 | - // what we have |
|
862 | - $question_groups = $wpdb->get_col($SQL); |
|
863 | - // check the response |
|
864 | - $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
865 | - // what we should have |
|
866 | - $QSG_systems = array(1, 2); |
|
867 | - // loop thru what we should have and compare to what we have |
|
868 | - foreach ($QSG_systems as $QSG_system) { |
|
869 | - // reset values array |
|
870 | - $QSG_values = array(); |
|
871 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
872 | - if (! in_array("$QSG_system", $question_groups)) { |
|
873 | - // add it |
|
874 | - switch ($QSG_system) { |
|
875 | - case 1: |
|
876 | - $QSG_values = array( |
|
877 | - 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
878 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
879 | - 'QSG_desc' => '', |
|
880 | - 'QSG_order' => 1, |
|
881 | - 'QSG_show_group_name' => 1, |
|
882 | - 'QSG_show_group_desc' => 1, |
|
883 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
884 | - 'QSG_deleted' => 0, |
|
885 | - ); |
|
886 | - break; |
|
887 | - case 2: |
|
888 | - $QSG_values = array( |
|
889 | - 'QSG_name' => __('Address Information', 'event_espresso'), |
|
890 | - 'QSG_identifier' => 'address-information-' . time(), |
|
891 | - 'QSG_desc' => '', |
|
892 | - 'QSG_order' => 2, |
|
893 | - 'QSG_show_group_name' => 1, |
|
894 | - 'QSG_show_group_desc' => 1, |
|
895 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
896 | - 'QSG_deleted' => 0, |
|
897 | - ); |
|
898 | - break; |
|
899 | - } |
|
900 | - // make sure we have some values before inserting them |
|
901 | - if (! empty($QSG_values)) { |
|
902 | - // insert system question |
|
903 | - $wpdb->insert( |
|
904 | - $table_name, |
|
905 | - $QSG_values, |
|
906 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
907 | - ); |
|
908 | - $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
909 | - } |
|
910 | - } |
|
911 | - } |
|
912 | - // QUESTIONS |
|
913 | - global $wpdb; |
|
914 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
915 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
916 | - // what we have |
|
917 | - $questions = $wpdb->get_col($SQL); |
|
918 | - // what we should have |
|
919 | - $QST_systems = array( |
|
920 | - 'fname', |
|
921 | - 'lname', |
|
922 | - 'email', |
|
923 | - 'address', |
|
924 | - 'address2', |
|
925 | - 'city', |
|
926 | - 'country', |
|
927 | - 'state', |
|
928 | - 'zip', |
|
929 | - 'phone', |
|
930 | - ); |
|
931 | - $order_for_group_1 = 1; |
|
932 | - $order_for_group_2 = 1; |
|
933 | - // loop thru what we should have and compare to what we have |
|
934 | - foreach ($QST_systems as $QST_system) { |
|
935 | - // reset values array |
|
936 | - $QST_values = array(); |
|
937 | - // if we don't have what we should have |
|
938 | - if (! in_array($QST_system, $questions)) { |
|
939 | - // add it |
|
940 | - switch ($QST_system) { |
|
941 | - case 'fname': |
|
942 | - $QST_values = array( |
|
943 | - 'QST_display_text' => __('First Name', 'event_espresso'), |
|
944 | - 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
945 | - 'QST_system' => 'fname', |
|
946 | - 'QST_type' => 'TEXT', |
|
947 | - 'QST_required' => 1, |
|
948 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
949 | - 'QST_order' => 1, |
|
950 | - 'QST_admin_only' => 0, |
|
951 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
952 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
953 | - 'QST_deleted' => 0, |
|
954 | - ); |
|
955 | - break; |
|
956 | - case 'lname': |
|
957 | - $QST_values = array( |
|
958 | - 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
959 | - 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
960 | - 'QST_system' => 'lname', |
|
961 | - 'QST_type' => 'TEXT', |
|
962 | - 'QST_required' => 1, |
|
963 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
964 | - 'QST_order' => 2, |
|
965 | - 'QST_admin_only' => 0, |
|
966 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
967 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
968 | - 'QST_deleted' => 0, |
|
969 | - ); |
|
970 | - break; |
|
971 | - case 'email': |
|
972 | - $QST_values = array( |
|
973 | - 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
974 | - 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
975 | - 'QST_system' => 'email', |
|
976 | - 'QST_type' => 'EMAIL', |
|
977 | - 'QST_required' => 1, |
|
978 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
979 | - 'QST_order' => 3, |
|
980 | - 'QST_admin_only' => 0, |
|
981 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
982 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
983 | - 'QST_deleted' => 0, |
|
984 | - ); |
|
985 | - break; |
|
986 | - case 'address': |
|
987 | - $QST_values = array( |
|
988 | - 'QST_display_text' => __('Address', 'event_espresso'), |
|
989 | - 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
990 | - 'QST_system' => 'address', |
|
991 | - 'QST_type' => 'TEXT', |
|
992 | - 'QST_required' => 0, |
|
993 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
994 | - 'QST_order' => 4, |
|
995 | - 'QST_admin_only' => 0, |
|
996 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
997 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
998 | - 'QST_deleted' => 0, |
|
999 | - ); |
|
1000 | - break; |
|
1001 | - case 'address2': |
|
1002 | - $QST_values = array( |
|
1003 | - 'QST_display_text' => __('Address2', 'event_espresso'), |
|
1004 | - 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
1005 | - 'QST_system' => 'address2', |
|
1006 | - 'QST_type' => 'TEXT', |
|
1007 | - 'QST_required' => 0, |
|
1008 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1009 | - 'QST_order' => 5, |
|
1010 | - 'QST_admin_only' => 0, |
|
1011 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1012 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1013 | - 'QST_deleted' => 0, |
|
1014 | - ); |
|
1015 | - break; |
|
1016 | - case 'city': |
|
1017 | - $QST_values = array( |
|
1018 | - 'QST_display_text' => __('City', 'event_espresso'), |
|
1019 | - 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1020 | - 'QST_system' => 'city', |
|
1021 | - 'QST_type' => 'TEXT', |
|
1022 | - 'QST_required' => 0, |
|
1023 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1024 | - 'QST_order' => 6, |
|
1025 | - 'QST_admin_only' => 0, |
|
1026 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1027 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1028 | - 'QST_deleted' => 0, |
|
1029 | - ); |
|
1030 | - break; |
|
1031 | - case 'country': |
|
1032 | - $QST_values = array( |
|
1033 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
1034 | - 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1035 | - 'QST_system' => 'country', |
|
1036 | - 'QST_type' => 'COUNTRY', |
|
1037 | - 'QST_required' => 0, |
|
1038 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1039 | - 'QST_order' => 7, |
|
1040 | - 'QST_admin_only' => 0, |
|
1041 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1042 | - 'QST_deleted' => 0, |
|
1043 | - ); |
|
1044 | - break; |
|
1045 | - case 'state': |
|
1046 | - $QST_values = array( |
|
1047 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1048 | - 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1049 | - 'QST_system' => 'state', |
|
1050 | - 'QST_type' => 'STATE', |
|
1051 | - 'QST_required' => 0, |
|
1052 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1053 | - 'QST_order' => 8, |
|
1054 | - 'QST_admin_only' => 0, |
|
1055 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1056 | - 'QST_deleted' => 0, |
|
1057 | - ); |
|
1058 | - break; |
|
1059 | - case 'zip': |
|
1060 | - $QST_values = array( |
|
1061 | - 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1062 | - 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1063 | - 'QST_system' => 'zip', |
|
1064 | - 'QST_type' => 'TEXT', |
|
1065 | - 'QST_required' => 0, |
|
1066 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1067 | - 'QST_order' => 9, |
|
1068 | - 'QST_admin_only' => 0, |
|
1069 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1070 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1071 | - 'QST_deleted' => 0, |
|
1072 | - ); |
|
1073 | - break; |
|
1074 | - case 'phone': |
|
1075 | - $QST_values = array( |
|
1076 | - 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1077 | - 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1078 | - 'QST_system' => 'phone', |
|
1079 | - 'QST_type' => 'TEXT', |
|
1080 | - 'QST_required' => 0, |
|
1081 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1082 | - 'QST_order' => 10, |
|
1083 | - 'QST_admin_only' => 0, |
|
1084 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1085 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1086 | - 'QST_deleted' => 0, |
|
1087 | - ); |
|
1088 | - break; |
|
1089 | - } |
|
1090 | - if (! empty($QST_values)) { |
|
1091 | - // insert system question |
|
1092 | - $wpdb->insert( |
|
1093 | - $table_name, |
|
1094 | - $QST_values, |
|
1095 | - array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1096 | - ); |
|
1097 | - $QST_ID = $wpdb->insert_id; |
|
1098 | - // QUESTION GROUP QUESTIONS |
|
1099 | - if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
1100 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
1101 | - } else { |
|
1102 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
1103 | - } |
|
1104 | - if (isset($QSG_IDs[$system_question_we_want])) { |
|
1105 | - $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
1106 | - } else { |
|
1107 | - $id_col = EEM_Question_Group::instance() |
|
1108 | - ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1109 | - if (is_array($id_col)) { |
|
1110 | - $QSG_ID = reset($id_col); |
|
1111 | - } else { |
|
1112 | - //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1113 | - EE_Log::instance()->log( |
|
1114 | - __FILE__, |
|
1115 | - __FUNCTION__, |
|
1116 | - sprintf( |
|
1117 | - __( |
|
1118 | - 'Could not associate question %1$s to a question group because no system question |
|
835 | + 'event_espresso' |
|
836 | + ), |
|
837 | + __FILE__, |
|
838 | + __FUNCTION__, |
|
839 | + __LINE__ |
|
840 | + ); |
|
841 | + return false; |
|
842 | + } |
|
843 | + return true; |
|
844 | + } |
|
845 | + |
|
846 | + |
|
847 | + |
|
848 | + /** |
|
849 | + * initialize_system_questions |
|
850 | + * |
|
851 | + * @access public |
|
852 | + * @static |
|
853 | + * @return void |
|
854 | + */ |
|
855 | + public static function initialize_system_questions() |
|
856 | + { |
|
857 | + // QUESTION GROUPS |
|
858 | + global $wpdb; |
|
859 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
860 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
861 | + // what we have |
|
862 | + $question_groups = $wpdb->get_col($SQL); |
|
863 | + // check the response |
|
864 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
865 | + // what we should have |
|
866 | + $QSG_systems = array(1, 2); |
|
867 | + // loop thru what we should have and compare to what we have |
|
868 | + foreach ($QSG_systems as $QSG_system) { |
|
869 | + // reset values array |
|
870 | + $QSG_values = array(); |
|
871 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
872 | + if (! in_array("$QSG_system", $question_groups)) { |
|
873 | + // add it |
|
874 | + switch ($QSG_system) { |
|
875 | + case 1: |
|
876 | + $QSG_values = array( |
|
877 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
878 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
879 | + 'QSG_desc' => '', |
|
880 | + 'QSG_order' => 1, |
|
881 | + 'QSG_show_group_name' => 1, |
|
882 | + 'QSG_show_group_desc' => 1, |
|
883 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
884 | + 'QSG_deleted' => 0, |
|
885 | + ); |
|
886 | + break; |
|
887 | + case 2: |
|
888 | + $QSG_values = array( |
|
889 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
890 | + 'QSG_identifier' => 'address-information-' . time(), |
|
891 | + 'QSG_desc' => '', |
|
892 | + 'QSG_order' => 2, |
|
893 | + 'QSG_show_group_name' => 1, |
|
894 | + 'QSG_show_group_desc' => 1, |
|
895 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
896 | + 'QSG_deleted' => 0, |
|
897 | + ); |
|
898 | + break; |
|
899 | + } |
|
900 | + // make sure we have some values before inserting them |
|
901 | + if (! empty($QSG_values)) { |
|
902 | + // insert system question |
|
903 | + $wpdb->insert( |
|
904 | + $table_name, |
|
905 | + $QSG_values, |
|
906 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
907 | + ); |
|
908 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
909 | + } |
|
910 | + } |
|
911 | + } |
|
912 | + // QUESTIONS |
|
913 | + global $wpdb; |
|
914 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
915 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
916 | + // what we have |
|
917 | + $questions = $wpdb->get_col($SQL); |
|
918 | + // what we should have |
|
919 | + $QST_systems = array( |
|
920 | + 'fname', |
|
921 | + 'lname', |
|
922 | + 'email', |
|
923 | + 'address', |
|
924 | + 'address2', |
|
925 | + 'city', |
|
926 | + 'country', |
|
927 | + 'state', |
|
928 | + 'zip', |
|
929 | + 'phone', |
|
930 | + ); |
|
931 | + $order_for_group_1 = 1; |
|
932 | + $order_for_group_2 = 1; |
|
933 | + // loop thru what we should have and compare to what we have |
|
934 | + foreach ($QST_systems as $QST_system) { |
|
935 | + // reset values array |
|
936 | + $QST_values = array(); |
|
937 | + // if we don't have what we should have |
|
938 | + if (! in_array($QST_system, $questions)) { |
|
939 | + // add it |
|
940 | + switch ($QST_system) { |
|
941 | + case 'fname': |
|
942 | + $QST_values = array( |
|
943 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
944 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
945 | + 'QST_system' => 'fname', |
|
946 | + 'QST_type' => 'TEXT', |
|
947 | + 'QST_required' => 1, |
|
948 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
949 | + 'QST_order' => 1, |
|
950 | + 'QST_admin_only' => 0, |
|
951 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
952 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
953 | + 'QST_deleted' => 0, |
|
954 | + ); |
|
955 | + break; |
|
956 | + case 'lname': |
|
957 | + $QST_values = array( |
|
958 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
959 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
960 | + 'QST_system' => 'lname', |
|
961 | + 'QST_type' => 'TEXT', |
|
962 | + 'QST_required' => 1, |
|
963 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
964 | + 'QST_order' => 2, |
|
965 | + 'QST_admin_only' => 0, |
|
966 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
967 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
968 | + 'QST_deleted' => 0, |
|
969 | + ); |
|
970 | + break; |
|
971 | + case 'email': |
|
972 | + $QST_values = array( |
|
973 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
974 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
975 | + 'QST_system' => 'email', |
|
976 | + 'QST_type' => 'EMAIL', |
|
977 | + 'QST_required' => 1, |
|
978 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
979 | + 'QST_order' => 3, |
|
980 | + 'QST_admin_only' => 0, |
|
981 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
982 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
983 | + 'QST_deleted' => 0, |
|
984 | + ); |
|
985 | + break; |
|
986 | + case 'address': |
|
987 | + $QST_values = array( |
|
988 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
989 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
990 | + 'QST_system' => 'address', |
|
991 | + 'QST_type' => 'TEXT', |
|
992 | + 'QST_required' => 0, |
|
993 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
994 | + 'QST_order' => 4, |
|
995 | + 'QST_admin_only' => 0, |
|
996 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
997 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
998 | + 'QST_deleted' => 0, |
|
999 | + ); |
|
1000 | + break; |
|
1001 | + case 'address2': |
|
1002 | + $QST_values = array( |
|
1003 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
1004 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
1005 | + 'QST_system' => 'address2', |
|
1006 | + 'QST_type' => 'TEXT', |
|
1007 | + 'QST_required' => 0, |
|
1008 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1009 | + 'QST_order' => 5, |
|
1010 | + 'QST_admin_only' => 0, |
|
1011 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1012 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1013 | + 'QST_deleted' => 0, |
|
1014 | + ); |
|
1015 | + break; |
|
1016 | + case 'city': |
|
1017 | + $QST_values = array( |
|
1018 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
1019 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1020 | + 'QST_system' => 'city', |
|
1021 | + 'QST_type' => 'TEXT', |
|
1022 | + 'QST_required' => 0, |
|
1023 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1024 | + 'QST_order' => 6, |
|
1025 | + 'QST_admin_only' => 0, |
|
1026 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1027 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1028 | + 'QST_deleted' => 0, |
|
1029 | + ); |
|
1030 | + break; |
|
1031 | + case 'country': |
|
1032 | + $QST_values = array( |
|
1033 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
1034 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1035 | + 'QST_system' => 'country', |
|
1036 | + 'QST_type' => 'COUNTRY', |
|
1037 | + 'QST_required' => 0, |
|
1038 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1039 | + 'QST_order' => 7, |
|
1040 | + 'QST_admin_only' => 0, |
|
1041 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1042 | + 'QST_deleted' => 0, |
|
1043 | + ); |
|
1044 | + break; |
|
1045 | + case 'state': |
|
1046 | + $QST_values = array( |
|
1047 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1048 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1049 | + 'QST_system' => 'state', |
|
1050 | + 'QST_type' => 'STATE', |
|
1051 | + 'QST_required' => 0, |
|
1052 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1053 | + 'QST_order' => 8, |
|
1054 | + 'QST_admin_only' => 0, |
|
1055 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1056 | + 'QST_deleted' => 0, |
|
1057 | + ); |
|
1058 | + break; |
|
1059 | + case 'zip': |
|
1060 | + $QST_values = array( |
|
1061 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1062 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1063 | + 'QST_system' => 'zip', |
|
1064 | + 'QST_type' => 'TEXT', |
|
1065 | + 'QST_required' => 0, |
|
1066 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1067 | + 'QST_order' => 9, |
|
1068 | + 'QST_admin_only' => 0, |
|
1069 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1070 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1071 | + 'QST_deleted' => 0, |
|
1072 | + ); |
|
1073 | + break; |
|
1074 | + case 'phone': |
|
1075 | + $QST_values = array( |
|
1076 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1077 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1078 | + 'QST_system' => 'phone', |
|
1079 | + 'QST_type' => 'TEXT', |
|
1080 | + 'QST_required' => 0, |
|
1081 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1082 | + 'QST_order' => 10, |
|
1083 | + 'QST_admin_only' => 0, |
|
1084 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1085 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1086 | + 'QST_deleted' => 0, |
|
1087 | + ); |
|
1088 | + break; |
|
1089 | + } |
|
1090 | + if (! empty($QST_values)) { |
|
1091 | + // insert system question |
|
1092 | + $wpdb->insert( |
|
1093 | + $table_name, |
|
1094 | + $QST_values, |
|
1095 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1096 | + ); |
|
1097 | + $QST_ID = $wpdb->insert_id; |
|
1098 | + // QUESTION GROUP QUESTIONS |
|
1099 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
1100 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
1101 | + } else { |
|
1102 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
1103 | + } |
|
1104 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
1105 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
1106 | + } else { |
|
1107 | + $id_col = EEM_Question_Group::instance() |
|
1108 | + ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1109 | + if (is_array($id_col)) { |
|
1110 | + $QSG_ID = reset($id_col); |
|
1111 | + } else { |
|
1112 | + //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1113 | + EE_Log::instance()->log( |
|
1114 | + __FILE__, |
|
1115 | + __FUNCTION__, |
|
1116 | + sprintf( |
|
1117 | + __( |
|
1118 | + 'Could not associate question %1$s to a question group because no system question |
|
1119 | 1119 | group existed', |
1120 | - 'event_espresso' |
|
1121 | - ), |
|
1122 | - $QST_ID), |
|
1123 | - 'error'); |
|
1124 | - continue; |
|
1125 | - } |
|
1126 | - } |
|
1127 | - // add system questions to groups |
|
1128 | - $wpdb->insert( |
|
1129 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1130 | - array( |
|
1131 | - 'QSG_ID' => $QSG_ID, |
|
1132 | - 'QST_ID' => $QST_ID, |
|
1133 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1134 | - ), |
|
1135 | - array('%d', '%d', '%d') |
|
1136 | - ); |
|
1137 | - } |
|
1138 | - } |
|
1139 | - } |
|
1140 | - } |
|
1141 | - |
|
1142 | - |
|
1143 | - /** |
|
1144 | - * Makes sure the default payment method (Invoice) is active. |
|
1145 | - * This used to be done automatically as part of constructing the old gateways config |
|
1146 | - * |
|
1147 | - * @throws \EE_Error |
|
1148 | - */ |
|
1149 | - public static function insert_default_payment_methods() |
|
1150 | - { |
|
1151 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1152 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1153 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1154 | - } else { |
|
1155 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
1156 | - } |
|
1157 | - } |
|
1158 | - |
|
1159 | - /** |
|
1160 | - * insert_default_status_codes |
|
1161 | - * |
|
1162 | - * @access public |
|
1163 | - * @static |
|
1164 | - * @return void |
|
1165 | - */ |
|
1166 | - public static function insert_default_status_codes() |
|
1167 | - { |
|
1168 | - |
|
1169 | - global $wpdb; |
|
1170 | - |
|
1171 | - if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1172 | - |
|
1173 | - $table_name = EEM_Status::instance()->table(); |
|
1174 | - |
|
1175 | - $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1176 | - $wpdb->query($SQL); |
|
1177 | - |
|
1178 | - $SQL = "INSERT INTO $table_name |
|
1120 | + 'event_espresso' |
|
1121 | + ), |
|
1122 | + $QST_ID), |
|
1123 | + 'error'); |
|
1124 | + continue; |
|
1125 | + } |
|
1126 | + } |
|
1127 | + // add system questions to groups |
|
1128 | + $wpdb->insert( |
|
1129 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1130 | + array( |
|
1131 | + 'QSG_ID' => $QSG_ID, |
|
1132 | + 'QST_ID' => $QST_ID, |
|
1133 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1134 | + ), |
|
1135 | + array('%d', '%d', '%d') |
|
1136 | + ); |
|
1137 | + } |
|
1138 | + } |
|
1139 | + } |
|
1140 | + } |
|
1141 | + |
|
1142 | + |
|
1143 | + /** |
|
1144 | + * Makes sure the default payment method (Invoice) is active. |
|
1145 | + * This used to be done automatically as part of constructing the old gateways config |
|
1146 | + * |
|
1147 | + * @throws \EE_Error |
|
1148 | + */ |
|
1149 | + public static function insert_default_payment_methods() |
|
1150 | + { |
|
1151 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1152 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1153 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1154 | + } else { |
|
1155 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
1156 | + } |
|
1157 | + } |
|
1158 | + |
|
1159 | + /** |
|
1160 | + * insert_default_status_codes |
|
1161 | + * |
|
1162 | + * @access public |
|
1163 | + * @static |
|
1164 | + * @return void |
|
1165 | + */ |
|
1166 | + public static function insert_default_status_codes() |
|
1167 | + { |
|
1168 | + |
|
1169 | + global $wpdb; |
|
1170 | + |
|
1171 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1172 | + |
|
1173 | + $table_name = EEM_Status::instance()->table(); |
|
1174 | + |
|
1175 | + $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1176 | + $wpdb->query($SQL); |
|
1177 | + |
|
1178 | + $SQL = "INSERT INTO $table_name |
|
1179 | 1179 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
1180 | 1180 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
1181 | 1181 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1215,523 +1215,523 @@ discard block |
||
1215 | 1215 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
1216 | 1216 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
1217 | 1217 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
1218 | - $wpdb->query($SQL); |
|
1219 | - |
|
1220 | - } |
|
1221 | - |
|
1222 | - } |
|
1223 | - |
|
1224 | - |
|
1225 | - /** |
|
1226 | - * create_upload_directories |
|
1227 | - * Creates folders in the uploads directory to facilitate addons and templates |
|
1228 | - * |
|
1229 | - * @access public |
|
1230 | - * @static |
|
1231 | - * @return boolean success of verifying upload directories exist |
|
1232 | - */ |
|
1233 | - public static function create_upload_directories() |
|
1234 | - { |
|
1235 | - // Create the required folders |
|
1236 | - $folders = array( |
|
1237 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
1238 | - EVENT_ESPRESSO_GATEWAY_DIR, |
|
1239 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
1240 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
1241 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
1242 | - ); |
|
1243 | - foreach ($folders as $folder) { |
|
1244 | - try { |
|
1245 | - EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
1246 | - @ chmod($folder, 0755); |
|
1247 | - } catch (EE_Error $e) { |
|
1248 | - EE_Error::add_error( |
|
1249 | - sprintf( |
|
1250 | - __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
1251 | - $folder, |
|
1252 | - '<br />' . $e->getMessage() |
|
1253 | - ), |
|
1254 | - __FILE__, __FUNCTION__, __LINE__ |
|
1255 | - ); |
|
1256 | - //indicate we'll need to fix this later |
|
1257 | - update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
1258 | - return false; |
|
1259 | - } |
|
1260 | - } |
|
1261 | - //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
1262 | - //is disabled, there might be activation errors recorded in there |
|
1263 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
1264 | - //remember EE's folders are all good |
|
1265 | - delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
1266 | - return true; |
|
1267 | - } |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * Whether the upload directories need to be fixed or not. |
|
1271 | - * If EE is installed but filesystem access isn't initially available, |
|
1272 | - * we need to get the user's filesystem credentials and THEN create them, |
|
1273 | - * so there might be period of time when EE is installed but its |
|
1274 | - * upload directories aren't available. This indicates such a state |
|
1275 | - * |
|
1276 | - * @return boolean |
|
1277 | - */ |
|
1278 | - public static function upload_directories_incomplete() |
|
1279 | - { |
|
1280 | - return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
1281 | - } |
|
1282 | - |
|
1283 | - |
|
1284 | - /** |
|
1285 | - * generate_default_message_templates |
|
1286 | - * |
|
1287 | - * @static |
|
1288 | - * @throws EE_Error |
|
1289 | - * @return bool true means new templates were created. |
|
1290 | - * false means no templates were created. |
|
1291 | - * This is NOT an error flag. To check for errors you will want |
|
1292 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
1293 | - */ |
|
1294 | - public static function generate_default_message_templates() |
|
1295 | - { |
|
1296 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1297 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1298 | - /* |
|
1218 | + $wpdb->query($SQL); |
|
1219 | + |
|
1220 | + } |
|
1221 | + |
|
1222 | + } |
|
1223 | + |
|
1224 | + |
|
1225 | + /** |
|
1226 | + * create_upload_directories |
|
1227 | + * Creates folders in the uploads directory to facilitate addons and templates |
|
1228 | + * |
|
1229 | + * @access public |
|
1230 | + * @static |
|
1231 | + * @return boolean success of verifying upload directories exist |
|
1232 | + */ |
|
1233 | + public static function create_upload_directories() |
|
1234 | + { |
|
1235 | + // Create the required folders |
|
1236 | + $folders = array( |
|
1237 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
1238 | + EVENT_ESPRESSO_GATEWAY_DIR, |
|
1239 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
1240 | + EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
1241 | + EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
1242 | + ); |
|
1243 | + foreach ($folders as $folder) { |
|
1244 | + try { |
|
1245 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
1246 | + @ chmod($folder, 0755); |
|
1247 | + } catch (EE_Error $e) { |
|
1248 | + EE_Error::add_error( |
|
1249 | + sprintf( |
|
1250 | + __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
1251 | + $folder, |
|
1252 | + '<br />' . $e->getMessage() |
|
1253 | + ), |
|
1254 | + __FILE__, __FUNCTION__, __LINE__ |
|
1255 | + ); |
|
1256 | + //indicate we'll need to fix this later |
|
1257 | + update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
1258 | + return false; |
|
1259 | + } |
|
1260 | + } |
|
1261 | + //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
1262 | + //is disabled, there might be activation errors recorded in there |
|
1263 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
1264 | + //remember EE's folders are all good |
|
1265 | + delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
1266 | + return true; |
|
1267 | + } |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * Whether the upload directories need to be fixed or not. |
|
1271 | + * If EE is installed but filesystem access isn't initially available, |
|
1272 | + * we need to get the user's filesystem credentials and THEN create them, |
|
1273 | + * so there might be period of time when EE is installed but its |
|
1274 | + * upload directories aren't available. This indicates such a state |
|
1275 | + * |
|
1276 | + * @return boolean |
|
1277 | + */ |
|
1278 | + public static function upload_directories_incomplete() |
|
1279 | + { |
|
1280 | + return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
1281 | + } |
|
1282 | + |
|
1283 | + |
|
1284 | + /** |
|
1285 | + * generate_default_message_templates |
|
1286 | + * |
|
1287 | + * @static |
|
1288 | + * @throws EE_Error |
|
1289 | + * @return bool true means new templates were created. |
|
1290 | + * false means no templates were created. |
|
1291 | + * This is NOT an error flag. To check for errors you will want |
|
1292 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
1293 | + */ |
|
1294 | + public static function generate_default_message_templates() |
|
1295 | + { |
|
1296 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1297 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1298 | + /* |
|
1299 | 1299 | * This first method is taking care of ensuring any default messengers |
1300 | 1300 | * that should be made active and have templates generated are done. |
1301 | 1301 | */ |
1302 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1303 | - $message_resource_manager |
|
1304 | - ); |
|
1305 | - /** |
|
1306 | - * This method is verifying there are no NEW default message types |
|
1307 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1308 | - */ |
|
1309 | - $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1310 | - $message_resource_manager |
|
1311 | - ); |
|
1312 | - //after all is done, let's persist these changes to the db. |
|
1313 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
1314 | - $message_resource_manager->update_active_messengers_option(); |
|
1315 | - // will return true if either of these are true. Otherwise will return false. |
|
1316 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1317 | - } |
|
1318 | - |
|
1319 | - |
|
1320 | - |
|
1321 | - /** |
|
1322 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
1323 | - * @return array|bool |
|
1324 | - * @throws \EE_Error |
|
1325 | - */ |
|
1326 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1327 | - EE_Message_Resource_Manager $message_resource_manager |
|
1328 | - ) { |
|
1329 | - /** @type EE_messenger[] $active_messengers */ |
|
1330 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1331 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1332 | - $templates_created = false; |
|
1333 | - foreach ($active_messengers as $active_messenger) { |
|
1334 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1335 | - $default_message_type_names_to_activate = array(); |
|
1336 | - // looping through each default message type reported by the messenger |
|
1337 | - // and setup the actual message types to activate. |
|
1338 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1339 | - // if already active or has already been activated before we skip |
|
1340 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1341 | - // we also skip if the message type is not installed. |
|
1342 | - if ( |
|
1343 | - $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1344 | - $default_message_type_name_for_messenger, |
|
1345 | - $active_messenger->name |
|
1346 | - ) |
|
1347 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
1348 | - $active_messenger->name, |
|
1349 | - $default_message_type_name_for_messenger |
|
1350 | - ) |
|
1351 | - || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
1352 | - ) { |
|
1353 | - continue; |
|
1354 | - } |
|
1355 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1356 | - } |
|
1357 | - //let's activate! |
|
1358 | - $message_resource_manager->ensure_message_types_are_active( |
|
1359 | - $default_message_type_names_to_activate, |
|
1360 | - $active_messenger->name, |
|
1361 | - false |
|
1362 | - ); |
|
1363 | - //activate the templates for these message types |
|
1364 | - if ( ! empty($default_message_type_names_to_activate)) { |
|
1365 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1366 | - $active_messenger->name, |
|
1367 | - $default_message_type_names_for_messenger, |
|
1368 | - '', |
|
1369 | - true |
|
1370 | - ); |
|
1371 | - } |
|
1372 | - } |
|
1373 | - return $templates_created; |
|
1374 | - } |
|
1375 | - |
|
1376 | - |
|
1377 | - |
|
1378 | - /** |
|
1379 | - * This will activate and generate default messengers and default message types for those messengers. |
|
1380 | - * |
|
1381 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
1382 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
1383 | - * False means that there were no templates generated |
|
1384 | - * (which could simply mean there are no default message types for a messenger). |
|
1385 | - * @throws EE_Error |
|
1386 | - */ |
|
1387 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1388 | - EE_Message_Resource_Manager $message_resource_manager |
|
1389 | - ) { |
|
1390 | - /** @type EE_messenger[] $messengers_to_generate */ |
|
1391 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1392 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1393 | - $templates_generated = false; |
|
1394 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1395 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1396 | - //verify the default message types match an installed message type. |
|
1397 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1398 | - if ( |
|
1399 | - ! isset($installed_message_types[$name]) |
|
1400 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1401 | - $name, |
|
1402 | - $messenger_to_generate->name |
|
1403 | - ) |
|
1404 | - ) { |
|
1405 | - unset($default_message_type_names_for_messenger[$key]); |
|
1406 | - } |
|
1407 | - } |
|
1408 | - // in previous iterations, the active_messengers option in the db |
|
1409 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1410 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
1411 | - // passing off to create templates (after the refactor is done). |
|
1412 | - // @todo remove this comment when determined not necessary. |
|
1413 | - $message_resource_manager->activate_messenger( |
|
1414 | - $messenger_to_generate->name, |
|
1415 | - $default_message_type_names_for_messenger, |
|
1416 | - false |
|
1417 | - ); |
|
1418 | - //create any templates needing created (or will reactivate templates already generated as necessary). |
|
1419 | - if ( ! empty($default_message_type_names_for_messenger)) { |
|
1420 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1421 | - $messenger_to_generate->name, |
|
1422 | - $default_message_type_names_for_messenger, |
|
1423 | - '', |
|
1424 | - true |
|
1425 | - ); |
|
1426 | - } |
|
1427 | - } |
|
1428 | - return $templates_generated; |
|
1429 | - } |
|
1430 | - |
|
1431 | - |
|
1432 | - /** |
|
1433 | - * This returns the default messengers to generate templates for on activation of EE. |
|
1434 | - * It considers: |
|
1435 | - * - whether a messenger is already active in the db. |
|
1436 | - * - whether a messenger has been made active at any time in the past. |
|
1437 | - * |
|
1438 | - * @static |
|
1439 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
1440 | - * @return EE_messenger[] |
|
1441 | - */ |
|
1442 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
1443 | - EE_Message_Resource_Manager $message_resource_manager |
|
1444 | - ) { |
|
1445 | - // make sure EED_Messages is loaded because it sets the autoloaders |
|
1446 | - require_once EE_MODULES . 'messages' . DS . 'EED_Messages.module.php'; |
|
1447 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1448 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1449 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1450 | - |
|
1451 | - $messengers_to_generate = array(); |
|
1452 | - foreach ($installed_messengers as $installed_messenger) { |
|
1453 | - //if installed messenger is a messenger that should be activated on install |
|
1454 | - //and is not already active |
|
1455 | - //and has never been activated |
|
1456 | - if ( |
|
1457 | - ! $installed_messenger->activate_on_install |
|
1458 | - || isset($active_messengers[$installed_messenger->name]) |
|
1459 | - || isset($has_activated[$installed_messenger->name]) |
|
1460 | - ) { |
|
1461 | - continue; |
|
1462 | - } |
|
1463 | - $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
1464 | - } |
|
1465 | - return $messengers_to_generate; |
|
1466 | - } |
|
1467 | - |
|
1468 | - |
|
1469 | - /** |
|
1470 | - * This simply validates active message types to ensure they actually match installed |
|
1471 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1472 | - * rows are set inactive. |
|
1473 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1474 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1475 | - * are still handled in here. |
|
1476 | - * |
|
1477 | - * @since 4.3.1 |
|
1478 | - * @return void |
|
1479 | - */ |
|
1480 | - public static function validate_messages_system() |
|
1481 | - { |
|
1482 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1483 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1484 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
1485 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1486 | - } |
|
1487 | - |
|
1488 | - |
|
1489 | - /** |
|
1490 | - * create_no_ticket_prices_array |
|
1491 | - * |
|
1492 | - * @access public |
|
1493 | - * @static |
|
1494 | - * @return void |
|
1495 | - */ |
|
1496 | - public static function create_no_ticket_prices_array() |
|
1497 | - { |
|
1498 | - // this creates an array for tracking events that have no active ticket prices created |
|
1499 | - // this allows us to warn admins of the situation so that it can be corrected |
|
1500 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1501 | - if (! $espresso_no_ticket_prices) { |
|
1502 | - add_option('ee_no_ticket_prices', array(), '', false); |
|
1503 | - } |
|
1504 | - } |
|
1505 | - |
|
1506 | - |
|
1507 | - /** |
|
1508 | - * plugin_deactivation |
|
1509 | - * |
|
1510 | - * @access public |
|
1511 | - * @static |
|
1512 | - * @return void |
|
1513 | - */ |
|
1514 | - public static function plugin_deactivation() |
|
1515 | - { |
|
1516 | - } |
|
1517 | - |
|
1518 | - |
|
1519 | - /** |
|
1520 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1521 | - * (like post meta or term relations) |
|
1522 | - * |
|
1523 | - * @global wpdb $wpdb |
|
1524 | - * @throws \EE_Error |
|
1525 | - */ |
|
1526 | - public static function delete_all_espresso_cpt_data() |
|
1527 | - { |
|
1528 | - global $wpdb; |
|
1529 | - //get all the CPT post_types |
|
1530 | - $ee_post_types = array(); |
|
1531 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1532 | - if (method_exists($model_name, 'instance')) { |
|
1533 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
1534 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
1535 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1536 | - } |
|
1537 | - } |
|
1538 | - } |
|
1539 | - //get all our CPTs |
|
1540 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1541 | - $cpt_ids = $wpdb->get_col($query); |
|
1542 | - //delete each post meta and term relations too |
|
1543 | - foreach ($cpt_ids as $post_id) { |
|
1544 | - wp_delete_post($post_id, true); |
|
1545 | - } |
|
1546 | - } |
|
1547 | - |
|
1548 | - /** |
|
1549 | - * Deletes all EE custom tables |
|
1550 | - * |
|
1551 | - * @return array |
|
1552 | - */ |
|
1553 | - public static function drop_espresso_tables() |
|
1554 | - { |
|
1555 | - $tables = array(); |
|
1556 | - // load registry |
|
1557 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1558 | - if (method_exists($model_name, 'instance')) { |
|
1559 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
1560 | - if ($model_obj instanceof EEM_Base) { |
|
1561 | - foreach ($model_obj->get_tables() as $table) { |
|
1562 | - if (strpos($table->get_table_name(), 'esp_') |
|
1563 | - && |
|
1564 | - ( |
|
1565 | - is_main_site()//main site? nuke them all |
|
1566 | - || ! $table->is_global()//not main site,but not global either. nuke it |
|
1567 | - ) |
|
1568 | - ) { |
|
1569 | - $tables[$table->get_table_name()] = $table->get_table_name(); |
|
1570 | - } |
|
1571 | - } |
|
1572 | - } |
|
1573 | - } |
|
1574 | - } |
|
1575 | - |
|
1576 | - //there are some tables whose models were removed. |
|
1577 | - //they should be removed when removing all EE core's data |
|
1578 | - $tables_without_models = array( |
|
1579 | - 'esp_promotion', |
|
1580 | - 'esp_promotion_applied', |
|
1581 | - 'esp_promotion_object', |
|
1582 | - 'esp_promotion_rule', |
|
1583 | - 'esp_rule', |
|
1584 | - ); |
|
1585 | - foreach ($tables_without_models as $table) { |
|
1586 | - $tables[$table] = $table; |
|
1587 | - } |
|
1588 | - return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1589 | - } |
|
1590 | - |
|
1591 | - |
|
1592 | - |
|
1593 | - /** |
|
1594 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1595 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
1596 | - * Returns the list actually deleted |
|
1597 | - * |
|
1598 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1599 | - * @global WPDB $wpdb |
|
1600 | - * @param array $table_names |
|
1601 | - * @return array of table names which we deleted |
|
1602 | - */ |
|
1603 | - public static function drop_tables($table_names) |
|
1604 | - { |
|
1605 | - return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1606 | - } |
|
1607 | - |
|
1608 | - |
|
1609 | - |
|
1610 | - /** |
|
1611 | - * plugin_uninstall |
|
1612 | - * |
|
1613 | - * @access public |
|
1614 | - * @static |
|
1615 | - * @param bool $remove_all |
|
1616 | - * @return void |
|
1617 | - */ |
|
1618 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1619 | - { |
|
1620 | - global $wpdb; |
|
1621 | - self::drop_espresso_tables(); |
|
1622 | - $wp_options_to_delete = array( |
|
1623 | - 'ee_no_ticket_prices' => true, |
|
1624 | - 'ee_active_messengers' => true, |
|
1625 | - 'ee_has_activated_messenger' => true, |
|
1626 | - 'ee_flush_rewrite_rules' => true, |
|
1627 | - 'ee_config' => false, |
|
1628 | - 'ee_data_migration_current_db_state' => true, |
|
1629 | - 'ee_data_migration_mapping_' => false, |
|
1630 | - 'ee_data_migration_script_' => false, |
|
1631 | - 'ee_data_migrations' => true, |
|
1632 | - 'ee_dms_map' => false, |
|
1633 | - 'ee_notices' => true, |
|
1634 | - 'lang_file_check_' => false, |
|
1635 | - 'ee_maintenance_mode' => true, |
|
1636 | - 'ee_ueip_optin' => true, |
|
1637 | - 'ee_ueip_has_notified' => true, |
|
1638 | - 'ee_plugin_activation_errors' => true, |
|
1639 | - 'ee_id_mapping_from' => false, |
|
1640 | - 'espresso_persistent_admin_notices' => true, |
|
1641 | - 'ee_encryption_key' => true, |
|
1642 | - 'pue_force_upgrade_' => false, |
|
1643 | - 'pue_json_error_' => false, |
|
1644 | - 'pue_install_key_' => false, |
|
1645 | - 'pue_verification_error_' => false, |
|
1646 | - 'pu_dismissed_upgrade_' => false, |
|
1647 | - 'external_updates-' => false, |
|
1648 | - 'ee_extra_data' => true, |
|
1649 | - 'ee_ssn_' => false, |
|
1650 | - 'ee_rss_' => false, |
|
1651 | - 'ee_rte_n_tx_' => false, |
|
1652 | - 'ee_pers_admin_notices' => true, |
|
1653 | - 'ee_job_parameters_' => false, |
|
1654 | - 'ee_upload_directories_incomplete' => true, |
|
1655 | - 'ee_verified_db_collations' => true, |
|
1656 | - ); |
|
1657 | - if (is_main_site()) { |
|
1658 | - $wp_options_to_delete['ee_network_config'] = true; |
|
1659 | - } |
|
1660 | - $undeleted_options = array(); |
|
1661 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1662 | - if ($no_wildcard) { |
|
1663 | - if ( ! delete_option($option_name)) { |
|
1664 | - $undeleted_options[] = $option_name; |
|
1665 | - } |
|
1666 | - } else { |
|
1667 | - $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1668 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1669 | - if ( ! delete_option($option_name_from_wildcard)) { |
|
1670 | - $undeleted_options[] = $option_name_from_wildcard; |
|
1671 | - } |
|
1672 | - } |
|
1673 | - } |
|
1674 | - } |
|
1675 | - //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1676 | - remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1677 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1678 | - $db_update_sans_ee4 = array(); |
|
1679 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
1680 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
1681 | - $db_update_sans_ee4[$version] = $times_activated; |
|
1682 | - } |
|
1683 | - } |
|
1684 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
1685 | - } |
|
1686 | - $errors = ''; |
|
1687 | - if ( ! empty($undeleted_options)) { |
|
1688 | - $errors .= sprintf( |
|
1689 | - __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1690 | - '<br/>', |
|
1691 | - implode(',<br/>', $undeleted_options) |
|
1692 | - ); |
|
1693 | - } |
|
1694 | - if ( ! empty($errors)) { |
|
1695 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1696 | - } |
|
1697 | - } |
|
1698 | - |
|
1699 | - /** |
|
1700 | - * Gets the mysql error code from the last used query by wpdb |
|
1701 | - * |
|
1702 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1703 | - */ |
|
1704 | - public static function last_wpdb_error_code() |
|
1705 | - { |
|
1706 | - global $wpdb; |
|
1707 | - if ($wpdb->use_mysqli) { |
|
1708 | - return mysqli_errno($wpdb->dbh); |
|
1709 | - } else { |
|
1710 | - return mysql_errno($wpdb->dbh); |
|
1711 | - } |
|
1712 | - } |
|
1713 | - |
|
1714 | - /** |
|
1715 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1716 | - * |
|
1717 | - * @global wpdb $wpdb |
|
1718 | - * @deprecated instead use TableAnalysis::tableExists() |
|
1719 | - * @param string $table_name with or without $wpdb->prefix |
|
1720 | - * @return boolean |
|
1721 | - */ |
|
1722 | - public static function table_exists($table_name) |
|
1723 | - { |
|
1724 | - return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1725 | - } |
|
1726 | - |
|
1727 | - /** |
|
1728 | - * Resets the cache on EEH_Activation |
|
1729 | - */ |
|
1730 | - public static function reset() |
|
1731 | - { |
|
1732 | - self::$_default_creator_id = null; |
|
1733 | - self::$_initialized_db_content_already_in_this_request = false; |
|
1734 | - } |
|
1302 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1303 | + $message_resource_manager |
|
1304 | + ); |
|
1305 | + /** |
|
1306 | + * This method is verifying there are no NEW default message types |
|
1307 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1308 | + */ |
|
1309 | + $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1310 | + $message_resource_manager |
|
1311 | + ); |
|
1312 | + //after all is done, let's persist these changes to the db. |
|
1313 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
1314 | + $message_resource_manager->update_active_messengers_option(); |
|
1315 | + // will return true if either of these are true. Otherwise will return false. |
|
1316 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1317 | + } |
|
1318 | + |
|
1319 | + |
|
1320 | + |
|
1321 | + /** |
|
1322 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
1323 | + * @return array|bool |
|
1324 | + * @throws \EE_Error |
|
1325 | + */ |
|
1326 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1327 | + EE_Message_Resource_Manager $message_resource_manager |
|
1328 | + ) { |
|
1329 | + /** @type EE_messenger[] $active_messengers */ |
|
1330 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1331 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1332 | + $templates_created = false; |
|
1333 | + foreach ($active_messengers as $active_messenger) { |
|
1334 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1335 | + $default_message_type_names_to_activate = array(); |
|
1336 | + // looping through each default message type reported by the messenger |
|
1337 | + // and setup the actual message types to activate. |
|
1338 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1339 | + // if already active or has already been activated before we skip |
|
1340 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1341 | + // we also skip if the message type is not installed. |
|
1342 | + if ( |
|
1343 | + $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1344 | + $default_message_type_name_for_messenger, |
|
1345 | + $active_messenger->name |
|
1346 | + ) |
|
1347 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
1348 | + $active_messenger->name, |
|
1349 | + $default_message_type_name_for_messenger |
|
1350 | + ) |
|
1351 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
1352 | + ) { |
|
1353 | + continue; |
|
1354 | + } |
|
1355 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1356 | + } |
|
1357 | + //let's activate! |
|
1358 | + $message_resource_manager->ensure_message_types_are_active( |
|
1359 | + $default_message_type_names_to_activate, |
|
1360 | + $active_messenger->name, |
|
1361 | + false |
|
1362 | + ); |
|
1363 | + //activate the templates for these message types |
|
1364 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
1365 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1366 | + $active_messenger->name, |
|
1367 | + $default_message_type_names_for_messenger, |
|
1368 | + '', |
|
1369 | + true |
|
1370 | + ); |
|
1371 | + } |
|
1372 | + } |
|
1373 | + return $templates_created; |
|
1374 | + } |
|
1375 | + |
|
1376 | + |
|
1377 | + |
|
1378 | + /** |
|
1379 | + * This will activate and generate default messengers and default message types for those messengers. |
|
1380 | + * |
|
1381 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
1382 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
1383 | + * False means that there were no templates generated |
|
1384 | + * (which could simply mean there are no default message types for a messenger). |
|
1385 | + * @throws EE_Error |
|
1386 | + */ |
|
1387 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1388 | + EE_Message_Resource_Manager $message_resource_manager |
|
1389 | + ) { |
|
1390 | + /** @type EE_messenger[] $messengers_to_generate */ |
|
1391 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1392 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1393 | + $templates_generated = false; |
|
1394 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1395 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1396 | + //verify the default message types match an installed message type. |
|
1397 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1398 | + if ( |
|
1399 | + ! isset($installed_message_types[$name]) |
|
1400 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1401 | + $name, |
|
1402 | + $messenger_to_generate->name |
|
1403 | + ) |
|
1404 | + ) { |
|
1405 | + unset($default_message_type_names_for_messenger[$key]); |
|
1406 | + } |
|
1407 | + } |
|
1408 | + // in previous iterations, the active_messengers option in the db |
|
1409 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1410 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
1411 | + // passing off to create templates (after the refactor is done). |
|
1412 | + // @todo remove this comment when determined not necessary. |
|
1413 | + $message_resource_manager->activate_messenger( |
|
1414 | + $messenger_to_generate->name, |
|
1415 | + $default_message_type_names_for_messenger, |
|
1416 | + false |
|
1417 | + ); |
|
1418 | + //create any templates needing created (or will reactivate templates already generated as necessary). |
|
1419 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
1420 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1421 | + $messenger_to_generate->name, |
|
1422 | + $default_message_type_names_for_messenger, |
|
1423 | + '', |
|
1424 | + true |
|
1425 | + ); |
|
1426 | + } |
|
1427 | + } |
|
1428 | + return $templates_generated; |
|
1429 | + } |
|
1430 | + |
|
1431 | + |
|
1432 | + /** |
|
1433 | + * This returns the default messengers to generate templates for on activation of EE. |
|
1434 | + * It considers: |
|
1435 | + * - whether a messenger is already active in the db. |
|
1436 | + * - whether a messenger has been made active at any time in the past. |
|
1437 | + * |
|
1438 | + * @static |
|
1439 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
1440 | + * @return EE_messenger[] |
|
1441 | + */ |
|
1442 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
1443 | + EE_Message_Resource_Manager $message_resource_manager |
|
1444 | + ) { |
|
1445 | + // make sure EED_Messages is loaded because it sets the autoloaders |
|
1446 | + require_once EE_MODULES . 'messages' . DS . 'EED_Messages.module.php'; |
|
1447 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1448 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1449 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1450 | + |
|
1451 | + $messengers_to_generate = array(); |
|
1452 | + foreach ($installed_messengers as $installed_messenger) { |
|
1453 | + //if installed messenger is a messenger that should be activated on install |
|
1454 | + //and is not already active |
|
1455 | + //and has never been activated |
|
1456 | + if ( |
|
1457 | + ! $installed_messenger->activate_on_install |
|
1458 | + || isset($active_messengers[$installed_messenger->name]) |
|
1459 | + || isset($has_activated[$installed_messenger->name]) |
|
1460 | + ) { |
|
1461 | + continue; |
|
1462 | + } |
|
1463 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
1464 | + } |
|
1465 | + return $messengers_to_generate; |
|
1466 | + } |
|
1467 | + |
|
1468 | + |
|
1469 | + /** |
|
1470 | + * This simply validates active message types to ensure they actually match installed |
|
1471 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1472 | + * rows are set inactive. |
|
1473 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1474 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1475 | + * are still handled in here. |
|
1476 | + * |
|
1477 | + * @since 4.3.1 |
|
1478 | + * @return void |
|
1479 | + */ |
|
1480 | + public static function validate_messages_system() |
|
1481 | + { |
|
1482 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1483 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1484 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
1485 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1486 | + } |
|
1487 | + |
|
1488 | + |
|
1489 | + /** |
|
1490 | + * create_no_ticket_prices_array |
|
1491 | + * |
|
1492 | + * @access public |
|
1493 | + * @static |
|
1494 | + * @return void |
|
1495 | + */ |
|
1496 | + public static function create_no_ticket_prices_array() |
|
1497 | + { |
|
1498 | + // this creates an array for tracking events that have no active ticket prices created |
|
1499 | + // this allows us to warn admins of the situation so that it can be corrected |
|
1500 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1501 | + if (! $espresso_no_ticket_prices) { |
|
1502 | + add_option('ee_no_ticket_prices', array(), '', false); |
|
1503 | + } |
|
1504 | + } |
|
1505 | + |
|
1506 | + |
|
1507 | + /** |
|
1508 | + * plugin_deactivation |
|
1509 | + * |
|
1510 | + * @access public |
|
1511 | + * @static |
|
1512 | + * @return void |
|
1513 | + */ |
|
1514 | + public static function plugin_deactivation() |
|
1515 | + { |
|
1516 | + } |
|
1517 | + |
|
1518 | + |
|
1519 | + /** |
|
1520 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1521 | + * (like post meta or term relations) |
|
1522 | + * |
|
1523 | + * @global wpdb $wpdb |
|
1524 | + * @throws \EE_Error |
|
1525 | + */ |
|
1526 | + public static function delete_all_espresso_cpt_data() |
|
1527 | + { |
|
1528 | + global $wpdb; |
|
1529 | + //get all the CPT post_types |
|
1530 | + $ee_post_types = array(); |
|
1531 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1532 | + if (method_exists($model_name, 'instance')) { |
|
1533 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1534 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
1535 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1536 | + } |
|
1537 | + } |
|
1538 | + } |
|
1539 | + //get all our CPTs |
|
1540 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1541 | + $cpt_ids = $wpdb->get_col($query); |
|
1542 | + //delete each post meta and term relations too |
|
1543 | + foreach ($cpt_ids as $post_id) { |
|
1544 | + wp_delete_post($post_id, true); |
|
1545 | + } |
|
1546 | + } |
|
1547 | + |
|
1548 | + /** |
|
1549 | + * Deletes all EE custom tables |
|
1550 | + * |
|
1551 | + * @return array |
|
1552 | + */ |
|
1553 | + public static function drop_espresso_tables() |
|
1554 | + { |
|
1555 | + $tables = array(); |
|
1556 | + // load registry |
|
1557 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1558 | + if (method_exists($model_name, 'instance')) { |
|
1559 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1560 | + if ($model_obj instanceof EEM_Base) { |
|
1561 | + foreach ($model_obj->get_tables() as $table) { |
|
1562 | + if (strpos($table->get_table_name(), 'esp_') |
|
1563 | + && |
|
1564 | + ( |
|
1565 | + is_main_site()//main site? nuke them all |
|
1566 | + || ! $table->is_global()//not main site,but not global either. nuke it |
|
1567 | + ) |
|
1568 | + ) { |
|
1569 | + $tables[$table->get_table_name()] = $table->get_table_name(); |
|
1570 | + } |
|
1571 | + } |
|
1572 | + } |
|
1573 | + } |
|
1574 | + } |
|
1575 | + |
|
1576 | + //there are some tables whose models were removed. |
|
1577 | + //they should be removed when removing all EE core's data |
|
1578 | + $tables_without_models = array( |
|
1579 | + 'esp_promotion', |
|
1580 | + 'esp_promotion_applied', |
|
1581 | + 'esp_promotion_object', |
|
1582 | + 'esp_promotion_rule', |
|
1583 | + 'esp_rule', |
|
1584 | + ); |
|
1585 | + foreach ($tables_without_models as $table) { |
|
1586 | + $tables[$table] = $table; |
|
1587 | + } |
|
1588 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1589 | + } |
|
1590 | + |
|
1591 | + |
|
1592 | + |
|
1593 | + /** |
|
1594 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1595 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
1596 | + * Returns the list actually deleted |
|
1597 | + * |
|
1598 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1599 | + * @global WPDB $wpdb |
|
1600 | + * @param array $table_names |
|
1601 | + * @return array of table names which we deleted |
|
1602 | + */ |
|
1603 | + public static function drop_tables($table_names) |
|
1604 | + { |
|
1605 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1606 | + } |
|
1607 | + |
|
1608 | + |
|
1609 | + |
|
1610 | + /** |
|
1611 | + * plugin_uninstall |
|
1612 | + * |
|
1613 | + * @access public |
|
1614 | + * @static |
|
1615 | + * @param bool $remove_all |
|
1616 | + * @return void |
|
1617 | + */ |
|
1618 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1619 | + { |
|
1620 | + global $wpdb; |
|
1621 | + self::drop_espresso_tables(); |
|
1622 | + $wp_options_to_delete = array( |
|
1623 | + 'ee_no_ticket_prices' => true, |
|
1624 | + 'ee_active_messengers' => true, |
|
1625 | + 'ee_has_activated_messenger' => true, |
|
1626 | + 'ee_flush_rewrite_rules' => true, |
|
1627 | + 'ee_config' => false, |
|
1628 | + 'ee_data_migration_current_db_state' => true, |
|
1629 | + 'ee_data_migration_mapping_' => false, |
|
1630 | + 'ee_data_migration_script_' => false, |
|
1631 | + 'ee_data_migrations' => true, |
|
1632 | + 'ee_dms_map' => false, |
|
1633 | + 'ee_notices' => true, |
|
1634 | + 'lang_file_check_' => false, |
|
1635 | + 'ee_maintenance_mode' => true, |
|
1636 | + 'ee_ueip_optin' => true, |
|
1637 | + 'ee_ueip_has_notified' => true, |
|
1638 | + 'ee_plugin_activation_errors' => true, |
|
1639 | + 'ee_id_mapping_from' => false, |
|
1640 | + 'espresso_persistent_admin_notices' => true, |
|
1641 | + 'ee_encryption_key' => true, |
|
1642 | + 'pue_force_upgrade_' => false, |
|
1643 | + 'pue_json_error_' => false, |
|
1644 | + 'pue_install_key_' => false, |
|
1645 | + 'pue_verification_error_' => false, |
|
1646 | + 'pu_dismissed_upgrade_' => false, |
|
1647 | + 'external_updates-' => false, |
|
1648 | + 'ee_extra_data' => true, |
|
1649 | + 'ee_ssn_' => false, |
|
1650 | + 'ee_rss_' => false, |
|
1651 | + 'ee_rte_n_tx_' => false, |
|
1652 | + 'ee_pers_admin_notices' => true, |
|
1653 | + 'ee_job_parameters_' => false, |
|
1654 | + 'ee_upload_directories_incomplete' => true, |
|
1655 | + 'ee_verified_db_collations' => true, |
|
1656 | + ); |
|
1657 | + if (is_main_site()) { |
|
1658 | + $wp_options_to_delete['ee_network_config'] = true; |
|
1659 | + } |
|
1660 | + $undeleted_options = array(); |
|
1661 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1662 | + if ($no_wildcard) { |
|
1663 | + if ( ! delete_option($option_name)) { |
|
1664 | + $undeleted_options[] = $option_name; |
|
1665 | + } |
|
1666 | + } else { |
|
1667 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1668 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1669 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
1670 | + $undeleted_options[] = $option_name_from_wildcard; |
|
1671 | + } |
|
1672 | + } |
|
1673 | + } |
|
1674 | + } |
|
1675 | + //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1676 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1677 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1678 | + $db_update_sans_ee4 = array(); |
|
1679 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
1680 | + if ((string)$version[0] === '3') {//if its NON EE4 |
|
1681 | + $db_update_sans_ee4[$version] = $times_activated; |
|
1682 | + } |
|
1683 | + } |
|
1684 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
1685 | + } |
|
1686 | + $errors = ''; |
|
1687 | + if ( ! empty($undeleted_options)) { |
|
1688 | + $errors .= sprintf( |
|
1689 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1690 | + '<br/>', |
|
1691 | + implode(',<br/>', $undeleted_options) |
|
1692 | + ); |
|
1693 | + } |
|
1694 | + if ( ! empty($errors)) { |
|
1695 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1696 | + } |
|
1697 | + } |
|
1698 | + |
|
1699 | + /** |
|
1700 | + * Gets the mysql error code from the last used query by wpdb |
|
1701 | + * |
|
1702 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1703 | + */ |
|
1704 | + public static function last_wpdb_error_code() |
|
1705 | + { |
|
1706 | + global $wpdb; |
|
1707 | + if ($wpdb->use_mysqli) { |
|
1708 | + return mysqli_errno($wpdb->dbh); |
|
1709 | + } else { |
|
1710 | + return mysql_errno($wpdb->dbh); |
|
1711 | + } |
|
1712 | + } |
|
1713 | + |
|
1714 | + /** |
|
1715 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1716 | + * |
|
1717 | + * @global wpdb $wpdb |
|
1718 | + * @deprecated instead use TableAnalysis::tableExists() |
|
1719 | + * @param string $table_name with or without $wpdb->prefix |
|
1720 | + * @return boolean |
|
1721 | + */ |
|
1722 | + public static function table_exists($table_name) |
|
1723 | + { |
|
1724 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1725 | + } |
|
1726 | + |
|
1727 | + /** |
|
1728 | + * Resets the cache on EEH_Activation |
|
1729 | + */ |
|
1730 | + public static function reset() |
|
1731 | + { |
|
1732 | + self::$_default_creator_id = null; |
|
1733 | + self::$_initialized_db_content_already_in_this_request = false; |
|
1734 | + } |
|
1735 | 1735 | } |
1736 | 1736 | // End of file EEH_Activation.helper.php |
1737 | 1737 | // Location: /helpers/EEH_Activation.core.php |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public static function getTableAnalysis() |
67 | 67 | { |
68 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
68 | + if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
69 | 69 | self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
70 | 70 | } |
71 | 71 | return self::$table_analysis; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public static function getTableManager() |
79 | 79 | { |
80 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
80 | + if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
81 | 81 | self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
82 | 82 | } |
83 | 83 | return self::$table_manager; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | if ($which_to_include === 'old') { |
194 | 194 | $cron_tasks = array_filter( |
195 | 195 | $cron_tasks, |
196 | - function ($value) { |
|
196 | + function($value) { |
|
197 | 197 | return $value === EEH_Activation::cron_task_no_longer_in_use; |
198 | 198 | } |
199 | 199 | ); |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | { |
224 | 224 | |
225 | 225 | foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
226 | - if (! wp_next_scheduled($hook_name)) { |
|
226 | + if ( ! wp_next_scheduled($hook_name)) { |
|
227 | 227 | /** |
228 | 228 | * This allows client code to define the initial start timestamp for this schedule. |
229 | 229 | */ |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | 3 |
329 | 329 | ); |
330 | 330 | //EE_Config::reset(); |
331 | - if (! EE_Config::logging_enabled()) { |
|
331 | + if ( ! EE_Config::logging_enabled()) { |
|
332 | 332 | delete_option(EE_Config::LOG_NAME); |
333 | 333 | } |
334 | 334 | } |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | public static function load_calendar_config() |
344 | 344 | { |
345 | 345 | // grab array of all plugin folders and loop thru it |
346 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
346 | + $plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR); |
|
347 | 347 | if (empty($plugins)) { |
348 | 348 | return; |
349 | 349 | } |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | || strpos($plugin, 'calendar') !== false |
361 | 361 | ) { |
362 | 362 | // this is what we are looking for |
363 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
363 | + $calendar_config = $plugin_path.DS.'EE_Calendar_Config.php'; |
|
364 | 364 | // does it exist in this folder ? |
365 | 365 | if (is_readable($calendar_config)) { |
366 | 366 | // YEAH! let's load it |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | ) { |
489 | 489 | //update Config with post ID |
490 | 490 | $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
491 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
491 | + if ( ! EE_Config::instance()->update_espresso_config(false, false)) { |
|
492 | 492 | $msg = __( |
493 | 493 | 'The Event Espresso critical page configuration settings could not be updated.', |
494 | 494 | 'event_espresso' |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
512 | 512 | 'event_espresso' |
513 | 513 | ), |
514 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
514 | + '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">' |
|
515 | 515 | . __('Event Espresso Critical Pages Settings', 'event_espresso') |
516 | 516 | . '</a>' |
517 | 517 | ) |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | public static function get_page_by_ee_shortcode($ee_shortcode) |
538 | 538 | { |
539 | 539 | global $wpdb; |
540 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
540 | + $shortcode_and_opening_bracket = '['.$ee_shortcode; |
|
541 | 541 | $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
542 | 542 | if ($post_id) { |
543 | 543 | return get_post($post_id); |
@@ -563,11 +563,11 @@ discard block |
||
563 | 563 | 'post_status' => 'publish', |
564 | 564 | 'post_type' => 'page', |
565 | 565 | 'comment_status' => 'closed', |
566 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
566 | + 'post_content' => '['.$critical_page['code'].']', |
|
567 | 567 | ); |
568 | 568 | |
569 | 569 | $post_id = wp_insert_post($post_args); |
570 | - if (! $post_id) { |
|
570 | + if ( ! $post_id) { |
|
571 | 571 | $msg = sprintf( |
572 | 572 | __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
573 | 573 | $critical_page['name'] |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | return $critical_page; |
577 | 577 | } |
578 | 578 | // get newly created post's details |
579 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
579 | + if ( ! $critical_page['post'] = get_post($post_id)) { |
|
580 | 580 | $msg = sprintf( |
581 | 581 | __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
582 | 582 | $critical_page['name'] |
@@ -613,17 +613,17 @@ discard block |
||
613 | 613 | $role_to_check |
614 | 614 | ); |
615 | 615 | if ($pre_filtered_id !== false) { |
616 | - return (int)$pre_filtered_id; |
|
616 | + return (int) $pre_filtered_id; |
|
617 | 617 | } |
618 | 618 | $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
619 | 619 | $query = $wpdb->prepare( |
620 | 620 | "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
621 | - '%' . $role_to_check . '%' |
|
621 | + '%'.$role_to_check.'%' |
|
622 | 622 | ); |
623 | 623 | $user_id = $wpdb->get_var($query); |
624 | 624 | $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
625 | - if ($user_id && (int)$user_id) { |
|
626 | - self::$_default_creator_id = (int)$user_id; |
|
625 | + if ($user_id && (int) $user_id) { |
|
626 | + self::$_default_creator_id = (int) $user_id; |
|
627 | 627 | return self::$_default_creator_id; |
628 | 628 | } else { |
629 | 629 | return null; |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | } |
659 | 659 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
660 | 660 | if ( ! function_exists('dbDelta')) { |
661 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
661 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
662 | 662 | } |
663 | 663 | $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
664 | 664 | $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
@@ -869,13 +869,13 @@ discard block |
||
869 | 869 | // reset values array |
870 | 870 | $QSG_values = array(); |
871 | 871 | // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
872 | - if (! in_array("$QSG_system", $question_groups)) { |
|
872 | + if ( ! in_array("$QSG_system", $question_groups)) { |
|
873 | 873 | // add it |
874 | 874 | switch ($QSG_system) { |
875 | 875 | case 1: |
876 | 876 | $QSG_values = array( |
877 | 877 | 'QSG_name' => __('Personal Information', 'event_espresso'), |
878 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
878 | + 'QSG_identifier' => 'personal-information-'.time(), |
|
879 | 879 | 'QSG_desc' => '', |
880 | 880 | 'QSG_order' => 1, |
881 | 881 | 'QSG_show_group_name' => 1, |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | case 2: |
888 | 888 | $QSG_values = array( |
889 | 889 | 'QSG_name' => __('Address Information', 'event_espresso'), |
890 | - 'QSG_identifier' => 'address-information-' . time(), |
|
890 | + 'QSG_identifier' => 'address-information-'.time(), |
|
891 | 891 | 'QSG_desc' => '', |
892 | 892 | 'QSG_order' => 2, |
893 | 893 | 'QSG_show_group_name' => 1, |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | break; |
899 | 899 | } |
900 | 900 | // make sure we have some values before inserting them |
901 | - if (! empty($QSG_values)) { |
|
901 | + if ( ! empty($QSG_values)) { |
|
902 | 902 | // insert system question |
903 | 903 | $wpdb->insert( |
904 | 904 | $table_name, |
@@ -935,7 +935,7 @@ discard block |
||
935 | 935 | // reset values array |
936 | 936 | $QST_values = array(); |
937 | 937 | // if we don't have what we should have |
938 | - if (! in_array($QST_system, $questions)) { |
|
938 | + if ( ! in_array($QST_system, $questions)) { |
|
939 | 939 | // add it |
940 | 940 | switch ($QST_system) { |
941 | 941 | case 'fname': |
@@ -1087,7 +1087,7 @@ discard block |
||
1087 | 1087 | ); |
1088 | 1088 | break; |
1089 | 1089 | } |
1090 | - if (! empty($QST_values)) { |
|
1090 | + if ( ! empty($QST_values)) { |
|
1091 | 1091 | // insert system question |
1092 | 1092 | $wpdb->insert( |
1093 | 1093 | $table_name, |
@@ -1148,7 +1148,7 @@ discard block |
||
1148 | 1148 | */ |
1149 | 1149 | public static function insert_default_payment_methods() |
1150 | 1150 | { |
1151 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1151 | + if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1152 | 1152 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
1153 | 1153 | EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
1154 | 1154 | } else { |
@@ -1236,9 +1236,9 @@ discard block |
||
1236 | 1236 | $folders = array( |
1237 | 1237 | EVENT_ESPRESSO_TEMPLATE_DIR, |
1238 | 1238 | EVENT_ESPRESSO_GATEWAY_DIR, |
1239 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
1240 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
1241 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
1239 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/', |
|
1240 | + EVENT_ESPRESSO_UPLOAD_DIR.'css/', |
|
1241 | + EVENT_ESPRESSO_UPLOAD_DIR.'tickets/', |
|
1242 | 1242 | ); |
1243 | 1243 | foreach ($folders as $folder) { |
1244 | 1244 | try { |
@@ -1249,7 +1249,7 @@ discard block |
||
1249 | 1249 | sprintf( |
1250 | 1250 | __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
1251 | 1251 | $folder, |
1252 | - '<br />' . $e->getMessage() |
|
1252 | + '<br />'.$e->getMessage() |
|
1253 | 1253 | ), |
1254 | 1254 | __FILE__, __FUNCTION__, __LINE__ |
1255 | 1255 | ); |
@@ -1260,7 +1260,7 @@ discard block |
||
1260 | 1260 | } |
1261 | 1261 | //just add the .htaccess file to the logs directory to begin with. Even if logging |
1262 | 1262 | //is disabled, there might be activation errors recorded in there |
1263 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
1263 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs/'); |
|
1264 | 1264 | //remember EE's folders are all good |
1265 | 1265 | delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
1266 | 1266 | return true; |
@@ -1443,7 +1443,7 @@ discard block |
||
1443 | 1443 | EE_Message_Resource_Manager $message_resource_manager |
1444 | 1444 | ) { |
1445 | 1445 | // make sure EED_Messages is loaded because it sets the autoloaders |
1446 | - require_once EE_MODULES . 'messages' . DS . 'EED_Messages.module.php'; |
|
1446 | + require_once EE_MODULES.'messages'.DS.'EED_Messages.module.php'; |
|
1447 | 1447 | $active_messengers = $message_resource_manager->active_messengers(); |
1448 | 1448 | $installed_messengers = $message_resource_manager->installed_messengers(); |
1449 | 1449 | $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
@@ -1498,7 +1498,7 @@ discard block |
||
1498 | 1498 | // this creates an array for tracking events that have no active ticket prices created |
1499 | 1499 | // this allows us to warn admins of the situation so that it can be corrected |
1500 | 1500 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
1501 | - if (! $espresso_no_ticket_prices) { |
|
1501 | + if ( ! $espresso_no_ticket_prices) { |
|
1502 | 1502 | add_option('ee_no_ticket_prices', array(), '', false); |
1503 | 1503 | } |
1504 | 1504 | } |
@@ -1537,7 +1537,7 @@ discard block |
||
1537 | 1537 | } |
1538 | 1538 | } |
1539 | 1539 | //get all our CPTs |
1540 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1540 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")"; |
|
1541 | 1541 | $cpt_ids = $wpdb->get_col($query); |
1542 | 1542 | //delete each post meta and term relations too |
1543 | 1543 | foreach ($cpt_ids as $post_id) { |
@@ -1677,7 +1677,7 @@ discard block |
||
1677 | 1677 | if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
1678 | 1678 | $db_update_sans_ee4 = array(); |
1679 | 1679 | foreach ($espresso_db_update as $version => $times_activated) { |
1680 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
1680 | + if ((string) $version[0] === '3') {//if its NON EE4 |
|
1681 | 1681 | $db_update_sans_ee4[$version] = $times_activated; |
1682 | 1682 | } |
1683 | 1683 | } |
@@ -1,3 +1,3 @@ |
||
1 | 1 | <h2><?php esc_html_e('What is the Event Espresso Messages System?', 'event_espresso'); ?></h2> |
2 | -<p><?php printf( esc_html__('The Event Espresso Messages system is a powerful framework that Event Espresso uses to prepare %1$smessages%2$s for different types of use (message types) and delivered by different %1$smessengers%2$s.', 'event_espresso'), '<strong>', '</strong>' ); ?></p> |
|
2 | +<p><?php printf(esc_html__('The Event Espresso Messages system is a powerful framework that Event Espresso uses to prepare %1$smessages%2$s for different types of use (message types) and delivered by different %1$smessengers%2$s.', 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
3 | 3 | <p><?php esc_html_e('We\'ve intentionally created this framework so that we have as much flexibility as possible for future ideas that we think of (or customers think of) for the kinds of messages that get sent out related to your events.', 'event_espresso'); ?></p> |
4 | 4 | \ No newline at end of file |
@@ -31,35 +31,35 @@ discard block |
||
31 | 31 | <tbody> |
32 | 32 | <tr> |
33 | 33 | <td> |
34 | - <h2><?php printf( esc_html__( 'Hello, %s:', 'event_espresso' ), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]' ); ?></h2> |
|
35 | - <p class="lead"><?php printf( esc_html__( 'Your payment was %1$sCANCELLED%2$s for the following transaction and ticket purchases:', 'event_espresso' ), '<strong>', '</strong>'); ?></p> |
|
36 | - <h3><?php esc_html_e( 'Payment Details:', 'event_espresso' ); ?></h3> |
|
34 | + <h2><?php printf(esc_html__('Hello, %s:', 'event_espresso'), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]'); ?></h2> |
|
35 | + <p class="lead"><?php printf(esc_html__('Your payment was %1$sCANCELLED%2$s for the following transaction and ticket purchases:', 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
36 | + <h3><?php esc_html_e('Payment Details:', 'event_espresso'); ?></h3> |
|
37 | 37 | <ul> |
38 | 38 | <li> |
39 | - <strong><?php esc_html_e( 'Payment Status:', 'event_espresso' ); ?></strong> [PAYMENT_STATUS] |
|
39 | + <strong><?php esc_html_e('Payment Status:', 'event_espresso'); ?></strong> [PAYMENT_STATUS] |
|
40 | 40 | </li> |
41 | 41 | <li> |
42 | - <strong><?php esc_html_e( 'Transaction ID:', 'event_espresso' ); ?></strong> [TXN_ID] |
|
42 | + <strong><?php esc_html_e('Transaction ID:', 'event_espresso'); ?></strong> [TXN_ID] |
|
43 | 43 | </li> |
44 | 44 | <li> |
45 | - <strong><?php esc_html_e( 'Total Cost:', 'event_espresso' ); ?></strong> [TOTAL_COST] |
|
45 | + <strong><?php esc_html_e('Total Cost:', 'event_espresso'); ?></strong> [TOTAL_COST] |
|
46 | 46 | </li> |
47 | 47 | <li> |
48 | - <strong><?php esc_html_e( 'Payment Method:', 'event_espresso' ); ?></strong> [PAYMENT_GATEWAY] |
|
48 | + <strong><?php esc_html_e('Payment Method:', 'event_espresso'); ?></strong> [PAYMENT_GATEWAY] |
|
49 | 49 | </li> |
50 | 50 | <li> |
51 | - <strong><?php esc_html_e( 'Payment Amount:', 'event_espresso' ); ?></strong> [AMOUNT_PAID] |
|
51 | + <strong><?php esc_html_e('Payment Amount:', 'event_espresso'); ?></strong> [AMOUNT_PAID] |
|
52 | 52 | </li> |
53 | 53 | <li> |
54 | - <strong><?php esc_html_e( 'Amount Due:', 'event_espresso' ); ?></strong> [TOTAL_OWING] |
|
54 | + <strong><?php esc_html_e('Amount Due:', 'event_espresso'); ?></strong> [TOTAL_OWING] |
|
55 | 55 | </li> |
56 | 56 | </ul> |
57 | 57 | <p class="callout"> |
58 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
58 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
59 | 59 | </p> |
60 | 60 | [EVENT_LIST] |
61 | 61 | <p class="callout"> |
62 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
62 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
63 | 63 | </p> |
64 | 64 | </td> |
65 | 65 | </tr> |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | <tbody> |
85 | 85 | <tr> |
86 | 86 | <td> |
87 | - <h3><?php esc_html_e( 'Connect with Us:', 'event_espresso' ); ?></h3> |
|
88 | - <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e( 'Facebook', 'event_espresso' ); ?></a> |
|
89 | - <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e( 'Twitter', 'event_espresso' ); ?></a> |
|
90 | - <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e( 'Google+', 'event_espresso' ); ?></a> |
|
87 | + <h3><?php esc_html_e('Connect with Us:', 'event_espresso'); ?></h3> |
|
88 | + <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e('Facebook', 'event_espresso'); ?></a> |
|
89 | + <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e('Twitter', 'event_espresso'); ?></a> |
|
90 | + <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e('Google+', 'event_espresso'); ?></a> |
|
91 | 91 | </td> |
92 | 92 | </tr> |
93 | 93 | </tbody> |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | <tbody> |
98 | 98 | <tr> |
99 | 99 | <td> |
100 | - <h3><?php esc_html_e( 'Contact Info:', 'event_espresso' ); ?></h3> |
|
101 | - <?php esc_html_e( 'Phone:', 'event_espresso' ); ?> <strong>[CO_PHONE]</strong> |
|
102 | - <?php esc_html_e( 'Email:', 'event_espresso' ); ?> <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
|
100 | + <h3><?php esc_html_e('Contact Info:', 'event_espresso'); ?></h3> |
|
101 | + <?php esc_html_e('Phone:', 'event_espresso'); ?> <strong>[CO_PHONE]</strong> |
|
102 | + <?php esc_html_e('Email:', 'event_espresso'); ?> <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
|
103 | 103 | </td> |
104 | 104 | </tr> |
105 | 105 | </tbody> |