@@ -36,55 +36,55 @@ discard block |
||
| 36 | 36 | <h3 class="espresso-header ee-status-bg--info"> |
| 37 | 37 | <span class="dashicons dashicons-flag ee-icon-size-22"></span> |
| 38 | 38 | <?php |
| 39 | - echo esc_html( |
|
| 40 | - apply_filters( |
|
| 41 | - 'FHEE__ee_migration_page__header', |
|
| 42 | - sprintf( |
|
| 43 | - __("Your Event Espresso data needs to be updated.", "event_espresso"), |
|
| 44 | - $current_db_state, |
|
| 45 | - $next_db_state |
|
| 46 | - ), |
|
| 47 | - $current_db_state, |
|
| 48 | - $next_db_state |
|
| 49 | - ) |
|
| 50 | - ); |
|
| 51 | - ?> |
|
| 39 | + echo esc_html( |
|
| 40 | + apply_filters( |
|
| 41 | + 'FHEE__ee_migration_page__header', |
|
| 42 | + sprintf( |
|
| 43 | + __("Your Event Espresso data needs to be updated.", "event_espresso"), |
|
| 44 | + $current_db_state, |
|
| 45 | + $next_db_state |
|
| 46 | + ), |
|
| 47 | + $current_db_state, |
|
| 48 | + $next_db_state |
|
| 49 | + ) |
|
| 50 | + ); |
|
| 51 | + ?> |
|
| 52 | 52 | </h3> |
| 53 | 53 | <?php } elseif ($show_most_recent_migration) { ?> |
| 54 | 54 | <h3 class="espresso-header ee-status-bg--info"> |
| 55 | 55 | <span class="dashicons dashicons-awards ee-icon-size-22"></span> |
| 56 | 56 | <?php echo esc_html( |
| 57 | - apply_filters( |
|
| 58 | - 'FHEE__ee_migration_page__done_migration_header', |
|
| 59 | - sprintf( |
|
| 60 | - __( |
|
| 61 | - 'Congratulations! Your database is "up-to-date" and you are ready to begin using %s', |
|
| 62 | - "event_espresso" |
|
| 63 | - ), |
|
| 64 | - $ultimate_db_state |
|
| 65 | - ) |
|
| 66 | - ) |
|
| 67 | - ); ?> |
|
| 57 | + apply_filters( |
|
| 58 | + 'FHEE__ee_migration_page__done_migration_header', |
|
| 59 | + sprintf( |
|
| 60 | + __( |
|
| 61 | + 'Congratulations! Your database is "up-to-date" and you are ready to begin using %s', |
|
| 62 | + "event_espresso" |
|
| 63 | + ), |
|
| 64 | + $ultimate_db_state |
|
| 65 | + ) |
|
| 66 | + ) |
|
| 67 | + ); ?> |
|
| 68 | 68 | </h3> |
| 69 | 69 | <p> |
| 70 | 70 | <?php echo esc_html( |
| 71 | - apply_filters( |
|
| 72 | - 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
| 73 | - sprintf( |
|
| 74 | - __( |
|
| 75 | - "Time to find out about all the great new features %s has to offer.", |
|
| 76 | - "event_espresso" |
|
| 77 | - ), |
|
| 78 | - $ultimate_db_state |
|
| 79 | - ) |
|
| 80 | - ) |
|
| 81 | - ); ?> |
|
| 71 | + apply_filters( |
|
| 72 | + 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
| 73 | + sprintf( |
|
| 74 | + __( |
|
| 75 | + "Time to find out about all the great new features %s has to offer.", |
|
| 76 | + "event_espresso" |
|
| 77 | + ), |
|
| 78 | + $ultimate_db_state |
|
| 79 | + ) |
|
| 80 | + ) |
|
| 81 | + ); ?> |
|
| 82 | 82 | <b> |
| 83 | 83 | <a class="button--primary" |
| 84 | 84 | id='get-started-after-migrate' |
| 85 | 85 | href="<?php |
| 86 | - echo esc_url_raw(add_query_arg(['page' => 'espresso_about'], admin_url('admin.php'))); |
|
| 87 | - ?>" |
|
| 86 | + echo esc_url_raw(add_query_arg(['page' => 'espresso_about'], admin_url('admin.php'))); |
|
| 87 | + ?>" |
|
| 88 | 88 | > |
| 89 | 89 | <?php esc_html_e("Let's Get Started", "event_espresso"); ?> |
| 90 | 90 | <span class="dashicons dashicons-arrow-right ee-icon-size-22" style="margin:0;"></span> |
@@ -95,46 +95,46 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | |
| 97 | 97 | <?php |
| 98 | - if ($show_backup_db_text) { |
|
| 99 | - echo wp_kses($migration_options_html, AllowedTags::getAllowedTags()); |
|
| 100 | - } ?> |
|
| 98 | + if ($show_backup_db_text) { |
|
| 99 | + echo wp_kses($migration_options_html, AllowedTags::getAllowedTags()); |
|
| 100 | + } ?> |
|
| 101 | 101 | |
| 102 | 102 | <?php |
| 103 | - if ($show_most_recent_migration) { |
|
| 104 | - if ($most_recent_migration instanceof EE_Data_Migration_Script_Base) { |
|
| 105 | - if ($most_recent_migration->can_continue()) { |
|
| 106 | - // tell the user they should continue their migration because it appears to be unfinished... well, assuming there were no errors ?> |
|
| 103 | + if ($show_most_recent_migration) { |
|
| 104 | + if ($most_recent_migration instanceof EE_Data_Migration_Script_Base) { |
|
| 105 | + if ($most_recent_migration->can_continue()) { |
|
| 106 | + // tell the user they should continue their migration because it appears to be unfinished... well, assuming there were no errors ?> |
|
| 107 | 107 | <h3 class="espresso-header ee-status-bg--info"> |
| 108 | 108 | <span class="dashicons dashicons-star-half ee-icon-size-22"></span> |
| 109 | 109 | <?php printf( |
| 110 | - esc_html__( |
|
| 111 | - "It appears that your previous Database Update (%s) is incomplete, and should be resumed", |
|
| 112 | - "event_espresso" |
|
| 113 | - ), |
|
| 114 | - $most_recent_migration->pretty_name() |
|
| 115 | - ); ?> |
|
| 110 | + esc_html__( |
|
| 111 | + "It appears that your previous Database Update (%s) is incomplete, and should be resumed", |
|
| 112 | + "event_espresso" |
|
| 113 | + ), |
|
| 114 | + $most_recent_migration->pretty_name() |
|
| 115 | + ); ?> |
|
| 116 | 116 | </h3> |
| 117 | 117 | <?php |
| 118 | - } elseif ($most_recent_migration->is_broken()) { |
|
| 119 | - // tell the user the migration failed, and they should notify EE?> |
|
| 118 | + } elseif ($most_recent_migration->is_broken()) { |
|
| 119 | + // tell the user the migration failed, and they should notify EE?> |
|
| 120 | 120 | <h3 class="espresso-header ee-status-bg--info"> |
| 121 | 121 | <span class="dashicons dashicons-no ee-icon-size-22"></span> |
| 122 | 122 | <?php echo esc_html($most_recent_migration->get_feedback_message()) ?> |
| 123 | 123 | </h3> |
| 124 | 124 | <?php |
| 125 | - } |
|
| 126 | - // display errors or not of the most recent migration ran |
|
| 127 | - if ($most_recent_migration->get_errors()) { |
|
| 128 | - ?> |
|
| 125 | + } |
|
| 126 | + // display errors or not of the most recent migration ran |
|
| 127 | + if ($most_recent_migration->get_errors()) { |
|
| 128 | + ?> |
|
| 129 | 129 | <div class="ee-attention"> |
| 130 | 130 | <strong> |
| 131 | 131 | <?php printf( |
| 132 | - esc_html__( |
|
| 133 | - "Warnings occurred during your last Database Update (%s):", |
|
| 134 | - 'event_espresso' |
|
| 135 | - ), |
|
| 136 | - $most_recent_migration->pretty_name() |
|
| 137 | - ); ?> |
|
| 132 | + esc_html__( |
|
| 133 | + "Warnings occurred during your last Database Update (%s):", |
|
| 134 | + 'event_espresso' |
|
| 135 | + ), |
|
| 136 | + $most_recent_migration->pretty_name() |
|
| 137 | + ); ?> |
|
| 138 | 138 | </strong> |
| 139 | 139 | <a id="show-hide-migration-warnings" class="display-the-hidden"> |
| 140 | 140 | <?php esc_html_e("Show Warnings", 'event_espresso'); ?> |
@@ -146,29 +146,29 @@ discard block |
||
| 146 | 146 | </ul> |
| 147 | 147 | </div> |
| 148 | 148 | <?php |
| 149 | - } else { |
|
| 150 | - // there were no errors during the last migration, just say so?> |
|
| 149 | + } else { |
|
| 150 | + // there were no errors during the last migration, just say so?> |
|
| 151 | 151 | <h2> |
| 152 | 152 | <?php printf( |
| 153 | - esc_html__( |
|
| 154 | - "The last Database Update (%s) ran successfully without errors.", |
|
| 155 | - "event_espresso" |
|
| 156 | - ), |
|
| 157 | - $most_recent_migration->pretty_name() |
|
| 158 | - ); ?> |
|
| 153 | + esc_html__( |
|
| 154 | + "The last Database Update (%s) ran successfully without errors.", |
|
| 155 | + "event_espresso" |
|
| 156 | + ), |
|
| 157 | + $most_recent_migration->pretty_name() |
|
| 158 | + ); ?> |
|
| 159 | 159 | </h2> |
| 160 | 160 | <?php |
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - // end of: if ( $show_most_recent_migration ) |
|
| 165 | - ?> |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + // end of: if ( $show_most_recent_migration ) |
|
| 165 | + ?> |
|
| 166 | 166 | |
| 167 | 167 | </div> |
| 168 | 168 | <!--end of #migration-prep--> |
| 169 | 169 | |
| 170 | 170 | <?php |
| 171 | - if ($show_migration_progress) { ?> |
|
| 171 | + if ($show_migration_progress) { ?> |
|
| 172 | 172 | <div id='migration-monitor' <?php if ($show_backup_db_text) : ?>style="display:none"<?php endif; ?>> |
| 173 | 173 | <?php if ($show_backup_db_text) { ?> |
| 174 | 174 | <p> |
@@ -180,19 +180,19 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | </p> |
| 182 | 182 | <?php |
| 183 | - } ?> |
|
| 183 | + } ?> |
|
| 184 | 184 | <div id='progress-area'> |
| 185 | 185 | <h3 class="espresso-header ee-status-bg--info"> |
| 186 | 186 | <?php |
| 187 | - echo sprintf( |
|
| 188 | - _n( |
|
| 189 | - "The following task needs to be performed:", |
|
| 190 | - "The following %s tasks need to be performed:", |
|
| 191 | - count($script_names), |
|
| 192 | - "event_espresso" |
|
| 193 | - ), |
|
| 194 | - count($script_names) |
|
| 195 | - ); ?> |
|
| 187 | + echo sprintf( |
|
| 188 | + _n( |
|
| 189 | + "The following task needs to be performed:", |
|
| 190 | + "The following %s tasks need to be performed:", |
|
| 191 | + count($script_names), |
|
| 192 | + "event_espresso" |
|
| 193 | + ), |
|
| 194 | + count($script_names) |
|
| 195 | + ); ?> |
|
| 196 | 196 | </h3> |
| 197 | 197 | <ul style="list-style: inside;"> |
| 198 | 198 | <?php foreach ($script_names as $script_name) { ?> |
@@ -203,9 +203,9 @@ discard block |
||
| 203 | 203 | <?php if (count($script_names) > 1) { ?> |
| 204 | 204 | <p> |
| 205 | 205 | <?php esc_html_e( |
| 206 | - "Please note: after each task is completed you will need to continue the Database Update, or report an error to Event Espresso.", |
|
| 207 | - "event_espresso" |
|
| 208 | - ); ?> |
|
| 206 | + "Please note: after each task is completed you will need to continue the Database Update, or report an error to Event Espresso.", |
|
| 207 | + "event_espresso" |
|
| 208 | + ); ?> |
|
| 209 | 209 | </p> |
| 210 | 210 | <?php } ?> |
| 211 | 211 | |
@@ -216,19 +216,19 @@ discard block |
||
| 216 | 216 | </span> |
| 217 | 217 | <br /> |
| 218 | 218 | <?php esc_html_e( |
| 219 | - "Depending on the number of events and the complexity of the information in your database, this could take a few minutes.", |
|
| 220 | - "event_espresso" |
|
| 221 | - ); ?> |
|
| 219 | + "Depending on the number of events and the complexity of the information in your database, this could take a few minutes.", |
|
| 220 | + "event_espresso" |
|
| 221 | + ); ?> |
|
| 222 | 222 | </p> |
| 223 | 223 | <p> |
| 224 | 224 | <?php printf( |
| 225 | - esc_html__( |
|
| 226 | - "%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.", |
|
| 227 | - "event_espresso" |
|
| 228 | - ), |
|
| 229 | - '<strong>', |
|
| 230 | - '</strong>' |
|
| 231 | - ); ?> |
|
| 225 | + esc_html__( |
|
| 226 | + "%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.", |
|
| 227 | + "event_espresso" |
|
| 228 | + ), |
|
| 229 | + '<strong>', |
|
| 230 | + '</strong>' |
|
| 231 | + ); ?> |
|
| 232 | 232 | </p> |
| 233 | 233 | <p> |
| 234 | 234 | <?php esc_html_e("Click the button below to begin the migration process.", "event_espresso") ?> |
@@ -244,10 +244,10 @@ discard block |
||
| 244 | 244 | |
| 245 | 245 | <button id='start-migration' class='button button--primary'> |
| 246 | 246 | <?php echo esc_html( |
| 247 | - $show_continue_current_migration_script |
|
| 248 | - ? __("Continue Database Update", "event_espresso") |
|
| 249 | - : __("Begin Database Update", "event_espresso") |
|
| 250 | - ); ?> |
|
| 247 | + $show_continue_current_migration_script |
|
| 248 | + ? __("Continue Database Update", "event_espresso") |
|
| 249 | + : __("Begin Database Update", "event_espresso") |
|
| 250 | + ); ?> |
|
| 251 | 251 | </button> |
| 252 | 252 | <br class="clear" /> |
| 253 | 253 | |
@@ -263,9 +263,9 @@ discard block |
||
| 263 | 263 | </div> |
| 264 | 264 | |
| 265 | 265 | <?php |
| 266 | - } |
|
| 267 | - if ($show_maintenance_switch) { |
|
| 268 | - ?> |
|
| 266 | + } |
|
| 267 | + if ($show_maintenance_switch) { |
|
| 268 | + ?> |
|
| 269 | 269 | <h2> |
| 270 | 270 | <span class="dashicons dashicons-admin-tools"></span> |
| 271 | 271 | <?php esc_html_e('Set Event Espresso Maintenance Mode', 'event_espresso'); ?> |
@@ -288,9 +288,9 @@ discard block |
||
| 288 | 288 | </label> |
| 289 | 289 | <p class='description' style="font-weight: normal;"> |
| 290 | 290 | <?php esc_html_e( |
| 291 | - "This is the normal operating mode for Event Espresso and allows all functionality to be viewed by all site visitors.", |
|
| 292 | - "event_espresso" |
|
| 293 | - ); ?> |
|
| 291 | + "This is the normal operating mode for Event Espresso and allows all functionality to be viewed by all site visitors.", |
|
| 292 | + "event_espresso" |
|
| 293 | + ); ?> |
|
| 294 | 294 | </p> |
| 295 | 295 | </th> |
| 296 | 296 | </tr> |
@@ -309,9 +309,9 @@ discard block |
||
| 309 | 309 | </label> |
| 310 | 310 | <p class='description' style="font-weight: normal;"> |
| 311 | 311 | <?php esc_html_e( |
| 312 | - "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.", |
|
| 313 | - "event_espresso" |
|
| 314 | - ); ?> |
|
| 312 | + "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.", |
|
| 313 | + "event_espresso" |
|
| 314 | + ); ?> |
|
| 315 | 315 | </p> |
| 316 | 316 | </th> |
| 317 | 317 | </tr> |
@@ -325,6 +325,6 @@ discard block |
||
| 325 | 325 | </p> |
| 326 | 326 | </form> |
| 327 | 327 | <?php |
| 328 | - } ?> |
|
| 328 | + } ?> |
|
| 329 | 329 | |
| 330 | 330 | </div> |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | name="maintenance_mode_level" |
| 280 | 280 | type='radio' |
| 281 | 281 | value="0" |
| 282 | - <?php echo esc_attr($m_mode_active ? '' : 'checked');?> |
|
| 282 | + <?php echo esc_attr($m_mode_active ? '' : 'checked'); ?> |
|
| 283 | 283 | /> |
| 284 | 284 | </td> |
| 285 | 285 | <th align="left"> |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | name="maintenance_mode_level" |
| 301 | 301 | type='radio' |
| 302 | 302 | value="1" |
| 303 | - <?php echo esc_attr($m_mode_active ? 'checked' : '');?> |
|
| 303 | + <?php echo esc_attr($m_mode_active ? 'checked' : ''); ?> |
|
| 304 | 304 | /> |
| 305 | 305 | </td> |
| 306 | 306 | <th align="left"> |
@@ -10,382 +10,382 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class Messages_Template_List_Table extends EE_Admin_List_Table |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @var Messages_Admin_Page |
|
| 15 | - */ |
|
| 16 | - protected EE_Admin_Page $_admin_page; |
|
| 17 | - |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @return Messages_Admin_Page |
|
| 21 | - */ |
|
| 22 | - public function get_admin_page() |
|
| 23 | - { |
|
| 24 | - return $this->_admin_page; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Setup data object |
|
| 30 | - * |
|
| 31 | - * @throws EE_Error |
|
| 32 | - * @throws ReflectionException |
|
| 33 | - */ |
|
| 34 | - protected function _setup_data() |
|
| 35 | - { |
|
| 36 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
| 37 | - $this->_per_page, |
|
| 38 | - $this->_view |
|
| 39 | - ); |
|
| 40 | - $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
| 41 | - $this->_per_page, |
|
| 42 | - $this->_view, |
|
| 43 | - true, |
|
| 44 | - true |
|
| 45 | - ); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Set internal properties |
|
| 51 | - */ |
|
| 52 | - protected function _set_properties() |
|
| 53 | - { |
|
| 54 | - $this->_wp_list_args = [ |
|
| 55 | - 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
| 56 | - 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
| 57 | - 'ajax' => true, // for now, |
|
| 58 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
| 59 | - ]; |
|
| 60 | - $this->_columns = [ |
|
| 61 | - // 'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
| 62 | - 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
| 63 | - 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
| 64 | - 'recipients' => esc_html__('Recipients', 'event_espresso'), |
|
| 65 | - 'description' => esc_html__('Description', 'event_espresso'), |
|
| 66 | - ]; |
|
| 67 | - |
|
| 68 | - $this->_sortable_columns = [ |
|
| 69 | - 'messenger' => ['MTP_messenger' => true], |
|
| 70 | - ]; |
|
| 71 | - |
|
| 72 | - $this->_hidden_columns = []; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
| 78 | - * message_type or messenger object before generating the row. |
|
| 79 | - * |
|
| 80 | - * @param EE_Message_Template_Group $item |
|
| 81 | - * @return void |
|
| 82 | - * @throws EE_Error |
|
| 83 | - */ |
|
| 84 | - public function single_row($item) |
|
| 85 | - { |
|
| 86 | - if ( |
|
| 87 | - ! $item->message_type_obj() instanceof EE_message_type |
|
| 88 | - || ! $item->messenger_obj() instanceof EE_messenger |
|
| 89 | - ) { |
|
| 90 | - return; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - parent::single_row($item); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @return array |
|
| 99 | - * @throws EE_Error |
|
| 100 | - * @throws ReflectionException |
|
| 101 | - */ |
|
| 102 | - protected function _get_table_filters() |
|
| 103 | - { |
|
| 104 | - $filters = []; |
|
| 105 | - |
|
| 106 | - // get select inputs |
|
| 107 | - $select_inputs = [ |
|
| 108 | - $this->_get_messengers_dropdown_filter(), |
|
| 109 | - $this->_get_message_types_dropdown_filter(), |
|
| 110 | - ]; |
|
| 111 | - |
|
| 112 | - // set filters to select inputs if they aren't empty |
|
| 113 | - foreach ($select_inputs as $select_input) { |
|
| 114 | - if ($select_input) { |
|
| 115 | - $filters[] = $select_input; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - return $filters; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * We're just removing the search box for message templates, not needed. |
|
| 124 | - * |
|
| 125 | - * @param string $text |
|
| 126 | - * @param string $input_id |
|
| 127 | - * @return string ; |
|
| 128 | - */ |
|
| 129 | - public function search_box($text, $input_id) |
|
| 130 | - { |
|
| 131 | - return ''; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Add counts to the _views property |
|
| 137 | - * |
|
| 138 | - * @throws EE_Error |
|
| 139 | - * @throws ReflectionException |
|
| 140 | - */ |
|
| 141 | - protected function _add_view_counts() |
|
| 142 | - { |
|
| 143 | - foreach ($this->_views as $view => $args) { |
|
| 144 | - $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
| 145 | - $this->_per_page, |
|
| 146 | - $view, |
|
| 147 | - true, |
|
| 148 | - true |
|
| 149 | - ); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @param EE_Message_Template_Group $item |
|
| 156 | - * @return string |
|
| 157 | - */ |
|
| 158 | - public function column_cb($item) |
|
| 159 | - { |
|
| 160 | - return ''; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @param EE_Message_Template_Group $item |
|
| 166 | - * @return string |
|
| 167 | - * @throws EE_Error |
|
| 168 | - */ |
|
| 169 | - public function column_description(EE_Message_Template_Group $item): string |
|
| 170 | - { |
|
| 171 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @param EE_Message_Template_Group $item |
|
| 177 | - * @return string |
|
| 178 | - * @throws EE_Error |
|
| 179 | - */ |
|
| 180 | - public function column_messenger(EE_Message_Template_Group $item): string |
|
| 181 | - { |
|
| 182 | - // Return the name contents |
|
| 183 | - return sprintf( |
|
| 184 | - '%1$s <span style="color:silver">(id:%2$s)</span>', |
|
| 185 | - /* $1%s */ |
|
| 186 | - ucwords($item->messenger_obj()->label['singular']), |
|
| 187 | - /* $2%s */ |
|
| 188 | - $item->GRP_ID() |
|
| 189 | - ); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @param EE_Message_Template_Group $item |
|
| 195 | - * @return string |
|
| 196 | - * @throws EE_Error |
|
| 197 | - * @throws ReflectionException |
|
| 198 | - */ |
|
| 199 | - public function column_recipients(EE_Message_Template_Group $item): string |
|
| 200 | - { |
|
| 201 | - // Return the name contents |
|
| 202 | - return $this->_get_context_links($item); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * column_message_type |
|
| 208 | - * |
|
| 209 | - * @param EE_Message_Template_Group $item message info for the row |
|
| 210 | - * @return string message_type name |
|
| 211 | - * @throws EE_Error |
|
| 212 | - */ |
|
| 213 | - public function column_message_type(EE_Message_Template_Group $item): string |
|
| 214 | - { |
|
| 215 | - return ucwords($item->message_type_obj()->label['singular']); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Generate dropdown filter select input for messengers |
|
| 221 | - * |
|
| 222 | - * @param bool $global |
|
| 223 | - * @return string |
|
| 224 | - * @throws EE_Error |
|
| 225 | - * @throws ReflectionException |
|
| 226 | - */ |
|
| 227 | - protected function _get_messengers_dropdown_filter(bool $global = true): string |
|
| 228 | - { |
|
| 229 | - $messenger_options = []; |
|
| 230 | - $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
| 231 | - [ |
|
| 232 | - [ |
|
| 233 | - 'MTP_is_active' => true, |
|
| 234 | - 'MTP_is_global' => $global, |
|
| 235 | - ], |
|
| 236 | - 'group_by' => 'MTP_messenger', |
|
| 237 | - ] |
|
| 238 | - ); |
|
| 239 | - |
|
| 240 | - foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
| 241 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 242 | - $messenger = $active_message_template_group->messenger_obj(); |
|
| 243 | - $messenger_name = $active_message_template_group->messenger(); |
|
| 244 | - $messenger_label = $messenger instanceof EE_messenger |
|
| 245 | - ? $messenger->label['singular'] |
|
| 246 | - : $messenger_name; |
|
| 247 | - $messenger_options[ $messenger_name ] = ucwords($messenger_label); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Generate dropdown filter select input for message types |
|
| 256 | - * |
|
| 257 | - * @param bool $global |
|
| 258 | - * @return string |
|
| 259 | - * @throws EE_Error |
|
| 260 | - * @throws ReflectionException |
|
| 261 | - */ |
|
| 262 | - protected function _get_message_types_dropdown_filter(bool $global = true): string |
|
| 263 | - { |
|
| 264 | - $message_type_options = []; |
|
| 265 | - $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
| 266 | - [ |
|
| 267 | - [ |
|
| 268 | - 'MTP_is_active' => true, |
|
| 269 | - 'MTP_is_global' => $global, |
|
| 270 | - ], |
|
| 271 | - 'group_by' => 'MTP_message_type', |
|
| 272 | - ] |
|
| 273 | - ); |
|
| 274 | - |
|
| 275 | - foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
| 276 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 277 | - $message_type = $active_message_template_group->message_type_obj(); |
|
| 278 | - $message_type_name = $active_message_template_group->message_type(); |
|
| 279 | - $message_type_label = $message_type instanceof EE_message_type |
|
| 280 | - ? $message_type->label['singular'] |
|
| 281 | - : $message_type_name; |
|
| 282 | - $message_type_options[ $message_type_name ] = ucwords($message_type_label); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Return the edit url for the message template group. |
|
| 291 | - * |
|
| 292 | - * @param EE_Message_Template_Group $item |
|
| 293 | - * @return string |
|
| 294 | - * @throws EE_Error |
|
| 295 | - * @throws ReflectionException |
|
| 296 | - */ |
|
| 297 | - protected function _get_edit_url(EE_Message_Template_Group $item): string |
|
| 298 | - { |
|
| 299 | - $edit_url = ''; |
|
| 300 | - // edit link but only if item isn't trashed. |
|
| 301 | - if ( |
|
| 302 | - ! $item->get('MTP_deleted') |
|
| 303 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 304 | - 'ee_edit_message', |
|
| 305 | - 'espresso_messages_edit_message_template', |
|
| 306 | - $item->ID() |
|
| 307 | - ) |
|
| 308 | - ) { |
|
| 309 | - $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 310 | - [ |
|
| 311 | - 'action' => 'edit_message_template', |
|
| 312 | - 'id' => $item->GRP_ID(), |
|
| 313 | - ], |
|
| 314 | - EE_MSG_ADMIN_URL |
|
| 315 | - ); |
|
| 316 | - } |
|
| 317 | - return $edit_url; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Get the context link string for the messenger column. |
|
| 323 | - * |
|
| 324 | - * @param EE_Message_Template_Group $item |
|
| 325 | - * @return string |
|
| 326 | - * @throws EE_Error |
|
| 327 | - * @throws ReflectionException |
|
| 328 | - */ |
|
| 329 | - protected function _get_context_links(EE_Message_Template_Group $item): string |
|
| 330 | - { |
|
| 331 | - // first check if we even show the context links or not. |
|
| 332 | - if ( |
|
| 333 | - ! EE_Registry::instance()->CAP->current_user_can( |
|
| 334 | - 'ee_edit_message', |
|
| 335 | - 'espresso_messages_edit_message_template', |
|
| 336 | - $item->ID() |
|
| 337 | - ) |
|
| 338 | - || $item->get('MTP_deleted') |
|
| 339 | - ) { |
|
| 340 | - return ''; |
|
| 341 | - } |
|
| 342 | - // we want to display the contexts in here, so we need to set them up |
|
| 343 | - $c_configs = $item->contexts_config(); |
|
| 344 | - $context_array = []; |
|
| 345 | - $context_templates = $item->context_templates(); |
|
| 346 | - foreach ($context_templates as $context => $template_fields) { |
|
| 347 | - $mtp_to = ! empty($template_fields['to']) |
|
| 348 | - && $template_fields['to'] instanceof EE_Message_Template |
|
| 349 | - ? $template_fields['to']->get('MTP_content') |
|
| 350 | - : null; |
|
| 351 | - $inactive_class = (empty($mtp_to) && ! empty($template_fields['to'])) |
|
| 352 | - || ! $item->is_context_active($context) |
|
| 353 | - ? ' mtp-inactive' |
|
| 354 | - : ''; |
|
| 355 | - $context_title = ucwords($c_configs[ $context ]['label']); |
|
| 356 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 357 | - [ |
|
| 358 | - 'action' => 'edit_message_template', |
|
| 359 | - 'id' => $item->GRP_ID(), |
|
| 360 | - 'context' => $context, |
|
| 361 | - ], |
|
| 362 | - EE_MSG_ADMIN_URL |
|
| 363 | - ); |
|
| 364 | - $label = sprintf( |
|
| 365 | - esc_attr__('Edit message content for the %1$s', 'event_espresso'), |
|
| 366 | - $context_title |
|
| 367 | - ); |
|
| 368 | - $context_array[] = '<a href="' . $edit_link . '"' |
|
| 369 | - . ' class="' . "{$item->message_type()}-{$context}-edit-link{$inactive_class}" . ' ee-aria-tooltip"' |
|
| 370 | - . ' aria-label="' . $label . '">' |
|
| 371 | - . $context_title |
|
| 372 | - . '</a>'; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - return implode(' | ', $context_array); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Returns the actions for the messenger column. |
|
| 381 | - * |
|
| 382 | - * Note: Children classes may override this, so do not remove it. |
|
| 383 | - * |
|
| 384 | - * @param EE_Message_Template_Group $item |
|
| 385 | - * @return array |
|
| 386 | - */ |
|
| 387 | - protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item): array |
|
| 388 | - { |
|
| 389 | - return []; |
|
| 390 | - } |
|
| 13 | + /** |
|
| 14 | + * @var Messages_Admin_Page |
|
| 15 | + */ |
|
| 16 | + protected EE_Admin_Page $_admin_page; |
|
| 17 | + |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @return Messages_Admin_Page |
|
| 21 | + */ |
|
| 22 | + public function get_admin_page() |
|
| 23 | + { |
|
| 24 | + return $this->_admin_page; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Setup data object |
|
| 30 | + * |
|
| 31 | + * @throws EE_Error |
|
| 32 | + * @throws ReflectionException |
|
| 33 | + */ |
|
| 34 | + protected function _setup_data() |
|
| 35 | + { |
|
| 36 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
| 37 | + $this->_per_page, |
|
| 38 | + $this->_view |
|
| 39 | + ); |
|
| 40 | + $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
| 41 | + $this->_per_page, |
|
| 42 | + $this->_view, |
|
| 43 | + true, |
|
| 44 | + true |
|
| 45 | + ); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Set internal properties |
|
| 51 | + */ |
|
| 52 | + protected function _set_properties() |
|
| 53 | + { |
|
| 54 | + $this->_wp_list_args = [ |
|
| 55 | + 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
| 56 | + 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
| 57 | + 'ajax' => true, // for now, |
|
| 58 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
| 59 | + ]; |
|
| 60 | + $this->_columns = [ |
|
| 61 | + // 'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
| 62 | + 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
| 63 | + 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
| 64 | + 'recipients' => esc_html__('Recipients', 'event_espresso'), |
|
| 65 | + 'description' => esc_html__('Description', 'event_espresso'), |
|
| 66 | + ]; |
|
| 67 | + |
|
| 68 | + $this->_sortable_columns = [ |
|
| 69 | + 'messenger' => ['MTP_messenger' => true], |
|
| 70 | + ]; |
|
| 71 | + |
|
| 72 | + $this->_hidden_columns = []; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
| 78 | + * message_type or messenger object before generating the row. |
|
| 79 | + * |
|
| 80 | + * @param EE_Message_Template_Group $item |
|
| 81 | + * @return void |
|
| 82 | + * @throws EE_Error |
|
| 83 | + */ |
|
| 84 | + public function single_row($item) |
|
| 85 | + { |
|
| 86 | + if ( |
|
| 87 | + ! $item->message_type_obj() instanceof EE_message_type |
|
| 88 | + || ! $item->messenger_obj() instanceof EE_messenger |
|
| 89 | + ) { |
|
| 90 | + return; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + parent::single_row($item); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @return array |
|
| 99 | + * @throws EE_Error |
|
| 100 | + * @throws ReflectionException |
|
| 101 | + */ |
|
| 102 | + protected function _get_table_filters() |
|
| 103 | + { |
|
| 104 | + $filters = []; |
|
| 105 | + |
|
| 106 | + // get select inputs |
|
| 107 | + $select_inputs = [ |
|
| 108 | + $this->_get_messengers_dropdown_filter(), |
|
| 109 | + $this->_get_message_types_dropdown_filter(), |
|
| 110 | + ]; |
|
| 111 | + |
|
| 112 | + // set filters to select inputs if they aren't empty |
|
| 113 | + foreach ($select_inputs as $select_input) { |
|
| 114 | + if ($select_input) { |
|
| 115 | + $filters[] = $select_input; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + return $filters; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * We're just removing the search box for message templates, not needed. |
|
| 124 | + * |
|
| 125 | + * @param string $text |
|
| 126 | + * @param string $input_id |
|
| 127 | + * @return string ; |
|
| 128 | + */ |
|
| 129 | + public function search_box($text, $input_id) |
|
| 130 | + { |
|
| 131 | + return ''; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Add counts to the _views property |
|
| 137 | + * |
|
| 138 | + * @throws EE_Error |
|
| 139 | + * @throws ReflectionException |
|
| 140 | + */ |
|
| 141 | + protected function _add_view_counts() |
|
| 142 | + { |
|
| 143 | + foreach ($this->_views as $view => $args) { |
|
| 144 | + $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
| 145 | + $this->_per_page, |
|
| 146 | + $view, |
|
| 147 | + true, |
|
| 148 | + true |
|
| 149 | + ); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @param EE_Message_Template_Group $item |
|
| 156 | + * @return string |
|
| 157 | + */ |
|
| 158 | + public function column_cb($item) |
|
| 159 | + { |
|
| 160 | + return ''; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @param EE_Message_Template_Group $item |
|
| 166 | + * @return string |
|
| 167 | + * @throws EE_Error |
|
| 168 | + */ |
|
| 169 | + public function column_description(EE_Message_Template_Group $item): string |
|
| 170 | + { |
|
| 171 | + return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @param EE_Message_Template_Group $item |
|
| 177 | + * @return string |
|
| 178 | + * @throws EE_Error |
|
| 179 | + */ |
|
| 180 | + public function column_messenger(EE_Message_Template_Group $item): string |
|
| 181 | + { |
|
| 182 | + // Return the name contents |
|
| 183 | + return sprintf( |
|
| 184 | + '%1$s <span style="color:silver">(id:%2$s)</span>', |
|
| 185 | + /* $1%s */ |
|
| 186 | + ucwords($item->messenger_obj()->label['singular']), |
|
| 187 | + /* $2%s */ |
|
| 188 | + $item->GRP_ID() |
|
| 189 | + ); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @param EE_Message_Template_Group $item |
|
| 195 | + * @return string |
|
| 196 | + * @throws EE_Error |
|
| 197 | + * @throws ReflectionException |
|
| 198 | + */ |
|
| 199 | + public function column_recipients(EE_Message_Template_Group $item): string |
|
| 200 | + { |
|
| 201 | + // Return the name contents |
|
| 202 | + return $this->_get_context_links($item); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * column_message_type |
|
| 208 | + * |
|
| 209 | + * @param EE_Message_Template_Group $item message info for the row |
|
| 210 | + * @return string message_type name |
|
| 211 | + * @throws EE_Error |
|
| 212 | + */ |
|
| 213 | + public function column_message_type(EE_Message_Template_Group $item): string |
|
| 214 | + { |
|
| 215 | + return ucwords($item->message_type_obj()->label['singular']); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Generate dropdown filter select input for messengers |
|
| 221 | + * |
|
| 222 | + * @param bool $global |
|
| 223 | + * @return string |
|
| 224 | + * @throws EE_Error |
|
| 225 | + * @throws ReflectionException |
|
| 226 | + */ |
|
| 227 | + protected function _get_messengers_dropdown_filter(bool $global = true): string |
|
| 228 | + { |
|
| 229 | + $messenger_options = []; |
|
| 230 | + $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
| 231 | + [ |
|
| 232 | + [ |
|
| 233 | + 'MTP_is_active' => true, |
|
| 234 | + 'MTP_is_global' => $global, |
|
| 235 | + ], |
|
| 236 | + 'group_by' => 'MTP_messenger', |
|
| 237 | + ] |
|
| 238 | + ); |
|
| 239 | + |
|
| 240 | + foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
| 241 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 242 | + $messenger = $active_message_template_group->messenger_obj(); |
|
| 243 | + $messenger_name = $active_message_template_group->messenger(); |
|
| 244 | + $messenger_label = $messenger instanceof EE_messenger |
|
| 245 | + ? $messenger->label['singular'] |
|
| 246 | + : $messenger_name; |
|
| 247 | + $messenger_options[ $messenger_name ] = ucwords($messenger_label); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Generate dropdown filter select input for message types |
|
| 256 | + * |
|
| 257 | + * @param bool $global |
|
| 258 | + * @return string |
|
| 259 | + * @throws EE_Error |
|
| 260 | + * @throws ReflectionException |
|
| 261 | + */ |
|
| 262 | + protected function _get_message_types_dropdown_filter(bool $global = true): string |
|
| 263 | + { |
|
| 264 | + $message_type_options = []; |
|
| 265 | + $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
| 266 | + [ |
|
| 267 | + [ |
|
| 268 | + 'MTP_is_active' => true, |
|
| 269 | + 'MTP_is_global' => $global, |
|
| 270 | + ], |
|
| 271 | + 'group_by' => 'MTP_message_type', |
|
| 272 | + ] |
|
| 273 | + ); |
|
| 274 | + |
|
| 275 | + foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
| 276 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 277 | + $message_type = $active_message_template_group->message_type_obj(); |
|
| 278 | + $message_type_name = $active_message_template_group->message_type(); |
|
| 279 | + $message_type_label = $message_type instanceof EE_message_type |
|
| 280 | + ? $message_type->label['singular'] |
|
| 281 | + : $message_type_name; |
|
| 282 | + $message_type_options[ $message_type_name ] = ucwords($message_type_label); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Return the edit url for the message template group. |
|
| 291 | + * |
|
| 292 | + * @param EE_Message_Template_Group $item |
|
| 293 | + * @return string |
|
| 294 | + * @throws EE_Error |
|
| 295 | + * @throws ReflectionException |
|
| 296 | + */ |
|
| 297 | + protected function _get_edit_url(EE_Message_Template_Group $item): string |
|
| 298 | + { |
|
| 299 | + $edit_url = ''; |
|
| 300 | + // edit link but only if item isn't trashed. |
|
| 301 | + if ( |
|
| 302 | + ! $item->get('MTP_deleted') |
|
| 303 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 304 | + 'ee_edit_message', |
|
| 305 | + 'espresso_messages_edit_message_template', |
|
| 306 | + $item->ID() |
|
| 307 | + ) |
|
| 308 | + ) { |
|
| 309 | + $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 310 | + [ |
|
| 311 | + 'action' => 'edit_message_template', |
|
| 312 | + 'id' => $item->GRP_ID(), |
|
| 313 | + ], |
|
| 314 | + EE_MSG_ADMIN_URL |
|
| 315 | + ); |
|
| 316 | + } |
|
| 317 | + return $edit_url; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Get the context link string for the messenger column. |
|
| 323 | + * |
|
| 324 | + * @param EE_Message_Template_Group $item |
|
| 325 | + * @return string |
|
| 326 | + * @throws EE_Error |
|
| 327 | + * @throws ReflectionException |
|
| 328 | + */ |
|
| 329 | + protected function _get_context_links(EE_Message_Template_Group $item): string |
|
| 330 | + { |
|
| 331 | + // first check if we even show the context links or not. |
|
| 332 | + if ( |
|
| 333 | + ! EE_Registry::instance()->CAP->current_user_can( |
|
| 334 | + 'ee_edit_message', |
|
| 335 | + 'espresso_messages_edit_message_template', |
|
| 336 | + $item->ID() |
|
| 337 | + ) |
|
| 338 | + || $item->get('MTP_deleted') |
|
| 339 | + ) { |
|
| 340 | + return ''; |
|
| 341 | + } |
|
| 342 | + // we want to display the contexts in here, so we need to set them up |
|
| 343 | + $c_configs = $item->contexts_config(); |
|
| 344 | + $context_array = []; |
|
| 345 | + $context_templates = $item->context_templates(); |
|
| 346 | + foreach ($context_templates as $context => $template_fields) { |
|
| 347 | + $mtp_to = ! empty($template_fields['to']) |
|
| 348 | + && $template_fields['to'] instanceof EE_Message_Template |
|
| 349 | + ? $template_fields['to']->get('MTP_content') |
|
| 350 | + : null; |
|
| 351 | + $inactive_class = (empty($mtp_to) && ! empty($template_fields['to'])) |
|
| 352 | + || ! $item->is_context_active($context) |
|
| 353 | + ? ' mtp-inactive' |
|
| 354 | + : ''; |
|
| 355 | + $context_title = ucwords($c_configs[ $context ]['label']); |
|
| 356 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 357 | + [ |
|
| 358 | + 'action' => 'edit_message_template', |
|
| 359 | + 'id' => $item->GRP_ID(), |
|
| 360 | + 'context' => $context, |
|
| 361 | + ], |
|
| 362 | + EE_MSG_ADMIN_URL |
|
| 363 | + ); |
|
| 364 | + $label = sprintf( |
|
| 365 | + esc_attr__('Edit message content for the %1$s', 'event_espresso'), |
|
| 366 | + $context_title |
|
| 367 | + ); |
|
| 368 | + $context_array[] = '<a href="' . $edit_link . '"' |
|
| 369 | + . ' class="' . "{$item->message_type()}-{$context}-edit-link{$inactive_class}" . ' ee-aria-tooltip"' |
|
| 370 | + . ' aria-label="' . $label . '">' |
|
| 371 | + . $context_title |
|
| 372 | + . '</a>'; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + return implode(' | ', $context_array); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Returns the actions for the messenger column. |
|
| 381 | + * |
|
| 382 | + * Note: Children classes may override this, so do not remove it. |
|
| 383 | + * |
|
| 384 | + * @param EE_Message_Template_Group $item |
|
| 385 | + * @return array |
|
| 386 | + */ |
|
| 387 | + protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item): array |
|
| 388 | + { |
|
| 389 | + return []; |
|
| 390 | + } |
|
| 391 | 391 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | protected function _setup_data() |
| 35 | 35 | { |
| 36 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
| 36 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
| 37 | 37 | $this->_per_page, |
| 38 | 38 | $this->_view |
| 39 | 39 | ); |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | 'ajax' => true, // for now, |
| 58 | 58 | 'screen' => $this->get_admin_page()->get_current_screen()->id, |
| 59 | 59 | ]; |
| 60 | - $this->_columns = [ |
|
| 60 | + $this->_columns = [ |
|
| 61 | 61 | // 'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
| 62 | 62 | 'message_type' => esc_html__('Message Type', 'event_espresso'), |
| 63 | 63 | 'messenger' => esc_html__('Messenger', 'event_espresso'), |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | protected function _add_view_counts() |
| 142 | 142 | { |
| 143 | 143 | foreach ($this->_views as $view => $args) { |
| 144 | - $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
| 144 | + $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
| 145 | 145 | $this->_per_page, |
| 146 | 146 | $view, |
| 147 | 147 | true, |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | public function column_description(EE_Message_Template_Group $item): string |
| 170 | 170 | { |
| 171 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
| 171 | + return '<p>'.$item->message_type_obj()->description.'</p>'; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | $messenger_label = $messenger instanceof EE_messenger |
| 245 | 245 | ? $messenger->label['singular'] |
| 246 | 246 | : $messenger_name; |
| 247 | - $messenger_options[ $messenger_name ] = ucwords($messenger_label); |
|
| 247 | + $messenger_options[$messenger_name] = ucwords($messenger_label); |
|
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | $message_type_label = $message_type instanceof EE_message_type |
| 280 | 280 | ? $message_type->label['singular'] |
| 281 | 281 | : $message_type_name; |
| 282 | - $message_type_options[ $message_type_name ] = ucwords($message_type_label); |
|
| 282 | + $message_type_options[$message_type_name] = ucwords($message_type_label); |
|
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
@@ -344,15 +344,15 @@ discard block |
||
| 344 | 344 | $context_array = []; |
| 345 | 345 | $context_templates = $item->context_templates(); |
| 346 | 346 | foreach ($context_templates as $context => $template_fields) { |
| 347 | - $mtp_to = ! empty($template_fields['to']) |
|
| 347 | + $mtp_to = ! empty($template_fields['to']) |
|
| 348 | 348 | && $template_fields['to'] instanceof EE_Message_Template |
| 349 | 349 | ? $template_fields['to']->get('MTP_content') |
| 350 | 350 | : null; |
| 351 | - $inactive_class = (empty($mtp_to) && ! empty($template_fields['to'])) |
|
| 351 | + $inactive_class = (empty($mtp_to) && ! empty($template_fields['to'])) |
|
| 352 | 352 | || ! $item->is_context_active($context) |
| 353 | 353 | ? ' mtp-inactive' |
| 354 | 354 | : ''; |
| 355 | - $context_title = ucwords($c_configs[ $context ]['label']); |
|
| 355 | + $context_title = ucwords($c_configs[$context]['label']); |
|
| 356 | 356 | $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
| 357 | 357 | [ |
| 358 | 358 | 'action' => 'edit_message_template', |
@@ -361,13 +361,13 @@ discard block |
||
| 361 | 361 | ], |
| 362 | 362 | EE_MSG_ADMIN_URL |
| 363 | 363 | ); |
| 364 | - $label = sprintf( |
|
| 364 | + $label = sprintf( |
|
| 365 | 365 | esc_attr__('Edit message content for the %1$s', 'event_espresso'), |
| 366 | 366 | $context_title |
| 367 | 367 | ); |
| 368 | - $context_array[] = '<a href="' . $edit_link . '"' |
|
| 369 | - . ' class="' . "{$item->message_type()}-{$context}-edit-link{$inactive_class}" . ' ee-aria-tooltip"' |
|
| 370 | - . ' aria-label="' . $label . '">' |
|
| 368 | + $context_array[] = '<a href="'.$edit_link.'"' |
|
| 369 | + . ' class="'."{$item->message_type()}-{$context}-edit-link{$inactive_class}".' ee-aria-tooltip"' |
|
| 370 | + . ' aria-label="'.$label.'">' |
|
| 371 | 371 | . $context_title |
| 372 | 372 | . '</a>'; |
| 373 | 373 | } |
@@ -17,140 +17,140 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | class About_Admin_Page extends EE_Admin_Page |
| 19 | 19 | { |
| 20 | - protected function _init_page_props() |
|
| 21 | - { |
|
| 22 | - $this->page_slug = EE_ABOUT_PG_SLUG; |
|
| 23 | - $this->page_label = esc_html__('About Event Espresso', 'event_espresso'); |
|
| 24 | - $this->_admin_base_url = EE_ABOUT_ADMIN_URL; |
|
| 25 | - $this->_admin_base_path = EE_ABOUT_ADMIN; |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - protected function _ajax_hooks() |
|
| 30 | - { |
|
| 31 | - // todo: all hooks for ajax goes here. |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - protected function _define_page_props() |
|
| 36 | - { |
|
| 37 | - $this->_labels = array(); |
|
| 38 | - $this->_admin_page_title = $this->page_label; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - protected function _set_page_routes() |
|
| 43 | - { |
|
| 44 | - $this->_page_routes = array( |
|
| 45 | - 'default' => array( |
|
| 46 | - 'func' => '_overview', |
|
| 47 | - 'capability' => 'manage_options', |
|
| 48 | - ), |
|
| 49 | - // 'overview' => '_overview', |
|
| 50 | - // 'func' => '_overview', |
|
| 51 | - // 'capability' => 'ee_read_ee' |
|
| 52 | - // ), |
|
| 53 | - 'credits' => array( |
|
| 54 | - 'func' => '_credits', |
|
| 55 | - 'capability' => 'manage_options', |
|
| 56 | - ), |
|
| 57 | - |
|
| 58 | - 'decafvpro' => array( |
|
| 59 | - 'func' => '_decafvpro', |
|
| 60 | - 'capability' => 'manage_options', |
|
| 61 | - ), |
|
| 62 | - 'reviews' => array( |
|
| 63 | - 'func' => '_reviews', |
|
| 64 | - 'capability' => 'manage_options', |
|
| 65 | - ), |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - protected function _set_page_config() |
|
| 71 | - { |
|
| 72 | - $this->_page_config = array( |
|
| 73 | - /*'default' => array( |
|
| 20 | + protected function _init_page_props() |
|
| 21 | + { |
|
| 22 | + $this->page_slug = EE_ABOUT_PG_SLUG; |
|
| 23 | + $this->page_label = esc_html__('About Event Espresso', 'event_espresso'); |
|
| 24 | + $this->_admin_base_url = EE_ABOUT_ADMIN_URL; |
|
| 25 | + $this->_admin_base_path = EE_ABOUT_ADMIN; |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + protected function _ajax_hooks() |
|
| 30 | + { |
|
| 31 | + // todo: all hooks for ajax goes here. |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + protected function _define_page_props() |
|
| 36 | + { |
|
| 37 | + $this->_labels = array(); |
|
| 38 | + $this->_admin_page_title = $this->page_label; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + protected function _set_page_routes() |
|
| 43 | + { |
|
| 44 | + $this->_page_routes = array( |
|
| 45 | + 'default' => array( |
|
| 46 | + 'func' => '_overview', |
|
| 47 | + 'capability' => 'manage_options', |
|
| 48 | + ), |
|
| 49 | + // 'overview' => '_overview', |
|
| 50 | + // 'func' => '_overview', |
|
| 51 | + // 'capability' => 'ee_read_ee' |
|
| 52 | + // ), |
|
| 53 | + 'credits' => array( |
|
| 54 | + 'func' => '_credits', |
|
| 55 | + 'capability' => 'manage_options', |
|
| 56 | + ), |
|
| 57 | + |
|
| 58 | + 'decafvpro' => array( |
|
| 59 | + 'func' => '_decafvpro', |
|
| 60 | + 'capability' => 'manage_options', |
|
| 61 | + ), |
|
| 62 | + 'reviews' => array( |
|
| 63 | + 'func' => '_reviews', |
|
| 64 | + 'capability' => 'manage_options', |
|
| 65 | + ), |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + protected function _set_page_config() |
|
| 71 | + { |
|
| 72 | + $this->_page_config = array( |
|
| 73 | + /*'default' => array( |
|
| 74 | 74 | 'nav' => array( |
| 75 | 75 | 'label' => esc_html__('What\'s New', 'event_espresso'), |
| 76 | 76 | 'order' => 10), |
| 77 | 77 | 'require_nonce' => FALSE |
| 78 | 78 | ),*/ |
| 79 | - // 'overview' => array( |
|
| 80 | - 'default' => array( |
|
| 81 | - 'nav' => array( |
|
| 82 | - 'label' => esc_html__('About', 'event_espresso'), |
|
| 83 | - 'icon' => 'dashicons-welcome-learn-more', |
|
| 84 | - 'order' => 20, |
|
| 85 | - ), |
|
| 86 | - 'require_nonce' => false, |
|
| 87 | - ), |
|
| 88 | - 'credits' => array( |
|
| 89 | - 'nav' => array( |
|
| 90 | - 'label' => esc_html__('Credits', 'event_espresso'), |
|
| 91 | - 'icon' => 'dashicons-thumbs-up', |
|
| 92 | - 'order' => 30, |
|
| 93 | - ), |
|
| 94 | - 'require_nonce' => false, |
|
| 95 | - ), |
|
| 96 | - |
|
| 97 | - 'decafvpro' => array( |
|
| 98 | - 'nav' => array( |
|
| 99 | - 'label' => esc_html__('Decaf vs Regular', 'event_espresso'), |
|
| 100 | - 'icon' => 'dashicons-editor-code', |
|
| 101 | - 'order' => 40, |
|
| 102 | - ), |
|
| 103 | - 'require_nonce' => false, |
|
| 104 | - ), |
|
| 105 | - 'reviews' => array( |
|
| 106 | - 'nav' => array( |
|
| 107 | - 'label' => esc_html__('Reviews', 'event_espresso'), |
|
| 108 | - 'icon' => 'dashicons-star-filled', |
|
| 109 | - 'order' => 50, |
|
| 110 | - ), |
|
| 111 | - 'require_nonce' => false, |
|
| 112 | - ), |
|
| 113 | - ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - // none of the below group are currently used for Support pages |
|
| 118 | - protected function _add_screen_options() |
|
| 119 | - { |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - protected function _add_feature_pointers() |
|
| 123 | - { |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - public function admin_init() |
|
| 127 | - { |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - public function admin_notices() |
|
| 131 | - { |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - public function admin_footer_scripts() |
|
| 135 | - { |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - public function load_scripts_styles() |
|
| 139 | - { |
|
| 140 | - // enqueue style |
|
| 141 | - wp_register_style( |
|
| 142 | - 'espresso_about_admin', |
|
| 143 | - EE_ABOUT_ASSETS_URL . 'espresso_about_admin.css', |
|
| 144 | - [], |
|
| 145 | - EVENT_ESPRESSO_VERSION |
|
| 146 | - ); |
|
| 147 | - wp_enqueue_style('espresso_about_admin'); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - protected function _whats_new() |
|
| 152 | - { |
|
| 153 | - /*$steps = EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::STATUS_FULL_SITE ? $this->_get_started_steps() : FALSE; |
|
| 79 | + // 'overview' => array( |
|
| 80 | + 'default' => array( |
|
| 81 | + 'nav' => array( |
|
| 82 | + 'label' => esc_html__('About', 'event_espresso'), |
|
| 83 | + 'icon' => 'dashicons-welcome-learn-more', |
|
| 84 | + 'order' => 20, |
|
| 85 | + ), |
|
| 86 | + 'require_nonce' => false, |
|
| 87 | + ), |
|
| 88 | + 'credits' => array( |
|
| 89 | + 'nav' => array( |
|
| 90 | + 'label' => esc_html__('Credits', 'event_espresso'), |
|
| 91 | + 'icon' => 'dashicons-thumbs-up', |
|
| 92 | + 'order' => 30, |
|
| 93 | + ), |
|
| 94 | + 'require_nonce' => false, |
|
| 95 | + ), |
|
| 96 | + |
|
| 97 | + 'decafvpro' => array( |
|
| 98 | + 'nav' => array( |
|
| 99 | + 'label' => esc_html__('Decaf vs Regular', 'event_espresso'), |
|
| 100 | + 'icon' => 'dashicons-editor-code', |
|
| 101 | + 'order' => 40, |
|
| 102 | + ), |
|
| 103 | + 'require_nonce' => false, |
|
| 104 | + ), |
|
| 105 | + 'reviews' => array( |
|
| 106 | + 'nav' => array( |
|
| 107 | + 'label' => esc_html__('Reviews', 'event_espresso'), |
|
| 108 | + 'icon' => 'dashicons-star-filled', |
|
| 109 | + 'order' => 50, |
|
| 110 | + ), |
|
| 111 | + 'require_nonce' => false, |
|
| 112 | + ), |
|
| 113 | + ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + // none of the below group are currently used for Support pages |
|
| 118 | + protected function _add_screen_options() |
|
| 119 | + { |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + protected function _add_feature_pointers() |
|
| 123 | + { |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + public function admin_init() |
|
| 127 | + { |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + public function admin_notices() |
|
| 131 | + { |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + public function admin_footer_scripts() |
|
| 135 | + { |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + public function load_scripts_styles() |
|
| 139 | + { |
|
| 140 | + // enqueue style |
|
| 141 | + wp_register_style( |
|
| 142 | + 'espresso_about_admin', |
|
| 143 | + EE_ABOUT_ASSETS_URL . 'espresso_about_admin.css', |
|
| 144 | + [], |
|
| 145 | + EVENT_ESPRESSO_VERSION |
|
| 146 | + ); |
|
| 147 | + wp_enqueue_style('espresso_about_admin'); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + protected function _whats_new() |
|
| 152 | + { |
|
| 153 | + /*$steps = EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::STATUS_FULL_SITE ? $this->_get_started_steps() : FALSE; |
|
| 154 | 154 | $steps = $steps !== FALSE ? $steps : ''; |
| 155 | 155 | $this->_admin_page_title = sprintf( esc_html__('Welcome to Event Espresso %s', 'event_espresso'), EVENT_ESPRESSO_VERSION ); |
| 156 | 156 | $settings_message = $steps; |
@@ -158,167 +158,167 @@ discard block |
||
| 158 | 158 | $template = EE_ABOUT_TEMPLATE_PATH . 'whats_new.template.php'; |
| 159 | 159 | $this->_template_args['about_admin_page_content'] = EEH_Template::display_template( $template, $this->_template_args, TRUE ); |
| 160 | 160 | $this->display_about_admin_page();*/ |
| 161 | - } |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | 163 | |
| 164 | - protected function _overview() |
|
| 165 | - { |
|
| 166 | - /*$this->_template_args['admin_page_title'] = esc_html__('About Event Espresso', 'event_espresso'); |
|
| 164 | + protected function _overview() |
|
| 165 | + { |
|
| 166 | + /*$this->_template_args['admin_page_title'] = esc_html__('About Event Espresso', 'event_espresso'); |
|
| 167 | 167 | $this->_template_args['admin_page_subtitle'] = esc_html__('Thank you for choosing Event Espresso Decaf, the most powerful, and free, Event Management plugin for WordPress.', 'event_espresso'); |
| 168 | 168 | $template = EE_ABOUT_TEMPLATE_PATH . 'ee4-overview.template.php'; |
| 169 | 169 | $this->_template_args['about_admin_page_content'] = EEH_Template::display_template( $template, $this->_template_args, TRUE ); |
| 170 | 170 | $this->display_about_admin_page();*/ |
| 171 | 171 | |
| 172 | - // Copied from _whats_new() |
|
| 173 | - $steps = DbStatus::isOnline() ? $this->_get_started_steps() : false; |
|
| 174 | - $steps = $steps !== false ? $steps : ''; |
|
| 175 | - $this->_admin_page_title = sprintf( |
|
| 176 | - esc_html__('Welcome to Event Espresso %s', 'event_espresso'), |
|
| 177 | - EVENT_ESPRESSO_VERSION |
|
| 178 | - ); |
|
| 179 | - $settings_message = $steps; |
|
| 180 | - $this->_template_args['admin_page_subtitle'] = esc_html__( |
|
| 181 | - 'Thank you for choosing Event Espresso, the most powerful, and free, Event Management plugin for WordPress.', |
|
| 182 | - 'event_espresso' |
|
| 183 | - ) . $settings_message; |
|
| 184 | - $template = EE_ABOUT_TEMPLATE_PATH . 'ee4-overview.template.php'; |
|
| 185 | - $this->_template_args['about_admin_page_content'] = EEH_Template::display_template( |
|
| 186 | - $template, |
|
| 187 | - $this->_template_args, |
|
| 188 | - true |
|
| 189 | - ); |
|
| 190 | - $this->display_about_admin_page(); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - protected function _get_started_steps() |
|
| 195 | - { |
|
| 196 | - $steps = '<h2>' . esc_html__('Getting Started', 'event_espresso') . '</h2>'; |
|
| 197 | - $step_one = '<p>' |
|
| 198 | - . sprintf( |
|
| 199 | - esc_html__( |
|
| 200 | - '%sStep 1%s: Visit your %sOrganization Settings%s and add/update your details.', |
|
| 201 | - 'event_espresso' |
|
| 202 | - ), |
|
| 203 | - '<strong>', |
|
| 204 | - '</strong>', |
|
| 205 | - '<a href="admin.php?page=espresso_general_settings">', |
|
| 206 | - '</a>' |
|
| 207 | - ) . '</strong></p>'; |
|
| 208 | - $step_two = '<p>' |
|
| 209 | - . sprintf( |
|
| 210 | - esc_html__('%sStep 2%s: Setup your %sPayment Methods%s.', 'event_espresso'), |
|
| 211 | - '<strong>', |
|
| 212 | - '</strong>', |
|
| 213 | - '<a href="admin.php?page=espresso_payment_settings">', |
|
| 214 | - '</a>' |
|
| 215 | - ) . '</strong></p>'; |
|
| 216 | - $step_three = '<p>' |
|
| 217 | - . sprintf( |
|
| 218 | - esc_html__('%sStep 3%s: Create your %sFirst Event%s.', 'event_espresso'), |
|
| 219 | - '<strong>', |
|
| 220 | - '</strong>', |
|
| 221 | - '<a href="admin.php?page=espresso_events&action=create_new">', |
|
| 222 | - '</a>' |
|
| 223 | - ) . '</strong></p>'; |
|
| 224 | - |
|
| 225 | - // done? |
|
| 226 | - $done_step_one = EE_Registry::instance()->CFG->organization->address_1 == '123 Onna Road' ? false : true; |
|
| 227 | - $active_invoice_pm = EEM_Payment_Method::instance()->get_one_active( |
|
| 228 | - EEM_Payment_Method::scope_cart, |
|
| 229 | - array(array('PMD_type' => 'Invoice')) |
|
| 230 | - ); |
|
| 231 | - $active_pms_count = EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart); |
|
| 232 | - // done step two if a non-invoice paymetn method is active; or there is more than one PM active, or |
|
| 233 | - // if only the invoice is active but it's clearly been updated |
|
| 234 | - $done_step_two = $active_pms_count > 1 || |
|
| 235 | - ($active_pms_count === 1 && ! $active_invoice_pm) || |
|
| 236 | - ($active_invoice_pm instanceof EE_Payment_Method && ( |
|
| 237 | - $active_invoice_pm->get_extra_meta('pdf_payee_name', true, '') || |
|
| 238 | - $active_invoice_pm->get_extra_meta('pdf_payee_email', true, '') || |
|
| 239 | - $active_invoice_pm->get_extra_meta('pdf_payee_tax_number', true, '') || |
|
| 240 | - $active_invoice_pm->get_extra_meta('pdf_payee_address', true, '') || |
|
| 241 | - $active_invoice_pm->get_extra_meta('page_extra_info', true, '') |
|
| 242 | - ) |
|
| 243 | - ); |
|
| 244 | - $done_step_three = EE_Registry::instance()->load_model('Event')->count() > 0 ? true : false; |
|
| 245 | - |
|
| 246 | - // if ALL steps are done, let's just return FALSE so we don't display anything |
|
| 247 | - if ($done_step_one && $done_step_two && $done_step_three) { |
|
| 248 | - return false; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // now let's put it together |
|
| 252 | - $steps .= sprintf('%s' . $step_one . '%s', $done_step_one ? '<strike>' : '', $done_step_one ? '</strike>' : ''); |
|
| 253 | - $steps .= sprintf('%s' . $step_two . '%s', $done_step_two ? '<strike>' : '', $done_step_two ? '</strike>' : ''); |
|
| 254 | - $steps .= sprintf( |
|
| 255 | - '%s' . $step_three . '%s', |
|
| 256 | - $done_step_three ? '<strike>' : '', |
|
| 257 | - $done_step_three ? '</strike>' : '' |
|
| 258 | - ); |
|
| 259 | - |
|
| 260 | - return $steps; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - protected function _credits() |
|
| 265 | - { |
|
| 266 | - $this->_template_args['admin_page_title'] = sprintf( |
|
| 267 | - esc_html__('Welcome to Event Espresso %s', 'event_espresso'), |
|
| 268 | - EVENT_ESPRESSO_VERSION |
|
| 269 | - ); |
|
| 270 | - $this->_template_args['admin_page_subtitle'] = esc_html__( |
|
| 271 | - 'Thank you for choosing Event Espresso Decaf, the most powerful, and free, Event Management plugin for WordPress.', |
|
| 272 | - 'event_espresso' |
|
| 273 | - ); |
|
| 274 | - $template = EE_ABOUT_TEMPLATE_PATH . 'credits.template.php'; |
|
| 275 | - $this->_template_args['about_admin_page_content'] = EEH_Template::display_template( |
|
| 276 | - $template, |
|
| 277 | - $this->_template_args, |
|
| 278 | - true |
|
| 279 | - ); |
|
| 280 | - $this->display_about_admin_page(); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - protected function _decafvpro() |
|
| 285 | - { |
|
| 286 | - $this->_template_args['admin_page_title'] = sprintf( |
|
| 287 | - esc_html__('Welcome to Event Espresso %s', 'event_espresso'), |
|
| 288 | - EVENT_ESPRESSO_VERSION |
|
| 289 | - ); |
|
| 290 | - $this->_template_args['admin_page_subtitle'] = sprintf( |
|
| 291 | - esc_html__( |
|
| 292 | - 'Event Espresso lets you focus on doing %swhat you love%s — %sorganizing your events%s', |
|
| 293 | - 'event_espresso' |
|
| 294 | - ), |
|
| 295 | - '<em>', |
|
| 296 | - '</em>', |
|
| 297 | - '<strong>', |
|
| 298 | - '</strong>' |
|
| 299 | - ); |
|
| 300 | - $template = EE_ABOUT_TEMPLATE_PATH . 'decafvpro.template.php'; |
|
| 301 | - $this->_template_args['about_admin_page_content'] = EEH_Template::display_template( |
|
| 302 | - $template, |
|
| 303 | - $this->_template_args, |
|
| 304 | - true |
|
| 305 | - ); |
|
| 306 | - $this->display_about_admin_page(); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - protected function _reviews() |
|
| 310 | - { |
|
| 311 | - $this->_template_args['admin_page_title'] = esc_html__('Rave Reviews About Event Espresso 4', 'event_espresso'); |
|
| 312 | - $this->_template_args['admin_page_subtitle'] = esc_html__( |
|
| 313 | - 'At Event Espresso, customer satisfaction is our ultimate goal.', |
|
| 314 | - 'event_espresso' |
|
| 315 | - ); |
|
| 316 | - $template = EE_ABOUT_TEMPLATE_PATH . 'reviews.template.php'; |
|
| 317 | - $this->_template_args['about_admin_page_content'] = EEH_Template::display_template( |
|
| 318 | - $template, |
|
| 319 | - $this->_template_args, |
|
| 320 | - true |
|
| 321 | - ); |
|
| 322 | - $this->display_about_admin_page(); |
|
| 323 | - } |
|
| 172 | + // Copied from _whats_new() |
|
| 173 | + $steps = DbStatus::isOnline() ? $this->_get_started_steps() : false; |
|
| 174 | + $steps = $steps !== false ? $steps : ''; |
|
| 175 | + $this->_admin_page_title = sprintf( |
|
| 176 | + esc_html__('Welcome to Event Espresso %s', 'event_espresso'), |
|
| 177 | + EVENT_ESPRESSO_VERSION |
|
| 178 | + ); |
|
| 179 | + $settings_message = $steps; |
|
| 180 | + $this->_template_args['admin_page_subtitle'] = esc_html__( |
|
| 181 | + 'Thank you for choosing Event Espresso, the most powerful, and free, Event Management plugin for WordPress.', |
|
| 182 | + 'event_espresso' |
|
| 183 | + ) . $settings_message; |
|
| 184 | + $template = EE_ABOUT_TEMPLATE_PATH . 'ee4-overview.template.php'; |
|
| 185 | + $this->_template_args['about_admin_page_content'] = EEH_Template::display_template( |
|
| 186 | + $template, |
|
| 187 | + $this->_template_args, |
|
| 188 | + true |
|
| 189 | + ); |
|
| 190 | + $this->display_about_admin_page(); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + protected function _get_started_steps() |
|
| 195 | + { |
|
| 196 | + $steps = '<h2>' . esc_html__('Getting Started', 'event_espresso') . '</h2>'; |
|
| 197 | + $step_one = '<p>' |
|
| 198 | + . sprintf( |
|
| 199 | + esc_html__( |
|
| 200 | + '%sStep 1%s: Visit your %sOrganization Settings%s and add/update your details.', |
|
| 201 | + 'event_espresso' |
|
| 202 | + ), |
|
| 203 | + '<strong>', |
|
| 204 | + '</strong>', |
|
| 205 | + '<a href="admin.php?page=espresso_general_settings">', |
|
| 206 | + '</a>' |
|
| 207 | + ) . '</strong></p>'; |
|
| 208 | + $step_two = '<p>' |
|
| 209 | + . sprintf( |
|
| 210 | + esc_html__('%sStep 2%s: Setup your %sPayment Methods%s.', 'event_espresso'), |
|
| 211 | + '<strong>', |
|
| 212 | + '</strong>', |
|
| 213 | + '<a href="admin.php?page=espresso_payment_settings">', |
|
| 214 | + '</a>' |
|
| 215 | + ) . '</strong></p>'; |
|
| 216 | + $step_three = '<p>' |
|
| 217 | + . sprintf( |
|
| 218 | + esc_html__('%sStep 3%s: Create your %sFirst Event%s.', 'event_espresso'), |
|
| 219 | + '<strong>', |
|
| 220 | + '</strong>', |
|
| 221 | + '<a href="admin.php?page=espresso_events&action=create_new">', |
|
| 222 | + '</a>' |
|
| 223 | + ) . '</strong></p>'; |
|
| 224 | + |
|
| 225 | + // done? |
|
| 226 | + $done_step_one = EE_Registry::instance()->CFG->organization->address_1 == '123 Onna Road' ? false : true; |
|
| 227 | + $active_invoice_pm = EEM_Payment_Method::instance()->get_one_active( |
|
| 228 | + EEM_Payment_Method::scope_cart, |
|
| 229 | + array(array('PMD_type' => 'Invoice')) |
|
| 230 | + ); |
|
| 231 | + $active_pms_count = EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart); |
|
| 232 | + // done step two if a non-invoice paymetn method is active; or there is more than one PM active, or |
|
| 233 | + // if only the invoice is active but it's clearly been updated |
|
| 234 | + $done_step_two = $active_pms_count > 1 || |
|
| 235 | + ($active_pms_count === 1 && ! $active_invoice_pm) || |
|
| 236 | + ($active_invoice_pm instanceof EE_Payment_Method && ( |
|
| 237 | + $active_invoice_pm->get_extra_meta('pdf_payee_name', true, '') || |
|
| 238 | + $active_invoice_pm->get_extra_meta('pdf_payee_email', true, '') || |
|
| 239 | + $active_invoice_pm->get_extra_meta('pdf_payee_tax_number', true, '') || |
|
| 240 | + $active_invoice_pm->get_extra_meta('pdf_payee_address', true, '') || |
|
| 241 | + $active_invoice_pm->get_extra_meta('page_extra_info', true, '') |
|
| 242 | + ) |
|
| 243 | + ); |
|
| 244 | + $done_step_three = EE_Registry::instance()->load_model('Event')->count() > 0 ? true : false; |
|
| 245 | + |
|
| 246 | + // if ALL steps are done, let's just return FALSE so we don't display anything |
|
| 247 | + if ($done_step_one && $done_step_two && $done_step_three) { |
|
| 248 | + return false; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // now let's put it together |
|
| 252 | + $steps .= sprintf('%s' . $step_one . '%s', $done_step_one ? '<strike>' : '', $done_step_one ? '</strike>' : ''); |
|
| 253 | + $steps .= sprintf('%s' . $step_two . '%s', $done_step_two ? '<strike>' : '', $done_step_two ? '</strike>' : ''); |
|
| 254 | + $steps .= sprintf( |
|
| 255 | + '%s' . $step_three . '%s', |
|
| 256 | + $done_step_three ? '<strike>' : '', |
|
| 257 | + $done_step_three ? '</strike>' : '' |
|
| 258 | + ); |
|
| 259 | + |
|
| 260 | + return $steps; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + protected function _credits() |
|
| 265 | + { |
|
| 266 | + $this->_template_args['admin_page_title'] = sprintf( |
|
| 267 | + esc_html__('Welcome to Event Espresso %s', 'event_espresso'), |
|
| 268 | + EVENT_ESPRESSO_VERSION |
|
| 269 | + ); |
|
| 270 | + $this->_template_args['admin_page_subtitle'] = esc_html__( |
|
| 271 | + 'Thank you for choosing Event Espresso Decaf, the most powerful, and free, Event Management plugin for WordPress.', |
|
| 272 | + 'event_espresso' |
|
| 273 | + ); |
|
| 274 | + $template = EE_ABOUT_TEMPLATE_PATH . 'credits.template.php'; |
|
| 275 | + $this->_template_args['about_admin_page_content'] = EEH_Template::display_template( |
|
| 276 | + $template, |
|
| 277 | + $this->_template_args, |
|
| 278 | + true |
|
| 279 | + ); |
|
| 280 | + $this->display_about_admin_page(); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + protected function _decafvpro() |
|
| 285 | + { |
|
| 286 | + $this->_template_args['admin_page_title'] = sprintf( |
|
| 287 | + esc_html__('Welcome to Event Espresso %s', 'event_espresso'), |
|
| 288 | + EVENT_ESPRESSO_VERSION |
|
| 289 | + ); |
|
| 290 | + $this->_template_args['admin_page_subtitle'] = sprintf( |
|
| 291 | + esc_html__( |
|
| 292 | + 'Event Espresso lets you focus on doing %swhat you love%s — %sorganizing your events%s', |
|
| 293 | + 'event_espresso' |
|
| 294 | + ), |
|
| 295 | + '<em>', |
|
| 296 | + '</em>', |
|
| 297 | + '<strong>', |
|
| 298 | + '</strong>' |
|
| 299 | + ); |
|
| 300 | + $template = EE_ABOUT_TEMPLATE_PATH . 'decafvpro.template.php'; |
|
| 301 | + $this->_template_args['about_admin_page_content'] = EEH_Template::display_template( |
|
| 302 | + $template, |
|
| 303 | + $this->_template_args, |
|
| 304 | + true |
|
| 305 | + ); |
|
| 306 | + $this->display_about_admin_page(); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + protected function _reviews() |
|
| 310 | + { |
|
| 311 | + $this->_template_args['admin_page_title'] = esc_html__('Rave Reviews About Event Espresso 4', 'event_espresso'); |
|
| 312 | + $this->_template_args['admin_page_subtitle'] = esc_html__( |
|
| 313 | + 'At Event Espresso, customer satisfaction is our ultimate goal.', |
|
| 314 | + 'event_espresso' |
|
| 315 | + ); |
|
| 316 | + $template = EE_ABOUT_TEMPLATE_PATH . 'reviews.template.php'; |
|
| 317 | + $this->_template_args['about_admin_page_content'] = EEH_Template::display_template( |
|
| 318 | + $template, |
|
| 319 | + $this->_template_args, |
|
| 320 | + true |
|
| 321 | + ); |
|
| 322 | + $this->display_about_admin_page(); |
|
| 323 | + } |
|
| 324 | 324 | } |
@@ -19,47 +19,47 @@ |
||
| 19 | 19 | </h3> |
| 20 | 20 | <p> |
| 21 | 21 | <?php |
| 22 | - echo printf( |
|
| 23 | - esc_html__('%3$sVersion %1$s%4$s is a %2$s bug fix/enhancement release.', 'event_espresso'), |
|
| 24 | - EVENT_ESPRESSO_VERSION, |
|
| 25 | - $type, |
|
| 26 | - '<strong>', |
|
| 27 | - '</strong>' |
|
| 28 | - ); |
|
| 29 | - printf( |
|
| 30 | - esc_html__('For more information, see %1$sthe release notes%2$s.', 'event_espresso'), |
|
| 31 | - '<a href="https://eventespresso.com/wiki/ee4-changelog/#' . $version . '">', |
|
| 32 | - '</a>' |
|
| 33 | - ); |
|
| 34 | - ?> |
|
| 22 | + echo printf( |
|
| 23 | + esc_html__('%3$sVersion %1$s%4$s is a %2$s bug fix/enhancement release.', 'event_espresso'), |
|
| 24 | + EVENT_ESPRESSO_VERSION, |
|
| 25 | + $type, |
|
| 26 | + '<strong>', |
|
| 27 | + '</strong>' |
|
| 28 | + ); |
|
| 29 | + printf( |
|
| 30 | + esc_html__('For more information, see %1$sthe release notes%2$s.', 'event_espresso'), |
|
| 31 | + '<a href="https://eventespresso.com/wiki/ee4-changelog/#' . $version . '">', |
|
| 32 | + '</a>' |
|
| 33 | + ); |
|
| 34 | + ?> |
|
| 35 | 35 | </p> |
| 36 | 36 | </div> |
| 37 | 37 | |
| 38 | 38 | <div class="changelog"> |
| 39 | 39 | <?php |
| 40 | - // maintenance mode on? |
|
| 41 | - if (MaintenanceStatus::isFullSite()) { |
|
| 42 | - ?> |
|
| 40 | + // maintenance mode on? |
|
| 41 | + if (MaintenanceStatus::isFullSite()) { |
|
| 42 | + ?> |
|
| 43 | 43 | <div class="ee-attention"> |
| 44 | 44 | <h2 class="ee-maintenance-mode-callout"> |
| 45 | 45 | <?php esc_html_e('Event Espresso is in full maintenance mode.', 'event_espresso'); ?> |
| 46 | 46 | </h2> |
| 47 | 47 | <p> |
| 48 | 48 | <?php |
| 49 | - printf( |
|
| 50 | - esc_html__( |
|
| 51 | - 'A previous version of Event Espresso has detected. But before anything else can happen, we need to know whether or not to migrate (copy over) your existing event data so that it can be utilized by EE4. For more instructions on what to do, please visit the %sEvent Espresso Maintenance%s page.', |
|
| 52 | - 'event_espresso' |
|
| 53 | - ), |
|
| 54 | - '<a href="admin.php?page=espresso_maintenance_settings">', |
|
| 55 | - '</a>' |
|
| 56 | - ); |
|
| 57 | - ?> |
|
| 49 | + printf( |
|
| 50 | + esc_html__( |
|
| 51 | + 'A previous version of Event Espresso has detected. But before anything else can happen, we need to know whether or not to migrate (copy over) your existing event data so that it can be utilized by EE4. For more instructions on what to do, please visit the %sEvent Espresso Maintenance%s page.', |
|
| 52 | + 'event_espresso' |
|
| 53 | + ), |
|
| 54 | + '<a href="admin.php?page=espresso_maintenance_settings">', |
|
| 55 | + '</a>' |
|
| 56 | + ); |
|
| 57 | + ?> |
|
| 58 | 58 | </p> |
| 59 | 59 | </div> |
| 60 | 60 | <?php |
| 61 | - } |
|
| 62 | - ?> |
|
| 61 | + } |
|
| 62 | + ?> |
|
| 63 | 63 | |
| 64 | 64 | <h2 class="about-headline-callout">Initial EE4 Decaf (free) Release</h2> |
| 65 | 65 | <p>This is the initial release of EE4 Decaf. This is the free version of our very powerful event registration and |
@@ -4,25 +4,25 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | // maintenance mode on? |
| 6 | 6 | if (MaintenanceStatus::isFullSite()) { |
| 7 | - ?> |
|
| 7 | + ?> |
|
| 8 | 8 | <div class="ee-attention"> |
| 9 | 9 | <h2 class="ee-maintenance-mode-callout"> |
| 10 | 10 | <?php esc_html_e( |
| 11 | - 'Event Espresso is in full maintenance mode.', |
|
| 12 | - 'event_espresso' |
|
| 13 | - ); ?> |
|
| 11 | + 'Event Espresso is in full maintenance mode.', |
|
| 12 | + 'event_espresso' |
|
| 13 | + ); ?> |
|
| 14 | 14 | </h2> |
| 15 | 15 | <p> |
| 16 | 16 | <?php esc_html( |
| 17 | - sprintf( |
|
| 18 | - __( |
|
| 19 | - 'A previous version of Event Espresso has detected. But before anything else can happen, we need to know whether or not to migrate (copy over) your existing event data so that it can be utilized by EE4. For more instructions on what to do, please visit the %sEvent Espresso Maintenance%s page.', |
|
| 20 | - 'event_espresso' |
|
| 21 | - ), |
|
| 22 | - '<a href="admin.php?page=espresso_maintenance_settings">', |
|
| 23 | - '</a>' |
|
| 24 | - ) |
|
| 25 | - ); ?> |
|
| 17 | + sprintf( |
|
| 18 | + __( |
|
| 19 | + 'A previous version of Event Espresso has detected. But before anything else can happen, we need to know whether or not to migrate (copy over) your existing event data so that it can be utilized by EE4. For more instructions on what to do, please visit the %sEvent Espresso Maintenance%s page.', |
|
| 20 | + 'event_espresso' |
|
| 21 | + ), |
|
| 22 | + '<a href="admin.php?page=espresso_maintenance_settings">', |
|
| 23 | + '</a>' |
|
| 24 | + ) |
|
| 25 | + ); ?> |
|
| 26 | 26 | </p> |
| 27 | 27 | </div> |
| 28 | 28 | <?php |
@@ -31,37 +31,37 @@ discard block |
||
| 31 | 31 | <div class="headline-feature"> |
| 32 | 32 | <h2 class="about-headline-callout"> |
| 33 | 33 | <?php esc_html_e( |
| 34 | - 'Welcome to the Decaf (free) Version of Event Espresso 4!', |
|
| 35 | - 'event_espresso' |
|
| 36 | - ); ?> |
|
| 34 | + 'Welcome to the Decaf (free) Version of Event Espresso 4!', |
|
| 35 | + 'event_espresso' |
|
| 36 | + ); ?> |
|
| 37 | 37 | </h2> |
| 38 | 38 | <p> |
| 39 | 39 | <?php printf( |
| 40 | - esc_html__( |
|
| 41 | - 'Manage your events from your WordPress dashboard. Reduce your admin, reduce your costs, make your life easier! This is the Decaf version of Event Espresso, but we also have a premium version called %sEvent Espreso 4 Regular%s and a hosted version called %sEvent Smart%s (SaaS).', |
|
| 42 | - 'event_espresso' |
|
| 43 | - ), |
|
| 44 | - '<a href="?page=espresso_about&action=decafvpro">', |
|
| 45 | - '</a>', |
|
| 46 | - '<a href="https://eventsmart.com//?utm_source=ee4_decaf&utm_medium=link&utm_campaign=espresso_about_tab&utm_content=EE4+Decaf">', |
|
| 47 | - '</a>' |
|
| 48 | - ); ?> |
|
| 40 | + esc_html__( |
|
| 41 | + 'Manage your events from your WordPress dashboard. Reduce your admin, reduce your costs, make your life easier! This is the Decaf version of Event Espresso, but we also have a premium version called %sEvent Espreso 4 Regular%s and a hosted version called %sEvent Smart%s (SaaS).', |
|
| 42 | + 'event_espresso' |
|
| 43 | + ), |
|
| 44 | + '<a href="?page=espresso_about&action=decafvpro">', |
|
| 45 | + '</a>', |
|
| 46 | + '<a href="https://eventsmart.com//?utm_source=ee4_decaf&utm_medium=link&utm_campaign=espresso_about_tab&utm_content=EE4+Decaf">', |
|
| 47 | + '</a>' |
|
| 48 | + ); ?> |
|
| 49 | 49 | </p> |
| 50 | 50 | <h2> |
| 51 | 51 | <?php esc_html_e( |
| 52 | - 'Powering 40,000+ event websites; $100 million in ticket sales per year!', |
|
| 53 | - 'event_espresso' |
|
| 54 | - ); ?> |
|
| 52 | + 'Powering 40,000+ event websites; $100 million in ticket sales per year!', |
|
| 53 | + 'event_espresso' |
|
| 54 | + ); ?> |
|
| 55 | 55 | </h2> |
| 56 | 56 | <p> |
| 57 | 57 | <?php printf( |
| 58 | - esc_html__( |
|
| 59 | - 'Event Espresso is a %sWordPress event manager%s which makes it easy for you to register attendees for classes, workshops, events, trainings, conferences or concerts, all from your WordPress website. Event Espresso events are created from the WordPress admin area. You can create signup forms to collect information about your attendees, accept payments, and create reports. The Decaf (free) version of the plugin provides everything that you need to manage your event using WordPress.', |
|
| 60 | - 'event_espresso' |
|
| 61 | - ), |
|
| 62 | - '<a href="https://eventespresso.com/?utm_source=wordpress_org&utm_medium=link&utm_campaign=plugin_description_tab&utm_content=EE4+Decaf">', |
|
| 63 | - '</a>' |
|
| 64 | - ); ?> |
|
| 58 | + esc_html__( |
|
| 59 | + 'Event Espresso is a %sWordPress event manager%s which makes it easy for you to register attendees for classes, workshops, events, trainings, conferences or concerts, all from your WordPress website. Event Espresso events are created from the WordPress admin area. You can create signup forms to collect information about your attendees, accept payments, and create reports. The Decaf (free) version of the plugin provides everything that you need to manage your event using WordPress.', |
|
| 60 | + 'event_espresso' |
|
| 61 | + ), |
|
| 62 | + '<a href="https://eventespresso.com/?utm_source=wordpress_org&utm_medium=link&utm_campaign=plugin_description_tab&utm_content=EE4+Decaf">', |
|
| 63 | + '</a>' |
|
| 64 | + ); ?> |
|
| 65 | 65 | </p> |
| 66 | 66 | </div> |
| 67 | 67 | <div class="feature-section has-3-columns is-fullwidth three-col"> |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | <h3><?php esc_html_e('Optimized aesthetic', 'event_espresso'); ?></h3> |
| 71 | 71 | <p> |
| 72 | 72 | <?php esc_html_e( |
| 73 | - 'The Event Espresso 4 dashboard has a fresh, uncluttered design that embraces clarity and simplicity.', |
|
| 74 | - 'event_espresso' |
|
| 75 | - ); ?> |
|
| 73 | + 'The Event Espresso 4 dashboard has a fresh, uncluttered design that embraces clarity and simplicity.', |
|
| 74 | + 'event_espresso' |
|
| 75 | + ); ?> |
|
| 76 | 76 | </p> |
| 77 | 77 | </div> |
| 78 | 78 | <div class="column col"> |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | <h3><?php esc_html_e('Integrated management', 'event_espresso'); ?></h3> |
| 81 | 81 | <p> |
| 82 | 82 | <?php esc_html_e( |
| 83 | - 'We’ve made it easier to know who your customers are and how they’ve done business with you over time.', |
|
| 84 | - 'event_espresso' |
|
| 85 | - ); ?> |
|
| 83 | + 'We’ve made it easier to know who your customers are and how they’ve done business with you over time.', |
|
| 84 | + 'event_espresso' |
|
| 85 | + ); ?> |
|
| 86 | 86 | </p> |
| 87 | 87 | </div> |
| 88 | 88 | <div class="column col last-feature"> |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | <h3><?php esc_html_e('Easy bookkeeping', 'event_espresso'); ?></h3> |
| 91 | 91 | <p> |
| 92 | 92 | <?php esc_html_e( |
| 93 | - 'Registrations, payment, and transactions have been substantially improved in Event Espresso 4.', |
|
| 94 | - 'event_espresso' |
|
| 95 | - ); ?> |
|
| 93 | + 'Registrations, payment, and transactions have been substantially improved in Event Espresso 4.', |
|
| 94 | + 'event_espresso' |
|
| 95 | + ); ?> |
|
| 96 | 96 | </p> |
| 97 | 97 | </div> |
| 98 | 98 | </div> |
@@ -104,16 +104,16 @@ discard block |
||
| 104 | 104 | <h3><?php esc_html_e('Higher customer retention', 'event_espresso'); ?></h3> |
| 105 | 105 | <p> |
| 106 | 106 | <?php esc_html_e( |
| 107 | - 'The Event Espresso 4 registration process is faster than ever. With quick ticket selections, single page check-out, and customizable notifications! Registration that can scale to your business needs.', |
|
| 108 | - 'event_espresso' |
|
| 109 | - ); ?> |
|
| 107 | + 'The Event Espresso 4 registration process is faster than ever. With quick ticket selections, single page check-out, and customizable notifications! Registration that can scale to your business needs.', |
|
| 108 | + 'event_espresso' |
|
| 109 | + ); ?> |
|
| 110 | 110 | </p> |
| 111 | 111 | <h4><?php esc_html_e('Ticket selection boxes on any post page or post', 'event_espresso'); ?></h4> |
| 112 | 112 | <p> |
| 113 | 113 | <?php esc_html_e( |
| 114 | - 'Customers can easily register for classes, events, or conferences, in just a few simple steps. No matter how you use it, Event Espresso 4 will adapt to a multitude of different ticketing and pricing scenarios.', |
|
| 115 | - 'event_espresso' |
|
| 116 | - ); ?> |
|
| 114 | + 'Customers can easily register for classes, events, or conferences, in just a few simple steps. No matter how you use it, Event Espresso 4 will adapt to a multitude of different ticketing and pricing scenarios.', |
|
| 115 | + 'event_espresso' |
|
| 116 | + ); ?> |
|
| 117 | 117 | </p> |
| 118 | 118 | </div> |
| 119 | 119 | <div class="column col last-feature about-colors-img"> |
@@ -126,24 +126,24 @@ discard block |
||
| 126 | 126 | <h3><?php esc_html_e('Refined event management', 'event_espresso'); ?></h3> |
| 127 | 127 | <p> |
| 128 | 128 | <?php esc_html_e( |
| 129 | - 'The new event management screen lets you survey your events at a glance. Want more information? Click to view more. Quickly add/edit prices, dates, or information in any event.', |
|
| 130 | - 'event_espresso' |
|
| 131 | - ); ?> |
|
| 129 | + 'The new event management screen lets you survey your events at a glance. Want more information? Click to view more. Quickly add/edit prices, dates, or information in any event.', |
|
| 130 | + 'event_espresso' |
|
| 131 | + ); ?> |
|
| 132 | 132 | </p> |
| 133 | 133 | <h4> |
| 134 | 134 | <?php esc_html_e('Smoother price types, taxes, and price modifiers', 'event_espresso'); ?> |
| 135 | 135 | </h4> |
| 136 | 136 | <p> |
| 137 | 137 | <?php esc_html_e( |
| 138 | - 'Price Types allow you to create new prices that adjust the default ticket (base) price for your system-default ticket', |
|
| 139 | - 'event_espresso' |
|
| 140 | - ); ?> |
|
| 138 | + 'Price Types allow you to create new prices that adjust the default ticket (base) price for your system-default ticket', |
|
| 139 | + 'event_espresso' |
|
| 140 | + ); ?> |
|
| 141 | 141 | </p> |
| 142 | 142 | <p> |
| 143 | 143 | <?php esc_html_e( |
| 144 | - 'Easily categorize a price modifier and indicate how that price gets applied to the running total when a transaction occurs.', |
|
| 145 | - 'event_espresso' |
|
| 146 | - ); ?> |
|
| 144 | + 'Easily categorize a price modifier and indicate how that price gets applied to the running total when a transaction occurs.', |
|
| 145 | + 'event_espresso' |
|
| 146 | + ); ?> |
|
| 147 | 147 | </p> |
| 148 | 148 | </div> |
| 149 | 149 | <div class="column col last-feature about-themes-img"> |
@@ -155,45 +155,45 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | <h2 class="about-headline-callout"> |
| 157 | 157 | <?php esc_html_e( |
| 158 | - 'People Like You Manage Event Registration with WordPress', |
|
| 159 | - 'event_espresso' |
|
| 160 | - ); ?> |
|
| 158 | + 'People Like You Manage Event Registration with WordPress', |
|
| 159 | + 'event_espresso' |
|
| 160 | + ); ?> |
|
| 161 | 161 | </h2> |
| 162 | 162 | <div class="feature-section has-2-columns is-fullwidth two-col"> |
| 163 | 163 | <div class="column col"> |
| 164 | 164 | <p> |
| 165 | 165 | <?php printf( |
| 166 | - esc_html__( |
|
| 167 | - 'Trusted by thousands, Event Espresso is the best WordPress event online registration and ticketing manager plugin–and the best supported with full-time support. Turn your existing blog or website into a %sfully-featured event management website%s and a new way to make money. With Event Espresso you get it all; everything from custom registration forms and emails, seating limits, multiple price options, and discount codes to printable tickets.', |
|
| 168 | - 'event_espresso' |
|
| 169 | - ), |
|
| 170 | - '<strong>', |
|
| 171 | - '</strong>' |
|
| 172 | - ); ?> |
|
| 166 | + esc_html__( |
|
| 167 | + 'Trusted by thousands, Event Espresso is the best WordPress event online registration and ticketing manager plugin–and the best supported with full-time support. Turn your existing blog or website into a %sfully-featured event management website%s and a new way to make money. With Event Espresso you get it all; everything from custom registration forms and emails, seating limits, multiple price options, and discount codes to printable tickets.', |
|
| 168 | + 'event_espresso' |
|
| 169 | + ), |
|
| 170 | + '<strong>', |
|
| 171 | + '</strong>' |
|
| 172 | + ); ?> |
|
| 173 | 173 | </p> |
| 174 | 174 | <p> |
| 175 | 175 | <?php esc_html_e( |
| 176 | - 'Event Espresso works perfectly for classes, workshops, fundraisers, sporting, trainings, conferences, networking, religion, social, non-profit, and nearly any other type of event.', |
|
| 177 | - 'event_espresso' |
|
| 178 | - ); ?> |
|
| 176 | + 'Event Espresso works perfectly for classes, workshops, fundraisers, sporting, trainings, conferences, networking, religion, social, non-profit, and nearly any other type of event.', |
|
| 177 | + 'event_espresso' |
|
| 178 | + ); ?> |
|
| 179 | 179 | </p> |
| 180 | 180 | </div> |
| 181 | 181 | <div class="column col"> |
| 182 | 182 | <p> |
| 183 | 183 | <?php printf( |
| 184 | - esc_html__( |
|
| 185 | - 'Our online event registration software can %smake your organization more profitable and efficient%s by helping you save money on registration and ticketing fees, reduce the countless hours of time you spend manually processing registrations, create a “green” and paperless event registration process and you will be open for business to accept registrations and payment 24/7.', |
|
| 186 | - 'event_espresso' |
|
| 187 | - ), |
|
| 188 | - '<strong>', |
|
| 189 | - '</strong>' |
|
| 190 | - ); ?> |
|
| 184 | + esc_html__( |
|
| 185 | + 'Our online event registration software can %smake your organization more profitable and efficient%s by helping you save money on registration and ticketing fees, reduce the countless hours of time you spend manually processing registrations, create a “green” and paperless event registration process and you will be open for business to accept registrations and payment 24/7.', |
|
| 186 | + 'event_espresso' |
|
| 187 | + ), |
|
| 188 | + '<strong>', |
|
| 189 | + '</strong>' |
|
| 190 | + ); ?> |
|
| 191 | 191 | </p> |
| 192 | 192 | <p> |
| 193 | 193 | <?php esc_html_e( |
| 194 | - 'If you\'re doing event registration and ticketing any other way, then you’re wasting time and money. We offer packages and prices to fit any budget, so get started with your online event registration and ticketing management system today.', |
|
| 195 | - 'event_espresso' |
|
| 196 | - ); ?> |
|
| 194 | + 'If you\'re doing event registration and ticketing any other way, then you’re wasting time and money. We offer packages and prices to fit any budget, so get started with your online event registration and ticketing management system today.', |
|
| 195 | + 'event_espresso' |
|
| 196 | + ); ?> |
|
| 197 | 197 | </p> |
| 198 | 198 | </div> |
| 199 | 199 | </div> |
@@ -202,28 +202,28 @@ discard block |
||
| 202 | 202 | <div class="column col"> |
| 203 | 203 | <h3> |
| 204 | 204 | <?php esc_html_e( |
| 205 | - 'Turn your blog into a complete event registration and management system', |
|
| 206 | - 'event_espresso' |
|
| 207 | - ); ?> |
|
| 205 | + 'Turn your blog into a complete event registration and management system', |
|
| 206 | + 'event_espresso' |
|
| 207 | + ); ?> |
|
| 208 | 208 | </h3> |
| 209 | 209 | <p> |
| 210 | 210 | <?php esc_html_e( |
| 211 | - 'Create a beautiful event page with ticket selection, venue details, and an integrated single page checkout system. With WordPress, Event Espresso, and Espresso Arabica 2014 (based on the "Twenty Fourteen" theme by WordPress), your events will certainly sell out faster than ever!', |
|
| 212 | - 'event_espresso' |
|
| 213 | - ); ?> |
|
| 211 | + 'Create a beautiful event page with ticket selection, venue details, and an integrated single page checkout system. With WordPress, Event Espresso, and Espresso Arabica 2014 (based on the "Twenty Fourteen" theme by WordPress), your events will certainly sell out faster than ever!', |
|
| 212 | + 'event_espresso' |
|
| 213 | + ); ?> |
|
| 214 | 214 | </p> |
| 215 | 215 | <p> |
| 216 | 216 | <?php esc_html_e( |
| 217 | - 'With a striking design that does not compromise the simplicity of WordPress and Event Espresso 4, Espresso Arabica 2014 will be the best event theme on the market.', |
|
| 218 | - 'event_espresso' |
|
| 219 | - ); ?> |
|
| 217 | + 'With a striking design that does not compromise the simplicity of WordPress and Event Espresso 4, Espresso Arabica 2014 will be the best event theme on the market.', |
|
| 218 | + 'event_espresso' |
|
| 219 | + ); ?> |
|
| 220 | 220 | </p> |
| 221 | 221 | <p> |
| 222 | 222 | <?php printf( |
| 223 | - esc_html__('%sLearn more >>%s', 'event_espresso'), |
|
| 224 | - '<a href="https://eventespresso.com/wiki/setup-event-espresso-arabica-theme/">', |
|
| 225 | - '</a>' |
|
| 226 | - ); ?> |
|
| 223 | + esc_html__('%sLearn more >>%s', 'event_espresso'), |
|
| 224 | + '<a href="https://eventespresso.com/wiki/setup-event-espresso-arabica-theme/">', |
|
| 225 | + '</a>' |
|
| 226 | + ); ?> |
|
| 227 | 227 | </p> |
| 228 | 228 | </div> |
| 229 | 229 | <div class="column col"> |
@@ -238,9 +238,9 @@ discard block |
||
| 238 | 238 | <div class="column col"> |
| 239 | 239 | <p> |
| 240 | 240 | <?php esc_html_e( |
| 241 | - 'We’ve made it super easy to integrate Event Espresso with almost any properly coded WordPress theme, including many of the thousands of themes available on WordPress.org. The image below shows the same Event Espresso ticketing page across three diffrent WordPress themes.', |
|
| 242 | - 'event_espresso' |
|
| 243 | - ); ?> |
|
| 241 | + 'We’ve made it super easy to integrate Event Espresso with almost any properly coded WordPress theme, including many of the thousands of themes available on WordPress.org. The image below shows the same Event Espresso ticketing page across three diffrent WordPress themes.', |
|
| 242 | + 'event_espresso' |
|
| 243 | + ); ?> |
|
| 244 | 244 | </p> |
| 245 | 245 | <p> |
| 246 | 246 | <img class="about-overview-img" src="<?php echo EEH_Template::getScreenshotUrl('multiple-themes'); ?>" /> |
@@ -28,1324 +28,1324 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class EE_Data_Migration_Manager implements ResettableInterface |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * @var EE_Registry |
|
| 33 | - */ |
|
| 34 | - // protected $EE; |
|
| 35 | - /** |
|
| 36 | - * name of the WordPress option which stores an array of data about |
|
| 37 | - */ |
|
| 38 | - const data_migrations_option_name = 'ee_data_migration'; |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - const data_migration_script_option_prefix = 'ee_data_migration_script_'; |
|
| 42 | - |
|
| 43 | - const data_migration_script_mapping_option_prefix = 'ee_dms_map_'; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * name of the WordPress option which stores the database' current version. IE, the code may be at version 4.2.0, |
|
| 47 | - * but as migrations are performed the database will progress from 3.1.35 to 4.1.0 etc. |
|
| 48 | - */ |
|
| 49 | - const current_database_state = 'ee_data_migration_current_db_state'; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Special status string returned when we're positive there are no more data migration |
|
| 53 | - * scripts that can be run. |
|
| 54 | - */ |
|
| 55 | - const status_no_more_migration_scripts = 'no_more_migration_scripts'; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * string indicating the migration should continue |
|
| 59 | - */ |
|
| 60 | - const status_continue = 'status_continue'; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * string indicating the migration has completed and should be ended |
|
| 64 | - */ |
|
| 65 | - const status_completed = 'status_completed'; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * string indicating a fatal error occurred and the data migration should be completely aborted |
|
| 69 | - */ |
|
| 70 | - const status_fatal_error = 'status_fatal_error'; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * the number of 'items' (usually DB rows) to migrate on each 'step' (ajax request sent |
|
| 74 | - * during migration) |
|
| 75 | - */ |
|
| 76 | - const step_size = 50; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * option name that stores the queue of ee plugins needing to have |
|
| 80 | - * their data initialized (or re-initialized) once we are done migrations |
|
| 81 | - */ |
|
| 82 | - const db_init_queue_option_name = 'ee_db_init_queue'; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Array of information concerning data migrations that have run in the history |
|
| 86 | - * of this EE installation. Keys should be the name of the version the script upgraded to |
|
| 87 | - * |
|
| 88 | - * @var EE_Data_Migration_Script_Base[] |
|
| 89 | - */ |
|
| 90 | - private $_data_migrations_ran = null; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * The last run script. It's nice to store this somewhere accessible, as its easiest |
|
| 94 | - * to know which was the last run by which is the newest wp option; but in most of the code |
|
| 95 | - * we just use the local $_data_migration_ran array, which organized the scripts differently |
|
| 96 | - * |
|
| 97 | - * @var EE_Data_Migration_Script_Base |
|
| 98 | - */ |
|
| 99 | - private $_last_ran_script = null; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Similarly to _last_ran_script, but this is the last INCOMPLETE migration script. |
|
| 103 | - * |
|
| 104 | - * @var EE_Data_Migration_Script_Base |
|
| 105 | - */ |
|
| 106 | - private $_last_ran_incomplete_script = null; |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * array where keys are classnames, and values are filepaths of all the known migration scripts |
|
| 110 | - * |
|
| 111 | - * @var array |
|
| 112 | - */ |
|
| 113 | - private $_data_migration_class_to_filepath_map; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * the following 4 properties are fully set on construction. |
|
| 117 | - * Note: the first two apply to whether to continue running ALL migration scripts (ie, even though we're finished |
|
| 118 | - * one, we may want to start the next one); whereas the last two indicate whether to continue running a single |
|
| 119 | - * data migration script |
|
| 120 | - * |
|
| 121 | - * @var array |
|
| 122 | - */ |
|
| 123 | - public $stati_that_indicate_to_continue_migrations = []; |
|
| 124 | - |
|
| 125 | - public $stati_that_indicate_to_stop_migrations = []; |
|
| 126 | - |
|
| 127 | - public $stati_that_indicate_to_continue_single_migration_script = []; |
|
| 128 | - |
|
| 129 | - public $stati_that_indicate_to_stop_single_migration_script = []; |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @var TableManager $table_manager |
|
| 133 | - */ |
|
| 134 | - protected $_table_manager; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @var TableAnalysis $table_analysis |
|
| 138 | - */ |
|
| 139 | - protected $_table_analysis; |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @var array $script_migration_versions |
|
| 143 | - */ |
|
| 144 | - protected $script_migration_versions; |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @var array $dms_folders |
|
| 148 | - */ |
|
| 149 | - protected $dms_folders; |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @var EE_Data_Migration_Manager $_instance |
|
| 153 | - * @access private |
|
| 154 | - */ |
|
| 155 | - private static $_instance = null; |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @singleton method used to instantiate class object |
|
| 160 | - * @access public |
|
| 161 | - * @return EE_Data_Migration_Manager instance |
|
| 162 | - */ |
|
| 163 | - public static function instance() |
|
| 164 | - { |
|
| 165 | - // check if class object is instantiated |
|
| 166 | - if (! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
| 167 | - self::$_instance = new self(); |
|
| 168 | - } |
|
| 169 | - return self::$_instance; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * resets the singleton to its brand-new state (but does NOT delete old references to the old singleton. Meaning, |
|
| 175 | - * all new usages of the singleton should be made with Classname::instance()) and returns it |
|
| 176 | - * |
|
| 177 | - * @return EE_Data_Migration_Manager |
|
| 178 | - */ |
|
| 179 | - public static function reset() |
|
| 180 | - { |
|
| 181 | - self::$_instance = new self(); |
|
| 182 | - return self::instance(); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @throws EE_Error |
|
| 188 | - * @throws ReflectionException |
|
| 189 | - */ |
|
| 190 | - private function __construct() |
|
| 191 | - { |
|
| 192 | - $this->stati_that_indicate_to_continue_migrations = [ |
|
| 193 | - self::status_continue, |
|
| 194 | - self::status_completed, |
|
| 195 | - ]; |
|
| 196 | - $this->stati_that_indicate_to_stop_migrations = [ |
|
| 197 | - self::status_fatal_error, |
|
| 198 | - self::status_no_more_migration_scripts, |
|
| 199 | - ]; |
|
| 200 | - $this->stati_that_indicate_to_continue_single_migration_script = [ |
|
| 201 | - self::status_continue, |
|
| 202 | - ]; |
|
| 203 | - $this->stati_that_indicate_to_stop_single_migration_script = [ |
|
| 204 | - self::status_completed, |
|
| 205 | - self::status_fatal_error, |
|
| 206 | - // note: status_no_more_migration_scripts doesn't apply |
|
| 207 | - ]; |
|
| 208 | - $this->dms_folders = []; |
|
| 209 | - // make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class |
|
| 210 | - // to be defined, because right now it doesn't get autoloaded on its own |
|
| 211 | - EE_Registry::instance()->load_core('Data_Migration_Class_Base', [], true); |
|
| 212 | - EE_Registry::instance()->load_core('Data_Migration_Script_Base', [], true); |
|
| 213 | - EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', [], true); |
|
| 214 | - EE_Registry::instance()->load_core('Data_Migration_Script_Stage', [], true); |
|
| 215 | - EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', [], true); |
|
| 216 | - $this->_table_manager = EE_Registry::instance()->create('TableManager', [], true); |
|
| 217 | - $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Deciphers, from an option's name, what plugin and version it relates to (see _save_migrations_ran to see what |
|
| 223 | - * the option names are like, but generally they're like |
|
| 224 | - * 'ee_data_migration_script_Core.4.1.0' in 4.2 or 'ee_data_migration_script_4.1.0' before that). |
|
| 225 | - * The option name shouldn't ever be like 'ee_data_migration_script_Core.4.1.0.reg' because it's derived, |
|
| 226 | - * indirectly, from the data migration's classname, which should always be like EE_DMS_%s_%d_%d_%d.dms.php |
|
| 227 | - * (ex: EE_DMS_Core_4_1_0.dms.php) |
|
| 228 | - * |
|
| 229 | - * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set) |
|
| 230 | - * @return array where the first item is the plugin slug (eg 'Core','Calendar', etc.) and the 2nd is the version of |
|
| 231 | - * that plugin (eg '4.1.0') |
|
| 232 | - */ |
|
| 233 | - private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name) |
|
| 234 | - { |
|
| 235 | - $plugin_slug_and_version_string = str_replace( |
|
| 236 | - EE_Data_Migration_Manager::data_migration_script_option_prefix, |
|
| 237 | - "", |
|
| 238 | - $option_name |
|
| 239 | - ); |
|
| 240 | - // check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style) |
|
| 241 | - $parts = explode(".", $plugin_slug_and_version_string); |
|
| 242 | - |
|
| 243 | - if (count($parts) == 4) { |
|
| 244 | - // it's 4.2-style.eg Core.4.1.0 |
|
| 245 | - $plugin_slug = $parts[0]; // eg Core |
|
| 246 | - $version_string = $parts[1] . "." . $parts[2] . "." . $parts[3]; // eg 4.1.0 |
|
| 247 | - } else { |
|
| 248 | - // it's 4.1-style: eg 4.1.0 |
|
| 249 | - $plugin_slug = 'Core'; |
|
| 250 | - $version_string = $plugin_slug_and_version_string;// eg 4.1.0 |
|
| 251 | - } |
|
| 252 | - return [$plugin_slug, $version_string]; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Gets the DMS class from the WordPress option, otherwise throws an EE_Error if it's not |
|
| 258 | - * for a known DMS class. |
|
| 259 | - * |
|
| 260 | - * @param string $dms_option_name |
|
| 261 | - * @param string $dms_option_value (serialized) |
|
| 262 | - * @return EE_Data_Migration_Script_Base |
|
| 263 | - * @throws EE_Error |
|
| 264 | - */ |
|
| 265 | - private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value) |
|
| 266 | - { |
|
| 267 | - $data_migration_data = maybe_unserialize($dms_option_value); |
|
| 268 | - if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) { |
|
| 269 | - // During multisite migrations, it's possible we already grabbed another instance of this class |
|
| 270 | - // but for a different blog. Make sure we don't reuse them (as they store info specific |
|
| 271 | - // to their respective blog, like which database table to migrate). |
|
| 272 | - $class = LoaderFactory::getLoader()->getNew($data_migration_data['class']); |
|
| 273 | - if ($class instanceof EE_Data_Migration_Script_Base) { |
|
| 274 | - $class->instantiate_from_array_of_properties($data_migration_data); |
|
| 275 | - return $class; |
|
| 276 | - } else { |
|
| 277 | - // huh, so it's an object but not a data migration script?? that shouldn't happen |
|
| 278 | - // just leave it as an array (which will probably just get ignored) |
|
| 279 | - throw new EE_Error( |
|
| 280 | - sprintf( |
|
| 281 | - esc_html__( |
|
| 282 | - "Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", |
|
| 283 | - 'event_espresso' |
|
| 284 | - ), |
|
| 285 | - $data_migration_data['class'] |
|
| 286 | - ) |
|
| 287 | - ); |
|
| 288 | - } |
|
| 289 | - } else { |
|
| 290 | - // so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists |
|
| 291 | - throw new EE_Error( |
|
| 292 | - sprintf( |
|
| 293 | - esc_html__("The wp option with key '%s' does not represent a DMS", 'event_espresso'), |
|
| 294 | - $dms_option_name |
|
| 295 | - ) |
|
| 296 | - ); |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Gets the array describing what data migrations have run. |
|
| 303 | - * Also has a side effect of recording which was the last run, |
|
| 304 | - * and which was the last run which hasn't finished yet |
|
| 305 | - * |
|
| 306 | - * @return array where each element should be an array of EE_Data_Migration_Script_Base |
|
| 307 | - * (but also has a few legacy arrays in there - which should probably be ignored) |
|
| 308 | - * @throws EE_Error |
|
| 309 | - */ |
|
| 310 | - public function get_data_migrations_ran() |
|
| 311 | - { |
|
| 312 | - if (! $this->_data_migrations_ran) { |
|
| 313 | - // setup autoloaders for each of the scripts in there |
|
| 314 | - $this->get_all_data_migration_scripts_available(); |
|
| 315 | - $data_migrations_options = |
|
| 316 | - $this->get_all_migration_script_options();// get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
| 317 | - |
|
| 318 | - $data_migrations_ran = []; |
|
| 319 | - // convert into data migration script classes where possible |
|
| 320 | - foreach ($data_migrations_options as $data_migration_option) { |
|
| 321 | - [$plugin_slug, $version_string] = $this->_get_plugin_slug_and_version_string_from_dms_option_name( |
|
| 322 | - $data_migration_option['option_name'] |
|
| 323 | - ); |
|
| 324 | - |
|
| 325 | - try { |
|
| 326 | - $class = $this->_get_dms_class_from_wp_option( |
|
| 327 | - $data_migration_option['option_name'], |
|
| 328 | - $data_migration_option['option_value'] |
|
| 329 | - ); |
|
| 330 | - $data_migrations_ran[ $plugin_slug ][ $version_string ] = $class; |
|
| 331 | - // ok so far THIS is the 'last-run-script'... unless we find another on next iteration |
|
| 332 | - $this->_last_ran_script = $class; |
|
| 333 | - if (! $class->is_completed()) { |
|
| 334 | - // sometimes we also like to know which was the last incomplete script (or if there are any at all) |
|
| 335 | - $this->_last_ran_incomplete_script = $class; |
|
| 336 | - } |
|
| 337 | - } catch (EE_Error $e) { |
|
| 338 | - // ok so it's not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
|
| 339 | - $data_migrations_ran[ $plugin_slug ][ $version_string ] = maybe_unserialize( |
|
| 340 | - $data_migration_option['option_value'] |
|
| 341 | - ); |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - // so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
|
| 345 | - $this->_data_migrations_ran = $data_migrations_ran; |
|
| 346 | - if (! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
| 347 | - $this->_data_migrations_ran = []; |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - return $this->_data_migrations_ran; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * @param string $script_name eg 'DMS_Core_4_1_0' |
|
| 356 | - * @param string $old_table eg 'wp_events_detail' |
|
| 357 | - * @param string $old_pk eg 'wp_esp_posts' |
|
| 358 | - * @param $new_table |
|
| 359 | - * @return mixed string or int |
|
| 360 | - * @throws EE_Error |
|
| 361 | - * @throws ReflectionException |
|
| 362 | - */ |
|
| 363 | - public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) |
|
| 364 | - { |
|
| 365 | - $script = EE_Registry::instance()->load_dms($script_name); |
|
| 366 | - return $script->get_mapping_new_pk($old_table, $old_pk, $new_table); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * Gets all the options containing migration scripts that have been run. Ordering is important: it's assumed that |
|
| 372 | - * the last option returned in this array is the most-recently run DMS option |
|
| 373 | - * |
|
| 374 | - * @return array |
|
| 375 | - */ |
|
| 376 | - public function get_all_migration_script_options() |
|
| 377 | - { |
|
| 378 | - global $wpdb; |
|
| 379 | - return $wpdb->get_results( |
|
| 380 | - "SELECT * FROM {$wpdb->options} WHERE option_name like '" |
|
| 381 | - . EE_Data_Migration_Manager::data_migration_script_option_prefix |
|
| 382 | - . "%' ORDER BY option_id ASC", |
|
| 383 | - ARRAY_A |
|
| 384 | - ); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Gets the array of folders which contain data migration scripts. Also adds them to be auto-loaded |
|
| 390 | - * |
|
| 391 | - * @return array where each value is the full folder path of a folder containing data migration scripts, WITH |
|
| 392 | - * slashes at the end of the folder name. |
|
| 393 | - */ |
|
| 394 | - public function get_data_migration_script_folders() |
|
| 395 | - { |
|
| 396 | - if (empty($this->dms_folders)) { |
|
| 397 | - $this->dms_folders = (array) apply_filters( |
|
| 398 | - 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
| 399 | - ['Core' => EE_CORE . 'data_migration_scripts'] |
|
| 400 | - ); |
|
| 401 | - } |
|
| 402 | - return $this->dms_folders; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Gets the version the migration script upgrades to |
|
| 408 | - * |
|
| 409 | - * @param string $migration_script_name eg 'EE_DMS_Core_4_1_0' |
|
| 410 | - * @return array { |
|
| 411 | - * @type string $slug like 'Core','Calendar',etc |
|
| 412 | - * @type string $version like 4.3.0 |
|
| 413 | - * } |
|
| 414 | - * @throws EE_Error |
|
| 415 | - */ |
|
| 416 | - public function script_migrates_to_version($migration_script_name, $eeAddonClass = '') |
|
| 417 | - { |
|
| 418 | - if (isset($this->script_migration_versions[ $migration_script_name ])) { |
|
| 419 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
| 420 | - } |
|
| 421 | - $dms_info = $this->parse_dms_classname($migration_script_name); |
|
| 422 | - $this->script_migration_versions[ $migration_script_name ] = [ |
|
| 423 | - 'slug' => $eeAddonClass !== '' |
|
| 424 | - ? $eeAddonClass |
|
| 425 | - : $dms_info['slug'], |
|
| 426 | - 'version' => $dms_info['major_version'] |
|
| 427 | - . "." |
|
| 428 | - . $dms_info['minor_version'] |
|
| 429 | - . "." |
|
| 430 | - . $dms_info['micro_version'], |
|
| 431 | - ]; |
|
| 432 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Gets the juicy details out of a dms filename like 'EE_DMS_Core_4_1_0' |
|
| 438 | - * |
|
| 439 | - * @param string $classname |
|
| 440 | - * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are integers) |
|
| 441 | - * @throws EE_Error |
|
| 442 | - */ |
|
| 443 | - public function parse_dms_classname($classname) |
|
| 444 | - { |
|
| 445 | - $matches = []; |
|
| 446 | - preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
|
| 447 | - if (! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
| 448 | - throw new EE_Error( |
|
| 449 | - sprintf( |
|
| 450 | - esc_html__( |
|
| 451 | - "%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", |
|
| 452 | - "event_espresso" |
|
| 453 | - ), |
|
| 454 | - $classname |
|
| 455 | - ) |
|
| 456 | - ); |
|
| 457 | - } |
|
| 458 | - return [ |
|
| 459 | - 'slug' => $matches[1], |
|
| 460 | - 'major_version' => intval($matches[2]), |
|
| 461 | - 'minor_version' => intval($matches[3]), |
|
| 462 | - 'micro_version' => intval($matches[4]), |
|
| 463 | - ]; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Ensures that the option indicating the current DB version is set. This should only be |
|
| 469 | - * a concern when activating EE for the first time, THEORETICALLY. |
|
| 470 | - * If we detect that we're activating EE4 over top of EE3.1, then we set the current db state to 3.1.x, otherwise |
|
| 471 | - * to 4.1.x. |
|
| 472 | - * |
|
| 473 | - * @return string of current db state |
|
| 474 | - */ |
|
| 475 | - public function ensure_current_database_state_is_set() |
|
| 476 | - { |
|
| 477 | - $espresso_db_core_updates = get_option('espresso_db_update', []); |
|
| 478 | - $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
|
| 479 | - if (! $db_state) { |
|
| 480 | - // mark the DB as being in the state as the last version in there. |
|
| 481 | - // this is done to trigger maintenance mode and do data migration scripts |
|
| 482 | - // if the admin installed this version of EE over 3.1.x or 4.0.x |
|
| 483 | - // otherwise, the normal maintenance mode code is fine |
|
| 484 | - $previous_versions_installed = array_keys($espresso_db_core_updates); |
|
| 485 | - $previous_version_installed = end($previous_versions_installed); |
|
| 486 | - if (version_compare('4.1.0', $previous_version_installed)) { |
|
| 487 | - // last installed version was less than 4.1, so we want the data migrations to happen. |
|
| 488 | - // SO, we're going to say the DB is at that state |
|
| 489 | - $db_state = ['Core' => $previous_version_installed]; |
|
| 490 | - } else { |
|
| 491 | - $db_state = ['Core' => EVENT_ESPRESSO_VERSION]; |
|
| 492 | - } |
|
| 493 | - update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
| 494 | - } |
|
| 495 | - // in 4.1, $db_state would have only been a simple string like '4.1.0', |
|
| 496 | - // but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
|
| 497 | - // db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
|
| 498 | - if (! is_array($db_state)) { |
|
| 499 | - $db_state = ['Core' => $db_state]; |
|
| 500 | - update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
| 501 | - } |
|
| 502 | - return $db_state; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Checks if there are any data migration scripts that ought to be run. |
|
| 508 | - * If found, returns the instantiated classes. |
|
| 509 | - * If none are found (ie, they've all already been run, or they don't apply), returns an empty array |
|
| 510 | - * |
|
| 511 | - * @return EE_Data_Migration_Script_Base[] |
|
| 512 | - * @throws EE_Error |
|
| 513 | - */ |
|
| 514 | - public function check_for_applicable_data_migration_scripts() |
|
| 515 | - { |
|
| 516 | - // get the option describing what options have already run |
|
| 517 | - $scripts_ran = $this->get_data_migrations_ran(); |
|
| 518 | - // $scripts_ran = array('4.1.0.core'=>array('monkey'=>null)); |
|
| 519 | - $script_class_and_filepaths_available = $this->get_all_data_migration_scripts_available(); |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - $current_database_state = $this->ensure_current_database_state_is_set(); |
|
| 523 | - // determine which have already been run |
|
| 524 | - $script_classes_that_should_run_per_iteration = []; |
|
| 525 | - $iteration = 0; |
|
| 526 | - $next_database_state_to_consider = $current_database_state; |
|
| 527 | - $theoretical_database_state = null; |
|
| 528 | - do { |
|
| 529 | - // the next state after the currently-considered one |
|
| 530 | - // will start off looking the same as the current, but we may make additions... |
|
| 531 | - $theoretical_database_state = $next_database_state_to_consider; |
|
| 532 | - // the next db state to consider is |
|
| 533 | - // "what would the DB be like had we run all the scripts we found that applied last time?" |
|
| 534 | - foreach ($script_class_and_filepaths_available as $classname => $filepath) { |
|
| 535 | - $migrates_to_version = $this->script_migrates_to_version($classname); |
|
| 536 | - $script_converts_plugin_slug = $migrates_to_version['slug']; |
|
| 537 | - $script_converts_to_version = $migrates_to_version['version']; |
|
| 538 | - // check if this version script is DONE or not; or if it's never been run |
|
| 539 | - if ( |
|
| 540 | - ! $scripts_ran |
|
| 541 | - || ! isset($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]) |
|
| 542 | - ) { |
|
| 543 | - // we haven't run this conversion script before |
|
| 544 | - // now check if it applies... |
|
| 545 | - // note that we've added an autoloader for it on get_all_data_migration_scripts_available |
|
| 546 | - // Also, make sure we get a new one. It's possible this is being ran during a multisite migration, |
|
| 547 | - // in which case we don't want to reuse a DMS script from a different blog! |
|
| 548 | - $script = LoaderFactory::getLoader()->getNew($classname); |
|
| 549 | - /* @var $script EE_Data_Migration_Script_Base */ |
|
| 550 | - $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
|
| 551 | - if ($can_migrate) { |
|
| 552 | - $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
| 553 | - $migrates_to_version = |
|
| 554 | - $script->migrates_to_version(); |
|
| 555 | - $next_database_state_to_consider[ $migrates_to_version['slug'] ] = |
|
| 556 | - $migrates_to_version['version']; |
|
| 557 | - unset($script_class_and_filepaths_available[ $classname ]); |
|
| 558 | - } |
|
| 559 | - } elseif ( |
|
| 560 | - $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ] |
|
| 561 | - instanceof |
|
| 562 | - EE_Data_Migration_Script_Base |
|
| 563 | - ) { |
|
| 564 | - // this script has been run, or at least started |
|
| 565 | - $script = $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]; |
|
| 566 | - if ($script->get_status() !== self::status_completed) { |
|
| 567 | - // this script is already underway... keep going with it |
|
| 568 | - $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
| 569 | - $migrates_to_version = |
|
| 570 | - $script->migrates_to_version(); |
|
| 571 | - $next_database_state_to_consider[ $migrates_to_version['slug'] ] = |
|
| 572 | - $migrates_to_version['version']; |
|
| 573 | - unset($script_class_and_filepaths_available[ $classname ]); |
|
| 574 | - } |
|
| 575 | - // else it must have a status that indicates it has finished, |
|
| 576 | - // so we don't want to try and run it again |
|
| 577 | - } |
|
| 578 | - // else it exists, but it's not a proper data migration script maybe the script got renamed? |
|
| 579 | - // or was simply removed from EE? either way, it's certainly not runnable! |
|
| 580 | - } |
|
| 581 | - $iteration++; |
|
| 582 | - } while ($next_database_state_to_consider !== $theoretical_database_state && $iteration < 6); |
|
| 583 | - // ok we have all the scripts that should run, now let's make them into flat array |
|
| 584 | - $scripts_that_should_run = []; |
|
| 585 | - foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
|
| 586 | - ksort($scripts_at_priority); |
|
| 587 | - foreach ($scripts_at_priority as $scripts) { |
|
| 588 | - foreach ($scripts as $script) { |
|
| 589 | - $scripts_that_should_run[ get_class($script) ] = $script; |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - do_action( |
|
| 595 | - 'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', |
|
| 596 | - $scripts_that_should_run |
|
| 597 | - ); |
|
| 598 | - return $scripts_that_should_run; |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Gets the script which is currently being run, if there is one. If $include_completed_scripts is set to TRUE |
|
| 604 | - * it will return the last run script even if it's complete. |
|
| 605 | - * This means: if you want to find the currently-executing script, leave it as FALSE. |
|
| 606 | - * If you really just want to find the script which ran most recently, regardless of status, leave it as TRUE. |
|
| 607 | - * |
|
| 608 | - * @param bool $include_completed_scripts |
|
| 609 | - * @return EE_Data_Migration_Script_Base |
|
| 610 | - * @throws EE_Error |
|
| 611 | - */ |
|
| 612 | - public function get_last_ran_script($include_completed_scripts = false) |
|
| 613 | - { |
|
| 614 | - // make sure we've set up the class properties _last_ran_script and _last_ran_incomplete_script |
|
| 615 | - if (! $this->_data_migrations_ran) { |
|
| 616 | - $this->get_data_migrations_ran(); |
|
| 617 | - } |
|
| 618 | - if ($include_completed_scripts) { |
|
| 619 | - return $this->_last_ran_script; |
|
| 620 | - } else { |
|
| 621 | - return $this->_last_ran_incomplete_script; |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * Runs the data migration scripts (well, each request to this method calls one of the |
|
| 628 | - * data migration scripts' migration_step() functions). |
|
| 629 | - * |
|
| 630 | - * @param int $step_size |
|
| 631 | - * @return array { |
|
| 632 | - * // where the first item is one EE_Data_Migration_Script_Base's stati, |
|
| 633 | - * //and the second item is a string describing what was done |
|
| 634 | - * @type int $records_to_migrate from the current migration script |
|
| 635 | - * @type int $records_migrated |
|
| 636 | - * @type string $status one of EE_Data_Migration_Manager::status_* |
|
| 637 | - * @type string $script verbose name of the current DMS |
|
| 638 | - * @type string $message string describing what was done during this step |
|
| 639 | - * } |
|
| 640 | - * @throws EE_Error |
|
| 641 | - */ |
|
| 642 | - public function migration_step($step_size = 0) |
|
| 643 | - { |
|
| 644 | - // bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535 |
|
| 645 | - if (class_exists('EE_CPT_Strategy')) { |
|
| 646 | - remove_action('pre_get_posts', [EE_CPT_Strategy::instance(), 'pre_get_posts'], 5); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - try { |
|
| 650 | - $currently_executing_script = $this->get_last_ran_script(); |
|
| 651 | - if (! $currently_executing_script) { |
|
| 652 | - // Find the next script that needs to execute |
|
| 653 | - $scripts = $this->check_for_applicable_data_migration_scripts(); |
|
| 654 | - if (! $scripts) { |
|
| 655 | - // huh, no more scripts to run... apparently we're done! |
|
| 656 | - // but don't forget to make sure initial data is there |
|
| 657 | - // we should be good to allow them to exit maintenance mode now |
|
| 658 | - EE_Maintenance_Mode::instance()->deactivateMaintenanceMode(); |
|
| 659 | - // saving migrations run should actually be unnecessary, |
|
| 660 | - // but leaving in place just in case... remember this migration was finished |
|
| 661 | - // (even if we time out while initializing db for core and plugins) |
|
| 662 | - $this->_save_migrations_ran(); |
|
| 663 | - // make sure DB was updated AFTER we've recorded the migration was done |
|
| 664 | - $this->initialize_db_for_enqueued_ee_plugins(); |
|
| 665 | - return [ |
|
| 666 | - 'records_to_migrate' => 1, |
|
| 667 | - 'records_migrated' => 1, |
|
| 668 | - 'status' => self::status_no_more_migration_scripts, |
|
| 669 | - 'script' => esc_html__("Data Migration Completed Successfully", "event_espresso"), |
|
| 670 | - 'message' => esc_html__("All done!", "event_espresso"), |
|
| 671 | - ]; |
|
| 672 | - } |
|
| 673 | - $currently_executing_script = array_shift($scripts); |
|
| 674 | - // and add to the array/wp option showing the scripts run |
|
| 675 | - |
|
| 676 | - $migrates_to = |
|
| 677 | - $this->script_migrates_to_version(get_class($currently_executing_script)); |
|
| 678 | - $plugin_slug = $migrates_to['slug']; |
|
| 679 | - $version = $migrates_to['version']; |
|
| 680 | - $this->_data_migrations_ran[ $plugin_slug ][ $version ] = $currently_executing_script; |
|
| 681 | - } |
|
| 682 | - $current_script_name = get_class($currently_executing_script); |
|
| 683 | - } catch (Exception $e) { |
|
| 684 | - // an exception occurred while trying to get migration scripts |
|
| 685 | - |
|
| 686 | - $message = sprintf( |
|
| 687 | - esc_html__("Error Message: %sStack Trace:%s", "event_espresso"), |
|
| 688 | - $e->getMessage() . '<br>', |
|
| 689 | - $e->getTraceAsString() |
|
| 690 | - ); |
|
| 691 | - // record it on the array of data migration scripts run. This will be overwritten next time we try and try to run data migrations |
|
| 692 | - // but that's ok-- it's just an FYI to support that we couldn't even run any data migrations |
|
| 693 | - $this->add_error_to_migrations_ran( |
|
| 694 | - sprintf(esc_html__("Could not run data migrations because: %s", "event_espresso"), $message) |
|
| 695 | - ); |
|
| 696 | - return [ |
|
| 697 | - 'records_to_migrate' => 1, |
|
| 698 | - 'records_migrated' => 0, |
|
| 699 | - 'status' => self::status_fatal_error, |
|
| 700 | - 'script' => esc_html__("Error loading data migration scripts", "event_espresso"), |
|
| 701 | - 'message' => $message, |
|
| 702 | - ]; |
|
| 703 | - } |
|
| 704 | - // can we wrap it up and verify default data? |
|
| 705 | - $init_dbs = false; |
|
| 706 | - // ok so we definitely have a data migration script |
|
| 707 | - try { |
|
| 708 | - $init_dbs = false; |
|
| 709 | - // how big of a bite do we want to take? Allow users to easily override via their wp-config |
|
| 710 | - if (absint($step_size) < 1) { |
|
| 711 | - $step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE) |
|
| 712 | - ? EE_MIGRATION_STEP_SIZE |
|
| 713 | - : EE_Data_Migration_Manager::step_size; |
|
| 714 | - } |
|
| 715 | - // do what we came to do! |
|
| 716 | - $currently_executing_script->migration_step($step_size); |
|
| 717 | - switch ($currently_executing_script->get_status()) { |
|
| 718 | - case EE_Data_Migration_Manager::status_continue: |
|
| 719 | - $response_array = [ |
|
| 720 | - 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
| 721 | - 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
| 722 | - 'status' => EE_Data_Migration_Manager::status_continue, |
|
| 723 | - 'message' => $currently_executing_script->get_feedback_message(), |
|
| 724 | - 'script' => $currently_executing_script->pretty_name(), |
|
| 725 | - ]; |
|
| 726 | - break; |
|
| 727 | - case EE_Data_Migration_Manager::status_completed: |
|
| 728 | - // ok so THAT script has completed |
|
| 729 | - $this->update_current_database_state_to($this->script_migrates_to_version($current_script_name)); |
|
| 730 | - $response_array = [ |
|
| 731 | - 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
| 732 | - 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
| 733 | - 'status' => EE_Data_Migration_Manager::status_completed, |
|
| 734 | - 'message' => $currently_executing_script->get_feedback_message(), |
|
| 735 | - 'script' => sprintf( |
|
| 736 | - esc_html__("%s Completed", 'event_espresso'), |
|
| 737 | - $currently_executing_script->pretty_name() |
|
| 738 | - ), |
|
| 739 | - ]; |
|
| 740 | - // check if there are any more after this one. |
|
| 741 | - $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
|
| 742 | - if (! $scripts_remaining) { |
|
| 743 | - // we should be good to allow them to exit maintenance mode now |
|
| 744 | - EE_Maintenance_Mode::instance()->deactivateMaintenanceMode(); |
|
| 745 | - // huh, no more scripts to run... apparently we're done! |
|
| 746 | - // but don't forget to make sure initial data is there |
|
| 747 | - $init_dbs = true; |
|
| 748 | - $response_array['status'] = self::status_no_more_migration_scripts; |
|
| 749 | - } |
|
| 750 | - break; |
|
| 751 | - default: |
|
| 752 | - $response_array = [ |
|
| 753 | - 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
| 754 | - 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
| 755 | - 'status' => $currently_executing_script->get_status(), |
|
| 756 | - 'message' => sprintf( |
|
| 757 | - esc_html__("Minor errors occurred during %s: %s", "event_espresso"), |
|
| 758 | - $currently_executing_script->pretty_name(), |
|
| 759 | - implode(", ", $currently_executing_script->get_errors()) |
|
| 760 | - ), |
|
| 761 | - 'script' => $currently_executing_script->pretty_name(), |
|
| 762 | - ]; |
|
| 763 | - break; |
|
| 764 | - } |
|
| 765 | - } catch (Exception $e) { |
|
| 766 | - // ok so some exception was thrown which killed the data migration script |
|
| 767 | - // double-check we have a real script |
|
| 768 | - if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) { |
|
| 769 | - $script_name = $currently_executing_script->pretty_name(); |
|
| 770 | - $currently_executing_script->set_broken(); |
|
| 771 | - $currently_executing_script->add_error($e->getMessage()); |
|
| 772 | - } else { |
|
| 773 | - $script_name = esc_html__("Error getting Migration Script", "event_espresso"); |
|
| 774 | - } |
|
| 775 | - $response_array = [ |
|
| 776 | - 'records_to_migrate' => 1, |
|
| 777 | - 'records_migrated' => 0, |
|
| 778 | - 'status' => self::status_fatal_error, |
|
| 779 | - 'message' => sprintf( |
|
| 780 | - esc_html__("A fatal error occurred during the migration: %s", "event_espresso"), |
|
| 781 | - $e->getMessage() |
|
| 782 | - ), |
|
| 783 | - 'script' => $script_name, |
|
| 784 | - ]; |
|
| 785 | - } |
|
| 786 | - $successful_save = $this->_save_migrations_ran(); |
|
| 787 | - if ($successful_save !== true) { |
|
| 788 | - // ok so the current wp option didn't save. that's tricky, because we'd like to update it |
|
| 789 | - // and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION! |
|
| 790 | - // however, if we throw an exception, and return that, then the next request |
|
| 791 | - // won't have as much info in it, and it may be able to save |
|
| 792 | - throw new EE_Error( |
|
| 793 | - sprintf( |
|
| 794 | - esc_html__( |
|
| 795 | - "The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", |
|
| 796 | - "event_espresso" |
|
| 797 | - ), |
|
| 798 | - $successful_save |
|
| 799 | - ) |
|
| 800 | - ); |
|
| 801 | - } |
|
| 802 | - // if we're all done, initialize EE plugins' default data etc. |
|
| 803 | - if ($init_dbs) { |
|
| 804 | - $this->initialize_db_for_enqueued_ee_plugins(); |
|
| 805 | - } |
|
| 806 | - return $response_array; |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - |
|
| 810 | - /** |
|
| 811 | - * Echo out JSON response to migration script AJAX requests. Takes precautions |
|
| 812 | - * to buffer output so that we don't throw junk into our json. |
|
| 813 | - * |
|
| 814 | - * @return array with keys: |
|
| 815 | - * 'records_to_migrate' which counts ALL the records for the current migration, and should remain constant. (ie, |
|
| 816 | - * it's NOT the count of hwo many remain) |
|
| 817 | - * 'records_migrated' which also counts ALL the records which have been migrated (ie, percent_complete = |
|
| 818 | - * records_migrated/records_to_migrate) |
|
| 819 | - * 'status'=>a string, one of EE_Data_migration_Manager::status_* |
|
| 820 | - * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into |
|
| 821 | - * errors, notifications, and successes |
|
| 822 | - * 'script'=>a pretty name of the script currently running |
|
| 823 | - */ |
|
| 824 | - public function response_to_migration_ajax_request() |
|
| 825 | - { |
|
| 826 | - ob_start(); |
|
| 827 | - try { |
|
| 828 | - $response = $this->migration_step(); |
|
| 829 | - } catch (Exception $e) { |
|
| 830 | - $response = [ |
|
| 831 | - 'records_to_migrate' => 0, |
|
| 832 | - 'records_migrated' => 0, |
|
| 833 | - 'status' => EE_Data_Migration_Manager::status_fatal_error, |
|
| 834 | - 'message' => sprintf( |
|
| 835 | - esc_html__("Unknown fatal error occurred: %s", "event_espresso"), |
|
| 836 | - $e->getMessage() |
|
| 837 | - ), |
|
| 838 | - 'script' => 'Unknown', |
|
| 839 | - ]; |
|
| 840 | - $this->add_error_to_migrations_ran($e->getMessage() . "; Stack trace:" . $e->getTraceAsString()); |
|
| 841 | - } |
|
| 842 | - $warnings_etc = @ob_get_contents(); |
|
| 843 | - ob_end_clean(); |
|
| 844 | - $response['message'] .= $warnings_etc; |
|
| 845 | - return $response; |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - |
|
| 849 | - /** |
|
| 850 | - * Updates the WordPress option that keeps track of which EE version the database |
|
| 851 | - * is at (ie, the code may be at 4.1.0, but the database is still at 3.1.35) |
|
| 852 | - * |
|
| 853 | - * @param array $slug_and_version { |
|
| 854 | - * @type string $slug like 'Core' or 'Calendar', |
|
| 855 | - * @type string $version like '4.1.0' |
|
| 856 | - * } |
|
| 857 | - * @return void |
|
| 858 | - */ |
|
| 859 | - public function update_current_database_state_to($slug_and_version = null) |
|
| 860 | - { |
|
| 861 | - if (! $slug_and_version) { |
|
| 862 | - // no version was provided, assume it should be at the current code version |
|
| 863 | - $slug_and_version = ['slug' => 'Core', 'version' => espresso_version()]; |
|
| 864 | - } |
|
| 865 | - $current_database_state = get_option(self::current_database_state, []); |
|
| 866 | - $current_database_state[ $slug_and_version['slug'] ] = $slug_and_version['version']; |
|
| 867 | - update_option(self::current_database_state, $current_database_state); |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - |
|
| 871 | - /** |
|
| 872 | - * Determines if the database is currently at a state matching what's indicated in $slug and $version. |
|
| 873 | - * |
|
| 874 | - * @param array $slug_and_version { |
|
| 875 | - * @type string $slug like 'Core' or 'Calendar', |
|
| 876 | - * @type string $version like '4.1.0' |
|
| 877 | - * } |
|
| 878 | - * @return boolean |
|
| 879 | - */ |
|
| 880 | - public function database_needs_updating_to($slug_and_version) |
|
| 881 | - { |
|
| 882 | - $slug = $slug_and_version['slug']; |
|
| 883 | - $version = $slug_and_version['version']; |
|
| 884 | - $current_database_state = get_option(self::current_database_state, []); |
|
| 885 | - if (! isset($current_database_state[ $slug ])) { |
|
| 886 | - return true; |
|
| 887 | - } |
|
| 888 | - // just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes |
|
| 889 | - $version_parts_current_db_state = array_slice(explode('.', $current_database_state[ $slug ]), 0, 3); |
|
| 890 | - $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
|
| 891 | - $needs_updating = false; |
|
| 892 | - foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
|
| 893 | - if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ]) { |
|
| 894 | - $needs_updating = true; |
|
| 895 | - break; |
|
| 896 | - } |
|
| 897 | - } |
|
| 898 | - return $needs_updating; |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - |
|
| 902 | - /** |
|
| 903 | - * Gets all the data migration scripts available in the core folder and folders |
|
| 904 | - * in addons. Has the side effect of adding them for autoloading |
|
| 905 | - * |
|
| 906 | - * @return array keys are expected classnames, values are their filepaths |
|
| 907 | - * @throws InvalidInterfaceException |
|
| 908 | - * @throws InvalidDataTypeException |
|
| 909 | - * @throws EE_Error |
|
| 910 | - * @throws InvalidArgumentException |
|
| 911 | - */ |
|
| 912 | - public function get_all_data_migration_scripts_available() |
|
| 913 | - { |
|
| 914 | - if (! $this->_data_migration_class_to_filepath_map) { |
|
| 915 | - $this->_data_migration_class_to_filepath_map = []; |
|
| 916 | - foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
|
| 917 | - // strip any placeholders added to classname to make it a unique array key |
|
| 918 | - $eeAddonClass = trim($eeAddonClass, '*'); |
|
| 919 | - $eeAddonClass = $eeAddonClass === 'Core' || class_exists($eeAddonClass) |
|
| 920 | - ? $eeAddonClass |
|
| 921 | - : ''; |
|
| 922 | - $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
| 923 | - $files = glob($folder_path . '*.dms.php'); |
|
| 924 | - if (empty($files)) { |
|
| 925 | - continue; |
|
| 926 | - } |
|
| 927 | - natsort($files); |
|
| 928 | - foreach ($files as $file) { |
|
| 929 | - $pos_of_last_slash = strrpos($file, '/'); |
|
| 930 | - $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
|
| 931 | - $migrates_to = $this->script_migrates_to_version($classname, $eeAddonClass); |
|
| 932 | - $slug = $migrates_to['slug']; |
|
| 933 | - // check that the slug as contained in the DMS is associated with |
|
| 934 | - // the slug of an addon or core |
|
| 935 | - if ($slug !== 'Core' && EE_Registry::instance()->get_addon_by_name($slug) === null) { |
|
| 936 | - EE_Error::doing_it_wrong( |
|
| 937 | - __FUNCTION__, |
|
| 938 | - sprintf( |
|
| 939 | - esc_html__( |
|
| 940 | - 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', |
|
| 941 | - 'event_espresso' |
|
| 942 | - ), |
|
| 943 | - $classname, |
|
| 944 | - $slug, |
|
| 945 | - implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
| 946 | - ), |
|
| 947 | - '4.3.0.alpha.019' |
|
| 948 | - ); |
|
| 949 | - } |
|
| 950 | - $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
| 951 | - } |
|
| 952 | - } |
|
| 953 | - EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
|
| 954 | - } |
|
| 955 | - return $this->_data_migration_class_to_filepath_map; |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - |
|
| 959 | - /** |
|
| 960 | - * Once we have an addon that works with EE4.1, we will actually want to fetch the PUE slugs |
|
| 961 | - * from each addon, and check if they need updating, |
|
| 962 | - * |
|
| 963 | - * @return boolean |
|
| 964 | - */ |
|
| 965 | - public function addons_need_updating() |
|
| 966 | - { |
|
| 967 | - return false; |
|
| 968 | - } |
|
| 969 | - |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * Adds this error string to the data_migrations_ran array, but we don't necessarily know |
|
| 973 | - * where to put it, so we just throw it in there... better than nothing... |
|
| 974 | - * |
|
| 975 | - * @param string $error_message |
|
| 976 | - */ |
|
| 977 | - public function add_error_to_migrations_ran($error_message) |
|
| 978 | - { |
|
| 979 | - // get last-run migration script |
|
| 980 | - global $wpdb; |
|
| 981 | - $last_migration_script_option = $wpdb->get_row( |
|
| 982 | - "SELECT * FROM $wpdb->options WHERE option_name like '" |
|
| 983 | - . EE_Data_Migration_Manager::data_migration_script_option_prefix |
|
| 984 | - . "%' ORDER BY option_id DESC LIMIT 1", |
|
| 985 | - ARRAY_A |
|
| 986 | - ); |
|
| 987 | - |
|
| 988 | - $last_ran_migration_script_properties = isset($last_migration_script_option['option_value']) |
|
| 989 | - ? maybe_unserialize($last_migration_script_option['option_value']) |
|
| 990 | - : null; |
|
| 991 | - // now, tread lightly because we're here because a FATAL non-catchable error |
|
| 992 | - // was thrown last time when we were trying to run a data migration script |
|
| 993 | - // so the fatal error could have happened while getting the migration script |
|
| 994 | - // or doing running it... |
|
| 995 | - $versions_migrated_to = isset($last_migration_script_option['option_name']) |
|
| 996 | - ? str_replace( |
|
| 997 | - EE_Data_Migration_Manager::data_migration_script_option_prefix, |
|
| 998 | - "", |
|
| 999 | - $last_migration_script_option['option_name'] |
|
| 1000 | - ) |
|
| 1001 | - : null; |
|
| 1002 | - |
|
| 1003 | - // check if it THINKS it's a data migration script and especially if it's one that HASN'T finished yet |
|
| 1004 | - // because if it has finished, then it obviously couldn't be the cause of this error, right? (because it's all done) |
|
| 1005 | - if ( |
|
| 1006 | - isset($last_ran_migration_script_properties['class']) |
|
| 1007 | - && isset($last_ran_migration_script_properties['_status']) |
|
| 1008 | - && $last_ran_migration_script_properties['_status'] != self::status_completed |
|
| 1009 | - ) { |
|
| 1010 | - // ok then just add this error to its list of errors |
|
| 1011 | - $last_ran_migration_script_properties['_errors'][] = $error_message; |
|
| 1012 | - $last_ran_migration_script_properties['_status'] = self::status_fatal_error; |
|
| 1013 | - } else { |
|
| 1014 | - // so we don't even know which script was last running |
|
| 1015 | - // use the data migration error stub, which is designed specifically for this type of thing |
|
| 1016 | - $general_migration_error = new EE_DMS_Unknown_1_0_0(); |
|
| 1017 | - $general_migration_error->add_error($error_message); |
|
| 1018 | - $general_migration_error->set_broken(); |
|
| 1019 | - $last_ran_migration_script_properties = $general_migration_error->properties_as_array(); |
|
| 1020 | - $versions_migrated_to = 'Unknown.1.0.0'; |
|
| 1021 | - // now just to make sure appears as last (in case the were previously a fatal error like this) |
|
| 1022 | - // delete the old one |
|
| 1023 | - delete_option(self::data_migration_script_option_prefix . $versions_migrated_to); |
|
| 1024 | - } |
|
| 1025 | - update_option( |
|
| 1026 | - self::data_migration_script_option_prefix . $versions_migrated_to, |
|
| 1027 | - $last_ran_migration_script_properties |
|
| 1028 | - ); |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - |
|
| 1032 | - /** |
|
| 1033 | - * saves what data migrations have run to the database |
|
| 1034 | - * |
|
| 1035 | - * @return bool|string TRUE if successfully saved migrations ran, string if an error occurred |
|
| 1036 | - * @throws EE_Error |
|
| 1037 | - */ |
|
| 1038 | - protected function _save_migrations_ran() |
|
| 1039 | - { |
|
| 1040 | - if ($this->_data_migrations_ran == null) { |
|
| 1041 | - $this->get_data_migrations_ran(); |
|
| 1042 | - } |
|
| 1043 | - // now, we don't want to save actual classes to the DB because that's messy |
|
| 1044 | - $successful_updates = true; |
|
| 1045 | - foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
|
| 1046 | - foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
|
| 1047 | - $plugin_slug_for_use_in_option_name = $plugin_slug . "."; |
|
| 1048 | - $option_name = |
|
| 1049 | - self::data_migration_script_option_prefix . $plugin_slug_for_use_in_option_name . $version_string; |
|
| 1050 | - $old_option_value = get_option($option_name); |
|
| 1051 | - if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
|
| 1052 | - $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
|
| 1053 | - if ($old_option_value != $script_array_for_saving) { |
|
| 1054 | - $successful_updates = update_option($option_name, $script_array_for_saving); |
|
| 1055 | - } |
|
| 1056 | - } else {// we don't know what this array-thing is. So just save it as-is |
|
| 1057 | - if ($old_option_value != $array_or_migration_obj) { |
|
| 1058 | - $successful_updates = update_option($option_name, $array_or_migration_obj); |
|
| 1059 | - } |
|
| 1060 | - } |
|
| 1061 | - if (! $successful_updates) { |
|
| 1062 | - global $wpdb; |
|
| 1063 | - return $wpdb->last_error; |
|
| 1064 | - } |
|
| 1065 | - } |
|
| 1066 | - } |
|
| 1067 | - return true; |
|
| 1068 | - // $updated = update_option(self::data_migrations_option_name, $array_of_migrations); |
|
| 1069 | - // if ($updated !== true) { |
|
| 1070 | - // global $wpdb; |
|
| 1071 | - // return $wpdb->last_error; |
|
| 1072 | - // } else { |
|
| 1073 | - // return true; |
|
| 1074 | - // } |
|
| 1075 | - // wp_mail( |
|
| 1076 | - // "[email protected]", |
|
| 1077 | - // time() . " price debug info", |
|
| 1078 | - // "updated: $updated, last error: $last_error, byte length of option: " . strlen( |
|
| 1079 | - // serialize($array_of_migrations) |
|
| 1080 | - // ) |
|
| 1081 | - // ); |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * Takes an array of data migration script properties and re-creates the class from |
|
| 1087 | - * them. The argument $properties_array is assumed to have been made by |
|
| 1088 | - * EE_Data_Migration_Script_Base::properties_as_array() |
|
| 1089 | - * |
|
| 1090 | - * @param array $properties_array |
|
| 1091 | - * @return EE_Data_Migration_Script_Base |
|
| 1092 | - * @throws EE_Error |
|
| 1093 | - */ |
|
| 1094 | - public function _instantiate_script_from_properties_array($properties_array) |
|
| 1095 | - { |
|
| 1096 | - if (! isset($properties_array['class'])) { |
|
| 1097 | - throw new EE_Error( |
|
| 1098 | - sprintf( |
|
| 1099 | - esc_html__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), |
|
| 1100 | - implode(",", $properties_array) |
|
| 1101 | - ) |
|
| 1102 | - ); |
|
| 1103 | - } |
|
| 1104 | - $class_name = $properties_array['class']; |
|
| 1105 | - if (! class_exists($class_name)) { |
|
| 1106 | - throw new EE_Error(sprintf( |
|
| 1107 | - esc_html__("There is no migration script named %s", "event_espresso"), |
|
| 1108 | - $class_name |
|
| 1109 | - )); |
|
| 1110 | - } |
|
| 1111 | - $class = new $class_name(); |
|
| 1112 | - if (! $class instanceof EE_Data_Migration_Script_Base) { |
|
| 1113 | - throw new EE_Error( |
|
| 1114 | - sprintf( |
|
| 1115 | - esc_html__( |
|
| 1116 | - "Class '%s' is supposed to be a migration script. Its not, its a '%s'", |
|
| 1117 | - "event_espresso" |
|
| 1118 | - ), |
|
| 1119 | - $class_name, |
|
| 1120 | - get_class($class) |
|
| 1121 | - ) |
|
| 1122 | - ); |
|
| 1123 | - } |
|
| 1124 | - $class->instantiate_from_array_of_properties($properties_array); |
|
| 1125 | - return $class; |
|
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - |
|
| 1129 | - /** |
|
| 1130 | - * Gets the classname for the most up-to-date DMS (ie, the one that will finally |
|
| 1131 | - * leave the DB in a state usable by the current plugin code). |
|
| 1132 | - * |
|
| 1133 | - * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core' |
|
| 1134 | - * @return string |
|
| 1135 | - * @throws EE_Error |
|
| 1136 | - */ |
|
| 1137 | - public function get_most_up_to_date_dms($plugin_slug = 'Core') |
|
| 1138 | - { |
|
| 1139 | - $class_to_filepath_map = $this->get_all_data_migration_scripts_available(); |
|
| 1140 | - $most_up_to_date_dms_classname = null; |
|
| 1141 | - foreach ($class_to_filepath_map as $classname => $filepath) { |
|
| 1142 | - if ($most_up_to_date_dms_classname === null) { |
|
| 1143 | - $migrates_to = $this->script_migrates_to_version($classname); |
|
| 1144 | - $this_plugin_slug = $migrates_to['slug']; |
|
| 1145 | - if ($this_plugin_slug == $plugin_slug) { |
|
| 1146 | - // if it's for core, it wins |
|
| 1147 | - $most_up_to_date_dms_classname = $classname; |
|
| 1148 | - } |
|
| 1149 | - // if it wasn't for core, we must keep searching for one that is! |
|
| 1150 | - continue; |
|
| 1151 | - } |
|
| 1152 | - $champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
| 1153 | - $contender_migrates_to = $this->script_migrates_to_version($classname); |
|
| 1154 | - if ( |
|
| 1155 | - $contender_migrates_to['slug'] == $plugin_slug |
|
| 1156 | - && version_compare( |
|
| 1157 | - $champion_migrates_to['version'], |
|
| 1158 | - $contender_migrates_to['version'], |
|
| 1159 | - '<' |
|
| 1160 | - ) |
|
| 1161 | - ) { |
|
| 1162 | - // so the contenders version is higher, and it's for Core |
|
| 1163 | - $most_up_to_date_dms_classname = $classname; |
|
| 1164 | - } |
|
| 1165 | - } |
|
| 1166 | - return $most_up_to_date_dms_classname; |
|
| 1167 | - } |
|
| 1168 | - |
|
| 1169 | - |
|
| 1170 | - /** |
|
| 1171 | - * Gets the migration script specified but ONLY if it has already run. |
|
| 1172 | - * Eg, if you wanted to see if 'EE_DMS_Core_4_1_0' has run, you would run the following code: |
|
| 1173 | - * <code> $core_4_1_0_dms_ran = EE_Data_Migration_Manager::instance()->get_migration_ran( '4.1.0', 'Core' ) !== |
|
| 1174 | - * NULL;</code> This is especially useful in addons' data migration scripts, this way they can tell if a core (or |
|
| 1175 | - * other addon) DMS has run, in case the current DMS depends on it. |
|
| 1176 | - * |
|
| 1177 | - * @param string $version the version the DMS searched for migrates to. Usually just the content before the 3rd |
|
| 1178 | - * period. Eg '4.1.0' |
|
| 1179 | - * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
|
| 1180 | - * @return EE_Data_Migration_Script_Base |
|
| 1181 | - * @throws EE_Error |
|
| 1182 | - */ |
|
| 1183 | - public function get_migration_ran($version, $plugin_slug = 'Core') |
|
| 1184 | - { |
|
| 1185 | - $migrations_ran = $this->get_data_migrations_ran(); |
|
| 1186 | - if (isset($migrations_ran[ $plugin_slug ]) && isset($migrations_ran[ $plugin_slug ][ $version ])) { |
|
| 1187 | - return $migrations_ran[ $plugin_slug ][ $version ]; |
|
| 1188 | - } else { |
|
| 1189 | - return null; |
|
| 1190 | - } |
|
| 1191 | - } |
|
| 1192 | - |
|
| 1193 | - |
|
| 1194 | - /** |
|
| 1195 | - * Resets the borked data migration scripts, so they're no longer borked, and we can again attempt to migrate |
|
| 1196 | - * |
|
| 1197 | - * @return bool |
|
| 1198 | - * @throws EE_Error |
|
| 1199 | - */ |
|
| 1200 | - public function reattempt() |
|
| 1201 | - { |
|
| 1202 | - // find if the last-run script was borked |
|
| 1203 | - // set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
|
| 1204 | - // add an 'error' saying that we attempted to reset |
|
| 1205 | - // does it have a stage that was borked too? if so make it no longer borked |
|
| 1206 | - // add an 'error' saying we attempted to reset |
|
| 1207 | - $last_ran_script = $this->get_last_ran_script(); |
|
| 1208 | - if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) { |
|
| 1209 | - // if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it) |
|
| 1210 | - $last_ran_script->set_completed(); |
|
| 1211 | - } elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) { |
|
| 1212 | - $last_ran_script->reattempt(); |
|
| 1213 | - } else { |
|
| 1214 | - throw new EE_Error( |
|
| 1215 | - sprintf( |
|
| 1216 | - esc_html__( |
|
| 1217 | - 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', |
|
| 1218 | - 'event_espresso' |
|
| 1219 | - ), |
|
| 1220 | - print_r($last_ran_script, true) |
|
| 1221 | - ) |
|
| 1222 | - ); |
|
| 1223 | - } |
|
| 1224 | - return $this->_save_migrations_ran(); |
|
| 1225 | - } |
|
| 1226 | - |
|
| 1227 | - |
|
| 1228 | - /** |
|
| 1229 | - * Gets whether this particular migration has run or not |
|
| 1230 | - * |
|
| 1231 | - * @param string $version the version the DMS searched for migrates to. Usually just the content before the 3rd |
|
| 1232 | - * period. Eg '4.1.0' |
|
| 1233 | - * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
|
| 1234 | - * @return boolean |
|
| 1235 | - * @throws EE_Error |
|
| 1236 | - */ |
|
| 1237 | - public function migration_has_ran($version, $plugin_slug = 'Core') |
|
| 1238 | - { |
|
| 1239 | - return $this->get_migration_ran($version, $plugin_slug) !== null; |
|
| 1240 | - } |
|
| 1241 | - |
|
| 1242 | - |
|
| 1243 | - /** |
|
| 1244 | - * Enqueues this ee plugin to have its data initialized |
|
| 1245 | - * |
|
| 1246 | - * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value |
|
| 1247 | - */ |
|
| 1248 | - public function enqueue_db_initialization_for($plugin_slug) |
|
| 1249 | - { |
|
| 1250 | - $queue = $this->get_db_initialization_queue(); |
|
| 1251 | - if (! in_array($plugin_slug, $queue)) { |
|
| 1252 | - $queue[] = $plugin_slug; |
|
| 1253 | - } |
|
| 1254 | - update_option(self::db_init_queue_option_name, $queue); |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - |
|
| 1258 | - /** |
|
| 1259 | - * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon |
|
| 1260 | - * specified in EE_Data_Migration_Manager::get_db_init_queue(), and if 'Core' is |
|
| 1261 | - * in the queue, calls EE_System::initialize_db_if_no_migrations_required(). |
|
| 1262 | - * |
|
| 1263 | - * @throws EE_Error |
|
| 1264 | - */ |
|
| 1265 | - public function initialize_db_for_enqueued_ee_plugins() |
|
| 1266 | - { |
|
| 1267 | - $queue = $this->get_db_initialization_queue(); |
|
| 1268 | - foreach ($queue as $plugin_slug) { |
|
| 1269 | - $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
|
| 1270 | - if (! $most_up_to_date_dms) { |
|
| 1271 | - // if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
|
| 1272 | - $verify_db = false; |
|
| 1273 | - } else { |
|
| 1274 | - $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms); |
|
| 1275 | - $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to); |
|
| 1276 | - } |
|
| 1277 | - if ($plugin_slug == 'Core') { |
|
| 1278 | - EE_System::instance()->initialize_db_if_no_migrations_required( |
|
| 1279 | - false, |
|
| 1280 | - $verify_db |
|
| 1281 | - ); |
|
| 1282 | - } else { |
|
| 1283 | - // just loop through the addons to make sure their database is set up |
|
| 1284 | - foreach (EE_Registry::instance()->addons as $addon) { |
|
| 1285 | - if ($addon->name() == $plugin_slug) { |
|
| 1286 | - $addon->initialize_db_if_no_migrations_required($verify_db); |
|
| 1287 | - break; |
|
| 1288 | - } |
|
| 1289 | - } |
|
| 1290 | - } |
|
| 1291 | - } |
|
| 1292 | - // because we just initialized the DBs for the enqueued ee plugins |
|
| 1293 | - // we don't need to keep remembering which ones needed to be initialized |
|
| 1294 | - delete_option(self::db_init_queue_option_name); |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - |
|
| 1298 | - /** |
|
| 1299 | - * Gets a numerically-indexed array of plugin slugs that need to have their databases |
|
| 1300 | - * (re-)initialized after migrations are complete. ie, each element should be either |
|
| 1301 | - * 'Core', or the return value of EE_Addon::name() for an addon |
|
| 1302 | - * |
|
| 1303 | - * @return array |
|
| 1304 | - */ |
|
| 1305 | - public function get_db_initialization_queue() |
|
| 1306 | - { |
|
| 1307 | - return get_option(self::db_init_queue_option_name, []); |
|
| 1308 | - } |
|
| 1309 | - |
|
| 1310 | - |
|
| 1311 | - /** |
|
| 1312 | - * Gets the injected table analyzer, or throws an exception |
|
| 1313 | - * |
|
| 1314 | - * @return TableAnalysis |
|
| 1315 | - * @throws EE_Error |
|
| 1316 | - */ |
|
| 1317 | - protected function _get_table_analysis() |
|
| 1318 | - { |
|
| 1319 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
| 1320 | - return $this->_table_analysis; |
|
| 1321 | - } else { |
|
| 1322 | - throw new EE_Error( |
|
| 1323 | - sprintf( |
|
| 1324 | - esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1325 | - get_class($this) |
|
| 1326 | - ) |
|
| 1327 | - ); |
|
| 1328 | - } |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - |
|
| 1332 | - /** |
|
| 1333 | - * Gets the injected table manager, or throws an exception |
|
| 1334 | - * |
|
| 1335 | - * @return TableManager |
|
| 1336 | - * @throws EE_Error |
|
| 1337 | - */ |
|
| 1338 | - protected function _get_table_manager() |
|
| 1339 | - { |
|
| 1340 | - if ($this->_table_manager instanceof TableManager) { |
|
| 1341 | - return $this->_table_manager; |
|
| 1342 | - } else { |
|
| 1343 | - throw new EE_Error( |
|
| 1344 | - sprintf( |
|
| 1345 | - esc_html__('Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1346 | - get_class($this) |
|
| 1347 | - ) |
|
| 1348 | - ); |
|
| 1349 | - } |
|
| 1350 | - } |
|
| 31 | + /** |
|
| 32 | + * @var EE_Registry |
|
| 33 | + */ |
|
| 34 | + // protected $EE; |
|
| 35 | + /** |
|
| 36 | + * name of the WordPress option which stores an array of data about |
|
| 37 | + */ |
|
| 38 | + const data_migrations_option_name = 'ee_data_migration'; |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + const data_migration_script_option_prefix = 'ee_data_migration_script_'; |
|
| 42 | + |
|
| 43 | + const data_migration_script_mapping_option_prefix = 'ee_dms_map_'; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * name of the WordPress option which stores the database' current version. IE, the code may be at version 4.2.0, |
|
| 47 | + * but as migrations are performed the database will progress from 3.1.35 to 4.1.0 etc. |
|
| 48 | + */ |
|
| 49 | + const current_database_state = 'ee_data_migration_current_db_state'; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Special status string returned when we're positive there are no more data migration |
|
| 53 | + * scripts that can be run. |
|
| 54 | + */ |
|
| 55 | + const status_no_more_migration_scripts = 'no_more_migration_scripts'; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * string indicating the migration should continue |
|
| 59 | + */ |
|
| 60 | + const status_continue = 'status_continue'; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * string indicating the migration has completed and should be ended |
|
| 64 | + */ |
|
| 65 | + const status_completed = 'status_completed'; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * string indicating a fatal error occurred and the data migration should be completely aborted |
|
| 69 | + */ |
|
| 70 | + const status_fatal_error = 'status_fatal_error'; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * the number of 'items' (usually DB rows) to migrate on each 'step' (ajax request sent |
|
| 74 | + * during migration) |
|
| 75 | + */ |
|
| 76 | + const step_size = 50; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * option name that stores the queue of ee plugins needing to have |
|
| 80 | + * their data initialized (or re-initialized) once we are done migrations |
|
| 81 | + */ |
|
| 82 | + const db_init_queue_option_name = 'ee_db_init_queue'; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Array of information concerning data migrations that have run in the history |
|
| 86 | + * of this EE installation. Keys should be the name of the version the script upgraded to |
|
| 87 | + * |
|
| 88 | + * @var EE_Data_Migration_Script_Base[] |
|
| 89 | + */ |
|
| 90 | + private $_data_migrations_ran = null; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * The last run script. It's nice to store this somewhere accessible, as its easiest |
|
| 94 | + * to know which was the last run by which is the newest wp option; but in most of the code |
|
| 95 | + * we just use the local $_data_migration_ran array, which organized the scripts differently |
|
| 96 | + * |
|
| 97 | + * @var EE_Data_Migration_Script_Base |
|
| 98 | + */ |
|
| 99 | + private $_last_ran_script = null; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Similarly to _last_ran_script, but this is the last INCOMPLETE migration script. |
|
| 103 | + * |
|
| 104 | + * @var EE_Data_Migration_Script_Base |
|
| 105 | + */ |
|
| 106 | + private $_last_ran_incomplete_script = null; |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * array where keys are classnames, and values are filepaths of all the known migration scripts |
|
| 110 | + * |
|
| 111 | + * @var array |
|
| 112 | + */ |
|
| 113 | + private $_data_migration_class_to_filepath_map; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * the following 4 properties are fully set on construction. |
|
| 117 | + * Note: the first two apply to whether to continue running ALL migration scripts (ie, even though we're finished |
|
| 118 | + * one, we may want to start the next one); whereas the last two indicate whether to continue running a single |
|
| 119 | + * data migration script |
|
| 120 | + * |
|
| 121 | + * @var array |
|
| 122 | + */ |
|
| 123 | + public $stati_that_indicate_to_continue_migrations = []; |
|
| 124 | + |
|
| 125 | + public $stati_that_indicate_to_stop_migrations = []; |
|
| 126 | + |
|
| 127 | + public $stati_that_indicate_to_continue_single_migration_script = []; |
|
| 128 | + |
|
| 129 | + public $stati_that_indicate_to_stop_single_migration_script = []; |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @var TableManager $table_manager |
|
| 133 | + */ |
|
| 134 | + protected $_table_manager; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @var TableAnalysis $table_analysis |
|
| 138 | + */ |
|
| 139 | + protected $_table_analysis; |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @var array $script_migration_versions |
|
| 143 | + */ |
|
| 144 | + protected $script_migration_versions; |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @var array $dms_folders |
|
| 148 | + */ |
|
| 149 | + protected $dms_folders; |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @var EE_Data_Migration_Manager $_instance |
|
| 153 | + * @access private |
|
| 154 | + */ |
|
| 155 | + private static $_instance = null; |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @singleton method used to instantiate class object |
|
| 160 | + * @access public |
|
| 161 | + * @return EE_Data_Migration_Manager instance |
|
| 162 | + */ |
|
| 163 | + public static function instance() |
|
| 164 | + { |
|
| 165 | + // check if class object is instantiated |
|
| 166 | + if (! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
| 167 | + self::$_instance = new self(); |
|
| 168 | + } |
|
| 169 | + return self::$_instance; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * resets the singleton to its brand-new state (but does NOT delete old references to the old singleton. Meaning, |
|
| 175 | + * all new usages of the singleton should be made with Classname::instance()) and returns it |
|
| 176 | + * |
|
| 177 | + * @return EE_Data_Migration_Manager |
|
| 178 | + */ |
|
| 179 | + public static function reset() |
|
| 180 | + { |
|
| 181 | + self::$_instance = new self(); |
|
| 182 | + return self::instance(); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @throws EE_Error |
|
| 188 | + * @throws ReflectionException |
|
| 189 | + */ |
|
| 190 | + private function __construct() |
|
| 191 | + { |
|
| 192 | + $this->stati_that_indicate_to_continue_migrations = [ |
|
| 193 | + self::status_continue, |
|
| 194 | + self::status_completed, |
|
| 195 | + ]; |
|
| 196 | + $this->stati_that_indicate_to_stop_migrations = [ |
|
| 197 | + self::status_fatal_error, |
|
| 198 | + self::status_no_more_migration_scripts, |
|
| 199 | + ]; |
|
| 200 | + $this->stati_that_indicate_to_continue_single_migration_script = [ |
|
| 201 | + self::status_continue, |
|
| 202 | + ]; |
|
| 203 | + $this->stati_that_indicate_to_stop_single_migration_script = [ |
|
| 204 | + self::status_completed, |
|
| 205 | + self::status_fatal_error, |
|
| 206 | + // note: status_no_more_migration_scripts doesn't apply |
|
| 207 | + ]; |
|
| 208 | + $this->dms_folders = []; |
|
| 209 | + // make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class |
|
| 210 | + // to be defined, because right now it doesn't get autoloaded on its own |
|
| 211 | + EE_Registry::instance()->load_core('Data_Migration_Class_Base', [], true); |
|
| 212 | + EE_Registry::instance()->load_core('Data_Migration_Script_Base', [], true); |
|
| 213 | + EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', [], true); |
|
| 214 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage', [], true); |
|
| 215 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', [], true); |
|
| 216 | + $this->_table_manager = EE_Registry::instance()->create('TableManager', [], true); |
|
| 217 | + $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Deciphers, from an option's name, what plugin and version it relates to (see _save_migrations_ran to see what |
|
| 223 | + * the option names are like, but generally they're like |
|
| 224 | + * 'ee_data_migration_script_Core.4.1.0' in 4.2 or 'ee_data_migration_script_4.1.0' before that). |
|
| 225 | + * The option name shouldn't ever be like 'ee_data_migration_script_Core.4.1.0.reg' because it's derived, |
|
| 226 | + * indirectly, from the data migration's classname, which should always be like EE_DMS_%s_%d_%d_%d.dms.php |
|
| 227 | + * (ex: EE_DMS_Core_4_1_0.dms.php) |
|
| 228 | + * |
|
| 229 | + * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set) |
|
| 230 | + * @return array where the first item is the plugin slug (eg 'Core','Calendar', etc.) and the 2nd is the version of |
|
| 231 | + * that plugin (eg '4.1.0') |
|
| 232 | + */ |
|
| 233 | + private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name) |
|
| 234 | + { |
|
| 235 | + $plugin_slug_and_version_string = str_replace( |
|
| 236 | + EE_Data_Migration_Manager::data_migration_script_option_prefix, |
|
| 237 | + "", |
|
| 238 | + $option_name |
|
| 239 | + ); |
|
| 240 | + // check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style) |
|
| 241 | + $parts = explode(".", $plugin_slug_and_version_string); |
|
| 242 | + |
|
| 243 | + if (count($parts) == 4) { |
|
| 244 | + // it's 4.2-style.eg Core.4.1.0 |
|
| 245 | + $plugin_slug = $parts[0]; // eg Core |
|
| 246 | + $version_string = $parts[1] . "." . $parts[2] . "." . $parts[3]; // eg 4.1.0 |
|
| 247 | + } else { |
|
| 248 | + // it's 4.1-style: eg 4.1.0 |
|
| 249 | + $plugin_slug = 'Core'; |
|
| 250 | + $version_string = $plugin_slug_and_version_string;// eg 4.1.0 |
|
| 251 | + } |
|
| 252 | + return [$plugin_slug, $version_string]; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Gets the DMS class from the WordPress option, otherwise throws an EE_Error if it's not |
|
| 258 | + * for a known DMS class. |
|
| 259 | + * |
|
| 260 | + * @param string $dms_option_name |
|
| 261 | + * @param string $dms_option_value (serialized) |
|
| 262 | + * @return EE_Data_Migration_Script_Base |
|
| 263 | + * @throws EE_Error |
|
| 264 | + */ |
|
| 265 | + private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value) |
|
| 266 | + { |
|
| 267 | + $data_migration_data = maybe_unserialize($dms_option_value); |
|
| 268 | + if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) { |
|
| 269 | + // During multisite migrations, it's possible we already grabbed another instance of this class |
|
| 270 | + // but for a different blog. Make sure we don't reuse them (as they store info specific |
|
| 271 | + // to their respective blog, like which database table to migrate). |
|
| 272 | + $class = LoaderFactory::getLoader()->getNew($data_migration_data['class']); |
|
| 273 | + if ($class instanceof EE_Data_Migration_Script_Base) { |
|
| 274 | + $class->instantiate_from_array_of_properties($data_migration_data); |
|
| 275 | + return $class; |
|
| 276 | + } else { |
|
| 277 | + // huh, so it's an object but not a data migration script?? that shouldn't happen |
|
| 278 | + // just leave it as an array (which will probably just get ignored) |
|
| 279 | + throw new EE_Error( |
|
| 280 | + sprintf( |
|
| 281 | + esc_html__( |
|
| 282 | + "Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", |
|
| 283 | + 'event_espresso' |
|
| 284 | + ), |
|
| 285 | + $data_migration_data['class'] |
|
| 286 | + ) |
|
| 287 | + ); |
|
| 288 | + } |
|
| 289 | + } else { |
|
| 290 | + // so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists |
|
| 291 | + throw new EE_Error( |
|
| 292 | + sprintf( |
|
| 293 | + esc_html__("The wp option with key '%s' does not represent a DMS", 'event_espresso'), |
|
| 294 | + $dms_option_name |
|
| 295 | + ) |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Gets the array describing what data migrations have run. |
|
| 303 | + * Also has a side effect of recording which was the last run, |
|
| 304 | + * and which was the last run which hasn't finished yet |
|
| 305 | + * |
|
| 306 | + * @return array where each element should be an array of EE_Data_Migration_Script_Base |
|
| 307 | + * (but also has a few legacy arrays in there - which should probably be ignored) |
|
| 308 | + * @throws EE_Error |
|
| 309 | + */ |
|
| 310 | + public function get_data_migrations_ran() |
|
| 311 | + { |
|
| 312 | + if (! $this->_data_migrations_ran) { |
|
| 313 | + // setup autoloaders for each of the scripts in there |
|
| 314 | + $this->get_all_data_migration_scripts_available(); |
|
| 315 | + $data_migrations_options = |
|
| 316 | + $this->get_all_migration_script_options();// get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
| 317 | + |
|
| 318 | + $data_migrations_ran = []; |
|
| 319 | + // convert into data migration script classes where possible |
|
| 320 | + foreach ($data_migrations_options as $data_migration_option) { |
|
| 321 | + [$plugin_slug, $version_string] = $this->_get_plugin_slug_and_version_string_from_dms_option_name( |
|
| 322 | + $data_migration_option['option_name'] |
|
| 323 | + ); |
|
| 324 | + |
|
| 325 | + try { |
|
| 326 | + $class = $this->_get_dms_class_from_wp_option( |
|
| 327 | + $data_migration_option['option_name'], |
|
| 328 | + $data_migration_option['option_value'] |
|
| 329 | + ); |
|
| 330 | + $data_migrations_ran[ $plugin_slug ][ $version_string ] = $class; |
|
| 331 | + // ok so far THIS is the 'last-run-script'... unless we find another on next iteration |
|
| 332 | + $this->_last_ran_script = $class; |
|
| 333 | + if (! $class->is_completed()) { |
|
| 334 | + // sometimes we also like to know which was the last incomplete script (or if there are any at all) |
|
| 335 | + $this->_last_ran_incomplete_script = $class; |
|
| 336 | + } |
|
| 337 | + } catch (EE_Error $e) { |
|
| 338 | + // ok so it's not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
|
| 339 | + $data_migrations_ran[ $plugin_slug ][ $version_string ] = maybe_unserialize( |
|
| 340 | + $data_migration_option['option_value'] |
|
| 341 | + ); |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + // so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
|
| 345 | + $this->_data_migrations_ran = $data_migrations_ran; |
|
| 346 | + if (! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
| 347 | + $this->_data_migrations_ran = []; |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + return $this->_data_migrations_ran; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * @param string $script_name eg 'DMS_Core_4_1_0' |
|
| 356 | + * @param string $old_table eg 'wp_events_detail' |
|
| 357 | + * @param string $old_pk eg 'wp_esp_posts' |
|
| 358 | + * @param $new_table |
|
| 359 | + * @return mixed string or int |
|
| 360 | + * @throws EE_Error |
|
| 361 | + * @throws ReflectionException |
|
| 362 | + */ |
|
| 363 | + public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) |
|
| 364 | + { |
|
| 365 | + $script = EE_Registry::instance()->load_dms($script_name); |
|
| 366 | + return $script->get_mapping_new_pk($old_table, $old_pk, $new_table); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * Gets all the options containing migration scripts that have been run. Ordering is important: it's assumed that |
|
| 372 | + * the last option returned in this array is the most-recently run DMS option |
|
| 373 | + * |
|
| 374 | + * @return array |
|
| 375 | + */ |
|
| 376 | + public function get_all_migration_script_options() |
|
| 377 | + { |
|
| 378 | + global $wpdb; |
|
| 379 | + return $wpdb->get_results( |
|
| 380 | + "SELECT * FROM {$wpdb->options} WHERE option_name like '" |
|
| 381 | + . EE_Data_Migration_Manager::data_migration_script_option_prefix |
|
| 382 | + . "%' ORDER BY option_id ASC", |
|
| 383 | + ARRAY_A |
|
| 384 | + ); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Gets the array of folders which contain data migration scripts. Also adds them to be auto-loaded |
|
| 390 | + * |
|
| 391 | + * @return array where each value is the full folder path of a folder containing data migration scripts, WITH |
|
| 392 | + * slashes at the end of the folder name. |
|
| 393 | + */ |
|
| 394 | + public function get_data_migration_script_folders() |
|
| 395 | + { |
|
| 396 | + if (empty($this->dms_folders)) { |
|
| 397 | + $this->dms_folders = (array) apply_filters( |
|
| 398 | + 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
| 399 | + ['Core' => EE_CORE . 'data_migration_scripts'] |
|
| 400 | + ); |
|
| 401 | + } |
|
| 402 | + return $this->dms_folders; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Gets the version the migration script upgrades to |
|
| 408 | + * |
|
| 409 | + * @param string $migration_script_name eg 'EE_DMS_Core_4_1_0' |
|
| 410 | + * @return array { |
|
| 411 | + * @type string $slug like 'Core','Calendar',etc |
|
| 412 | + * @type string $version like 4.3.0 |
|
| 413 | + * } |
|
| 414 | + * @throws EE_Error |
|
| 415 | + */ |
|
| 416 | + public function script_migrates_to_version($migration_script_name, $eeAddonClass = '') |
|
| 417 | + { |
|
| 418 | + if (isset($this->script_migration_versions[ $migration_script_name ])) { |
|
| 419 | + return $this->script_migration_versions[ $migration_script_name ]; |
|
| 420 | + } |
|
| 421 | + $dms_info = $this->parse_dms_classname($migration_script_name); |
|
| 422 | + $this->script_migration_versions[ $migration_script_name ] = [ |
|
| 423 | + 'slug' => $eeAddonClass !== '' |
|
| 424 | + ? $eeAddonClass |
|
| 425 | + : $dms_info['slug'], |
|
| 426 | + 'version' => $dms_info['major_version'] |
|
| 427 | + . "." |
|
| 428 | + . $dms_info['minor_version'] |
|
| 429 | + . "." |
|
| 430 | + . $dms_info['micro_version'], |
|
| 431 | + ]; |
|
| 432 | + return $this->script_migration_versions[ $migration_script_name ]; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Gets the juicy details out of a dms filename like 'EE_DMS_Core_4_1_0' |
|
| 438 | + * |
|
| 439 | + * @param string $classname |
|
| 440 | + * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are integers) |
|
| 441 | + * @throws EE_Error |
|
| 442 | + */ |
|
| 443 | + public function parse_dms_classname($classname) |
|
| 444 | + { |
|
| 445 | + $matches = []; |
|
| 446 | + preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
|
| 447 | + if (! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
| 448 | + throw new EE_Error( |
|
| 449 | + sprintf( |
|
| 450 | + esc_html__( |
|
| 451 | + "%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", |
|
| 452 | + "event_espresso" |
|
| 453 | + ), |
|
| 454 | + $classname |
|
| 455 | + ) |
|
| 456 | + ); |
|
| 457 | + } |
|
| 458 | + return [ |
|
| 459 | + 'slug' => $matches[1], |
|
| 460 | + 'major_version' => intval($matches[2]), |
|
| 461 | + 'minor_version' => intval($matches[3]), |
|
| 462 | + 'micro_version' => intval($matches[4]), |
|
| 463 | + ]; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Ensures that the option indicating the current DB version is set. This should only be |
|
| 469 | + * a concern when activating EE for the first time, THEORETICALLY. |
|
| 470 | + * If we detect that we're activating EE4 over top of EE3.1, then we set the current db state to 3.1.x, otherwise |
|
| 471 | + * to 4.1.x. |
|
| 472 | + * |
|
| 473 | + * @return string of current db state |
|
| 474 | + */ |
|
| 475 | + public function ensure_current_database_state_is_set() |
|
| 476 | + { |
|
| 477 | + $espresso_db_core_updates = get_option('espresso_db_update', []); |
|
| 478 | + $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
|
| 479 | + if (! $db_state) { |
|
| 480 | + // mark the DB as being in the state as the last version in there. |
|
| 481 | + // this is done to trigger maintenance mode and do data migration scripts |
|
| 482 | + // if the admin installed this version of EE over 3.1.x or 4.0.x |
|
| 483 | + // otherwise, the normal maintenance mode code is fine |
|
| 484 | + $previous_versions_installed = array_keys($espresso_db_core_updates); |
|
| 485 | + $previous_version_installed = end($previous_versions_installed); |
|
| 486 | + if (version_compare('4.1.0', $previous_version_installed)) { |
|
| 487 | + // last installed version was less than 4.1, so we want the data migrations to happen. |
|
| 488 | + // SO, we're going to say the DB is at that state |
|
| 489 | + $db_state = ['Core' => $previous_version_installed]; |
|
| 490 | + } else { |
|
| 491 | + $db_state = ['Core' => EVENT_ESPRESSO_VERSION]; |
|
| 492 | + } |
|
| 493 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
| 494 | + } |
|
| 495 | + // in 4.1, $db_state would have only been a simple string like '4.1.0', |
|
| 496 | + // but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
|
| 497 | + // db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
|
| 498 | + if (! is_array($db_state)) { |
|
| 499 | + $db_state = ['Core' => $db_state]; |
|
| 500 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
| 501 | + } |
|
| 502 | + return $db_state; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Checks if there are any data migration scripts that ought to be run. |
|
| 508 | + * If found, returns the instantiated classes. |
|
| 509 | + * If none are found (ie, they've all already been run, or they don't apply), returns an empty array |
|
| 510 | + * |
|
| 511 | + * @return EE_Data_Migration_Script_Base[] |
|
| 512 | + * @throws EE_Error |
|
| 513 | + */ |
|
| 514 | + public function check_for_applicable_data_migration_scripts() |
|
| 515 | + { |
|
| 516 | + // get the option describing what options have already run |
|
| 517 | + $scripts_ran = $this->get_data_migrations_ran(); |
|
| 518 | + // $scripts_ran = array('4.1.0.core'=>array('monkey'=>null)); |
|
| 519 | + $script_class_and_filepaths_available = $this->get_all_data_migration_scripts_available(); |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + $current_database_state = $this->ensure_current_database_state_is_set(); |
|
| 523 | + // determine which have already been run |
|
| 524 | + $script_classes_that_should_run_per_iteration = []; |
|
| 525 | + $iteration = 0; |
|
| 526 | + $next_database_state_to_consider = $current_database_state; |
|
| 527 | + $theoretical_database_state = null; |
|
| 528 | + do { |
|
| 529 | + // the next state after the currently-considered one |
|
| 530 | + // will start off looking the same as the current, but we may make additions... |
|
| 531 | + $theoretical_database_state = $next_database_state_to_consider; |
|
| 532 | + // the next db state to consider is |
|
| 533 | + // "what would the DB be like had we run all the scripts we found that applied last time?" |
|
| 534 | + foreach ($script_class_and_filepaths_available as $classname => $filepath) { |
|
| 535 | + $migrates_to_version = $this->script_migrates_to_version($classname); |
|
| 536 | + $script_converts_plugin_slug = $migrates_to_version['slug']; |
|
| 537 | + $script_converts_to_version = $migrates_to_version['version']; |
|
| 538 | + // check if this version script is DONE or not; or if it's never been run |
|
| 539 | + if ( |
|
| 540 | + ! $scripts_ran |
|
| 541 | + || ! isset($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]) |
|
| 542 | + ) { |
|
| 543 | + // we haven't run this conversion script before |
|
| 544 | + // now check if it applies... |
|
| 545 | + // note that we've added an autoloader for it on get_all_data_migration_scripts_available |
|
| 546 | + // Also, make sure we get a new one. It's possible this is being ran during a multisite migration, |
|
| 547 | + // in which case we don't want to reuse a DMS script from a different blog! |
|
| 548 | + $script = LoaderFactory::getLoader()->getNew($classname); |
|
| 549 | + /* @var $script EE_Data_Migration_Script_Base */ |
|
| 550 | + $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
|
| 551 | + if ($can_migrate) { |
|
| 552 | + $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
| 553 | + $migrates_to_version = |
|
| 554 | + $script->migrates_to_version(); |
|
| 555 | + $next_database_state_to_consider[ $migrates_to_version['slug'] ] = |
|
| 556 | + $migrates_to_version['version']; |
|
| 557 | + unset($script_class_and_filepaths_available[ $classname ]); |
|
| 558 | + } |
|
| 559 | + } elseif ( |
|
| 560 | + $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ] |
|
| 561 | + instanceof |
|
| 562 | + EE_Data_Migration_Script_Base |
|
| 563 | + ) { |
|
| 564 | + // this script has been run, or at least started |
|
| 565 | + $script = $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]; |
|
| 566 | + if ($script->get_status() !== self::status_completed) { |
|
| 567 | + // this script is already underway... keep going with it |
|
| 568 | + $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
| 569 | + $migrates_to_version = |
|
| 570 | + $script->migrates_to_version(); |
|
| 571 | + $next_database_state_to_consider[ $migrates_to_version['slug'] ] = |
|
| 572 | + $migrates_to_version['version']; |
|
| 573 | + unset($script_class_and_filepaths_available[ $classname ]); |
|
| 574 | + } |
|
| 575 | + // else it must have a status that indicates it has finished, |
|
| 576 | + // so we don't want to try and run it again |
|
| 577 | + } |
|
| 578 | + // else it exists, but it's not a proper data migration script maybe the script got renamed? |
|
| 579 | + // or was simply removed from EE? either way, it's certainly not runnable! |
|
| 580 | + } |
|
| 581 | + $iteration++; |
|
| 582 | + } while ($next_database_state_to_consider !== $theoretical_database_state && $iteration < 6); |
|
| 583 | + // ok we have all the scripts that should run, now let's make them into flat array |
|
| 584 | + $scripts_that_should_run = []; |
|
| 585 | + foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
|
| 586 | + ksort($scripts_at_priority); |
|
| 587 | + foreach ($scripts_at_priority as $scripts) { |
|
| 588 | + foreach ($scripts as $script) { |
|
| 589 | + $scripts_that_should_run[ get_class($script) ] = $script; |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + do_action( |
|
| 595 | + 'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', |
|
| 596 | + $scripts_that_should_run |
|
| 597 | + ); |
|
| 598 | + return $scripts_that_should_run; |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Gets the script which is currently being run, if there is one. If $include_completed_scripts is set to TRUE |
|
| 604 | + * it will return the last run script even if it's complete. |
|
| 605 | + * This means: if you want to find the currently-executing script, leave it as FALSE. |
|
| 606 | + * If you really just want to find the script which ran most recently, regardless of status, leave it as TRUE. |
|
| 607 | + * |
|
| 608 | + * @param bool $include_completed_scripts |
|
| 609 | + * @return EE_Data_Migration_Script_Base |
|
| 610 | + * @throws EE_Error |
|
| 611 | + */ |
|
| 612 | + public function get_last_ran_script($include_completed_scripts = false) |
|
| 613 | + { |
|
| 614 | + // make sure we've set up the class properties _last_ran_script and _last_ran_incomplete_script |
|
| 615 | + if (! $this->_data_migrations_ran) { |
|
| 616 | + $this->get_data_migrations_ran(); |
|
| 617 | + } |
|
| 618 | + if ($include_completed_scripts) { |
|
| 619 | + return $this->_last_ran_script; |
|
| 620 | + } else { |
|
| 621 | + return $this->_last_ran_incomplete_script; |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * Runs the data migration scripts (well, each request to this method calls one of the |
|
| 628 | + * data migration scripts' migration_step() functions). |
|
| 629 | + * |
|
| 630 | + * @param int $step_size |
|
| 631 | + * @return array { |
|
| 632 | + * // where the first item is one EE_Data_Migration_Script_Base's stati, |
|
| 633 | + * //and the second item is a string describing what was done |
|
| 634 | + * @type int $records_to_migrate from the current migration script |
|
| 635 | + * @type int $records_migrated |
|
| 636 | + * @type string $status one of EE_Data_Migration_Manager::status_* |
|
| 637 | + * @type string $script verbose name of the current DMS |
|
| 638 | + * @type string $message string describing what was done during this step |
|
| 639 | + * } |
|
| 640 | + * @throws EE_Error |
|
| 641 | + */ |
|
| 642 | + public function migration_step($step_size = 0) |
|
| 643 | + { |
|
| 644 | + // bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535 |
|
| 645 | + if (class_exists('EE_CPT_Strategy')) { |
|
| 646 | + remove_action('pre_get_posts', [EE_CPT_Strategy::instance(), 'pre_get_posts'], 5); |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + try { |
|
| 650 | + $currently_executing_script = $this->get_last_ran_script(); |
|
| 651 | + if (! $currently_executing_script) { |
|
| 652 | + // Find the next script that needs to execute |
|
| 653 | + $scripts = $this->check_for_applicable_data_migration_scripts(); |
|
| 654 | + if (! $scripts) { |
|
| 655 | + // huh, no more scripts to run... apparently we're done! |
|
| 656 | + // but don't forget to make sure initial data is there |
|
| 657 | + // we should be good to allow them to exit maintenance mode now |
|
| 658 | + EE_Maintenance_Mode::instance()->deactivateMaintenanceMode(); |
|
| 659 | + // saving migrations run should actually be unnecessary, |
|
| 660 | + // but leaving in place just in case... remember this migration was finished |
|
| 661 | + // (even if we time out while initializing db for core and plugins) |
|
| 662 | + $this->_save_migrations_ran(); |
|
| 663 | + // make sure DB was updated AFTER we've recorded the migration was done |
|
| 664 | + $this->initialize_db_for_enqueued_ee_plugins(); |
|
| 665 | + return [ |
|
| 666 | + 'records_to_migrate' => 1, |
|
| 667 | + 'records_migrated' => 1, |
|
| 668 | + 'status' => self::status_no_more_migration_scripts, |
|
| 669 | + 'script' => esc_html__("Data Migration Completed Successfully", "event_espresso"), |
|
| 670 | + 'message' => esc_html__("All done!", "event_espresso"), |
|
| 671 | + ]; |
|
| 672 | + } |
|
| 673 | + $currently_executing_script = array_shift($scripts); |
|
| 674 | + // and add to the array/wp option showing the scripts run |
|
| 675 | + |
|
| 676 | + $migrates_to = |
|
| 677 | + $this->script_migrates_to_version(get_class($currently_executing_script)); |
|
| 678 | + $plugin_slug = $migrates_to['slug']; |
|
| 679 | + $version = $migrates_to['version']; |
|
| 680 | + $this->_data_migrations_ran[ $plugin_slug ][ $version ] = $currently_executing_script; |
|
| 681 | + } |
|
| 682 | + $current_script_name = get_class($currently_executing_script); |
|
| 683 | + } catch (Exception $e) { |
|
| 684 | + // an exception occurred while trying to get migration scripts |
|
| 685 | + |
|
| 686 | + $message = sprintf( |
|
| 687 | + esc_html__("Error Message: %sStack Trace:%s", "event_espresso"), |
|
| 688 | + $e->getMessage() . '<br>', |
|
| 689 | + $e->getTraceAsString() |
|
| 690 | + ); |
|
| 691 | + // record it on the array of data migration scripts run. This will be overwritten next time we try and try to run data migrations |
|
| 692 | + // but that's ok-- it's just an FYI to support that we couldn't even run any data migrations |
|
| 693 | + $this->add_error_to_migrations_ran( |
|
| 694 | + sprintf(esc_html__("Could not run data migrations because: %s", "event_espresso"), $message) |
|
| 695 | + ); |
|
| 696 | + return [ |
|
| 697 | + 'records_to_migrate' => 1, |
|
| 698 | + 'records_migrated' => 0, |
|
| 699 | + 'status' => self::status_fatal_error, |
|
| 700 | + 'script' => esc_html__("Error loading data migration scripts", "event_espresso"), |
|
| 701 | + 'message' => $message, |
|
| 702 | + ]; |
|
| 703 | + } |
|
| 704 | + // can we wrap it up and verify default data? |
|
| 705 | + $init_dbs = false; |
|
| 706 | + // ok so we definitely have a data migration script |
|
| 707 | + try { |
|
| 708 | + $init_dbs = false; |
|
| 709 | + // how big of a bite do we want to take? Allow users to easily override via their wp-config |
|
| 710 | + if (absint($step_size) < 1) { |
|
| 711 | + $step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE) |
|
| 712 | + ? EE_MIGRATION_STEP_SIZE |
|
| 713 | + : EE_Data_Migration_Manager::step_size; |
|
| 714 | + } |
|
| 715 | + // do what we came to do! |
|
| 716 | + $currently_executing_script->migration_step($step_size); |
|
| 717 | + switch ($currently_executing_script->get_status()) { |
|
| 718 | + case EE_Data_Migration_Manager::status_continue: |
|
| 719 | + $response_array = [ |
|
| 720 | + 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
| 721 | + 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
| 722 | + 'status' => EE_Data_Migration_Manager::status_continue, |
|
| 723 | + 'message' => $currently_executing_script->get_feedback_message(), |
|
| 724 | + 'script' => $currently_executing_script->pretty_name(), |
|
| 725 | + ]; |
|
| 726 | + break; |
|
| 727 | + case EE_Data_Migration_Manager::status_completed: |
|
| 728 | + // ok so THAT script has completed |
|
| 729 | + $this->update_current_database_state_to($this->script_migrates_to_version($current_script_name)); |
|
| 730 | + $response_array = [ |
|
| 731 | + 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
| 732 | + 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
| 733 | + 'status' => EE_Data_Migration_Manager::status_completed, |
|
| 734 | + 'message' => $currently_executing_script->get_feedback_message(), |
|
| 735 | + 'script' => sprintf( |
|
| 736 | + esc_html__("%s Completed", 'event_espresso'), |
|
| 737 | + $currently_executing_script->pretty_name() |
|
| 738 | + ), |
|
| 739 | + ]; |
|
| 740 | + // check if there are any more after this one. |
|
| 741 | + $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
|
| 742 | + if (! $scripts_remaining) { |
|
| 743 | + // we should be good to allow them to exit maintenance mode now |
|
| 744 | + EE_Maintenance_Mode::instance()->deactivateMaintenanceMode(); |
|
| 745 | + // huh, no more scripts to run... apparently we're done! |
|
| 746 | + // but don't forget to make sure initial data is there |
|
| 747 | + $init_dbs = true; |
|
| 748 | + $response_array['status'] = self::status_no_more_migration_scripts; |
|
| 749 | + } |
|
| 750 | + break; |
|
| 751 | + default: |
|
| 752 | + $response_array = [ |
|
| 753 | + 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
| 754 | + 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
| 755 | + 'status' => $currently_executing_script->get_status(), |
|
| 756 | + 'message' => sprintf( |
|
| 757 | + esc_html__("Minor errors occurred during %s: %s", "event_espresso"), |
|
| 758 | + $currently_executing_script->pretty_name(), |
|
| 759 | + implode(", ", $currently_executing_script->get_errors()) |
|
| 760 | + ), |
|
| 761 | + 'script' => $currently_executing_script->pretty_name(), |
|
| 762 | + ]; |
|
| 763 | + break; |
|
| 764 | + } |
|
| 765 | + } catch (Exception $e) { |
|
| 766 | + // ok so some exception was thrown which killed the data migration script |
|
| 767 | + // double-check we have a real script |
|
| 768 | + if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) { |
|
| 769 | + $script_name = $currently_executing_script->pretty_name(); |
|
| 770 | + $currently_executing_script->set_broken(); |
|
| 771 | + $currently_executing_script->add_error($e->getMessage()); |
|
| 772 | + } else { |
|
| 773 | + $script_name = esc_html__("Error getting Migration Script", "event_espresso"); |
|
| 774 | + } |
|
| 775 | + $response_array = [ |
|
| 776 | + 'records_to_migrate' => 1, |
|
| 777 | + 'records_migrated' => 0, |
|
| 778 | + 'status' => self::status_fatal_error, |
|
| 779 | + 'message' => sprintf( |
|
| 780 | + esc_html__("A fatal error occurred during the migration: %s", "event_espresso"), |
|
| 781 | + $e->getMessage() |
|
| 782 | + ), |
|
| 783 | + 'script' => $script_name, |
|
| 784 | + ]; |
|
| 785 | + } |
|
| 786 | + $successful_save = $this->_save_migrations_ran(); |
|
| 787 | + if ($successful_save !== true) { |
|
| 788 | + // ok so the current wp option didn't save. that's tricky, because we'd like to update it |
|
| 789 | + // and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION! |
|
| 790 | + // however, if we throw an exception, and return that, then the next request |
|
| 791 | + // won't have as much info in it, and it may be able to save |
|
| 792 | + throw new EE_Error( |
|
| 793 | + sprintf( |
|
| 794 | + esc_html__( |
|
| 795 | + "The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", |
|
| 796 | + "event_espresso" |
|
| 797 | + ), |
|
| 798 | + $successful_save |
|
| 799 | + ) |
|
| 800 | + ); |
|
| 801 | + } |
|
| 802 | + // if we're all done, initialize EE plugins' default data etc. |
|
| 803 | + if ($init_dbs) { |
|
| 804 | + $this->initialize_db_for_enqueued_ee_plugins(); |
|
| 805 | + } |
|
| 806 | + return $response_array; |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + |
|
| 810 | + /** |
|
| 811 | + * Echo out JSON response to migration script AJAX requests. Takes precautions |
|
| 812 | + * to buffer output so that we don't throw junk into our json. |
|
| 813 | + * |
|
| 814 | + * @return array with keys: |
|
| 815 | + * 'records_to_migrate' which counts ALL the records for the current migration, and should remain constant. (ie, |
|
| 816 | + * it's NOT the count of hwo many remain) |
|
| 817 | + * 'records_migrated' which also counts ALL the records which have been migrated (ie, percent_complete = |
|
| 818 | + * records_migrated/records_to_migrate) |
|
| 819 | + * 'status'=>a string, one of EE_Data_migration_Manager::status_* |
|
| 820 | + * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into |
|
| 821 | + * errors, notifications, and successes |
|
| 822 | + * 'script'=>a pretty name of the script currently running |
|
| 823 | + */ |
|
| 824 | + public function response_to_migration_ajax_request() |
|
| 825 | + { |
|
| 826 | + ob_start(); |
|
| 827 | + try { |
|
| 828 | + $response = $this->migration_step(); |
|
| 829 | + } catch (Exception $e) { |
|
| 830 | + $response = [ |
|
| 831 | + 'records_to_migrate' => 0, |
|
| 832 | + 'records_migrated' => 0, |
|
| 833 | + 'status' => EE_Data_Migration_Manager::status_fatal_error, |
|
| 834 | + 'message' => sprintf( |
|
| 835 | + esc_html__("Unknown fatal error occurred: %s", "event_espresso"), |
|
| 836 | + $e->getMessage() |
|
| 837 | + ), |
|
| 838 | + 'script' => 'Unknown', |
|
| 839 | + ]; |
|
| 840 | + $this->add_error_to_migrations_ran($e->getMessage() . "; Stack trace:" . $e->getTraceAsString()); |
|
| 841 | + } |
|
| 842 | + $warnings_etc = @ob_get_contents(); |
|
| 843 | + ob_end_clean(); |
|
| 844 | + $response['message'] .= $warnings_etc; |
|
| 845 | + return $response; |
|
| 846 | + } |
|
| 847 | + |
|
| 848 | + |
|
| 849 | + /** |
|
| 850 | + * Updates the WordPress option that keeps track of which EE version the database |
|
| 851 | + * is at (ie, the code may be at 4.1.0, but the database is still at 3.1.35) |
|
| 852 | + * |
|
| 853 | + * @param array $slug_and_version { |
|
| 854 | + * @type string $slug like 'Core' or 'Calendar', |
|
| 855 | + * @type string $version like '4.1.0' |
|
| 856 | + * } |
|
| 857 | + * @return void |
|
| 858 | + */ |
|
| 859 | + public function update_current_database_state_to($slug_and_version = null) |
|
| 860 | + { |
|
| 861 | + if (! $slug_and_version) { |
|
| 862 | + // no version was provided, assume it should be at the current code version |
|
| 863 | + $slug_and_version = ['slug' => 'Core', 'version' => espresso_version()]; |
|
| 864 | + } |
|
| 865 | + $current_database_state = get_option(self::current_database_state, []); |
|
| 866 | + $current_database_state[ $slug_and_version['slug'] ] = $slug_and_version['version']; |
|
| 867 | + update_option(self::current_database_state, $current_database_state); |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + |
|
| 871 | + /** |
|
| 872 | + * Determines if the database is currently at a state matching what's indicated in $slug and $version. |
|
| 873 | + * |
|
| 874 | + * @param array $slug_and_version { |
|
| 875 | + * @type string $slug like 'Core' or 'Calendar', |
|
| 876 | + * @type string $version like '4.1.0' |
|
| 877 | + * } |
|
| 878 | + * @return boolean |
|
| 879 | + */ |
|
| 880 | + public function database_needs_updating_to($slug_and_version) |
|
| 881 | + { |
|
| 882 | + $slug = $slug_and_version['slug']; |
|
| 883 | + $version = $slug_and_version['version']; |
|
| 884 | + $current_database_state = get_option(self::current_database_state, []); |
|
| 885 | + if (! isset($current_database_state[ $slug ])) { |
|
| 886 | + return true; |
|
| 887 | + } |
|
| 888 | + // just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes |
|
| 889 | + $version_parts_current_db_state = array_slice(explode('.', $current_database_state[ $slug ]), 0, 3); |
|
| 890 | + $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
|
| 891 | + $needs_updating = false; |
|
| 892 | + foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
|
| 893 | + if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ]) { |
|
| 894 | + $needs_updating = true; |
|
| 895 | + break; |
|
| 896 | + } |
|
| 897 | + } |
|
| 898 | + return $needs_updating; |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + |
|
| 902 | + /** |
|
| 903 | + * Gets all the data migration scripts available in the core folder and folders |
|
| 904 | + * in addons. Has the side effect of adding them for autoloading |
|
| 905 | + * |
|
| 906 | + * @return array keys are expected classnames, values are their filepaths |
|
| 907 | + * @throws InvalidInterfaceException |
|
| 908 | + * @throws InvalidDataTypeException |
|
| 909 | + * @throws EE_Error |
|
| 910 | + * @throws InvalidArgumentException |
|
| 911 | + */ |
|
| 912 | + public function get_all_data_migration_scripts_available() |
|
| 913 | + { |
|
| 914 | + if (! $this->_data_migration_class_to_filepath_map) { |
|
| 915 | + $this->_data_migration_class_to_filepath_map = []; |
|
| 916 | + foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
|
| 917 | + // strip any placeholders added to classname to make it a unique array key |
|
| 918 | + $eeAddonClass = trim($eeAddonClass, '*'); |
|
| 919 | + $eeAddonClass = $eeAddonClass === 'Core' || class_exists($eeAddonClass) |
|
| 920 | + ? $eeAddonClass |
|
| 921 | + : ''; |
|
| 922 | + $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
| 923 | + $files = glob($folder_path . '*.dms.php'); |
|
| 924 | + if (empty($files)) { |
|
| 925 | + continue; |
|
| 926 | + } |
|
| 927 | + natsort($files); |
|
| 928 | + foreach ($files as $file) { |
|
| 929 | + $pos_of_last_slash = strrpos($file, '/'); |
|
| 930 | + $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
|
| 931 | + $migrates_to = $this->script_migrates_to_version($classname, $eeAddonClass); |
|
| 932 | + $slug = $migrates_to['slug']; |
|
| 933 | + // check that the slug as contained in the DMS is associated with |
|
| 934 | + // the slug of an addon or core |
|
| 935 | + if ($slug !== 'Core' && EE_Registry::instance()->get_addon_by_name($slug) === null) { |
|
| 936 | + EE_Error::doing_it_wrong( |
|
| 937 | + __FUNCTION__, |
|
| 938 | + sprintf( |
|
| 939 | + esc_html__( |
|
| 940 | + 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', |
|
| 941 | + 'event_espresso' |
|
| 942 | + ), |
|
| 943 | + $classname, |
|
| 944 | + $slug, |
|
| 945 | + implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
| 946 | + ), |
|
| 947 | + '4.3.0.alpha.019' |
|
| 948 | + ); |
|
| 949 | + } |
|
| 950 | + $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
| 951 | + } |
|
| 952 | + } |
|
| 953 | + EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
|
| 954 | + } |
|
| 955 | + return $this->_data_migration_class_to_filepath_map; |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + |
|
| 959 | + /** |
|
| 960 | + * Once we have an addon that works with EE4.1, we will actually want to fetch the PUE slugs |
|
| 961 | + * from each addon, and check if they need updating, |
|
| 962 | + * |
|
| 963 | + * @return boolean |
|
| 964 | + */ |
|
| 965 | + public function addons_need_updating() |
|
| 966 | + { |
|
| 967 | + return false; |
|
| 968 | + } |
|
| 969 | + |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * Adds this error string to the data_migrations_ran array, but we don't necessarily know |
|
| 973 | + * where to put it, so we just throw it in there... better than nothing... |
|
| 974 | + * |
|
| 975 | + * @param string $error_message |
|
| 976 | + */ |
|
| 977 | + public function add_error_to_migrations_ran($error_message) |
|
| 978 | + { |
|
| 979 | + // get last-run migration script |
|
| 980 | + global $wpdb; |
|
| 981 | + $last_migration_script_option = $wpdb->get_row( |
|
| 982 | + "SELECT * FROM $wpdb->options WHERE option_name like '" |
|
| 983 | + . EE_Data_Migration_Manager::data_migration_script_option_prefix |
|
| 984 | + . "%' ORDER BY option_id DESC LIMIT 1", |
|
| 985 | + ARRAY_A |
|
| 986 | + ); |
|
| 987 | + |
|
| 988 | + $last_ran_migration_script_properties = isset($last_migration_script_option['option_value']) |
|
| 989 | + ? maybe_unserialize($last_migration_script_option['option_value']) |
|
| 990 | + : null; |
|
| 991 | + // now, tread lightly because we're here because a FATAL non-catchable error |
|
| 992 | + // was thrown last time when we were trying to run a data migration script |
|
| 993 | + // so the fatal error could have happened while getting the migration script |
|
| 994 | + // or doing running it... |
|
| 995 | + $versions_migrated_to = isset($last_migration_script_option['option_name']) |
|
| 996 | + ? str_replace( |
|
| 997 | + EE_Data_Migration_Manager::data_migration_script_option_prefix, |
|
| 998 | + "", |
|
| 999 | + $last_migration_script_option['option_name'] |
|
| 1000 | + ) |
|
| 1001 | + : null; |
|
| 1002 | + |
|
| 1003 | + // check if it THINKS it's a data migration script and especially if it's one that HASN'T finished yet |
|
| 1004 | + // because if it has finished, then it obviously couldn't be the cause of this error, right? (because it's all done) |
|
| 1005 | + if ( |
|
| 1006 | + isset($last_ran_migration_script_properties['class']) |
|
| 1007 | + && isset($last_ran_migration_script_properties['_status']) |
|
| 1008 | + && $last_ran_migration_script_properties['_status'] != self::status_completed |
|
| 1009 | + ) { |
|
| 1010 | + // ok then just add this error to its list of errors |
|
| 1011 | + $last_ran_migration_script_properties['_errors'][] = $error_message; |
|
| 1012 | + $last_ran_migration_script_properties['_status'] = self::status_fatal_error; |
|
| 1013 | + } else { |
|
| 1014 | + // so we don't even know which script was last running |
|
| 1015 | + // use the data migration error stub, which is designed specifically for this type of thing |
|
| 1016 | + $general_migration_error = new EE_DMS_Unknown_1_0_0(); |
|
| 1017 | + $general_migration_error->add_error($error_message); |
|
| 1018 | + $general_migration_error->set_broken(); |
|
| 1019 | + $last_ran_migration_script_properties = $general_migration_error->properties_as_array(); |
|
| 1020 | + $versions_migrated_to = 'Unknown.1.0.0'; |
|
| 1021 | + // now just to make sure appears as last (in case the were previously a fatal error like this) |
|
| 1022 | + // delete the old one |
|
| 1023 | + delete_option(self::data_migration_script_option_prefix . $versions_migrated_to); |
|
| 1024 | + } |
|
| 1025 | + update_option( |
|
| 1026 | + self::data_migration_script_option_prefix . $versions_migrated_to, |
|
| 1027 | + $last_ran_migration_script_properties |
|
| 1028 | + ); |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + |
|
| 1032 | + /** |
|
| 1033 | + * saves what data migrations have run to the database |
|
| 1034 | + * |
|
| 1035 | + * @return bool|string TRUE if successfully saved migrations ran, string if an error occurred |
|
| 1036 | + * @throws EE_Error |
|
| 1037 | + */ |
|
| 1038 | + protected function _save_migrations_ran() |
|
| 1039 | + { |
|
| 1040 | + if ($this->_data_migrations_ran == null) { |
|
| 1041 | + $this->get_data_migrations_ran(); |
|
| 1042 | + } |
|
| 1043 | + // now, we don't want to save actual classes to the DB because that's messy |
|
| 1044 | + $successful_updates = true; |
|
| 1045 | + foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
|
| 1046 | + foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
|
| 1047 | + $plugin_slug_for_use_in_option_name = $plugin_slug . "."; |
|
| 1048 | + $option_name = |
|
| 1049 | + self::data_migration_script_option_prefix . $plugin_slug_for_use_in_option_name . $version_string; |
|
| 1050 | + $old_option_value = get_option($option_name); |
|
| 1051 | + if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
|
| 1052 | + $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
|
| 1053 | + if ($old_option_value != $script_array_for_saving) { |
|
| 1054 | + $successful_updates = update_option($option_name, $script_array_for_saving); |
|
| 1055 | + } |
|
| 1056 | + } else {// we don't know what this array-thing is. So just save it as-is |
|
| 1057 | + if ($old_option_value != $array_or_migration_obj) { |
|
| 1058 | + $successful_updates = update_option($option_name, $array_or_migration_obj); |
|
| 1059 | + } |
|
| 1060 | + } |
|
| 1061 | + if (! $successful_updates) { |
|
| 1062 | + global $wpdb; |
|
| 1063 | + return $wpdb->last_error; |
|
| 1064 | + } |
|
| 1065 | + } |
|
| 1066 | + } |
|
| 1067 | + return true; |
|
| 1068 | + // $updated = update_option(self::data_migrations_option_name, $array_of_migrations); |
|
| 1069 | + // if ($updated !== true) { |
|
| 1070 | + // global $wpdb; |
|
| 1071 | + // return $wpdb->last_error; |
|
| 1072 | + // } else { |
|
| 1073 | + // return true; |
|
| 1074 | + // } |
|
| 1075 | + // wp_mail( |
|
| 1076 | + // "[email protected]", |
|
| 1077 | + // time() . " price debug info", |
|
| 1078 | + // "updated: $updated, last error: $last_error, byte length of option: " . strlen( |
|
| 1079 | + // serialize($array_of_migrations) |
|
| 1080 | + // ) |
|
| 1081 | + // ); |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * Takes an array of data migration script properties and re-creates the class from |
|
| 1087 | + * them. The argument $properties_array is assumed to have been made by |
|
| 1088 | + * EE_Data_Migration_Script_Base::properties_as_array() |
|
| 1089 | + * |
|
| 1090 | + * @param array $properties_array |
|
| 1091 | + * @return EE_Data_Migration_Script_Base |
|
| 1092 | + * @throws EE_Error |
|
| 1093 | + */ |
|
| 1094 | + public function _instantiate_script_from_properties_array($properties_array) |
|
| 1095 | + { |
|
| 1096 | + if (! isset($properties_array['class'])) { |
|
| 1097 | + throw new EE_Error( |
|
| 1098 | + sprintf( |
|
| 1099 | + esc_html__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), |
|
| 1100 | + implode(",", $properties_array) |
|
| 1101 | + ) |
|
| 1102 | + ); |
|
| 1103 | + } |
|
| 1104 | + $class_name = $properties_array['class']; |
|
| 1105 | + if (! class_exists($class_name)) { |
|
| 1106 | + throw new EE_Error(sprintf( |
|
| 1107 | + esc_html__("There is no migration script named %s", "event_espresso"), |
|
| 1108 | + $class_name |
|
| 1109 | + )); |
|
| 1110 | + } |
|
| 1111 | + $class = new $class_name(); |
|
| 1112 | + if (! $class instanceof EE_Data_Migration_Script_Base) { |
|
| 1113 | + throw new EE_Error( |
|
| 1114 | + sprintf( |
|
| 1115 | + esc_html__( |
|
| 1116 | + "Class '%s' is supposed to be a migration script. Its not, its a '%s'", |
|
| 1117 | + "event_espresso" |
|
| 1118 | + ), |
|
| 1119 | + $class_name, |
|
| 1120 | + get_class($class) |
|
| 1121 | + ) |
|
| 1122 | + ); |
|
| 1123 | + } |
|
| 1124 | + $class->instantiate_from_array_of_properties($properties_array); |
|
| 1125 | + return $class; |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + |
|
| 1129 | + /** |
|
| 1130 | + * Gets the classname for the most up-to-date DMS (ie, the one that will finally |
|
| 1131 | + * leave the DB in a state usable by the current plugin code). |
|
| 1132 | + * |
|
| 1133 | + * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core' |
|
| 1134 | + * @return string |
|
| 1135 | + * @throws EE_Error |
|
| 1136 | + */ |
|
| 1137 | + public function get_most_up_to_date_dms($plugin_slug = 'Core') |
|
| 1138 | + { |
|
| 1139 | + $class_to_filepath_map = $this->get_all_data_migration_scripts_available(); |
|
| 1140 | + $most_up_to_date_dms_classname = null; |
|
| 1141 | + foreach ($class_to_filepath_map as $classname => $filepath) { |
|
| 1142 | + if ($most_up_to_date_dms_classname === null) { |
|
| 1143 | + $migrates_to = $this->script_migrates_to_version($classname); |
|
| 1144 | + $this_plugin_slug = $migrates_to['slug']; |
|
| 1145 | + if ($this_plugin_slug == $plugin_slug) { |
|
| 1146 | + // if it's for core, it wins |
|
| 1147 | + $most_up_to_date_dms_classname = $classname; |
|
| 1148 | + } |
|
| 1149 | + // if it wasn't for core, we must keep searching for one that is! |
|
| 1150 | + continue; |
|
| 1151 | + } |
|
| 1152 | + $champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
| 1153 | + $contender_migrates_to = $this->script_migrates_to_version($classname); |
|
| 1154 | + if ( |
|
| 1155 | + $contender_migrates_to['slug'] == $plugin_slug |
|
| 1156 | + && version_compare( |
|
| 1157 | + $champion_migrates_to['version'], |
|
| 1158 | + $contender_migrates_to['version'], |
|
| 1159 | + '<' |
|
| 1160 | + ) |
|
| 1161 | + ) { |
|
| 1162 | + // so the contenders version is higher, and it's for Core |
|
| 1163 | + $most_up_to_date_dms_classname = $classname; |
|
| 1164 | + } |
|
| 1165 | + } |
|
| 1166 | + return $most_up_to_date_dms_classname; |
|
| 1167 | + } |
|
| 1168 | + |
|
| 1169 | + |
|
| 1170 | + /** |
|
| 1171 | + * Gets the migration script specified but ONLY if it has already run. |
|
| 1172 | + * Eg, if you wanted to see if 'EE_DMS_Core_4_1_0' has run, you would run the following code: |
|
| 1173 | + * <code> $core_4_1_0_dms_ran = EE_Data_Migration_Manager::instance()->get_migration_ran( '4.1.0', 'Core' ) !== |
|
| 1174 | + * NULL;</code> This is especially useful in addons' data migration scripts, this way they can tell if a core (or |
|
| 1175 | + * other addon) DMS has run, in case the current DMS depends on it. |
|
| 1176 | + * |
|
| 1177 | + * @param string $version the version the DMS searched for migrates to. Usually just the content before the 3rd |
|
| 1178 | + * period. Eg '4.1.0' |
|
| 1179 | + * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
|
| 1180 | + * @return EE_Data_Migration_Script_Base |
|
| 1181 | + * @throws EE_Error |
|
| 1182 | + */ |
|
| 1183 | + public function get_migration_ran($version, $plugin_slug = 'Core') |
|
| 1184 | + { |
|
| 1185 | + $migrations_ran = $this->get_data_migrations_ran(); |
|
| 1186 | + if (isset($migrations_ran[ $plugin_slug ]) && isset($migrations_ran[ $plugin_slug ][ $version ])) { |
|
| 1187 | + return $migrations_ran[ $plugin_slug ][ $version ]; |
|
| 1188 | + } else { |
|
| 1189 | + return null; |
|
| 1190 | + } |
|
| 1191 | + } |
|
| 1192 | + |
|
| 1193 | + |
|
| 1194 | + /** |
|
| 1195 | + * Resets the borked data migration scripts, so they're no longer borked, and we can again attempt to migrate |
|
| 1196 | + * |
|
| 1197 | + * @return bool |
|
| 1198 | + * @throws EE_Error |
|
| 1199 | + */ |
|
| 1200 | + public function reattempt() |
|
| 1201 | + { |
|
| 1202 | + // find if the last-run script was borked |
|
| 1203 | + // set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
|
| 1204 | + // add an 'error' saying that we attempted to reset |
|
| 1205 | + // does it have a stage that was borked too? if so make it no longer borked |
|
| 1206 | + // add an 'error' saying we attempted to reset |
|
| 1207 | + $last_ran_script = $this->get_last_ran_script(); |
|
| 1208 | + if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) { |
|
| 1209 | + // if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it) |
|
| 1210 | + $last_ran_script->set_completed(); |
|
| 1211 | + } elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) { |
|
| 1212 | + $last_ran_script->reattempt(); |
|
| 1213 | + } else { |
|
| 1214 | + throw new EE_Error( |
|
| 1215 | + sprintf( |
|
| 1216 | + esc_html__( |
|
| 1217 | + 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', |
|
| 1218 | + 'event_espresso' |
|
| 1219 | + ), |
|
| 1220 | + print_r($last_ran_script, true) |
|
| 1221 | + ) |
|
| 1222 | + ); |
|
| 1223 | + } |
|
| 1224 | + return $this->_save_migrations_ran(); |
|
| 1225 | + } |
|
| 1226 | + |
|
| 1227 | + |
|
| 1228 | + /** |
|
| 1229 | + * Gets whether this particular migration has run or not |
|
| 1230 | + * |
|
| 1231 | + * @param string $version the version the DMS searched for migrates to. Usually just the content before the 3rd |
|
| 1232 | + * period. Eg '4.1.0' |
|
| 1233 | + * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
|
| 1234 | + * @return boolean |
|
| 1235 | + * @throws EE_Error |
|
| 1236 | + */ |
|
| 1237 | + public function migration_has_ran($version, $plugin_slug = 'Core') |
|
| 1238 | + { |
|
| 1239 | + return $this->get_migration_ran($version, $plugin_slug) !== null; |
|
| 1240 | + } |
|
| 1241 | + |
|
| 1242 | + |
|
| 1243 | + /** |
|
| 1244 | + * Enqueues this ee plugin to have its data initialized |
|
| 1245 | + * |
|
| 1246 | + * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value |
|
| 1247 | + */ |
|
| 1248 | + public function enqueue_db_initialization_for($plugin_slug) |
|
| 1249 | + { |
|
| 1250 | + $queue = $this->get_db_initialization_queue(); |
|
| 1251 | + if (! in_array($plugin_slug, $queue)) { |
|
| 1252 | + $queue[] = $plugin_slug; |
|
| 1253 | + } |
|
| 1254 | + update_option(self::db_init_queue_option_name, $queue); |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + |
|
| 1258 | + /** |
|
| 1259 | + * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon |
|
| 1260 | + * specified in EE_Data_Migration_Manager::get_db_init_queue(), and if 'Core' is |
|
| 1261 | + * in the queue, calls EE_System::initialize_db_if_no_migrations_required(). |
|
| 1262 | + * |
|
| 1263 | + * @throws EE_Error |
|
| 1264 | + */ |
|
| 1265 | + public function initialize_db_for_enqueued_ee_plugins() |
|
| 1266 | + { |
|
| 1267 | + $queue = $this->get_db_initialization_queue(); |
|
| 1268 | + foreach ($queue as $plugin_slug) { |
|
| 1269 | + $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
|
| 1270 | + if (! $most_up_to_date_dms) { |
|
| 1271 | + // if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
|
| 1272 | + $verify_db = false; |
|
| 1273 | + } else { |
|
| 1274 | + $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms); |
|
| 1275 | + $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to); |
|
| 1276 | + } |
|
| 1277 | + if ($plugin_slug == 'Core') { |
|
| 1278 | + EE_System::instance()->initialize_db_if_no_migrations_required( |
|
| 1279 | + false, |
|
| 1280 | + $verify_db |
|
| 1281 | + ); |
|
| 1282 | + } else { |
|
| 1283 | + // just loop through the addons to make sure their database is set up |
|
| 1284 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
| 1285 | + if ($addon->name() == $plugin_slug) { |
|
| 1286 | + $addon->initialize_db_if_no_migrations_required($verify_db); |
|
| 1287 | + break; |
|
| 1288 | + } |
|
| 1289 | + } |
|
| 1290 | + } |
|
| 1291 | + } |
|
| 1292 | + // because we just initialized the DBs for the enqueued ee plugins |
|
| 1293 | + // we don't need to keep remembering which ones needed to be initialized |
|
| 1294 | + delete_option(self::db_init_queue_option_name); |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + |
|
| 1298 | + /** |
|
| 1299 | + * Gets a numerically-indexed array of plugin slugs that need to have their databases |
|
| 1300 | + * (re-)initialized after migrations are complete. ie, each element should be either |
|
| 1301 | + * 'Core', or the return value of EE_Addon::name() for an addon |
|
| 1302 | + * |
|
| 1303 | + * @return array |
|
| 1304 | + */ |
|
| 1305 | + public function get_db_initialization_queue() |
|
| 1306 | + { |
|
| 1307 | + return get_option(self::db_init_queue_option_name, []); |
|
| 1308 | + } |
|
| 1309 | + |
|
| 1310 | + |
|
| 1311 | + /** |
|
| 1312 | + * Gets the injected table analyzer, or throws an exception |
|
| 1313 | + * |
|
| 1314 | + * @return TableAnalysis |
|
| 1315 | + * @throws EE_Error |
|
| 1316 | + */ |
|
| 1317 | + protected function _get_table_analysis() |
|
| 1318 | + { |
|
| 1319 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
| 1320 | + return $this->_table_analysis; |
|
| 1321 | + } else { |
|
| 1322 | + throw new EE_Error( |
|
| 1323 | + sprintf( |
|
| 1324 | + esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1325 | + get_class($this) |
|
| 1326 | + ) |
|
| 1327 | + ); |
|
| 1328 | + } |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + |
|
| 1332 | + /** |
|
| 1333 | + * Gets the injected table manager, or throws an exception |
|
| 1334 | + * |
|
| 1335 | + * @return TableManager |
|
| 1336 | + * @throws EE_Error |
|
| 1337 | + */ |
|
| 1338 | + protected function _get_table_manager() |
|
| 1339 | + { |
|
| 1340 | + if ($this->_table_manager instanceof TableManager) { |
|
| 1341 | + return $this->_table_manager; |
|
| 1342 | + } else { |
|
| 1343 | + throw new EE_Error( |
|
| 1344 | + sprintf( |
|
| 1345 | + esc_html__('Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1346 | + get_class($this) |
|
| 1347 | + ) |
|
| 1348 | + ); |
|
| 1349 | + } |
|
| 1350 | + } |
|
| 1351 | 1351 | } |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | public static function instance() |
| 164 | 164 | { |
| 165 | 165 | // check if class object is instantiated |
| 166 | - if (! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
| 166 | + if ( ! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
| 167 | 167 | self::$_instance = new self(); |
| 168 | 168 | } |
| 169 | 169 | return self::$_instance; |
@@ -189,11 +189,11 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | private function __construct() |
| 191 | 191 | { |
| 192 | - $this->stati_that_indicate_to_continue_migrations = [ |
|
| 192 | + $this->stati_that_indicate_to_continue_migrations = [ |
|
| 193 | 193 | self::status_continue, |
| 194 | 194 | self::status_completed, |
| 195 | 195 | ]; |
| 196 | - $this->stati_that_indicate_to_stop_migrations = [ |
|
| 196 | + $this->stati_that_indicate_to_stop_migrations = [ |
|
| 197 | 197 | self::status_fatal_error, |
| 198 | 198 | self::status_no_more_migration_scripts, |
| 199 | 199 | ]; |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | self::status_fatal_error, |
| 206 | 206 | // note: status_no_more_migration_scripts doesn't apply |
| 207 | 207 | ]; |
| 208 | - $this->dms_folders = []; |
|
| 208 | + $this->dms_folders = []; |
|
| 209 | 209 | // make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class |
| 210 | 210 | // to be defined, because right now it doesn't get autoloaded on its own |
| 211 | 211 | EE_Registry::instance()->load_core('Data_Migration_Class_Base', [], true); |
@@ -242,12 +242,12 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | if (count($parts) == 4) { |
| 244 | 244 | // it's 4.2-style.eg Core.4.1.0 |
| 245 | - $plugin_slug = $parts[0]; // eg Core |
|
| 246 | - $version_string = $parts[1] . "." . $parts[2] . "." . $parts[3]; // eg 4.1.0 |
|
| 245 | + $plugin_slug = $parts[0]; // eg Core |
|
| 246 | + $version_string = $parts[1].".".$parts[2].".".$parts[3]; // eg 4.1.0 |
|
| 247 | 247 | } else { |
| 248 | 248 | // it's 4.1-style: eg 4.1.0 |
| 249 | 249 | $plugin_slug = 'Core'; |
| 250 | - $version_string = $plugin_slug_and_version_string;// eg 4.1.0 |
|
| 250 | + $version_string = $plugin_slug_and_version_string; // eg 4.1.0 |
|
| 251 | 251 | } |
| 252 | 252 | return [$plugin_slug, $version_string]; |
| 253 | 253 | } |
@@ -309,11 +309,11 @@ discard block |
||
| 309 | 309 | */ |
| 310 | 310 | public function get_data_migrations_ran() |
| 311 | 311 | { |
| 312 | - if (! $this->_data_migrations_ran) { |
|
| 312 | + if ( ! $this->_data_migrations_ran) { |
|
| 313 | 313 | // setup autoloaders for each of the scripts in there |
| 314 | 314 | $this->get_all_data_migration_scripts_available(); |
| 315 | 315 | $data_migrations_options = |
| 316 | - $this->get_all_migration_script_options();// get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
| 316 | + $this->get_all_migration_script_options(); // get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
| 317 | 317 | |
| 318 | 318 | $data_migrations_ran = []; |
| 319 | 319 | // convert into data migration script classes where possible |
@@ -323,27 +323,27 @@ discard block |
||
| 323 | 323 | ); |
| 324 | 324 | |
| 325 | 325 | try { |
| 326 | - $class = $this->_get_dms_class_from_wp_option( |
|
| 326 | + $class = $this->_get_dms_class_from_wp_option( |
|
| 327 | 327 | $data_migration_option['option_name'], |
| 328 | 328 | $data_migration_option['option_value'] |
| 329 | 329 | ); |
| 330 | - $data_migrations_ran[ $plugin_slug ][ $version_string ] = $class; |
|
| 330 | + $data_migrations_ran[$plugin_slug][$version_string] = $class; |
|
| 331 | 331 | // ok so far THIS is the 'last-run-script'... unless we find another on next iteration |
| 332 | 332 | $this->_last_ran_script = $class; |
| 333 | - if (! $class->is_completed()) { |
|
| 333 | + if ( ! $class->is_completed()) { |
|
| 334 | 334 | // sometimes we also like to know which was the last incomplete script (or if there are any at all) |
| 335 | 335 | $this->_last_ran_incomplete_script = $class; |
| 336 | 336 | } |
| 337 | 337 | } catch (EE_Error $e) { |
| 338 | 338 | // ok so it's not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
| 339 | - $data_migrations_ran[ $plugin_slug ][ $version_string ] = maybe_unserialize( |
|
| 339 | + $data_migrations_ran[$plugin_slug][$version_string] = maybe_unserialize( |
|
| 340 | 340 | $data_migration_option['option_value'] |
| 341 | 341 | ); |
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | // so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
| 345 | 345 | $this->_data_migrations_ran = $data_migrations_ran; |
| 346 | - if (! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
| 346 | + if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
| 347 | 347 | $this->_data_migrations_ran = []; |
| 348 | 348 | } |
| 349 | 349 | } |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | if (empty($this->dms_folders)) { |
| 397 | 397 | $this->dms_folders = (array) apply_filters( |
| 398 | 398 | 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
| 399 | - ['Core' => EE_CORE . 'data_migration_scripts'] |
|
| 399 | + ['Core' => EE_CORE.'data_migration_scripts'] |
|
| 400 | 400 | ); |
| 401 | 401 | } |
| 402 | 402 | return $this->dms_folders; |
@@ -415,11 +415,11 @@ discard block |
||
| 415 | 415 | */ |
| 416 | 416 | public function script_migrates_to_version($migration_script_name, $eeAddonClass = '') |
| 417 | 417 | { |
| 418 | - if (isset($this->script_migration_versions[ $migration_script_name ])) { |
|
| 419 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
| 418 | + if (isset($this->script_migration_versions[$migration_script_name])) { |
|
| 419 | + return $this->script_migration_versions[$migration_script_name]; |
|
| 420 | 420 | } |
| 421 | 421 | $dms_info = $this->parse_dms_classname($migration_script_name); |
| 422 | - $this->script_migration_versions[ $migration_script_name ] = [ |
|
| 422 | + $this->script_migration_versions[$migration_script_name] = [ |
|
| 423 | 423 | 'slug' => $eeAddonClass !== '' |
| 424 | 424 | ? $eeAddonClass |
| 425 | 425 | : $dms_info['slug'], |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | . "." |
| 430 | 430 | . $dms_info['micro_version'], |
| 431 | 431 | ]; |
| 432 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
| 432 | + return $this->script_migration_versions[$migration_script_name]; |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | { |
| 445 | 445 | $matches = []; |
| 446 | 446 | preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
| 447 | - if (! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
| 447 | + if ( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
| 448 | 448 | throw new EE_Error( |
| 449 | 449 | sprintf( |
| 450 | 450 | esc_html__( |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | { |
| 477 | 477 | $espresso_db_core_updates = get_option('espresso_db_update', []); |
| 478 | 478 | $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
| 479 | - if (! $db_state) { |
|
| 479 | + if ( ! $db_state) { |
|
| 480 | 480 | // mark the DB as being in the state as the last version in there. |
| 481 | 481 | // this is done to trigger maintenance mode and do data migration scripts |
| 482 | 482 | // if the admin installed this version of EE over 3.1.x or 4.0.x |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | // in 4.1, $db_state would have only been a simple string like '4.1.0', |
| 496 | 496 | // but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
| 497 | 497 | // db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
| 498 | - if (! is_array($db_state)) { |
|
| 498 | + if ( ! is_array($db_state)) { |
|
| 499 | 499 | $db_state = ['Core' => $db_state]; |
| 500 | 500 | update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
| 501 | 501 | } |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | // check if this version script is DONE or not; or if it's never been run |
| 539 | 539 | if ( |
| 540 | 540 | ! $scripts_ran |
| 541 | - || ! isset($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]) |
|
| 541 | + || ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version]) |
|
| 542 | 542 | ) { |
| 543 | 543 | // we haven't run this conversion script before |
| 544 | 544 | // now check if it applies... |
@@ -549,28 +549,28 @@ discard block |
||
| 549 | 549 | /* @var $script EE_Data_Migration_Script_Base */ |
| 550 | 550 | $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
| 551 | 551 | if ($can_migrate) { |
| 552 | - $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
| 552 | + $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
|
| 553 | 553 | $migrates_to_version = |
| 554 | 554 | $script->migrates_to_version(); |
| 555 | - $next_database_state_to_consider[ $migrates_to_version['slug'] ] = |
|
| 555 | + $next_database_state_to_consider[$migrates_to_version['slug']] = |
|
| 556 | 556 | $migrates_to_version['version']; |
| 557 | - unset($script_class_and_filepaths_available[ $classname ]); |
|
| 557 | + unset($script_class_and_filepaths_available[$classname]); |
|
| 558 | 558 | } |
| 559 | 559 | } elseif ( |
| 560 | - $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ] |
|
| 560 | + $scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] |
|
| 561 | 561 | instanceof |
| 562 | 562 | EE_Data_Migration_Script_Base |
| 563 | 563 | ) { |
| 564 | 564 | // this script has been run, or at least started |
| 565 | - $script = $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]; |
|
| 565 | + $script = $scripts_ran[$script_converts_plugin_slug][$script_converts_to_version]; |
|
| 566 | 566 | if ($script->get_status() !== self::status_completed) { |
| 567 | 567 | // this script is already underway... keep going with it |
| 568 | - $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
| 568 | + $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
|
| 569 | 569 | $migrates_to_version = |
| 570 | 570 | $script->migrates_to_version(); |
| 571 | - $next_database_state_to_consider[ $migrates_to_version['slug'] ] = |
|
| 571 | + $next_database_state_to_consider[$migrates_to_version['slug']] = |
|
| 572 | 572 | $migrates_to_version['version']; |
| 573 | - unset($script_class_and_filepaths_available[ $classname ]); |
|
| 573 | + unset($script_class_and_filepaths_available[$classname]); |
|
| 574 | 574 | } |
| 575 | 575 | // else it must have a status that indicates it has finished, |
| 576 | 576 | // so we don't want to try and run it again |
@@ -579,14 +579,14 @@ discard block |
||
| 579 | 579 | // or was simply removed from EE? either way, it's certainly not runnable! |
| 580 | 580 | } |
| 581 | 581 | $iteration++; |
| 582 | - } while ($next_database_state_to_consider !== $theoretical_database_state && $iteration < 6); |
|
| 582 | + }while ($next_database_state_to_consider !== $theoretical_database_state && $iteration < 6); |
|
| 583 | 583 | // ok we have all the scripts that should run, now let's make them into flat array |
| 584 | 584 | $scripts_that_should_run = []; |
| 585 | 585 | foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
| 586 | 586 | ksort($scripts_at_priority); |
| 587 | 587 | foreach ($scripts_at_priority as $scripts) { |
| 588 | 588 | foreach ($scripts as $script) { |
| 589 | - $scripts_that_should_run[ get_class($script) ] = $script; |
|
| 589 | + $scripts_that_should_run[get_class($script)] = $script; |
|
| 590 | 590 | } |
| 591 | 591 | } |
| 592 | 592 | } |
@@ -612,7 +612,7 @@ discard block |
||
| 612 | 612 | public function get_last_ran_script($include_completed_scripts = false) |
| 613 | 613 | { |
| 614 | 614 | // make sure we've set up the class properties _last_ran_script and _last_ran_incomplete_script |
| 615 | - if (! $this->_data_migrations_ran) { |
|
| 615 | + if ( ! $this->_data_migrations_ran) { |
|
| 616 | 616 | $this->get_data_migrations_ran(); |
| 617 | 617 | } |
| 618 | 618 | if ($include_completed_scripts) { |
@@ -648,10 +648,10 @@ discard block |
||
| 648 | 648 | |
| 649 | 649 | try { |
| 650 | 650 | $currently_executing_script = $this->get_last_ran_script(); |
| 651 | - if (! $currently_executing_script) { |
|
| 651 | + if ( ! $currently_executing_script) { |
|
| 652 | 652 | // Find the next script that needs to execute |
| 653 | 653 | $scripts = $this->check_for_applicable_data_migration_scripts(); |
| 654 | - if (! $scripts) { |
|
| 654 | + if ( ! $scripts) { |
|
| 655 | 655 | // huh, no more scripts to run... apparently we're done! |
| 656 | 656 | // but don't forget to make sure initial data is there |
| 657 | 657 | // we should be good to allow them to exit maintenance mode now |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | $this->script_migrates_to_version(get_class($currently_executing_script)); |
| 678 | 678 | $plugin_slug = $migrates_to['slug']; |
| 679 | 679 | $version = $migrates_to['version']; |
| 680 | - $this->_data_migrations_ran[ $plugin_slug ][ $version ] = $currently_executing_script; |
|
| 680 | + $this->_data_migrations_ran[$plugin_slug][$version] = $currently_executing_script; |
|
| 681 | 681 | } |
| 682 | 682 | $current_script_name = get_class($currently_executing_script); |
| 683 | 683 | } catch (Exception $e) { |
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | |
| 686 | 686 | $message = sprintf( |
| 687 | 687 | esc_html__("Error Message: %sStack Trace:%s", "event_espresso"), |
| 688 | - $e->getMessage() . '<br>', |
|
| 688 | + $e->getMessage().'<br>', |
|
| 689 | 689 | $e->getTraceAsString() |
| 690 | 690 | ); |
| 691 | 691 | // record it on the array of data migration scripts run. This will be overwritten next time we try and try to run data migrations |
@@ -739,7 +739,7 @@ discard block |
||
| 739 | 739 | ]; |
| 740 | 740 | // check if there are any more after this one. |
| 741 | 741 | $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
| 742 | - if (! $scripts_remaining) { |
|
| 742 | + if ( ! $scripts_remaining) { |
|
| 743 | 743 | // we should be good to allow them to exit maintenance mode now |
| 744 | 744 | EE_Maintenance_Mode::instance()->deactivateMaintenanceMode(); |
| 745 | 745 | // huh, no more scripts to run... apparently we're done! |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | ), |
| 838 | 838 | 'script' => 'Unknown', |
| 839 | 839 | ]; |
| 840 | - $this->add_error_to_migrations_ran($e->getMessage() . "; Stack trace:" . $e->getTraceAsString()); |
|
| 840 | + $this->add_error_to_migrations_ran($e->getMessage()."; Stack trace:".$e->getTraceAsString()); |
|
| 841 | 841 | } |
| 842 | 842 | $warnings_etc = @ob_get_contents(); |
| 843 | 843 | ob_end_clean(); |
@@ -858,12 +858,12 @@ discard block |
||
| 858 | 858 | */ |
| 859 | 859 | public function update_current_database_state_to($slug_and_version = null) |
| 860 | 860 | { |
| 861 | - if (! $slug_and_version) { |
|
| 861 | + if ( ! $slug_and_version) { |
|
| 862 | 862 | // no version was provided, assume it should be at the current code version |
| 863 | 863 | $slug_and_version = ['slug' => 'Core', 'version' => espresso_version()]; |
| 864 | 864 | } |
| 865 | 865 | $current_database_state = get_option(self::current_database_state, []); |
| 866 | - $current_database_state[ $slug_and_version['slug'] ] = $slug_and_version['version']; |
|
| 866 | + $current_database_state[$slug_and_version['slug']] = $slug_and_version['version']; |
|
| 867 | 867 | update_option(self::current_database_state, $current_database_state); |
| 868 | 868 | } |
| 869 | 869 | |
@@ -882,15 +882,15 @@ discard block |
||
| 882 | 882 | $slug = $slug_and_version['slug']; |
| 883 | 883 | $version = $slug_and_version['version']; |
| 884 | 884 | $current_database_state = get_option(self::current_database_state, []); |
| 885 | - if (! isset($current_database_state[ $slug ])) { |
|
| 885 | + if ( ! isset($current_database_state[$slug])) { |
|
| 886 | 886 | return true; |
| 887 | 887 | } |
| 888 | 888 | // just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes |
| 889 | - $version_parts_current_db_state = array_slice(explode('.', $current_database_state[ $slug ]), 0, 3); |
|
| 889 | + $version_parts_current_db_state = array_slice(explode('.', $current_database_state[$slug]), 0, 3); |
|
| 890 | 890 | $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
| 891 | 891 | $needs_updating = false; |
| 892 | 892 | foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
| 893 | - if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ]) { |
|
| 893 | + if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[$offset]) { |
|
| 894 | 894 | $needs_updating = true; |
| 895 | 895 | break; |
| 896 | 896 | } |
@@ -911,7 +911,7 @@ discard block |
||
| 911 | 911 | */ |
| 912 | 912 | public function get_all_data_migration_scripts_available() |
| 913 | 913 | { |
| 914 | - if (! $this->_data_migration_class_to_filepath_map) { |
|
| 914 | + if ( ! $this->_data_migration_class_to_filepath_map) { |
|
| 915 | 915 | $this->_data_migration_class_to_filepath_map = []; |
| 916 | 916 | foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
| 917 | 917 | // strip any placeholders added to classname to make it a unique array key |
@@ -920,7 +920,7 @@ discard block |
||
| 920 | 920 | ? $eeAddonClass |
| 921 | 921 | : ''; |
| 922 | 922 | $folder_path = EEH_File::end_with_directory_separator($folder_path); |
| 923 | - $files = glob($folder_path . '*.dms.php'); |
|
| 923 | + $files = glob($folder_path.'*.dms.php'); |
|
| 924 | 924 | if (empty($files)) { |
| 925 | 925 | continue; |
| 926 | 926 | } |
@@ -947,7 +947,7 @@ discard block |
||
| 947 | 947 | '4.3.0.alpha.019' |
| 948 | 948 | ); |
| 949 | 949 | } |
| 950 | - $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
| 950 | + $this->_data_migration_class_to_filepath_map[$classname] = $file; |
|
| 951 | 951 | } |
| 952 | 952 | } |
| 953 | 953 | EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
@@ -1020,10 +1020,10 @@ discard block |
||
| 1020 | 1020 | $versions_migrated_to = 'Unknown.1.0.0'; |
| 1021 | 1021 | // now just to make sure appears as last (in case the were previously a fatal error like this) |
| 1022 | 1022 | // delete the old one |
| 1023 | - delete_option(self::data_migration_script_option_prefix . $versions_migrated_to); |
|
| 1023 | + delete_option(self::data_migration_script_option_prefix.$versions_migrated_to); |
|
| 1024 | 1024 | } |
| 1025 | 1025 | update_option( |
| 1026 | - self::data_migration_script_option_prefix . $versions_migrated_to, |
|
| 1026 | + self::data_migration_script_option_prefix.$versions_migrated_to, |
|
| 1027 | 1027 | $last_ran_migration_script_properties |
| 1028 | 1028 | ); |
| 1029 | 1029 | } |
@@ -1044,9 +1044,9 @@ discard block |
||
| 1044 | 1044 | $successful_updates = true; |
| 1045 | 1045 | foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
| 1046 | 1046 | foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
| 1047 | - $plugin_slug_for_use_in_option_name = $plugin_slug . "."; |
|
| 1047 | + $plugin_slug_for_use_in_option_name = $plugin_slug."."; |
|
| 1048 | 1048 | $option_name = |
| 1049 | - self::data_migration_script_option_prefix . $plugin_slug_for_use_in_option_name . $version_string; |
|
| 1049 | + self::data_migration_script_option_prefix.$plugin_slug_for_use_in_option_name.$version_string; |
|
| 1050 | 1050 | $old_option_value = get_option($option_name); |
| 1051 | 1051 | if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
| 1052 | 1052 | $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
@@ -1058,7 +1058,7 @@ discard block |
||
| 1058 | 1058 | $successful_updates = update_option($option_name, $array_or_migration_obj); |
| 1059 | 1059 | } |
| 1060 | 1060 | } |
| 1061 | - if (! $successful_updates) { |
|
| 1061 | + if ( ! $successful_updates) { |
|
| 1062 | 1062 | global $wpdb; |
| 1063 | 1063 | return $wpdb->last_error; |
| 1064 | 1064 | } |
@@ -1093,7 +1093,7 @@ discard block |
||
| 1093 | 1093 | */ |
| 1094 | 1094 | public function _instantiate_script_from_properties_array($properties_array) |
| 1095 | 1095 | { |
| 1096 | - if (! isset($properties_array['class'])) { |
|
| 1096 | + if ( ! isset($properties_array['class'])) { |
|
| 1097 | 1097 | throw new EE_Error( |
| 1098 | 1098 | sprintf( |
| 1099 | 1099 | esc_html__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), |
@@ -1102,14 +1102,14 @@ discard block |
||
| 1102 | 1102 | ); |
| 1103 | 1103 | } |
| 1104 | 1104 | $class_name = $properties_array['class']; |
| 1105 | - if (! class_exists($class_name)) { |
|
| 1105 | + if ( ! class_exists($class_name)) { |
|
| 1106 | 1106 | throw new EE_Error(sprintf( |
| 1107 | 1107 | esc_html__("There is no migration script named %s", "event_espresso"), |
| 1108 | 1108 | $class_name |
| 1109 | 1109 | )); |
| 1110 | 1110 | } |
| 1111 | 1111 | $class = new $class_name(); |
| 1112 | - if (! $class instanceof EE_Data_Migration_Script_Base) { |
|
| 1112 | + if ( ! $class instanceof EE_Data_Migration_Script_Base) { |
|
| 1113 | 1113 | throw new EE_Error( |
| 1114 | 1114 | sprintf( |
| 1115 | 1115 | esc_html__( |
@@ -1183,8 +1183,8 @@ discard block |
||
| 1183 | 1183 | public function get_migration_ran($version, $plugin_slug = 'Core') |
| 1184 | 1184 | { |
| 1185 | 1185 | $migrations_ran = $this->get_data_migrations_ran(); |
| 1186 | - if (isset($migrations_ran[ $plugin_slug ]) && isset($migrations_ran[ $plugin_slug ][ $version ])) { |
|
| 1187 | - return $migrations_ran[ $plugin_slug ][ $version ]; |
|
| 1186 | + if (isset($migrations_ran[$plugin_slug]) && isset($migrations_ran[$plugin_slug][$version])) { |
|
| 1187 | + return $migrations_ran[$plugin_slug][$version]; |
|
| 1188 | 1188 | } else { |
| 1189 | 1189 | return null; |
| 1190 | 1190 | } |
@@ -1248,7 +1248,7 @@ discard block |
||
| 1248 | 1248 | public function enqueue_db_initialization_for($plugin_slug) |
| 1249 | 1249 | { |
| 1250 | 1250 | $queue = $this->get_db_initialization_queue(); |
| 1251 | - if (! in_array($plugin_slug, $queue)) { |
|
| 1251 | + if ( ! in_array($plugin_slug, $queue)) { |
|
| 1252 | 1252 | $queue[] = $plugin_slug; |
| 1253 | 1253 | } |
| 1254 | 1254 | update_option(self::db_init_queue_option_name, $queue); |
@@ -1267,7 +1267,7 @@ discard block |
||
| 1267 | 1267 | $queue = $this->get_db_initialization_queue(); |
| 1268 | 1268 | foreach ($queue as $plugin_slug) { |
| 1269 | 1269 | $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
| 1270 | - if (! $most_up_to_date_dms) { |
|
| 1270 | + if ( ! $most_up_to_date_dms) { |
|
| 1271 | 1271 | // if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
| 1272 | 1272 | $verify_db = false; |
| 1273 | 1273 | } else { |
@@ -14,588 +14,588 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class EE_Cron_Tasks extends EE_Base |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
|
| 19 | - * so we'll set our retry time for just over 10 minutes to avoid that |
|
| 20 | - */ |
|
| 21 | - const reschedule_timeout = 605; |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - private static ?EE_Cron_Tasks $_instance = null; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - public static function instance(): ?EE_Cron_Tasks |
|
| 28 | - { |
|
| 29 | - if (! self::$_instance instanceof EE_Cron_Tasks) { |
|
| 30 | - self::$_instance = new self(); |
|
| 31 | - } |
|
| 32 | - return self::$_instance; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @throws InvalidDataTypeException |
|
| 38 | - * @throws InvalidInterfaceException |
|
| 39 | - * @throws InvalidArgumentException |
|
| 40 | - * @throws EE_Error |
|
| 41 | - * @throws ReflectionException |
|
| 42 | - */ |
|
| 43 | - private function __construct() |
|
| 44 | - { |
|
| 45 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 46 | - // verify that WP Cron is enabled |
|
| 47 | - if ( |
|
| 48 | - defined('DISABLE_WP_CRON') |
|
| 49 | - && DISABLE_WP_CRON |
|
| 50 | - && is_admin() |
|
| 51 | - && ! get_option('ee_disabled_wp_cron_check') |
|
| 52 | - ) { |
|
| 53 | - /** |
|
| 54 | - * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before |
|
| 55 | - * config is loaded. |
|
| 56 | - * This is intentionally using a anonymous function so that its not easily de-registered. Client code |
|
| 57 | - * wanting to not have this functionality can just register its own action at a priority after this one to |
|
| 58 | - * reverse any changes. |
|
| 59 | - */ |
|
| 60 | - add_action( |
|
| 61 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
| 62 | - function () { |
|
| 63 | - EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
|
| 64 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 65 | - add_option('ee_disabled_wp_cron_check', 1, '', false); |
|
| 66 | - } |
|
| 67 | - ); |
|
| 68 | - } |
|
| 69 | - // UPDATE TRANSACTION WITH PAYMENT |
|
| 70 | - add_action( |
|
| 71 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 72 | - array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'), |
|
| 73 | - 10, |
|
| 74 | - 2 |
|
| 75 | - ); |
|
| 76 | - // ABANDONED / EXPIRED TRANSACTION CHECK |
|
| 77 | - add_action( |
|
| 78 | - 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
| 79 | - array('EE_Cron_Tasks', 'expired_transaction_check') |
|
| 80 | - ); |
|
| 81 | - // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
|
| 82 | - add_action( |
|
| 83 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 84 | - array('EE_Cron_Tasks', 'clean_out_junk_transactions') |
|
| 85 | - ); |
|
| 86 | - // logging |
|
| 87 | - add_action( |
|
| 88 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
| 89 | - array('EE_Cron_Tasks', 'log_scheduled_ee_crons') |
|
| 90 | - ); |
|
| 91 | - EE_Registry::instance()->load_lib('Messages_Scheduler'); |
|
| 92 | - // clean out old gateway logs |
|
| 93 | - add_action( |
|
| 94 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs', |
|
| 95 | - array('EE_Cron_Tasks', 'clean_out_old_gateway_logs') |
|
| 96 | - ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public static function log_scheduled_ee_crons(): void |
|
| 100 | - { |
|
| 101 | - $ee_crons = array( |
|
| 102 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment', |
|
| 103 | - 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
| 104 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 105 | - ); |
|
| 106 | - $crons = (array) get_option('cron'); |
|
| 107 | - foreach ($crons as $cron) { |
|
| 108 | - /** @var array[] $cron */ |
|
| 109 | - foreach ($ee_crons as $ee_cron) { |
|
| 110 | - if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) { |
|
| 111 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
| 112 | - foreach ($cron[ $ee_cron ] as $ee_cron_details) { |
|
| 113 | - if (! empty($ee_cron_details['args'])) { |
|
| 114 | - do_action( |
|
| 115 | - 'AHEE_log', |
|
| 116 | - __CLASS__, |
|
| 117 | - __FUNCTION__, |
|
| 118 | - print_r($ee_cron_details['args'], true), |
|
| 119 | - "$ee_cron args" |
|
| 120 | - ); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * reschedule_cron_for_transactions_if_maintenance_mode |
|
| 131 | - * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
|
| 132 | - * |
|
| 133 | - * @param string $cron_task |
|
| 134 | - * @param array $TXN_IDs |
|
| 135 | - * @return bool |
|
| 136 | - * @throws DomainException |
|
| 137 | - */ |
|
| 138 | - public static function reschedule_cron_for_transactions_if_maintenance_mode(string $cron_task, array $TXN_IDs): bool |
|
| 139 | - { |
|
| 140 | - if (! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
| 141 | - throw new DomainException( |
|
| 142 | - sprintf( |
|
| 143 | - esc_html__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
|
| 144 | - $cron_task |
|
| 145 | - ) |
|
| 146 | - ); |
|
| 147 | - } |
|
| 148 | - // reschedule the cron if we can't hit the db right now |
|
| 149 | - if (DbStatus::isOffline()) { |
|
| 150 | - foreach ($TXN_IDs as $TXN_ID => $additional_vars) { |
|
| 151 | - // ensure $additional_vars is an array |
|
| 152 | - $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
|
| 153 | - // reset cron job for the TXN |
|
| 154 | - call_user_func_array( |
|
| 155 | - array('EE_Cron_Tasks', $cron_task), |
|
| 156 | - array_merge( |
|
| 157 | - array( |
|
| 158 | - time() + (10 * MINUTE_IN_SECONDS), |
|
| 159 | - $TXN_ID, |
|
| 160 | - ), |
|
| 161 | - $additional_vars |
|
| 162 | - ) |
|
| 163 | - ); |
|
| 164 | - } |
|
| 165 | - return true; |
|
| 166 | - } |
|
| 167 | - return false; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /**************** UPDATE TRANSACTION WITH PAYMENT ****************/ |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * array of TXN IDs and the payment |
|
| 178 | - * |
|
| 179 | - * @var array |
|
| 180 | - */ |
|
| 181 | - protected static array $_update_transactions_with_payment = array(); |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * schedule_update_transaction_with_payment |
|
| 186 | - * sets a wp_schedule_single_event() for updating any TXNs that may |
|
| 187 | - * require updating due to recently received payments |
|
| 188 | - * |
|
| 189 | - * @param int $timestamp |
|
| 190 | - * @param int $TXN_ID |
|
| 191 | - * @param int $PAY_ID |
|
| 192 | - */ |
|
| 193 | - public static function schedule_update_transaction_with_payment( |
|
| 194 | - int $timestamp, |
|
| 195 | - int $TXN_ID, |
|
| 196 | - int $PAY_ID |
|
| 197 | - ): void { |
|
| 198 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 199 | - // validate $TXN_ID and $timestamp |
|
| 200 | - $TXN_ID = absint($TXN_ID); |
|
| 201 | - $timestamp = absint($timestamp); |
|
| 202 | - if ($TXN_ID && $timestamp) { |
|
| 203 | - wp_schedule_single_event( |
|
| 204 | - $timestamp, |
|
| 205 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 206 | - array($TXN_ID, $PAY_ID) |
|
| 207 | - ); |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * setup_update_for_transaction_with_payment |
|
| 214 | - * this is the callback for the action hook: |
|
| 215 | - * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
|
| 216 | - * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
|
| 217 | - * The passed TXN_ID and associated payment gets added to an array, and then |
|
| 218 | - * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
|
| 219 | - * 'shutdown' which will actually handle the processing of any |
|
| 220 | - * transactions requiring updating, because doing so now would be too early |
|
| 221 | - * and the required resources may not be available |
|
| 222 | - * |
|
| 223 | - * @param int $TXN_ID |
|
| 224 | - * @param int $PAY_ID |
|
| 225 | - */ |
|
| 226 | - public static function setup_update_for_transaction_with_payment(int $TXN_ID = 0, int $PAY_ID = 0): void |
|
| 227 | - { |
|
| 228 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
| 229 | - if (absint($TXN_ID)) { |
|
| 230 | - self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID; |
|
| 231 | - add_action( |
|
| 232 | - 'shutdown', |
|
| 233 | - array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
|
| 234 | - 5 |
|
| 235 | - ); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * update_transaction_with_payment |
|
| 242 | - * loops through the self::$_abandoned_transactions array |
|
| 243 | - * and attempts to finalize any TXNs that have not been completed |
|
| 244 | - * but have had their sessions expired, most likely due to a user not |
|
| 245 | - * returning from an off-site payment gateway |
|
| 246 | - * |
|
| 247 | - * @throws EE_Error |
|
| 248 | - * @throws DomainException |
|
| 249 | - * @throws InvalidDataTypeException |
|
| 250 | - * @throws InvalidInterfaceException |
|
| 251 | - * @throws InvalidArgumentException |
|
| 252 | - * @throws ReflectionException |
|
| 253 | - * @throws RuntimeException |
|
| 254 | - */ |
|
| 255 | - public static function update_transaction_with_payment(): void |
|
| 256 | - { |
|
| 257 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 258 | - if ( |
|
| 17 | + /** |
|
| 18 | + * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
|
| 19 | + * so we'll set our retry time for just over 10 minutes to avoid that |
|
| 20 | + */ |
|
| 21 | + const reschedule_timeout = 605; |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + private static ?EE_Cron_Tasks $_instance = null; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + public static function instance(): ?EE_Cron_Tasks |
|
| 28 | + { |
|
| 29 | + if (! self::$_instance instanceof EE_Cron_Tasks) { |
|
| 30 | + self::$_instance = new self(); |
|
| 31 | + } |
|
| 32 | + return self::$_instance; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @throws InvalidDataTypeException |
|
| 38 | + * @throws InvalidInterfaceException |
|
| 39 | + * @throws InvalidArgumentException |
|
| 40 | + * @throws EE_Error |
|
| 41 | + * @throws ReflectionException |
|
| 42 | + */ |
|
| 43 | + private function __construct() |
|
| 44 | + { |
|
| 45 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 46 | + // verify that WP Cron is enabled |
|
| 47 | + if ( |
|
| 48 | + defined('DISABLE_WP_CRON') |
|
| 49 | + && DISABLE_WP_CRON |
|
| 50 | + && is_admin() |
|
| 51 | + && ! get_option('ee_disabled_wp_cron_check') |
|
| 52 | + ) { |
|
| 53 | + /** |
|
| 54 | + * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before |
|
| 55 | + * config is loaded. |
|
| 56 | + * This is intentionally using a anonymous function so that its not easily de-registered. Client code |
|
| 57 | + * wanting to not have this functionality can just register its own action at a priority after this one to |
|
| 58 | + * reverse any changes. |
|
| 59 | + */ |
|
| 60 | + add_action( |
|
| 61 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
| 62 | + function () { |
|
| 63 | + EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
|
| 64 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 65 | + add_option('ee_disabled_wp_cron_check', 1, '', false); |
|
| 66 | + } |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | + // UPDATE TRANSACTION WITH PAYMENT |
|
| 70 | + add_action( |
|
| 71 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 72 | + array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'), |
|
| 73 | + 10, |
|
| 74 | + 2 |
|
| 75 | + ); |
|
| 76 | + // ABANDONED / EXPIRED TRANSACTION CHECK |
|
| 77 | + add_action( |
|
| 78 | + 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
| 79 | + array('EE_Cron_Tasks', 'expired_transaction_check') |
|
| 80 | + ); |
|
| 81 | + // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
|
| 82 | + add_action( |
|
| 83 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 84 | + array('EE_Cron_Tasks', 'clean_out_junk_transactions') |
|
| 85 | + ); |
|
| 86 | + // logging |
|
| 87 | + add_action( |
|
| 88 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
| 89 | + array('EE_Cron_Tasks', 'log_scheduled_ee_crons') |
|
| 90 | + ); |
|
| 91 | + EE_Registry::instance()->load_lib('Messages_Scheduler'); |
|
| 92 | + // clean out old gateway logs |
|
| 93 | + add_action( |
|
| 94 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs', |
|
| 95 | + array('EE_Cron_Tasks', 'clean_out_old_gateway_logs') |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public static function log_scheduled_ee_crons(): void |
|
| 100 | + { |
|
| 101 | + $ee_crons = array( |
|
| 102 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment', |
|
| 103 | + 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
| 104 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 105 | + ); |
|
| 106 | + $crons = (array) get_option('cron'); |
|
| 107 | + foreach ($crons as $cron) { |
|
| 108 | + /** @var array[] $cron */ |
|
| 109 | + foreach ($ee_crons as $ee_cron) { |
|
| 110 | + if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) { |
|
| 111 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
| 112 | + foreach ($cron[ $ee_cron ] as $ee_cron_details) { |
|
| 113 | + if (! empty($ee_cron_details['args'])) { |
|
| 114 | + do_action( |
|
| 115 | + 'AHEE_log', |
|
| 116 | + __CLASS__, |
|
| 117 | + __FUNCTION__, |
|
| 118 | + print_r($ee_cron_details['args'], true), |
|
| 119 | + "$ee_cron args" |
|
| 120 | + ); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * reschedule_cron_for_transactions_if_maintenance_mode |
|
| 131 | + * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
|
| 132 | + * |
|
| 133 | + * @param string $cron_task |
|
| 134 | + * @param array $TXN_IDs |
|
| 135 | + * @return bool |
|
| 136 | + * @throws DomainException |
|
| 137 | + */ |
|
| 138 | + public static function reschedule_cron_for_transactions_if_maintenance_mode(string $cron_task, array $TXN_IDs): bool |
|
| 139 | + { |
|
| 140 | + if (! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
| 141 | + throw new DomainException( |
|
| 142 | + sprintf( |
|
| 143 | + esc_html__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
|
| 144 | + $cron_task |
|
| 145 | + ) |
|
| 146 | + ); |
|
| 147 | + } |
|
| 148 | + // reschedule the cron if we can't hit the db right now |
|
| 149 | + if (DbStatus::isOffline()) { |
|
| 150 | + foreach ($TXN_IDs as $TXN_ID => $additional_vars) { |
|
| 151 | + // ensure $additional_vars is an array |
|
| 152 | + $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
|
| 153 | + // reset cron job for the TXN |
|
| 154 | + call_user_func_array( |
|
| 155 | + array('EE_Cron_Tasks', $cron_task), |
|
| 156 | + array_merge( |
|
| 157 | + array( |
|
| 158 | + time() + (10 * MINUTE_IN_SECONDS), |
|
| 159 | + $TXN_ID, |
|
| 160 | + ), |
|
| 161 | + $additional_vars |
|
| 162 | + ) |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | + return true; |
|
| 166 | + } |
|
| 167 | + return false; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /**************** UPDATE TRANSACTION WITH PAYMENT ****************/ |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * array of TXN IDs and the payment |
|
| 178 | + * |
|
| 179 | + * @var array |
|
| 180 | + */ |
|
| 181 | + protected static array $_update_transactions_with_payment = array(); |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * schedule_update_transaction_with_payment |
|
| 186 | + * sets a wp_schedule_single_event() for updating any TXNs that may |
|
| 187 | + * require updating due to recently received payments |
|
| 188 | + * |
|
| 189 | + * @param int $timestamp |
|
| 190 | + * @param int $TXN_ID |
|
| 191 | + * @param int $PAY_ID |
|
| 192 | + */ |
|
| 193 | + public static function schedule_update_transaction_with_payment( |
|
| 194 | + int $timestamp, |
|
| 195 | + int $TXN_ID, |
|
| 196 | + int $PAY_ID |
|
| 197 | + ): void { |
|
| 198 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 199 | + // validate $TXN_ID and $timestamp |
|
| 200 | + $TXN_ID = absint($TXN_ID); |
|
| 201 | + $timestamp = absint($timestamp); |
|
| 202 | + if ($TXN_ID && $timestamp) { |
|
| 203 | + wp_schedule_single_event( |
|
| 204 | + $timestamp, |
|
| 205 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 206 | + array($TXN_ID, $PAY_ID) |
|
| 207 | + ); |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * setup_update_for_transaction_with_payment |
|
| 214 | + * this is the callback for the action hook: |
|
| 215 | + * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
|
| 216 | + * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
|
| 217 | + * The passed TXN_ID and associated payment gets added to an array, and then |
|
| 218 | + * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
|
| 219 | + * 'shutdown' which will actually handle the processing of any |
|
| 220 | + * transactions requiring updating, because doing so now would be too early |
|
| 221 | + * and the required resources may not be available |
|
| 222 | + * |
|
| 223 | + * @param int $TXN_ID |
|
| 224 | + * @param int $PAY_ID |
|
| 225 | + */ |
|
| 226 | + public static function setup_update_for_transaction_with_payment(int $TXN_ID = 0, int $PAY_ID = 0): void |
|
| 227 | + { |
|
| 228 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
| 229 | + if (absint($TXN_ID)) { |
|
| 230 | + self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID; |
|
| 231 | + add_action( |
|
| 232 | + 'shutdown', |
|
| 233 | + array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
|
| 234 | + 5 |
|
| 235 | + ); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * update_transaction_with_payment |
|
| 242 | + * loops through the self::$_abandoned_transactions array |
|
| 243 | + * and attempts to finalize any TXNs that have not been completed |
|
| 244 | + * but have had their sessions expired, most likely due to a user not |
|
| 245 | + * returning from an off-site payment gateway |
|
| 246 | + * |
|
| 247 | + * @throws EE_Error |
|
| 248 | + * @throws DomainException |
|
| 249 | + * @throws InvalidDataTypeException |
|
| 250 | + * @throws InvalidInterfaceException |
|
| 251 | + * @throws InvalidArgumentException |
|
| 252 | + * @throws ReflectionException |
|
| 253 | + * @throws RuntimeException |
|
| 254 | + */ |
|
| 255 | + public static function update_transaction_with_payment(): void |
|
| 256 | + { |
|
| 257 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 258 | + if ( |
|
| 259 | 259 | // are there any TXNs that need cleaning up ? |
| 260 | - empty(self::$_update_transactions_with_payment) |
|
| 261 | - // reschedule the cron if we can't hit the db right now |
|
| 262 | - || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
| 263 | - 'schedule_update_transaction_with_payment', |
|
| 264 | - self::$_update_transactions_with_payment |
|
| 265 | - ) |
|
| 266 | - ) { |
|
| 267 | - return; |
|
| 268 | - } |
|
| 269 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 270 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 271 | - // set revisit flag for payment processor |
|
| 272 | - $payment_processor->set_revisit(); |
|
| 273 | - // load EEM_Transaction |
|
| 274 | - EE_Registry::instance()->load_model('Transaction'); |
|
| 275 | - foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
| 276 | - // reschedule the cron if we can't hit the db right now |
|
| 277 | - if (DbStatus::isOffline()) { |
|
| 278 | - // reset cron job for updating the TXN |
|
| 279 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
| 280 | - time() + EE_Cron_Tasks::reschedule_timeout, |
|
| 281 | - $TXN_ID, |
|
| 282 | - $PAY_ID |
|
| 283 | - ); |
|
| 284 | - continue; |
|
| 285 | - } |
|
| 286 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 287 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 288 | - // verify transaction |
|
| 289 | - if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) { |
|
| 290 | - // now try to update the TXN with any payments |
|
| 291 | - $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
| 292 | - } |
|
| 293 | - unset(self::$_update_transactions_with_payment[ $TXN_ID ]); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /************ END OF UPDATE TRANSACTION WITH PAYMENT ************/ |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - /***************** EXPIRED TRANSACTION CHECK *****************/ |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * array of TXN IDs |
|
| 307 | - * |
|
| 308 | - * @var array |
|
| 309 | - */ |
|
| 310 | - protected static array $_expired_transactions = array(); |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * schedule_expired_transaction_check |
|
| 315 | - * sets a wp_schedule_single_event() for following up on TXNs after their session has expired |
|
| 316 | - * |
|
| 317 | - * @param int $timestamp |
|
| 318 | - * @param int $TXN_ID |
|
| 319 | - */ |
|
| 320 | - public static function schedule_expired_transaction_check( |
|
| 321 | - int $timestamp, |
|
| 322 | - int $TXN_ID |
|
| 323 | - ): void { |
|
| 324 | - // validate $TXN_ID and $timestamp |
|
| 325 | - $TXN_ID = absint($TXN_ID); |
|
| 326 | - $timestamp = absint($timestamp); |
|
| 327 | - if ($TXN_ID && $timestamp) { |
|
| 328 | - wp_schedule_single_event( |
|
| 329 | - $timestamp, |
|
| 330 | - 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
| 331 | - array($TXN_ID) |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * expired_transaction_check |
|
| 339 | - * this is the callback for the action hook: |
|
| 340 | - * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check' |
|
| 341 | - * which is utilized by wp_schedule_single_event() |
|
| 342 | - * in \EED_Single_Page_Checkout::_initialize_transaction(). |
|
| 343 | - * The passed TXN_ID gets added to an array, and then the |
|
| 344 | - * process_expired_transactions() function is hooked into |
|
| 345 | - * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
| 346 | - * processing of any failed transactions, because doing so now would be |
|
| 347 | - * too early and the required resources may not be available |
|
| 348 | - * |
|
| 349 | - * @param int $TXN_ID |
|
| 350 | - */ |
|
| 351 | - public static function expired_transaction_check(int $TXN_ID = 0): void |
|
| 352 | - { |
|
| 353 | - if (absint($TXN_ID)) { |
|
| 354 | - self::$_expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
| 355 | - add_action( |
|
| 356 | - 'shutdown', |
|
| 357 | - array('EE_Cron_Tasks', 'process_expired_transactions'), |
|
| 358 | - 5 |
|
| 359 | - ); |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * process_expired_transactions |
|
| 366 | - * loops through the self::$_expired_transactions array and processes any failed TXNs |
|
| 367 | - * |
|
| 368 | - * @throws EE_Error |
|
| 369 | - * @throws InvalidDataTypeException |
|
| 370 | - * @throws InvalidInterfaceException |
|
| 371 | - * @throws InvalidArgumentException |
|
| 372 | - * @throws ReflectionException |
|
| 373 | - * @throws DomainException |
|
| 374 | - * @throws RuntimeException |
|
| 375 | - */ |
|
| 376 | - public static function process_expired_transactions(): void |
|
| 377 | - { |
|
| 378 | - if ( |
|
| 260 | + empty(self::$_update_transactions_with_payment) |
|
| 261 | + // reschedule the cron if we can't hit the db right now |
|
| 262 | + || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
| 263 | + 'schedule_update_transaction_with_payment', |
|
| 264 | + self::$_update_transactions_with_payment |
|
| 265 | + ) |
|
| 266 | + ) { |
|
| 267 | + return; |
|
| 268 | + } |
|
| 269 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 270 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 271 | + // set revisit flag for payment processor |
|
| 272 | + $payment_processor->set_revisit(); |
|
| 273 | + // load EEM_Transaction |
|
| 274 | + EE_Registry::instance()->load_model('Transaction'); |
|
| 275 | + foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
| 276 | + // reschedule the cron if we can't hit the db right now |
|
| 277 | + if (DbStatus::isOffline()) { |
|
| 278 | + // reset cron job for updating the TXN |
|
| 279 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
| 280 | + time() + EE_Cron_Tasks::reschedule_timeout, |
|
| 281 | + $TXN_ID, |
|
| 282 | + $PAY_ID |
|
| 283 | + ); |
|
| 284 | + continue; |
|
| 285 | + } |
|
| 286 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 287 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 288 | + // verify transaction |
|
| 289 | + if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) { |
|
| 290 | + // now try to update the TXN with any payments |
|
| 291 | + $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
| 292 | + } |
|
| 293 | + unset(self::$_update_transactions_with_payment[ $TXN_ID ]); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /************ END OF UPDATE TRANSACTION WITH PAYMENT ************/ |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + /***************** EXPIRED TRANSACTION CHECK *****************/ |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * array of TXN IDs |
|
| 307 | + * |
|
| 308 | + * @var array |
|
| 309 | + */ |
|
| 310 | + protected static array $_expired_transactions = array(); |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * schedule_expired_transaction_check |
|
| 315 | + * sets a wp_schedule_single_event() for following up on TXNs after their session has expired |
|
| 316 | + * |
|
| 317 | + * @param int $timestamp |
|
| 318 | + * @param int $TXN_ID |
|
| 319 | + */ |
|
| 320 | + public static function schedule_expired_transaction_check( |
|
| 321 | + int $timestamp, |
|
| 322 | + int $TXN_ID |
|
| 323 | + ): void { |
|
| 324 | + // validate $TXN_ID and $timestamp |
|
| 325 | + $TXN_ID = absint($TXN_ID); |
|
| 326 | + $timestamp = absint($timestamp); |
|
| 327 | + if ($TXN_ID && $timestamp) { |
|
| 328 | + wp_schedule_single_event( |
|
| 329 | + $timestamp, |
|
| 330 | + 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
| 331 | + array($TXN_ID) |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * expired_transaction_check |
|
| 339 | + * this is the callback for the action hook: |
|
| 340 | + * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check' |
|
| 341 | + * which is utilized by wp_schedule_single_event() |
|
| 342 | + * in \EED_Single_Page_Checkout::_initialize_transaction(). |
|
| 343 | + * The passed TXN_ID gets added to an array, and then the |
|
| 344 | + * process_expired_transactions() function is hooked into |
|
| 345 | + * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
| 346 | + * processing of any failed transactions, because doing so now would be |
|
| 347 | + * too early and the required resources may not be available |
|
| 348 | + * |
|
| 349 | + * @param int $TXN_ID |
|
| 350 | + */ |
|
| 351 | + public static function expired_transaction_check(int $TXN_ID = 0): void |
|
| 352 | + { |
|
| 353 | + if (absint($TXN_ID)) { |
|
| 354 | + self::$_expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
| 355 | + add_action( |
|
| 356 | + 'shutdown', |
|
| 357 | + array('EE_Cron_Tasks', 'process_expired_transactions'), |
|
| 358 | + 5 |
|
| 359 | + ); |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * process_expired_transactions |
|
| 366 | + * loops through the self::$_expired_transactions array and processes any failed TXNs |
|
| 367 | + * |
|
| 368 | + * @throws EE_Error |
|
| 369 | + * @throws InvalidDataTypeException |
|
| 370 | + * @throws InvalidInterfaceException |
|
| 371 | + * @throws InvalidArgumentException |
|
| 372 | + * @throws ReflectionException |
|
| 373 | + * @throws DomainException |
|
| 374 | + * @throws RuntimeException |
|
| 375 | + */ |
|
| 376 | + public static function process_expired_transactions(): void |
|
| 377 | + { |
|
| 378 | + if ( |
|
| 379 | 379 | // are there any TXNs that need cleaning up ? |
| 380 | - empty(self::$_expired_transactions) |
|
| 381 | - // reschedule the cron if we can't hit the db right now |
|
| 382 | - || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
| 383 | - 'schedule_expired_transaction_check', |
|
| 384 | - self::$_expired_transactions |
|
| 385 | - ) |
|
| 386 | - ) { |
|
| 387 | - return; |
|
| 388 | - } |
|
| 389 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 390 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 391 | - // set revisit flag for txn processor |
|
| 392 | - $transaction_processor->set_revisit(); |
|
| 393 | - // load EEM_Transaction |
|
| 394 | - EE_Registry::instance()->load_model('Transaction'); |
|
| 395 | - foreach (self::$_expired_transactions as $TXN_ID) { |
|
| 396 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 397 | - // verify transaction and whether it is failed or not |
|
| 398 | - if ($transaction instanceof EE_Transaction) { |
|
| 399 | - switch ($transaction->status_ID()) { |
|
| 400 | - // Completed TXNs |
|
| 401 | - case EEM_Transaction::complete_status_code: |
|
| 402 | - // Don't update the transaction/registrations if the Primary Registration is Not Approved. |
|
| 403 | - $primary_registration = $transaction->primary_registration(); |
|
| 404 | - if ( |
|
| 405 | - $primary_registration instanceof EE_Registration |
|
| 406 | - && $primary_registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 407 | - ) { |
|
| 408 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 409 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 410 | - $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
| 411 | - $transaction, |
|
| 412 | - $transaction->last_payment() |
|
| 413 | - ); |
|
| 414 | - do_action( |
|
| 415 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', |
|
| 416 | - $transaction |
|
| 417 | - ); |
|
| 418 | - } |
|
| 419 | - break; |
|
| 420 | - // Overpaid TXNs |
|
| 421 | - case EEM_Transaction::overpaid_status_code: |
|
| 422 | - do_action( |
|
| 423 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', |
|
| 424 | - $transaction |
|
| 425 | - ); |
|
| 426 | - break; |
|
| 427 | - // Incomplete TXNs |
|
| 428 | - case EEM_Transaction::incomplete_status_code: |
|
| 429 | - do_action( |
|
| 430 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 431 | - $transaction |
|
| 432 | - ); |
|
| 433 | - // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
| 434 | - break; |
|
| 435 | - // Abandoned TXNs |
|
| 436 | - case EEM_Transaction::abandoned_status_code: |
|
| 437 | - // run hook before updating transaction, primarily so |
|
| 438 | - // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets |
|
| 439 | - do_action( |
|
| 440 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 441 | - $transaction |
|
| 442 | - ); |
|
| 443 | - // don't finalize the TXN if it has already been completed |
|
| 444 | - if ($transaction->all_reg_steps_completed() !== true) { |
|
| 445 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 446 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 447 | - // let's simulate an IPN here which will trigger any notifications that need to go out |
|
| 448 | - $payment_processor->update_txn_based_on_payment( |
|
| 449 | - $transaction, |
|
| 450 | - $transaction->last_payment(), |
|
| 451 | - true, |
|
| 452 | - true |
|
| 453 | - ); |
|
| 454 | - } |
|
| 455 | - break; |
|
| 456 | - // Failed TXNs |
|
| 457 | - case EEM_Transaction::failed_status_code: |
|
| 458 | - do_action( |
|
| 459 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 460 | - $transaction |
|
| 461 | - ); |
|
| 462 | - // todo : |
|
| 463 | - // perform garbage collection here and remove clean_out_junk_transactions() |
|
| 464 | - // $registrations = $transaction->registrations(); |
|
| 465 | - // if (! empty($registrations)) { |
|
| 466 | - // foreach ($registrations as $registration) { |
|
| 467 | - // if ($registration instanceof EE_Registration) { |
|
| 468 | - // $delete_registration = true; |
|
| 469 | - // if ($registration->attendee() instanceof EE_Attendee) { |
|
| 470 | - // $delete_registration = false; |
|
| 471 | - // } |
|
| 472 | - // if ($delete_registration) { |
|
| 473 | - // $registration->delete_permanently(); |
|
| 474 | - // $registration->delete_related_permanently(); |
|
| 475 | - // } |
|
| 476 | - // } |
|
| 477 | - // } |
|
| 478 | - // } |
|
| 479 | - break; |
|
| 480 | - } |
|
| 481 | - } |
|
| 482 | - unset(self::$_expired_transactions[ $TXN_ID ]); |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - /************* END OF EXPIRED TRANSACTION CHECK *************/ |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /************* START CLEAN UP BOT TRANSACTIONS **********************/ |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' |
|
| 496 | - * which is setup during activation to run on an hourly cron |
|
| 497 | - * |
|
| 498 | - * @throws EE_Error |
|
| 499 | - * @throws InvalidArgumentException |
|
| 500 | - * @throws InvalidDataTypeException |
|
| 501 | - * @throws InvalidInterfaceException |
|
| 502 | - * @throws DomainException |
|
| 503 | - * @throws ReflectionException |
|
| 504 | - */ |
|
| 505 | - public static function clean_out_junk_transactions(): void |
|
| 506 | - { |
|
| 507 | - if (DbStatus::isOnline()) { |
|
| 508 | - EED_Ticket_Sales_Monitor::reset_reservation_counts(); |
|
| 509 | - EEM_Transaction::instance()->delete_junk_transactions(); |
|
| 510 | - EEM_Registration::instance()->delete_registrations_with_no_transaction(); |
|
| 511 | - EEM_Line_Item::instance()->delete_line_items_with_no_transaction(); |
|
| 512 | - } |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that. |
|
| 518 | - * |
|
| 519 | - * @throws EE_Error |
|
| 520 | - * @throws InvalidDataTypeException |
|
| 521 | - * @throws InvalidInterfaceException |
|
| 522 | - * @throws InvalidArgumentException |
|
| 523 | - * @throws ReflectionException |
|
| 524 | - * @throws Exception |
|
| 525 | - */ |
|
| 526 | - public static function clean_out_old_gateway_logs(): void |
|
| 527 | - { |
|
| 528 | - if (DbStatus::isOnline()) { |
|
| 529 | - $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
|
| 530 | - $time_diff_for_comparison = apply_filters( |
|
| 531 | - 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
|
| 532 | - '-' . $reg_config->gateway_log_lifespan |
|
| 533 | - ); |
|
| 534 | - EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison)); |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /***************** FINALIZE ABANDONED TRANSACTIONS *****************/ |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * @var array |
|
| 544 | - */ |
|
| 545 | - protected static array $_abandoned_transactions = array(); |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * @param int $timestamp |
|
| 550 | - * @param int $TXN_ID |
|
| 551 | - *@deprecated |
|
| 552 | - */ |
|
| 553 | - public static function schedule_finalize_abandoned_transactions_check(int $timestamp, int $TXN_ID): void |
|
| 554 | - { |
|
| 555 | - EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * @param int $TXN_ID |
|
| 561 | - *@deprecated |
|
| 562 | - */ |
|
| 563 | - public static function check_for_abandoned_transactions(int $TXN_ID = 0): void |
|
| 564 | - { |
|
| 565 | - EE_Cron_Tasks::expired_transaction_check($TXN_ID); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * @deprecated |
|
| 571 | - * @throws EE_Error |
|
| 572 | - * @throws DomainException |
|
| 573 | - * @throws InvalidDataTypeException |
|
| 574 | - * @throws InvalidInterfaceException |
|
| 575 | - * @throws InvalidArgumentException |
|
| 576 | - * @throws ReflectionException |
|
| 577 | - * @throws RuntimeException |
|
| 578 | - */ |
|
| 579 | - public static function finalize_abandoned_transactions(): void |
|
| 580 | - { |
|
| 581 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 582 | - if ( |
|
| 380 | + empty(self::$_expired_transactions) |
|
| 381 | + // reschedule the cron if we can't hit the db right now |
|
| 382 | + || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
| 383 | + 'schedule_expired_transaction_check', |
|
| 384 | + self::$_expired_transactions |
|
| 385 | + ) |
|
| 386 | + ) { |
|
| 387 | + return; |
|
| 388 | + } |
|
| 389 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 390 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 391 | + // set revisit flag for txn processor |
|
| 392 | + $transaction_processor->set_revisit(); |
|
| 393 | + // load EEM_Transaction |
|
| 394 | + EE_Registry::instance()->load_model('Transaction'); |
|
| 395 | + foreach (self::$_expired_transactions as $TXN_ID) { |
|
| 396 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 397 | + // verify transaction and whether it is failed or not |
|
| 398 | + if ($transaction instanceof EE_Transaction) { |
|
| 399 | + switch ($transaction->status_ID()) { |
|
| 400 | + // Completed TXNs |
|
| 401 | + case EEM_Transaction::complete_status_code: |
|
| 402 | + // Don't update the transaction/registrations if the Primary Registration is Not Approved. |
|
| 403 | + $primary_registration = $transaction->primary_registration(); |
|
| 404 | + if ( |
|
| 405 | + $primary_registration instanceof EE_Registration |
|
| 406 | + && $primary_registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 407 | + ) { |
|
| 408 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 409 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 410 | + $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
| 411 | + $transaction, |
|
| 412 | + $transaction->last_payment() |
|
| 413 | + ); |
|
| 414 | + do_action( |
|
| 415 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', |
|
| 416 | + $transaction |
|
| 417 | + ); |
|
| 418 | + } |
|
| 419 | + break; |
|
| 420 | + // Overpaid TXNs |
|
| 421 | + case EEM_Transaction::overpaid_status_code: |
|
| 422 | + do_action( |
|
| 423 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', |
|
| 424 | + $transaction |
|
| 425 | + ); |
|
| 426 | + break; |
|
| 427 | + // Incomplete TXNs |
|
| 428 | + case EEM_Transaction::incomplete_status_code: |
|
| 429 | + do_action( |
|
| 430 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 431 | + $transaction |
|
| 432 | + ); |
|
| 433 | + // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
| 434 | + break; |
|
| 435 | + // Abandoned TXNs |
|
| 436 | + case EEM_Transaction::abandoned_status_code: |
|
| 437 | + // run hook before updating transaction, primarily so |
|
| 438 | + // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets |
|
| 439 | + do_action( |
|
| 440 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 441 | + $transaction |
|
| 442 | + ); |
|
| 443 | + // don't finalize the TXN if it has already been completed |
|
| 444 | + if ($transaction->all_reg_steps_completed() !== true) { |
|
| 445 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 446 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 447 | + // let's simulate an IPN here which will trigger any notifications that need to go out |
|
| 448 | + $payment_processor->update_txn_based_on_payment( |
|
| 449 | + $transaction, |
|
| 450 | + $transaction->last_payment(), |
|
| 451 | + true, |
|
| 452 | + true |
|
| 453 | + ); |
|
| 454 | + } |
|
| 455 | + break; |
|
| 456 | + // Failed TXNs |
|
| 457 | + case EEM_Transaction::failed_status_code: |
|
| 458 | + do_action( |
|
| 459 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 460 | + $transaction |
|
| 461 | + ); |
|
| 462 | + // todo : |
|
| 463 | + // perform garbage collection here and remove clean_out_junk_transactions() |
|
| 464 | + // $registrations = $transaction->registrations(); |
|
| 465 | + // if (! empty($registrations)) { |
|
| 466 | + // foreach ($registrations as $registration) { |
|
| 467 | + // if ($registration instanceof EE_Registration) { |
|
| 468 | + // $delete_registration = true; |
|
| 469 | + // if ($registration->attendee() instanceof EE_Attendee) { |
|
| 470 | + // $delete_registration = false; |
|
| 471 | + // } |
|
| 472 | + // if ($delete_registration) { |
|
| 473 | + // $registration->delete_permanently(); |
|
| 474 | + // $registration->delete_related_permanently(); |
|
| 475 | + // } |
|
| 476 | + // } |
|
| 477 | + // } |
|
| 478 | + // } |
|
| 479 | + break; |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + unset(self::$_expired_transactions[ $TXN_ID ]); |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + /************* END OF EXPIRED TRANSACTION CHECK *************/ |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /************* START CLEAN UP BOT TRANSACTIONS **********************/ |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' |
|
| 496 | + * which is setup during activation to run on an hourly cron |
|
| 497 | + * |
|
| 498 | + * @throws EE_Error |
|
| 499 | + * @throws InvalidArgumentException |
|
| 500 | + * @throws InvalidDataTypeException |
|
| 501 | + * @throws InvalidInterfaceException |
|
| 502 | + * @throws DomainException |
|
| 503 | + * @throws ReflectionException |
|
| 504 | + */ |
|
| 505 | + public static function clean_out_junk_transactions(): void |
|
| 506 | + { |
|
| 507 | + if (DbStatus::isOnline()) { |
|
| 508 | + EED_Ticket_Sales_Monitor::reset_reservation_counts(); |
|
| 509 | + EEM_Transaction::instance()->delete_junk_transactions(); |
|
| 510 | + EEM_Registration::instance()->delete_registrations_with_no_transaction(); |
|
| 511 | + EEM_Line_Item::instance()->delete_line_items_with_no_transaction(); |
|
| 512 | + } |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that. |
|
| 518 | + * |
|
| 519 | + * @throws EE_Error |
|
| 520 | + * @throws InvalidDataTypeException |
|
| 521 | + * @throws InvalidInterfaceException |
|
| 522 | + * @throws InvalidArgumentException |
|
| 523 | + * @throws ReflectionException |
|
| 524 | + * @throws Exception |
|
| 525 | + */ |
|
| 526 | + public static function clean_out_old_gateway_logs(): void |
|
| 527 | + { |
|
| 528 | + if (DbStatus::isOnline()) { |
|
| 529 | + $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
|
| 530 | + $time_diff_for_comparison = apply_filters( |
|
| 531 | + 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
|
| 532 | + '-' . $reg_config->gateway_log_lifespan |
|
| 533 | + ); |
|
| 534 | + EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison)); |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /***************** FINALIZE ABANDONED TRANSACTIONS *****************/ |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * @var array |
|
| 544 | + */ |
|
| 545 | + protected static array $_abandoned_transactions = array(); |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * @param int $timestamp |
|
| 550 | + * @param int $TXN_ID |
|
| 551 | + *@deprecated |
|
| 552 | + */ |
|
| 553 | + public static function schedule_finalize_abandoned_transactions_check(int $timestamp, int $TXN_ID): void |
|
| 554 | + { |
|
| 555 | + EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * @param int $TXN_ID |
|
| 561 | + *@deprecated |
|
| 562 | + */ |
|
| 563 | + public static function check_for_abandoned_transactions(int $TXN_ID = 0): void |
|
| 564 | + { |
|
| 565 | + EE_Cron_Tasks::expired_transaction_check($TXN_ID); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * @deprecated |
|
| 571 | + * @throws EE_Error |
|
| 572 | + * @throws DomainException |
|
| 573 | + * @throws InvalidDataTypeException |
|
| 574 | + * @throws InvalidInterfaceException |
|
| 575 | + * @throws InvalidArgumentException |
|
| 576 | + * @throws ReflectionException |
|
| 577 | + * @throws RuntimeException |
|
| 578 | + */ |
|
| 579 | + public static function finalize_abandoned_transactions(): void |
|
| 580 | + { |
|
| 581 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 582 | + if ( |
|
| 583 | 583 | // are there any TXNs that need cleaning up ? |
| 584 | - empty(self::$_abandoned_transactions) |
|
| 585 | - // reschedule the cron if we can't hit the db right now |
|
| 586 | - || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
| 587 | - 'schedule_expired_transaction_check', |
|
| 588 | - self::$_abandoned_transactions |
|
| 589 | - ) |
|
| 590 | - ) { |
|
| 591 | - return; |
|
| 592 | - } |
|
| 593 | - // combine our arrays of transaction IDs |
|
| 594 | - self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions; |
|
| 595 | - // and deal with abandoned transactions here now... |
|
| 596 | - EE_Cron_Tasks::process_expired_transactions(); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - /************* END OF FINALIZE ABANDONED TRANSACTIONS *************/ |
|
| 584 | + empty(self::$_abandoned_transactions) |
|
| 585 | + // reschedule the cron if we can't hit the db right now |
|
| 586 | + || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
| 587 | + 'schedule_expired_transaction_check', |
|
| 588 | + self::$_abandoned_transactions |
|
| 589 | + ) |
|
| 590 | + ) { |
|
| 591 | + return; |
|
| 592 | + } |
|
| 593 | + // combine our arrays of transaction IDs |
|
| 594 | + self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions; |
|
| 595 | + // and deal with abandoned transactions here now... |
|
| 596 | + EE_Cron_Tasks::process_expired_transactions(); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + /************* END OF FINALIZE ABANDONED TRANSACTIONS *************/ |
|
| 601 | 601 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | public static function instance(): ?EE_Cron_Tasks |
| 28 | 28 | { |
| 29 | - if (! self::$_instance instanceof EE_Cron_Tasks) { |
|
| 29 | + if ( ! self::$_instance instanceof EE_Cron_Tasks) { |
|
| 30 | 30 | self::$_instance = new self(); |
| 31 | 31 | } |
| 32 | 32 | return self::$_instance; |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | add_action( |
| 61 | 61 | 'AHEE__EE_System__load_core_configuration__complete', |
| 62 | - function () { |
|
| 62 | + function() { |
|
| 63 | 63 | EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
| 64 | 64 | EE_Registry::instance()->NET_CFG->update_config(true, false); |
| 65 | 65 | add_option('ee_disabled_wp_cron_check', 1, '', false); |
@@ -107,10 +107,10 @@ discard block |
||
| 107 | 107 | foreach ($crons as $cron) { |
| 108 | 108 | /** @var array[] $cron */ |
| 109 | 109 | foreach ($ee_crons as $ee_cron) { |
| 110 | - if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) { |
|
| 110 | + if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) { |
|
| 111 | 111 | do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
| 112 | - foreach ($cron[ $ee_cron ] as $ee_cron_details) { |
|
| 113 | - if (! empty($ee_cron_details['args'])) { |
|
| 112 | + foreach ($cron[$ee_cron] as $ee_cron_details) { |
|
| 113 | + if ( ! empty($ee_cron_details['args'])) { |
|
| 114 | 114 | do_action( |
| 115 | 115 | 'AHEE_log', |
| 116 | 116 | __CLASS__, |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | public static function reschedule_cron_for_transactions_if_maintenance_mode(string $cron_task, array $TXN_IDs): bool |
| 139 | 139 | { |
| 140 | - if (! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
| 140 | + if ( ! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
| 141 | 141 | throw new DomainException( |
| 142 | 142 | sprintf( |
| 143 | 143 | esc_html__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | { |
| 228 | 228 | do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
| 229 | 229 | if (absint($TXN_ID)) { |
| 230 | - self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID; |
|
| 230 | + self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID; |
|
| 231 | 231 | add_action( |
| 232 | 232 | 'shutdown', |
| 233 | 233 | array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | // now try to update the TXN with any payments |
| 291 | 291 | $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
| 292 | 292 | } |
| 293 | - unset(self::$_update_transactions_with_payment[ $TXN_ID ]); |
|
| 293 | + unset(self::$_update_transactions_with_payment[$TXN_ID]); |
|
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | 296 | |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | public static function expired_transaction_check(int $TXN_ID = 0): void |
| 352 | 352 | { |
| 353 | 353 | if (absint($TXN_ID)) { |
| 354 | - self::$_expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
| 354 | + self::$_expired_transactions[$TXN_ID] = $TXN_ID; |
|
| 355 | 355 | add_action( |
| 356 | 356 | 'shutdown', |
| 357 | 357 | array('EE_Cron_Tasks', 'process_expired_transactions'), |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | break; |
| 480 | 480 | } |
| 481 | 481 | } |
| 482 | - unset(self::$_expired_transactions[ $TXN_ID ]); |
|
| 482 | + unset(self::$_expired_transactions[$TXN_ID]); |
|
| 483 | 483 | } |
| 484 | 484 | } |
| 485 | 485 | |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
| 530 | 530 | $time_diff_for_comparison = apply_filters( |
| 531 | 531 | 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
| 532 | - '-' . $reg_config->gateway_log_lifespan |
|
| 532 | + '-'.$reg_config->gateway_log_lifespan |
|
| 533 | 533 | ); |
| 534 | 534 | EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison)); |
| 535 | 535 | } |
@@ -9,125 +9,125 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | abstract class EE_Configurable extends EE_Base |
| 11 | 11 | { |
| 12 | - protected ?EE_Config_Base $_config = null; |
|
| 13 | - |
|
| 14 | - protected string $_config_section = ''; |
|
| 15 | - |
|
| 16 | - protected string $_config_class = ''; |
|
| 17 | - |
|
| 18 | - protected string $_config_name = ''; |
|
| 19 | - |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @param string $config_section |
|
| 23 | - */ |
|
| 24 | - public function set_config_section(string $config_section = '') |
|
| 25 | - { |
|
| 26 | - $this->_config_section = ! empty($config_section) ? $config_section : 'modules'; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @return string |
|
| 32 | - */ |
|
| 33 | - public function config_section(): string |
|
| 34 | - { |
|
| 35 | - return $this->_config_section; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @param string $config_class |
|
| 41 | - */ |
|
| 42 | - public function set_config_class(string $config_class = '') |
|
| 43 | - { |
|
| 44 | - $this->_config_class = $config_class; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function config_class(): string |
|
| 52 | - { |
|
| 53 | - return $this->_config_class; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param string $config_name |
|
| 59 | - */ |
|
| 60 | - public function set_config_name(string $config_name) |
|
| 61 | - { |
|
| 62 | - $this->_config_name = ! empty($config_name) ? $config_name : get_called_class(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 69 | - public function config_name(): string |
|
| 70 | - { |
|
| 71 | - return $this->_config_name; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * set_config |
|
| 77 | - * this method integrates directly with EE_Config to set up the config object for this class |
|
| 78 | - * |
|
| 79 | - * @access protected |
|
| 80 | - * @param EE_Config_Base $config_obj |
|
| 81 | - * @return EE_Config_Base|null |
|
| 82 | - */ |
|
| 83 | - protected function _set_config(EE_Config_Base $config_obj): ?EE_Config_Base |
|
| 84 | - { |
|
| 85 | - return EE_Config::instance()->set_config( |
|
| 86 | - $this->config_section(), |
|
| 87 | - $this->config_name(), |
|
| 88 | - $this->config_class(), |
|
| 89 | - $config_obj |
|
| 90 | - ); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * this method integrates directly with EE_Config to update an existing config object for this class |
|
| 96 | - * |
|
| 97 | - * @param EE_Config_Base $config_obj |
|
| 98 | - * @return bool |
|
| 99 | - * @throws EE_Error |
|
| 100 | - */ |
|
| 101 | - public function _update_config(EE_Config_Base $config_obj): bool |
|
| 102 | - { |
|
| 103 | - $config_class = $this->config_class(); |
|
| 104 | - if (! $config_obj instanceof $config_class) { |
|
| 105 | - throw new EE_Error( |
|
| 106 | - sprintf( |
|
| 107 | - esc_html__('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
|
| 108 | - print_r($config_obj, true), |
|
| 109 | - $config_class |
|
| 110 | - ) |
|
| 111 | - ); |
|
| 112 | - } |
|
| 113 | - return EE_Config::instance()->update_config($this->config_section(), $this->config_name(), $config_obj); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * gets the class's config object |
|
| 119 | - * |
|
| 120 | - * @return EE_Config_Base |
|
| 121 | - */ |
|
| 122 | - public function config() |
|
| 123 | - { |
|
| 124 | - if (empty($this->_config)) { |
|
| 125 | - $this->_config = EE_Config::instance()->get_config( |
|
| 126 | - $this->config_section(), |
|
| 127 | - $this->config_name(), |
|
| 128 | - $this->config_class() |
|
| 129 | - ); |
|
| 130 | - } |
|
| 131 | - return $this->_config; |
|
| 132 | - } |
|
| 12 | + protected ?EE_Config_Base $_config = null; |
|
| 13 | + |
|
| 14 | + protected string $_config_section = ''; |
|
| 15 | + |
|
| 16 | + protected string $_config_class = ''; |
|
| 17 | + |
|
| 18 | + protected string $_config_name = ''; |
|
| 19 | + |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @param string $config_section |
|
| 23 | + */ |
|
| 24 | + public function set_config_section(string $config_section = '') |
|
| 25 | + { |
|
| 26 | + $this->_config_section = ! empty($config_section) ? $config_section : 'modules'; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @return string |
|
| 32 | + */ |
|
| 33 | + public function config_section(): string |
|
| 34 | + { |
|
| 35 | + return $this->_config_section; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @param string $config_class |
|
| 41 | + */ |
|
| 42 | + public function set_config_class(string $config_class = '') |
|
| 43 | + { |
|
| 44 | + $this->_config_class = $config_class; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function config_class(): string |
|
| 52 | + { |
|
| 53 | + return $this->_config_class; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param string $config_name |
|
| 59 | + */ |
|
| 60 | + public function set_config_name(string $config_name) |
|
| 61 | + { |
|
| 62 | + $this->_config_name = ! empty($config_name) ? $config_name : get_called_class(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | + public function config_name(): string |
|
| 70 | + { |
|
| 71 | + return $this->_config_name; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * set_config |
|
| 77 | + * this method integrates directly with EE_Config to set up the config object for this class |
|
| 78 | + * |
|
| 79 | + * @access protected |
|
| 80 | + * @param EE_Config_Base $config_obj |
|
| 81 | + * @return EE_Config_Base|null |
|
| 82 | + */ |
|
| 83 | + protected function _set_config(EE_Config_Base $config_obj): ?EE_Config_Base |
|
| 84 | + { |
|
| 85 | + return EE_Config::instance()->set_config( |
|
| 86 | + $this->config_section(), |
|
| 87 | + $this->config_name(), |
|
| 88 | + $this->config_class(), |
|
| 89 | + $config_obj |
|
| 90 | + ); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * this method integrates directly with EE_Config to update an existing config object for this class |
|
| 96 | + * |
|
| 97 | + * @param EE_Config_Base $config_obj |
|
| 98 | + * @return bool |
|
| 99 | + * @throws EE_Error |
|
| 100 | + */ |
|
| 101 | + public function _update_config(EE_Config_Base $config_obj): bool |
|
| 102 | + { |
|
| 103 | + $config_class = $this->config_class(); |
|
| 104 | + if (! $config_obj instanceof $config_class) { |
|
| 105 | + throw new EE_Error( |
|
| 106 | + sprintf( |
|
| 107 | + esc_html__('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
|
| 108 | + print_r($config_obj, true), |
|
| 109 | + $config_class |
|
| 110 | + ) |
|
| 111 | + ); |
|
| 112 | + } |
|
| 113 | + return EE_Config::instance()->update_config($this->config_section(), $this->config_name(), $config_obj); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * gets the class's config object |
|
| 119 | + * |
|
| 120 | + * @return EE_Config_Base |
|
| 121 | + */ |
|
| 122 | + public function config() |
|
| 123 | + { |
|
| 124 | + if (empty($this->_config)) { |
|
| 125 | + $this->_config = EE_Config::instance()->get_config( |
|
| 126 | + $this->config_section(), |
|
| 127 | + $this->config_name(), |
|
| 128 | + $this->config_class() |
|
| 129 | + ); |
|
| 130 | + } |
|
| 131 | + return $this->_config; |
|
| 132 | + } |
|
| 133 | 133 | } |
@@ -101,7 +101,7 @@ |
||
| 101 | 101 | public function _update_config(EE_Config_Base $config_obj): bool |
| 102 | 102 | { |
| 103 | 103 | $config_class = $this->config_class(); |
| 104 | - if (! $config_obj instanceof $config_class) { |
|
| 104 | + if ( ! $config_obj instanceof $config_class) { |
|
| 105 | 105 | throw new EE_Error( |
| 106 | 106 | sprintf( |
| 107 | 107 | esc_html__('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
@@ -20,1512 +20,1512 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | final class EE_Config implements ResettableInterface |
| 22 | 22 | { |
| 23 | - const OPTION_NAME = 'ee_config'; |
|
| 24 | - |
|
| 25 | - const LOG_NAME = 'ee_config_log'; |
|
| 26 | - |
|
| 27 | - const LOG_LENGTH = 100; |
|
| 28 | - |
|
| 29 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * instance of the EE_Config object |
|
| 33 | - * |
|
| 34 | - * @var EE_Config $_instance |
|
| 35 | - * @access private |
|
| 36 | - */ |
|
| 37 | - private static $_instance; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var boolean $_logging_enabled |
|
| 41 | - */ |
|
| 42 | - private static $_logging_enabled = false; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 46 | - */ |
|
| 47 | - private $legacy_shortcodes_manager; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * An StdClass whose property names are addon slugs, |
|
| 51 | - * and values are their config classes |
|
| 52 | - * |
|
| 53 | - * @var StdClass |
|
| 54 | - */ |
|
| 55 | - public $addons; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var EE_Admin_Config |
|
| 59 | - */ |
|
| 60 | - public $admin; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var EE_Core_Config |
|
| 64 | - */ |
|
| 65 | - public $core; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var EE_Currency_Config |
|
| 69 | - */ |
|
| 70 | - public $currency; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @var EE_Organization_Config |
|
| 74 | - */ |
|
| 75 | - public $organization; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @var EE_Registration_Config |
|
| 79 | - */ |
|
| 80 | - public $registration; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @var EE_Template_Config |
|
| 84 | - */ |
|
| 85 | - public $template_settings; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Holds EE environment values. |
|
| 89 | - * |
|
| 90 | - * @var EE_Environment_Config |
|
| 91 | - */ |
|
| 92 | - public $environment; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * settings pertaining to Google maps |
|
| 96 | - * |
|
| 97 | - * @var EE_Map_Config |
|
| 98 | - */ |
|
| 99 | - public $map_settings; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * settings pertaining to Taxes |
|
| 103 | - * |
|
| 104 | - * @var EE_Tax_Config |
|
| 105 | - */ |
|
| 106 | - public $tax_settings; |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Settings pertaining to global messages settings. |
|
| 110 | - * |
|
| 111 | - * @var EE_Messages_Config |
|
| 112 | - */ |
|
| 113 | - public $messages; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @deprecated |
|
| 117 | - * @var EE_Gateway_Config |
|
| 118 | - */ |
|
| 119 | - public $gateway; |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @var array |
|
| 123 | - */ |
|
| 124 | - private $_addon_option_names = array(); |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @var array |
|
| 128 | - */ |
|
| 129 | - private static $_module_route_map = array(); |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @var array |
|
| 133 | - */ |
|
| 134 | - private static $_module_forward_map = array(); |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @var array |
|
| 138 | - */ |
|
| 139 | - private static $_module_view_map = array(); |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @var bool |
|
| 143 | - */ |
|
| 144 | - private static $initialized = false; |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @singleton method used to instantiate class object |
|
| 149 | - * @access public |
|
| 150 | - * @return EE_Config instance |
|
| 151 | - */ |
|
| 152 | - public static function instance() |
|
| 153 | - { |
|
| 154 | - // check if class object is instantiated, and instantiated properly |
|
| 155 | - if (! self::$_instance instanceof EE_Config) { |
|
| 156 | - self::$_instance = new self(); |
|
| 157 | - } |
|
| 158 | - return self::$_instance; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Resets the config |
|
| 164 | - * |
|
| 165 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 166 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 167 | - * reflect its state in the database |
|
| 168 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 169 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 170 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 171 | - * site was put into maintenance mode) |
|
| 172 | - * @return EE_Config |
|
| 173 | - */ |
|
| 174 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 175 | - { |
|
| 176 | - if (self::$_instance instanceof EE_Config) { |
|
| 177 | - if ($hard_reset) { |
|
| 178 | - self::$_instance->legacy_shortcodes_manager = null; |
|
| 179 | - self::$_instance->_addon_option_names = array(); |
|
| 180 | - self::$_instance->_initialize_config(); |
|
| 181 | - self::$_instance->update_espresso_config(); |
|
| 182 | - } |
|
| 183 | - self::$_instance->update_addon_option_names(); |
|
| 184 | - } |
|
| 185 | - self::$_instance = null; |
|
| 186 | - self::$initialized = false; |
|
| 187 | - // we don't need to reset the static properties imo because those should |
|
| 188 | - // only change when a module is added or removed. Currently we don't |
|
| 189 | - // support removing a module during a request when it previously existed |
|
| 190 | - if ($reinstantiate) { |
|
| 191 | - return self::instance(); |
|
| 192 | - } else { |
|
| 193 | - return null; |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - private function __construct() |
|
| 199 | - { |
|
| 200 | - if (self::$initialized) { |
|
| 201 | - return; |
|
| 202 | - } |
|
| 203 | - self::$initialized = true; |
|
| 204 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 205 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 206 | - // setup empty config classes |
|
| 207 | - $this->_initialize_config(); |
|
| 208 | - // load existing EE site settings |
|
| 209 | - $this->_load_core_config(); |
|
| 210 | - // confirm everything loaded correctly and set filtered defaults if not |
|
| 211 | - $this->_verify_config(); |
|
| 212 | - // register shortcodes and modules |
|
| 213 | - add_action( |
|
| 214 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 215 | - [$this, 'register_shortcodes_and_modules'], |
|
| 216 | - 999 |
|
| 217 | - ); |
|
| 218 | - // initialize shortcodes and modules |
|
| 219 | - add_action('AHEE__EE_System__core_loaded_and_ready', [$this, 'initialize_shortcodes_and_modules']); |
|
| 220 | - // register widgets |
|
| 221 | - add_action('widgets_init', [$this, 'widgets_init'], 10); |
|
| 222 | - // shutdown |
|
| 223 | - add_action('shutdown', [$this, 'shutdown'], 10); |
|
| 224 | - // construct__end hook |
|
| 225 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
| 226 | - // hardcoded hack |
|
| 227 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * @return boolean |
|
| 233 | - */ |
|
| 234 | - public static function logging_enabled() |
|
| 235 | - { |
|
| 236 | - return self::$_logging_enabled; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * use to get the current theme if needed from static context |
|
| 242 | - * |
|
| 243 | - * @return string current theme set. |
|
| 244 | - */ |
|
| 245 | - public static function get_current_theme() |
|
| 246 | - { |
|
| 247 | - return self::$_instance->template_settings->current_espresso_theme ?? 'Espresso_Arabica_2014'; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * _initialize_config |
|
| 253 | - * |
|
| 254 | - * @access private |
|
| 255 | - * @return void |
|
| 256 | - */ |
|
| 257 | - private function _initialize_config() |
|
| 258 | - { |
|
| 259 | - EE_Config::trim_log(); |
|
| 260 | - // set defaults |
|
| 261 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 262 | - $this->addons = new stdClass(); |
|
| 263 | - // set _module_route_map |
|
| 264 | - EE_Config::$_module_route_map = array(); |
|
| 265 | - // set _module_forward_map |
|
| 266 | - EE_Config::$_module_forward_map = array(); |
|
| 267 | - // set _module_view_map |
|
| 268 | - EE_Config::$_module_view_map = array(); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * load core plugin configuration |
|
| 274 | - * |
|
| 275 | - * @access private |
|
| 276 | - * @return void |
|
| 277 | - */ |
|
| 278 | - private function _load_core_config() |
|
| 279 | - { |
|
| 280 | - // load_core_config__start hook |
|
| 281 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 282 | - $espresso_config = (array) $this->get_espresso_config(); |
|
| 283 | - // need to move the "addons" element to the end of the config array |
|
| 284 | - // in case an addon config references one of the other config classes |
|
| 285 | - $addons = $espresso_config['addons'] ?? new StdClass(); |
|
| 286 | - unset($espresso_config['addons']); |
|
| 287 | - $espresso_config['addons'] = $addons; |
|
| 288 | - foreach ($espresso_config as $config => $settings) { |
|
| 289 | - // load_core_config__start hook |
|
| 290 | - $settings = apply_filters( |
|
| 291 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 292 | - $settings, |
|
| 293 | - $config, |
|
| 294 | - $this |
|
| 295 | - ); |
|
| 296 | - if (is_object($settings) && property_exists($this, $config)) { |
|
| 297 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 298 | - // call configs populate method to ensure any defaults are set for empty values. |
|
| 299 | - if (method_exists($settings, 'populate')) { |
|
| 300 | - $this->{$config}->populate(); |
|
| 301 | - } |
|
| 302 | - if (method_exists($settings, 'do_hooks')) { |
|
| 303 | - $this->{$config}->do_hooks(); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 308 | - $this->update_espresso_config(); |
|
| 309 | - } |
|
| 310 | - // load_core_config__end hook |
|
| 311 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * _verify_config |
|
| 317 | - * |
|
| 318 | - * @access protected |
|
| 319 | - * @return void |
|
| 320 | - */ |
|
| 321 | - protected function _verify_config() |
|
| 322 | - { |
|
| 323 | - $this->core = $this->core instanceof EE_Core_Config |
|
| 324 | - ? $this->core |
|
| 325 | - : new EE_Core_Config(); |
|
| 326 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 327 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 328 | - ? $this->organization |
|
| 329 | - : new EE_Organization_Config(); |
|
| 330 | - $this->organization = apply_filters( |
|
| 331 | - 'FHEE__EE_Config___initialize_config__organization', |
|
| 332 | - $this->organization |
|
| 333 | - ); |
|
| 334 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 335 | - ? $this->currency |
|
| 336 | - : new EE_Currency_Config(); |
|
| 337 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 338 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 339 | - ? $this->registration |
|
| 340 | - : new EE_Registration_Config(); |
|
| 341 | - $this->registration = apply_filters( |
|
| 342 | - 'FHEE__EE_Config___initialize_config__registration', |
|
| 343 | - $this->registration |
|
| 344 | - ); |
|
| 345 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 346 | - ? $this->admin |
|
| 347 | - : new EE_Admin_Config(); |
|
| 348 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 349 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 350 | - ? $this->template_settings |
|
| 351 | - : new EE_Template_Config(); |
|
| 352 | - $this->template_settings = apply_filters( |
|
| 353 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 354 | - $this->template_settings |
|
| 355 | - ); |
|
| 356 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 357 | - ? $this->map_settings |
|
| 358 | - : new EE_Map_Config(); |
|
| 359 | - $this->map_settings = apply_filters( |
|
| 360 | - 'FHEE__EE_Config___initialize_config__map_settings', |
|
| 361 | - $this->map_settings |
|
| 362 | - ); |
|
| 363 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 364 | - ? $this->environment |
|
| 365 | - : new EE_Environment_Config(); |
|
| 366 | - $this->environment = apply_filters( |
|
| 367 | - 'FHEE__EE_Config___initialize_config__environment', |
|
| 368 | - $this->environment |
|
| 369 | - ); |
|
| 370 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 371 | - ? $this->tax_settings |
|
| 372 | - : new EE_Tax_Config(); |
|
| 373 | - $this->tax_settings = apply_filters( |
|
| 374 | - 'FHEE__EE_Config___initialize_config__tax_settings', |
|
| 375 | - $this->tax_settings |
|
| 376 | - ); |
|
| 377 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 378 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 379 | - ? $this->messages |
|
| 380 | - : new EE_Messages_Config(); |
|
| 381 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 382 | - ? $this->gateway |
|
| 383 | - : new EE_Gateway_Config(); |
|
| 384 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 385 | - $this->legacy_shortcodes_manager = null; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * get_espresso_config |
|
| 391 | - * |
|
| 392 | - * @access public |
|
| 393 | - * @return array of espresso config stuff |
|
| 394 | - */ |
|
| 395 | - public function get_espresso_config() |
|
| 396 | - { |
|
| 397 | - // grab espresso configuration |
|
| 398 | - return apply_filters( |
|
| 399 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 400 | - get_option(EE_Config::OPTION_NAME, array()) |
|
| 401 | - ); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * double_check_config_comparison |
|
| 407 | - * |
|
| 408 | - * @access public |
|
| 409 | - * @param string $option |
|
| 410 | - * @param $old_value |
|
| 411 | - * @param $value |
|
| 412 | - */ |
|
| 413 | - public function double_check_config_comparison($option, $old_value, $value) |
|
| 414 | - { |
|
| 415 | - // make sure we're checking the ee config |
|
| 416 | - if ($option === EE_Config::OPTION_NAME) { |
|
| 417 | - // run a loose comparison of the old value against the new value for type and properties, |
|
| 418 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 419 | - if ($value != $old_value) { |
|
| 420 | - // if they are NOT the same, then remove the hook, |
|
| 421 | - // which means the subsequent update results will be based solely on the update query results |
|
| 422 | - // the reason we do this is because, as stated above, |
|
| 423 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 424 | - // this happens PRIOR to serialization and any subsequent update. |
|
| 425 | - // If values are found to match their previous old value, |
|
| 426 | - // then WP bails before performing any update. |
|
| 427 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 428 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 429 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 430 | - // MySQL MAY ALSO NOT perform the update because |
|
| 431 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 432 | - // This results in the query returning an "affected rows" value of ZERO, |
|
| 433 | - // which gets returned immediately by WP update_option and looks like an error. |
|
| 434 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * update_espresso_config |
|
| 442 | - * |
|
| 443 | - * @access public |
|
| 444 | - */ |
|
| 445 | - protected function _reset_espresso_addon_config() |
|
| 446 | - { |
|
| 447 | - $this->_addon_option_names = array(); |
|
| 448 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 449 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 450 | - if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 451 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 452 | - } |
|
| 453 | - $this->addons->{$addon_name} = null; |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * update_espresso_config |
|
| 460 | - * |
|
| 461 | - * @access public |
|
| 462 | - * @param bool $add_success |
|
| 463 | - * @param bool $add_error |
|
| 464 | - * @return bool |
|
| 465 | - */ |
|
| 466 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
| 467 | - { |
|
| 468 | - // don't allow config updates during WP heartbeats |
|
| 469 | - /** @var RequestInterface $request */ |
|
| 470 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 471 | - if ($request->isWordPressHeartbeat()) { |
|
| 472 | - return false; |
|
| 473 | - } |
|
| 474 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 475 | - // $clone = clone( self::$_instance ); |
|
| 476 | - // self::$_instance = NULL; |
|
| 477 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 478 | - $this->_reset_espresso_addon_config(); |
|
| 479 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 480 | - // but BEFORE the actual update occurs |
|
| 481 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 482 | - // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 483 | - $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 484 | - $this->legacy_shortcodes_manager = null; |
|
| 485 | - // now update "ee_config" |
|
| 486 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 487 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 488 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
| 489 | - // if not saved... check if the hook we just added still exists; |
|
| 490 | - // if it does, it means one of two things: |
|
| 491 | - // that update_option bailed at the($value === $old_value) conditional, |
|
| 492 | - // or... |
|
| 493 | - // the db update query returned 0 rows affected |
|
| 494 | - // (probably because the data value was the same from its perspective) |
|
| 495 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 496 | - // but just means no update occurred, so don't display an error to the user. |
|
| 497 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 498 | - // then it means that something truly went wrong |
|
| 499 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 500 | - // remove our action since we don't want it in the system anymore |
|
| 501 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 502 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 503 | - // self::$_instance = $clone; |
|
| 504 | - // unset( $clone ); |
|
| 505 | - // if config remains the same or was updated successfully |
|
| 506 | - if ($saved) { |
|
| 507 | - if ($add_success) { |
|
| 508 | - EE_Error::add_success( |
|
| 509 | - esc_html__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 510 | - __FILE__, |
|
| 511 | - __FUNCTION__, |
|
| 512 | - __LINE__ |
|
| 513 | - ); |
|
| 514 | - } |
|
| 515 | - return true; |
|
| 516 | - } else { |
|
| 517 | - if ($add_error) { |
|
| 518 | - EE_Error::add_error( |
|
| 519 | - esc_html__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 520 | - __FILE__, |
|
| 521 | - __FUNCTION__, |
|
| 522 | - __LINE__ |
|
| 523 | - ); |
|
| 524 | - } |
|
| 525 | - return false; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * _verify_config_params |
|
| 532 | - * |
|
| 533 | - * @access private |
|
| 534 | - * @param string $section |
|
| 535 | - * @param string $name |
|
| 536 | - * @param string $config_class |
|
| 537 | - * @param EE_Config_Base $config_obj |
|
| 538 | - * @param array $tests_to_run |
|
| 539 | - * @param bool $display_errors |
|
| 540 | - * @return bool TRUE on success, FALSE on fail |
|
| 541 | - */ |
|
| 542 | - private function _verify_config_params( |
|
| 543 | - $section = '', |
|
| 544 | - $name = '', |
|
| 545 | - $config_class = '', |
|
| 546 | - $config_obj = null, |
|
| 547 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 548 | - $display_errors = true |
|
| 549 | - ) { |
|
| 550 | - try { |
|
| 551 | - foreach ($tests_to_run as $test) { |
|
| 552 | - switch ($test) { |
|
| 553 | - // TEST #1 : check that section was set |
|
| 554 | - case 1: |
|
| 555 | - if (empty($section)) { |
|
| 556 | - if ($display_errors) { |
|
| 557 | - throw new EE_Error( |
|
| 558 | - sprintf( |
|
| 559 | - esc_html__( |
|
| 560 | - 'No configuration section has been provided while attempting to save "%s".', |
|
| 561 | - 'event_espresso' |
|
| 562 | - ), |
|
| 563 | - $config_class |
|
| 564 | - ) |
|
| 565 | - ); |
|
| 566 | - } |
|
| 567 | - return false; |
|
| 568 | - } |
|
| 569 | - break; |
|
| 570 | - // TEST #2 : check that settings section exists |
|
| 571 | - case 2: |
|
| 572 | - if (! isset($this->{$section})) { |
|
| 573 | - if ($display_errors) { |
|
| 574 | - throw new EE_Error( |
|
| 575 | - sprintf( |
|
| 576 | - esc_html__('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 577 | - $section |
|
| 578 | - ) |
|
| 579 | - ); |
|
| 580 | - } |
|
| 581 | - return false; |
|
| 582 | - } |
|
| 583 | - break; |
|
| 584 | - // TEST #3 : check that section is the proper format |
|
| 585 | - case 3: |
|
| 586 | - if ( |
|
| 587 | - ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 588 | - ) { |
|
| 589 | - if ($display_errors) { |
|
| 590 | - throw new EE_Error( |
|
| 591 | - sprintf( |
|
| 592 | - esc_html__( |
|
| 593 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
| 594 | - 'event_espresso' |
|
| 595 | - ), |
|
| 596 | - $section |
|
| 597 | - ) |
|
| 598 | - ); |
|
| 599 | - } |
|
| 600 | - return false; |
|
| 601 | - } |
|
| 602 | - break; |
|
| 603 | - // TEST #4 : check that config section name has been set |
|
| 604 | - case 4: |
|
| 605 | - if (empty($name)) { |
|
| 606 | - if ($display_errors) { |
|
| 607 | - throw new EE_Error( |
|
| 608 | - esc_html__( |
|
| 609 | - 'No name has been provided for the specific configuration section.', |
|
| 610 | - 'event_espresso' |
|
| 611 | - ) |
|
| 612 | - ); |
|
| 613 | - } |
|
| 614 | - return false; |
|
| 615 | - } |
|
| 616 | - break; |
|
| 617 | - // TEST #5 : check that a config class name has been set |
|
| 618 | - case 5: |
|
| 619 | - if (empty($config_class)) { |
|
| 620 | - if ($display_errors) { |
|
| 621 | - throw new EE_Error( |
|
| 622 | - esc_html__( |
|
| 623 | - 'No class name has been provided for the specific configuration section.', |
|
| 624 | - 'event_espresso' |
|
| 625 | - ) |
|
| 626 | - ); |
|
| 627 | - } |
|
| 628 | - return false; |
|
| 629 | - } |
|
| 630 | - break; |
|
| 631 | - // TEST #6 : verify config class is accessible |
|
| 632 | - case 6: |
|
| 633 | - if (! class_exists($config_class)) { |
|
| 634 | - if ($display_errors) { |
|
| 635 | - throw new EE_Error( |
|
| 636 | - sprintf( |
|
| 637 | - esc_html__( |
|
| 638 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 639 | - 'event_espresso' |
|
| 640 | - ), |
|
| 641 | - $config_class |
|
| 642 | - ) |
|
| 643 | - ); |
|
| 644 | - } |
|
| 645 | - return false; |
|
| 646 | - } |
|
| 647 | - break; |
|
| 648 | - // TEST #7 : check that config has even been set |
|
| 649 | - case 7: |
|
| 650 | - if (! isset($this->{$section}->{$name})) { |
|
| 651 | - if ($display_errors) { |
|
| 652 | - throw new EE_Error( |
|
| 653 | - sprintf( |
|
| 654 | - esc_html__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 655 | - $section, |
|
| 656 | - $name |
|
| 657 | - ) |
|
| 658 | - ); |
|
| 659 | - } |
|
| 660 | - return false; |
|
| 661 | - } else { |
|
| 662 | - // and make sure it's not serialized |
|
| 663 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 664 | - } |
|
| 665 | - break; |
|
| 666 | - // TEST #8 : check that config is the requested type |
|
| 667 | - case 8: |
|
| 668 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 669 | - if ($display_errors) { |
|
| 670 | - throw new EE_Error( |
|
| 671 | - sprintf( |
|
| 672 | - esc_html__( |
|
| 673 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 674 | - 'event_espresso' |
|
| 675 | - ), |
|
| 676 | - $section, |
|
| 677 | - $name, |
|
| 678 | - $config_class |
|
| 679 | - ) |
|
| 680 | - ); |
|
| 681 | - } |
|
| 682 | - return false; |
|
| 683 | - } |
|
| 684 | - break; |
|
| 685 | - // TEST #9 : verify config object |
|
| 686 | - case 9: |
|
| 687 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 688 | - if ($display_errors) { |
|
| 689 | - throw new EE_Error( |
|
| 690 | - sprintf( |
|
| 691 | - esc_html__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 692 | - print_r($config_obj, true) |
|
| 693 | - ) |
|
| 694 | - ); |
|
| 695 | - } |
|
| 696 | - return false; |
|
| 697 | - } |
|
| 698 | - break; |
|
| 699 | - } |
|
| 700 | - } |
|
| 701 | - } catch (EE_Error $e) { |
|
| 702 | - $e->get_error(); |
|
| 703 | - } |
|
| 704 | - // you have successfully run the gauntlet |
|
| 705 | - return true; |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * _generate_config_option_name |
|
| 711 | - * |
|
| 712 | - * @access protected |
|
| 713 | - * @param string $section |
|
| 714 | - * @param string $name |
|
| 715 | - * @return string |
|
| 716 | - */ |
|
| 717 | - private function _generate_config_option_name($section = '', $name = '') |
|
| 718 | - { |
|
| 719 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * _set_config_class |
|
| 725 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 726 | - * |
|
| 727 | - * @access private |
|
| 728 | - * @param string $config_class |
|
| 729 | - * @param string $name |
|
| 730 | - * @return string |
|
| 731 | - */ |
|
| 732 | - private function _set_config_class($config_class = '', $name = '') |
|
| 733 | - { |
|
| 734 | - return ! empty($config_class) |
|
| 735 | - ? $config_class |
|
| 736 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * @param string $section |
|
| 742 | - * @param string $name |
|
| 743 | - * @param string $config_class |
|
| 744 | - * @param EE_Config_Base|null $config_obj |
|
| 745 | - * @return EE_Config_Base |
|
| 746 | - */ |
|
| 747 | - public function set_config( |
|
| 748 | - string $section = '', |
|
| 749 | - string $name = '', |
|
| 750 | - string $config_class = '', |
|
| 751 | - EE_Config_Base $config_obj = null |
|
| 752 | - ): ?EE_Config_Base { |
|
| 753 | - // ensure config class is set to something |
|
| 754 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 755 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 756 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 757 | - return null; |
|
| 758 | - } |
|
| 759 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 760 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 761 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 762 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 763 | - $this->update_addon_option_names(); |
|
| 764 | - } |
|
| 765 | - // verify the incoming config object but suppress errors |
|
| 766 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 767 | - $config_obj = new $config_class(); |
|
| 768 | - } |
|
| 769 | - if (get_option($config_option_name)) { |
|
| 770 | - EE_Config::log($config_option_name); |
|
| 771 | - try { |
|
| 772 | - update_option($config_option_name, $config_obj); |
|
| 773 | - } catch (Exception $exception) { |
|
| 774 | - throw new DomainException( |
|
| 775 | - sprintf( |
|
| 776 | - esc_html__( |
|
| 777 | - 'The following exception occurred while attempting to update the "%1$s" class for config section "%2$s->%3$s": %4$s', |
|
| 778 | - 'event_espresso' |
|
| 779 | - ), |
|
| 780 | - $config_class, |
|
| 781 | - $section, |
|
| 782 | - $name, |
|
| 783 | - $exception->getMessage() |
|
| 784 | - ) |
|
| 785 | - ); |
|
| 786 | - } |
|
| 787 | - $this->{$section}->{$name} = $config_obj; |
|
| 788 | - return $this->{$section}->{$name}; |
|
| 789 | - } else { |
|
| 790 | - // create a wp-option for this config |
|
| 791 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 792 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 793 | - return $this->{$section}->{$name}; |
|
| 794 | - } else { |
|
| 795 | - EE_Error::add_error( |
|
| 796 | - sprintf(esc_html__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 797 | - __FILE__, |
|
| 798 | - __FUNCTION__, |
|
| 799 | - __LINE__ |
|
| 800 | - ); |
|
| 801 | - return null; |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - |
|
| 807 | - /** |
|
| 808 | - * update_config |
|
| 809 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 810 | - * |
|
| 811 | - * @access public |
|
| 812 | - * @param string $section |
|
| 813 | - * @param string $name |
|
| 814 | - * @param EE_Config_Base|string $config_obj |
|
| 815 | - * @param bool $throw_errors |
|
| 816 | - * @return bool |
|
| 817 | - */ |
|
| 818 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 819 | - { |
|
| 820 | - // don't allow config updates during WP heartbeats |
|
| 821 | - /** @var RequestInterface $request */ |
|
| 822 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 823 | - if ($request->isWordPressHeartbeat()) { |
|
| 824 | - return false; |
|
| 825 | - } |
|
| 826 | - $config_obj = maybe_unserialize($config_obj); |
|
| 827 | - // get class name of the incoming object |
|
| 828 | - $config_class = get_class($config_obj); |
|
| 829 | - // run tests 1-5 and 9 to verify config |
|
| 830 | - if ( |
|
| 831 | - ! $this->_verify_config_params( |
|
| 832 | - $section, |
|
| 833 | - $name, |
|
| 834 | - $config_class, |
|
| 835 | - $config_obj, |
|
| 836 | - array(1, 2, 3, 4, 7, 9) |
|
| 837 | - ) |
|
| 838 | - ) { |
|
| 839 | - return false; |
|
| 840 | - } |
|
| 841 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 842 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 843 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 844 | - // save new config to db |
|
| 845 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 846 | - return true; |
|
| 847 | - } |
|
| 848 | - } else { |
|
| 849 | - // first check if the record already exists |
|
| 850 | - $existing_config = get_option($config_option_name); |
|
| 851 | - $config_obj = serialize($config_obj); |
|
| 852 | - // just return if db record is already up-to-date (NOT type safe comparison) |
|
| 853 | - if ($existing_config == $config_obj) { |
|
| 854 | - $this->{$section}->{$name} = $config_obj; |
|
| 855 | - return true; |
|
| 856 | - } elseif (update_option($config_option_name, $config_obj)) { |
|
| 857 | - EE_Config::log($config_option_name); |
|
| 858 | - // update wp-option for this config class |
|
| 859 | - $this->{$section}->{$name} = $config_obj; |
|
| 860 | - return true; |
|
| 861 | - } elseif ($throw_errors) { |
|
| 862 | - EE_Error::add_error( |
|
| 863 | - sprintf( |
|
| 864 | - esc_html__( |
|
| 865 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 866 | - 'event_espresso' |
|
| 867 | - ), |
|
| 868 | - $config_class, |
|
| 869 | - 'EE_Config->' . $section . '->' . $name |
|
| 870 | - ), |
|
| 871 | - __FILE__, |
|
| 872 | - __FUNCTION__, |
|
| 873 | - __LINE__ |
|
| 874 | - ); |
|
| 875 | - } |
|
| 876 | - } |
|
| 877 | - return false; |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - |
|
| 881 | - /** |
|
| 882 | - * get_config |
|
| 883 | - * |
|
| 884 | - * @access public |
|
| 885 | - * @param string $section |
|
| 886 | - * @param string $name |
|
| 887 | - * @param string $config_class |
|
| 888 | - * @return mixed EE_Config_Base | NULL |
|
| 889 | - */ |
|
| 890 | - public function get_config($section = '', $name = '', $config_class = '') |
|
| 891 | - { |
|
| 892 | - // ensure config class is set to something |
|
| 893 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 894 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 895 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 896 | - return null; |
|
| 897 | - } |
|
| 898 | - // now test if the requested config object exists, but suppress errors |
|
| 899 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 900 | - // config already exists, so pass it back |
|
| 901 | - return $this->{$section}->{$name}; |
|
| 902 | - } |
|
| 903 | - // load config option from db if it exists |
|
| 904 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 905 | - // verify the newly retrieved config object, but suppress errors |
|
| 906 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 907 | - // config is good, so set it and pass it back |
|
| 908 | - $this->{$section}->{$name} = $config_obj; |
|
| 909 | - return $this->{$section}->{$name}; |
|
| 910 | - } |
|
| 911 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 912 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
| 913 | - // verify the newly created config object |
|
| 914 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 915 | - return $this->{$section}->{$name}; |
|
| 916 | - } else { |
|
| 917 | - EE_Error::add_error( |
|
| 918 | - sprintf(esc_html__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 919 | - __FILE__, |
|
| 920 | - __FUNCTION__, |
|
| 921 | - __LINE__ |
|
| 922 | - ); |
|
| 923 | - } |
|
| 924 | - return null; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * get_config_option |
|
| 930 | - * |
|
| 931 | - * @access public |
|
| 932 | - * @param string $config_option_name |
|
| 933 | - * @return mixed EE_Config_Base | FALSE |
|
| 934 | - */ |
|
| 935 | - public function get_config_option($config_option_name = '') |
|
| 936 | - { |
|
| 937 | - // retrieve the wp-option for this config class. |
|
| 938 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 939 | - if (empty($config_option)) { |
|
| 940 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 941 | - } |
|
| 942 | - return $config_option; |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - |
|
| 946 | - /** |
|
| 947 | - * log |
|
| 948 | - * |
|
| 949 | - * @param string $config_option_name |
|
| 950 | - */ |
|
| 951 | - public static function log($config_option_name = '') |
|
| 952 | - { |
|
| 953 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 954 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 955 | - /** @var RequestParams $request */ |
|
| 956 | - $request = LoaderFactory::getLoader()->getShared(RequestParams::class); |
|
| 957 | - $config_log[ (string) microtime(true) ] = array( |
|
| 958 | - 'config_name' => $config_option_name, |
|
| 959 | - 'request' => $request->requestParams(), |
|
| 960 | - ); |
|
| 961 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 962 | - } |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - |
|
| 966 | - /** |
|
| 967 | - * trim_log |
|
| 968 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 969 | - */ |
|
| 970 | - public static function trim_log() |
|
| 971 | - { |
|
| 972 | - if (! EE_Config::logging_enabled()) { |
|
| 973 | - return; |
|
| 974 | - } |
|
| 975 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 976 | - $log_length = count($config_log); |
|
| 977 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 978 | - ksort($config_log); |
|
| 979 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 980 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 981 | - } |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - |
|
| 985 | - /** |
|
| 986 | - * get_page_for_posts |
|
| 987 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 988 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 989 | - * |
|
| 990 | - * @access public |
|
| 991 | - * @return string |
|
| 992 | - */ |
|
| 993 | - public static function get_page_for_posts() |
|
| 994 | - { |
|
| 995 | - $page_for_posts = get_option('page_for_posts'); |
|
| 996 | - if (! $page_for_posts) { |
|
| 997 | - return 'posts'; |
|
| 998 | - } |
|
| 999 | - global $wpdb; |
|
| 1000 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 1001 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 1002 | - } |
|
| 1003 | - |
|
| 1004 | - |
|
| 1005 | - /** |
|
| 1006 | - * register_shortcodes_and_modules. |
|
| 1007 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 1008 | - * In fact, this is where we give modules a chance to let core know they exist |
|
| 1009 | - * so they can help trigger maintenance mode if it's needed |
|
| 1010 | - * |
|
| 1011 | - * @access public |
|
| 1012 | - * @return void |
|
| 1013 | - */ |
|
| 1014 | - public function register_shortcodes_and_modules() |
|
| 1015 | - { |
|
| 1016 | - // allow modules to set hooks for the rest of the system |
|
| 1017 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - |
|
| 1021 | - /** |
|
| 1022 | - * initialize_shortcodes_and_modules |
|
| 1023 | - * meaning they can start adding their hooks to get stuff done |
|
| 1024 | - * |
|
| 1025 | - * @access public |
|
| 1026 | - * @return void |
|
| 1027 | - */ |
|
| 1028 | - public function initialize_shortcodes_and_modules() |
|
| 1029 | - { |
|
| 1030 | - // allow modules to set hooks for the rest of the system |
|
| 1031 | - $this->_initialize_modules(); |
|
| 1032 | - } |
|
| 1033 | - |
|
| 1034 | - |
|
| 1035 | - /** |
|
| 1036 | - * widgets_init |
|
| 1037 | - * |
|
| 1038 | - * @access private |
|
| 1039 | - * @return void |
|
| 1040 | - */ |
|
| 1041 | - public function widgets_init() |
|
| 1042 | - { |
|
| 1043 | - // only init widgets on admin pages when not in complete maintenance, and |
|
| 1044 | - // on frontend when not in any maintenance mode |
|
| 1045 | - if ( |
|
| 1046 | - MaintenanceStatus::isDisabled() |
|
| 1047 | - || (is_admin() && MaintenanceStatus::isNotFullSite()) |
|
| 1048 | - ) { |
|
| 1049 | - // grab list of installed widgets |
|
| 1050 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1051 | - // filter list of modules to register |
|
| 1052 | - $widgets_to_register = apply_filters( |
|
| 1053 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1054 | - $widgets_to_register |
|
| 1055 | - ); |
|
| 1056 | - if (! empty($widgets_to_register)) { |
|
| 1057 | - // cycle thru widget folders |
|
| 1058 | - foreach ($widgets_to_register as $widget_path) { |
|
| 1059 | - // add to list of installed widget modules |
|
| 1060 | - EE_Config::register_ee_widget($widget_path); |
|
| 1061 | - } |
|
| 1062 | - } |
|
| 1063 | - // filter list of installed modules |
|
| 1064 | - EE_Registry::instance()->widgets = apply_filters( |
|
| 1065 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1066 | - EE_Registry::instance()->widgets |
|
| 1067 | - ); |
|
| 1068 | - } |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - |
|
| 1072 | - /** |
|
| 1073 | - * register_ee_widget - makes core aware of this widget |
|
| 1074 | - * |
|
| 1075 | - * @access public |
|
| 1076 | - * @param string $widget_path - full path up to and including widget folder |
|
| 1077 | - * @return void |
|
| 1078 | - */ |
|
| 1079 | - public static function register_ee_widget($widget_path = null) |
|
| 1080 | - { |
|
| 1081 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1082 | - $widget_ext = '.widget.php'; |
|
| 1083 | - // make all separators match |
|
| 1084 | - $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1085 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1086 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1087 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1088 | - $file_name = explode('.', basename($widget_path)); |
|
| 1089 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1090 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1091 | - // sanitize shortcode directory name |
|
| 1092 | - $widget = sanitize_key($widget); |
|
| 1093 | - // now we need to rebuild the shortcode path |
|
| 1094 | - $widget_path = explode('/', $widget_path); |
|
| 1095 | - // remove last segment |
|
| 1096 | - array_pop($widget_path); |
|
| 1097 | - // glue it back together |
|
| 1098 | - $widget_path = implode(DS, $widget_path); |
|
| 1099 | - } else { |
|
| 1100 | - // grab and sanitize widget directory name |
|
| 1101 | - $widget = sanitize_key(basename($widget_path)); |
|
| 1102 | - } |
|
| 1103 | - // create classname from widget directory name |
|
| 1104 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1105 | - // add class prefix |
|
| 1106 | - $widget_class = 'EEW_' . $widget; |
|
| 1107 | - // does the widget exist ? |
|
| 1108 | - if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1109 | - $msg = sprintf( |
|
| 1110 | - esc_html__( |
|
| 1111 | - 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1112 | - 'event_espresso' |
|
| 1113 | - ), |
|
| 1114 | - $widget_class, |
|
| 1115 | - $widget_path . '/' . $widget_class . $widget_ext |
|
| 1116 | - ); |
|
| 1117 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1118 | - return; |
|
| 1119 | - } |
|
| 1120 | - // load the widget class file |
|
| 1121 | - require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1122 | - // verify that class exists |
|
| 1123 | - if (! class_exists($widget_class)) { |
|
| 1124 | - $msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1125 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1126 | - return; |
|
| 1127 | - } |
|
| 1128 | - register_widget($widget_class); |
|
| 1129 | - // add to array of registered widgets |
|
| 1130 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - |
|
| 1134 | - /** |
|
| 1135 | - * _register_modules |
|
| 1136 | - * |
|
| 1137 | - * @access private |
|
| 1138 | - * @return array |
|
| 1139 | - */ |
|
| 1140 | - private function _register_modules() |
|
| 1141 | - { |
|
| 1142 | - // grab list of installed modules |
|
| 1143 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1144 | - // filter list of modules to register |
|
| 1145 | - $modules_to_register = apply_filters( |
|
| 1146 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1147 | - $modules_to_register |
|
| 1148 | - ); |
|
| 1149 | - if (! empty($modules_to_register)) { |
|
| 1150 | - // loop through folders |
|
| 1151 | - foreach ($modules_to_register as $module_path) { |
|
| 1152 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1153 | - if ( |
|
| 1154 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1155 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1156 | - ) { |
|
| 1157 | - // add to list of installed modules |
|
| 1158 | - EE_Config::register_module($module_path); |
|
| 1159 | - } |
|
| 1160 | - } |
|
| 1161 | - } |
|
| 1162 | - // filter list of installed modules |
|
| 1163 | - return apply_filters( |
|
| 1164 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1165 | - EE_Registry::instance()->modules |
|
| 1166 | - ); |
|
| 1167 | - } |
|
| 1168 | - |
|
| 1169 | - |
|
| 1170 | - /** |
|
| 1171 | - * register_module - makes core aware of this module |
|
| 1172 | - * |
|
| 1173 | - * @access public |
|
| 1174 | - * @param string $module_path - full path up to and including module folder |
|
| 1175 | - * @return bool |
|
| 1176 | - */ |
|
| 1177 | - public static function register_module($module_path = null) |
|
| 1178 | - { |
|
| 1179 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1180 | - $module_ext = '.module.php'; |
|
| 1181 | - // make all separators match |
|
| 1182 | - $module_path = str_replace(array('\\', '/'), '/', $module_path); |
|
| 1183 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1184 | - if (strpos($module_path, $module_ext) !== false) { |
|
| 1185 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1186 | - $module_file = explode('.', basename($module_path)); |
|
| 1187 | - // now we need to rebuild the shortcode path |
|
| 1188 | - $module_path = explode('/', $module_path); |
|
| 1189 | - // remove last segment |
|
| 1190 | - array_pop($module_path); |
|
| 1191 | - // glue it back together |
|
| 1192 | - $module_path = implode('/', $module_path) . '/'; |
|
| 1193 | - // take first segment from file name pieces and sanitize it |
|
| 1194 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1195 | - // ensure class prefix is added |
|
| 1196 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1197 | - } else { |
|
| 1198 | - // we need to generate the filename based off of the folder name |
|
| 1199 | - // grab and sanitize module name |
|
| 1200 | - $module = strtolower(basename($module_path)); |
|
| 1201 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1202 | - // like trailingslashit() |
|
| 1203 | - $module_path = rtrim($module_path, '/') . '/'; |
|
| 1204 | - // create classname from module directory name |
|
| 1205 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1206 | - // add class prefix |
|
| 1207 | - $module_class = 'EED_' . $module; |
|
| 1208 | - } |
|
| 1209 | - // does the module exist ? |
|
| 1210 | - if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1211 | - $msg = sprintf( |
|
| 1212 | - esc_html__( |
|
| 1213 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1214 | - 'event_espresso' |
|
| 1215 | - ), |
|
| 1216 | - $module |
|
| 1217 | - ); |
|
| 1218 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1219 | - return false; |
|
| 1220 | - } |
|
| 1221 | - // load the module class file |
|
| 1222 | - require_once($module_path . $module_class . $module_ext); |
|
| 1223 | - // verify that class exists |
|
| 1224 | - if (! class_exists($module_class)) { |
|
| 1225 | - $msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1226 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1227 | - return false; |
|
| 1228 | - } |
|
| 1229 | - // add to array of registered modules |
|
| 1230 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1231 | - do_action( |
|
| 1232 | - 'AHEE__EE_Config__register_module__complete', |
|
| 1233 | - $module_class, |
|
| 1234 | - EE_Registry::instance()->modules->{$module_class} |
|
| 1235 | - ); |
|
| 1236 | - return true; |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - |
|
| 1240 | - /** |
|
| 1241 | - * _initialize_modules |
|
| 1242 | - * allow modules to set hooks for the rest of the system |
|
| 1243 | - * |
|
| 1244 | - * @access private |
|
| 1245 | - * @return void |
|
| 1246 | - */ |
|
| 1247 | - private function _initialize_modules() |
|
| 1248 | - { |
|
| 1249 | - // cycle thru shortcode folders |
|
| 1250 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1251 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1252 | - // which set hooks ? |
|
| 1253 | - if (is_admin() && is_callable([$module_class, 'set_hooks_admin'])) { |
|
| 1254 | - // fire immediately |
|
| 1255 | - call_user_func([$module_class, 'set_hooks_admin']); |
|
| 1256 | - } else { |
|
| 1257 | - // delay until other systems are online |
|
| 1258 | - add_action( |
|
| 1259 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1260 | - array($module_class, 'set_hooks') |
|
| 1261 | - ); |
|
| 1262 | - } |
|
| 1263 | - } |
|
| 1264 | - } |
|
| 1265 | - |
|
| 1266 | - |
|
| 1267 | - /** |
|
| 1268 | - * register_route - adds module method routes to route_map |
|
| 1269 | - * |
|
| 1270 | - * @access public |
|
| 1271 | - * @param string $route - "pretty" public alias for module method |
|
| 1272 | - * @param string $module - module name (classname without EED_ prefix) |
|
| 1273 | - * @param string $method_name - the actual module method to be routed to |
|
| 1274 | - * @param string $key - url param key indicating a route is being called |
|
| 1275 | - * @return bool |
|
| 1276 | - */ |
|
| 1277 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1278 | - { |
|
| 1279 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1280 | - $module = str_replace('EED_', '', $module); |
|
| 1281 | - $module_class = 'EED_' . $module; |
|
| 1282 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1283 | - $msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1284 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1285 | - return false; |
|
| 1286 | - } |
|
| 1287 | - if (empty($route)) { |
|
| 1288 | - $msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1289 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1290 | - return false; |
|
| 1291 | - } |
|
| 1292 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1293 | - $msg = sprintf( |
|
| 1294 | - esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1295 | - $route |
|
| 1296 | - ); |
|
| 1297 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1298 | - return false; |
|
| 1299 | - } |
|
| 1300 | - EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1301 | - return true; |
|
| 1302 | - } |
|
| 1303 | - |
|
| 1304 | - |
|
| 1305 | - /** |
|
| 1306 | - * get_route - get module method route |
|
| 1307 | - * |
|
| 1308 | - * @access public |
|
| 1309 | - * @param string $route - "pretty" public alias for module method |
|
| 1310 | - * @param string $key - url param key indicating a route is being called |
|
| 1311 | - * @return string |
|
| 1312 | - */ |
|
| 1313 | - public static function get_route($route = null, $key = 'ee') |
|
| 1314 | - { |
|
| 1315 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1316 | - $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1317 | - if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1318 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1319 | - } |
|
| 1320 | - return null; |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - |
|
| 1324 | - /** |
|
| 1325 | - * get_routes - get ALL module method routes |
|
| 1326 | - * |
|
| 1327 | - * @access public |
|
| 1328 | - * @return array |
|
| 1329 | - */ |
|
| 1330 | - public static function get_routes() |
|
| 1331 | - { |
|
| 1332 | - return EE_Config::$_module_route_map; |
|
| 1333 | - } |
|
| 1334 | - |
|
| 1335 | - |
|
| 1336 | - /** |
|
| 1337 | - * register_forward - allows modules to forward request to another module for further processing |
|
| 1338 | - * |
|
| 1339 | - * @access public |
|
| 1340 | - * @param string $route - "pretty" public alias for module method |
|
| 1341 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1342 | - * class, allows different forwards to be served based on status |
|
| 1343 | - * @param array|string $forward - function name or array( class, method ) |
|
| 1344 | - * @param string $key - url param key indicating a route is being called |
|
| 1345 | - * @return bool |
|
| 1346 | - */ |
|
| 1347 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1348 | - { |
|
| 1349 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1350 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1351 | - $msg = sprintf( |
|
| 1352 | - esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1353 | - $route |
|
| 1354 | - ); |
|
| 1355 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1356 | - return false; |
|
| 1357 | - } |
|
| 1358 | - if (empty($forward)) { |
|
| 1359 | - $msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1360 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1361 | - return false; |
|
| 1362 | - } |
|
| 1363 | - if (is_array($forward)) { |
|
| 1364 | - if (! isset($forward[1])) { |
|
| 1365 | - $msg = sprintf( |
|
| 1366 | - esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1367 | - $route |
|
| 1368 | - ); |
|
| 1369 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1370 | - return false; |
|
| 1371 | - } |
|
| 1372 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1373 | - $msg = sprintf( |
|
| 1374 | - esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1375 | - $forward[1], |
|
| 1376 | - $route |
|
| 1377 | - ); |
|
| 1378 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1379 | - return false; |
|
| 1380 | - } |
|
| 1381 | - } elseif (! function_exists($forward)) { |
|
| 1382 | - $msg = sprintf( |
|
| 1383 | - esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1384 | - $forward, |
|
| 1385 | - $route |
|
| 1386 | - ); |
|
| 1387 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1388 | - return false; |
|
| 1389 | - } |
|
| 1390 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1391 | - return true; |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - |
|
| 1395 | - /** |
|
| 1396 | - * get_forward - get forwarding route |
|
| 1397 | - * |
|
| 1398 | - * @access public |
|
| 1399 | - * @param string $route - "pretty" public alias for module method |
|
| 1400 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1401 | - * allows different forwards to be served based on status |
|
| 1402 | - * @param string $key - url param key indicating a route is being called |
|
| 1403 | - * @return string |
|
| 1404 | - */ |
|
| 1405 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1406 | - { |
|
| 1407 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1408 | - if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1409 | - return apply_filters( |
|
| 1410 | - 'FHEE__EE_Config__get_forward', |
|
| 1411 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1412 | - $route, |
|
| 1413 | - $status |
|
| 1414 | - ); |
|
| 1415 | - } |
|
| 1416 | - return null; |
|
| 1417 | - } |
|
| 1418 | - |
|
| 1419 | - |
|
| 1420 | - /** |
|
| 1421 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1422 | - * results |
|
| 1423 | - * |
|
| 1424 | - * @access public |
|
| 1425 | - * @param string $route - "pretty" public alias for module method |
|
| 1426 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1427 | - * allows different views to be served based on status |
|
| 1428 | - * @param string $view |
|
| 1429 | - * @param string $key - url param key indicating a route is being called |
|
| 1430 | - * @return bool |
|
| 1431 | - */ |
|
| 1432 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1433 | - { |
|
| 1434 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1435 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1436 | - $msg = sprintf( |
|
| 1437 | - esc_html__('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1438 | - $route |
|
| 1439 | - ); |
|
| 1440 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1441 | - return false; |
|
| 1442 | - } |
|
| 1443 | - if (! is_readable($view)) { |
|
| 1444 | - $msg = sprintf( |
|
| 1445 | - esc_html__( |
|
| 1446 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1447 | - 'event_espresso' |
|
| 1448 | - ), |
|
| 1449 | - $view |
|
| 1450 | - ); |
|
| 1451 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1452 | - return false; |
|
| 1453 | - } |
|
| 1454 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1455 | - return true; |
|
| 1456 | - } |
|
| 1457 | - |
|
| 1458 | - |
|
| 1459 | - /** |
|
| 1460 | - * get_view - get view for route and status |
|
| 1461 | - * |
|
| 1462 | - * @access public |
|
| 1463 | - * @param string $route - "pretty" public alias for module method |
|
| 1464 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1465 | - * allows different views to be served based on status |
|
| 1466 | - * @param string $key - url param key indicating a route is being called |
|
| 1467 | - * @return string |
|
| 1468 | - */ |
|
| 1469 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1470 | - { |
|
| 1471 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1472 | - if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1473 | - return apply_filters( |
|
| 1474 | - 'FHEE__EE_Config__get_view', |
|
| 1475 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1476 | - $route, |
|
| 1477 | - $status |
|
| 1478 | - ); |
|
| 1479 | - } |
|
| 1480 | - return null; |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - |
|
| 1484 | - public function update_addon_option_names() |
|
| 1485 | - { |
|
| 1486 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1487 | - } |
|
| 1488 | - |
|
| 1489 | - |
|
| 1490 | - public function shutdown() |
|
| 1491 | - { |
|
| 1492 | - $this->update_addon_option_names(); |
|
| 1493 | - } |
|
| 1494 | - |
|
| 1495 | - |
|
| 1496 | - /** |
|
| 1497 | - * @return LegacyShortcodesManager |
|
| 1498 | - */ |
|
| 1499 | - public static function getLegacyShortcodesManager() |
|
| 1500 | - { |
|
| 1501 | - if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1502 | - EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared( |
|
| 1503 | - LegacyShortcodesManager::class |
|
| 1504 | - ); |
|
| 1505 | - } |
|
| 1506 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1507 | - } |
|
| 1508 | - |
|
| 1509 | - |
|
| 1510 | - /** |
|
| 1511 | - * register_shortcode - makes core aware of this shortcode |
|
| 1512 | - * |
|
| 1513 | - * @deprecated 4.9.26 |
|
| 1514 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1515 | - * @return bool |
|
| 1516 | - */ |
|
| 1517 | - public static function register_shortcode($shortcode_path = null) |
|
| 1518 | - { |
|
| 1519 | - EE_Error::doing_it_wrong( |
|
| 1520 | - __METHOD__, |
|
| 1521 | - esc_html__( |
|
| 1522 | - 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1523 | - 'event_espresso' |
|
| 1524 | - ), |
|
| 1525 | - '4.9.26' |
|
| 1526 | - ); |
|
| 1527 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1528 | - } |
|
| 23 | + const OPTION_NAME = 'ee_config'; |
|
| 24 | + |
|
| 25 | + const LOG_NAME = 'ee_config_log'; |
|
| 26 | + |
|
| 27 | + const LOG_LENGTH = 100; |
|
| 28 | + |
|
| 29 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * instance of the EE_Config object |
|
| 33 | + * |
|
| 34 | + * @var EE_Config $_instance |
|
| 35 | + * @access private |
|
| 36 | + */ |
|
| 37 | + private static $_instance; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var boolean $_logging_enabled |
|
| 41 | + */ |
|
| 42 | + private static $_logging_enabled = false; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 46 | + */ |
|
| 47 | + private $legacy_shortcodes_manager; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * An StdClass whose property names are addon slugs, |
|
| 51 | + * and values are their config classes |
|
| 52 | + * |
|
| 53 | + * @var StdClass |
|
| 54 | + */ |
|
| 55 | + public $addons; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var EE_Admin_Config |
|
| 59 | + */ |
|
| 60 | + public $admin; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var EE_Core_Config |
|
| 64 | + */ |
|
| 65 | + public $core; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var EE_Currency_Config |
|
| 69 | + */ |
|
| 70 | + public $currency; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @var EE_Organization_Config |
|
| 74 | + */ |
|
| 75 | + public $organization; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @var EE_Registration_Config |
|
| 79 | + */ |
|
| 80 | + public $registration; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @var EE_Template_Config |
|
| 84 | + */ |
|
| 85 | + public $template_settings; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Holds EE environment values. |
|
| 89 | + * |
|
| 90 | + * @var EE_Environment_Config |
|
| 91 | + */ |
|
| 92 | + public $environment; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * settings pertaining to Google maps |
|
| 96 | + * |
|
| 97 | + * @var EE_Map_Config |
|
| 98 | + */ |
|
| 99 | + public $map_settings; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * settings pertaining to Taxes |
|
| 103 | + * |
|
| 104 | + * @var EE_Tax_Config |
|
| 105 | + */ |
|
| 106 | + public $tax_settings; |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Settings pertaining to global messages settings. |
|
| 110 | + * |
|
| 111 | + * @var EE_Messages_Config |
|
| 112 | + */ |
|
| 113 | + public $messages; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @deprecated |
|
| 117 | + * @var EE_Gateway_Config |
|
| 118 | + */ |
|
| 119 | + public $gateway; |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @var array |
|
| 123 | + */ |
|
| 124 | + private $_addon_option_names = array(); |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @var array |
|
| 128 | + */ |
|
| 129 | + private static $_module_route_map = array(); |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @var array |
|
| 133 | + */ |
|
| 134 | + private static $_module_forward_map = array(); |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @var array |
|
| 138 | + */ |
|
| 139 | + private static $_module_view_map = array(); |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @var bool |
|
| 143 | + */ |
|
| 144 | + private static $initialized = false; |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @singleton method used to instantiate class object |
|
| 149 | + * @access public |
|
| 150 | + * @return EE_Config instance |
|
| 151 | + */ |
|
| 152 | + public static function instance() |
|
| 153 | + { |
|
| 154 | + // check if class object is instantiated, and instantiated properly |
|
| 155 | + if (! self::$_instance instanceof EE_Config) { |
|
| 156 | + self::$_instance = new self(); |
|
| 157 | + } |
|
| 158 | + return self::$_instance; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Resets the config |
|
| 164 | + * |
|
| 165 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 166 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 167 | + * reflect its state in the database |
|
| 168 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 169 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 170 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 171 | + * site was put into maintenance mode) |
|
| 172 | + * @return EE_Config |
|
| 173 | + */ |
|
| 174 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 175 | + { |
|
| 176 | + if (self::$_instance instanceof EE_Config) { |
|
| 177 | + if ($hard_reset) { |
|
| 178 | + self::$_instance->legacy_shortcodes_manager = null; |
|
| 179 | + self::$_instance->_addon_option_names = array(); |
|
| 180 | + self::$_instance->_initialize_config(); |
|
| 181 | + self::$_instance->update_espresso_config(); |
|
| 182 | + } |
|
| 183 | + self::$_instance->update_addon_option_names(); |
|
| 184 | + } |
|
| 185 | + self::$_instance = null; |
|
| 186 | + self::$initialized = false; |
|
| 187 | + // we don't need to reset the static properties imo because those should |
|
| 188 | + // only change when a module is added or removed. Currently we don't |
|
| 189 | + // support removing a module during a request when it previously existed |
|
| 190 | + if ($reinstantiate) { |
|
| 191 | + return self::instance(); |
|
| 192 | + } else { |
|
| 193 | + return null; |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + private function __construct() |
|
| 199 | + { |
|
| 200 | + if (self::$initialized) { |
|
| 201 | + return; |
|
| 202 | + } |
|
| 203 | + self::$initialized = true; |
|
| 204 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 205 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 206 | + // setup empty config classes |
|
| 207 | + $this->_initialize_config(); |
|
| 208 | + // load existing EE site settings |
|
| 209 | + $this->_load_core_config(); |
|
| 210 | + // confirm everything loaded correctly and set filtered defaults if not |
|
| 211 | + $this->_verify_config(); |
|
| 212 | + // register shortcodes and modules |
|
| 213 | + add_action( |
|
| 214 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 215 | + [$this, 'register_shortcodes_and_modules'], |
|
| 216 | + 999 |
|
| 217 | + ); |
|
| 218 | + // initialize shortcodes and modules |
|
| 219 | + add_action('AHEE__EE_System__core_loaded_and_ready', [$this, 'initialize_shortcodes_and_modules']); |
|
| 220 | + // register widgets |
|
| 221 | + add_action('widgets_init', [$this, 'widgets_init'], 10); |
|
| 222 | + // shutdown |
|
| 223 | + add_action('shutdown', [$this, 'shutdown'], 10); |
|
| 224 | + // construct__end hook |
|
| 225 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
| 226 | + // hardcoded hack |
|
| 227 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @return boolean |
|
| 233 | + */ |
|
| 234 | + public static function logging_enabled() |
|
| 235 | + { |
|
| 236 | + return self::$_logging_enabled; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * use to get the current theme if needed from static context |
|
| 242 | + * |
|
| 243 | + * @return string current theme set. |
|
| 244 | + */ |
|
| 245 | + public static function get_current_theme() |
|
| 246 | + { |
|
| 247 | + return self::$_instance->template_settings->current_espresso_theme ?? 'Espresso_Arabica_2014'; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * _initialize_config |
|
| 253 | + * |
|
| 254 | + * @access private |
|
| 255 | + * @return void |
|
| 256 | + */ |
|
| 257 | + private function _initialize_config() |
|
| 258 | + { |
|
| 259 | + EE_Config::trim_log(); |
|
| 260 | + // set defaults |
|
| 261 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 262 | + $this->addons = new stdClass(); |
|
| 263 | + // set _module_route_map |
|
| 264 | + EE_Config::$_module_route_map = array(); |
|
| 265 | + // set _module_forward_map |
|
| 266 | + EE_Config::$_module_forward_map = array(); |
|
| 267 | + // set _module_view_map |
|
| 268 | + EE_Config::$_module_view_map = array(); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * load core plugin configuration |
|
| 274 | + * |
|
| 275 | + * @access private |
|
| 276 | + * @return void |
|
| 277 | + */ |
|
| 278 | + private function _load_core_config() |
|
| 279 | + { |
|
| 280 | + // load_core_config__start hook |
|
| 281 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 282 | + $espresso_config = (array) $this->get_espresso_config(); |
|
| 283 | + // need to move the "addons" element to the end of the config array |
|
| 284 | + // in case an addon config references one of the other config classes |
|
| 285 | + $addons = $espresso_config['addons'] ?? new StdClass(); |
|
| 286 | + unset($espresso_config['addons']); |
|
| 287 | + $espresso_config['addons'] = $addons; |
|
| 288 | + foreach ($espresso_config as $config => $settings) { |
|
| 289 | + // load_core_config__start hook |
|
| 290 | + $settings = apply_filters( |
|
| 291 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 292 | + $settings, |
|
| 293 | + $config, |
|
| 294 | + $this |
|
| 295 | + ); |
|
| 296 | + if (is_object($settings) && property_exists($this, $config)) { |
|
| 297 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 298 | + // call configs populate method to ensure any defaults are set for empty values. |
|
| 299 | + if (method_exists($settings, 'populate')) { |
|
| 300 | + $this->{$config}->populate(); |
|
| 301 | + } |
|
| 302 | + if (method_exists($settings, 'do_hooks')) { |
|
| 303 | + $this->{$config}->do_hooks(); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 308 | + $this->update_espresso_config(); |
|
| 309 | + } |
|
| 310 | + // load_core_config__end hook |
|
| 311 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * _verify_config |
|
| 317 | + * |
|
| 318 | + * @access protected |
|
| 319 | + * @return void |
|
| 320 | + */ |
|
| 321 | + protected function _verify_config() |
|
| 322 | + { |
|
| 323 | + $this->core = $this->core instanceof EE_Core_Config |
|
| 324 | + ? $this->core |
|
| 325 | + : new EE_Core_Config(); |
|
| 326 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 327 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 328 | + ? $this->organization |
|
| 329 | + : new EE_Organization_Config(); |
|
| 330 | + $this->organization = apply_filters( |
|
| 331 | + 'FHEE__EE_Config___initialize_config__organization', |
|
| 332 | + $this->organization |
|
| 333 | + ); |
|
| 334 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 335 | + ? $this->currency |
|
| 336 | + : new EE_Currency_Config(); |
|
| 337 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 338 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 339 | + ? $this->registration |
|
| 340 | + : new EE_Registration_Config(); |
|
| 341 | + $this->registration = apply_filters( |
|
| 342 | + 'FHEE__EE_Config___initialize_config__registration', |
|
| 343 | + $this->registration |
|
| 344 | + ); |
|
| 345 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 346 | + ? $this->admin |
|
| 347 | + : new EE_Admin_Config(); |
|
| 348 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 349 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 350 | + ? $this->template_settings |
|
| 351 | + : new EE_Template_Config(); |
|
| 352 | + $this->template_settings = apply_filters( |
|
| 353 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 354 | + $this->template_settings |
|
| 355 | + ); |
|
| 356 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 357 | + ? $this->map_settings |
|
| 358 | + : new EE_Map_Config(); |
|
| 359 | + $this->map_settings = apply_filters( |
|
| 360 | + 'FHEE__EE_Config___initialize_config__map_settings', |
|
| 361 | + $this->map_settings |
|
| 362 | + ); |
|
| 363 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 364 | + ? $this->environment |
|
| 365 | + : new EE_Environment_Config(); |
|
| 366 | + $this->environment = apply_filters( |
|
| 367 | + 'FHEE__EE_Config___initialize_config__environment', |
|
| 368 | + $this->environment |
|
| 369 | + ); |
|
| 370 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 371 | + ? $this->tax_settings |
|
| 372 | + : new EE_Tax_Config(); |
|
| 373 | + $this->tax_settings = apply_filters( |
|
| 374 | + 'FHEE__EE_Config___initialize_config__tax_settings', |
|
| 375 | + $this->tax_settings |
|
| 376 | + ); |
|
| 377 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 378 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 379 | + ? $this->messages |
|
| 380 | + : new EE_Messages_Config(); |
|
| 381 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 382 | + ? $this->gateway |
|
| 383 | + : new EE_Gateway_Config(); |
|
| 384 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 385 | + $this->legacy_shortcodes_manager = null; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * get_espresso_config |
|
| 391 | + * |
|
| 392 | + * @access public |
|
| 393 | + * @return array of espresso config stuff |
|
| 394 | + */ |
|
| 395 | + public function get_espresso_config() |
|
| 396 | + { |
|
| 397 | + // grab espresso configuration |
|
| 398 | + return apply_filters( |
|
| 399 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 400 | + get_option(EE_Config::OPTION_NAME, array()) |
|
| 401 | + ); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * double_check_config_comparison |
|
| 407 | + * |
|
| 408 | + * @access public |
|
| 409 | + * @param string $option |
|
| 410 | + * @param $old_value |
|
| 411 | + * @param $value |
|
| 412 | + */ |
|
| 413 | + public function double_check_config_comparison($option, $old_value, $value) |
|
| 414 | + { |
|
| 415 | + // make sure we're checking the ee config |
|
| 416 | + if ($option === EE_Config::OPTION_NAME) { |
|
| 417 | + // run a loose comparison of the old value against the new value for type and properties, |
|
| 418 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 419 | + if ($value != $old_value) { |
|
| 420 | + // if they are NOT the same, then remove the hook, |
|
| 421 | + // which means the subsequent update results will be based solely on the update query results |
|
| 422 | + // the reason we do this is because, as stated above, |
|
| 423 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 424 | + // this happens PRIOR to serialization and any subsequent update. |
|
| 425 | + // If values are found to match their previous old value, |
|
| 426 | + // then WP bails before performing any update. |
|
| 427 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 428 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 429 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 430 | + // MySQL MAY ALSO NOT perform the update because |
|
| 431 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 432 | + // This results in the query returning an "affected rows" value of ZERO, |
|
| 433 | + // which gets returned immediately by WP update_option and looks like an error. |
|
| 434 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * update_espresso_config |
|
| 442 | + * |
|
| 443 | + * @access public |
|
| 444 | + */ |
|
| 445 | + protected function _reset_espresso_addon_config() |
|
| 446 | + { |
|
| 447 | + $this->_addon_option_names = array(); |
|
| 448 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 449 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 450 | + if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 451 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 452 | + } |
|
| 453 | + $this->addons->{$addon_name} = null; |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * update_espresso_config |
|
| 460 | + * |
|
| 461 | + * @access public |
|
| 462 | + * @param bool $add_success |
|
| 463 | + * @param bool $add_error |
|
| 464 | + * @return bool |
|
| 465 | + */ |
|
| 466 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
| 467 | + { |
|
| 468 | + // don't allow config updates during WP heartbeats |
|
| 469 | + /** @var RequestInterface $request */ |
|
| 470 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 471 | + if ($request->isWordPressHeartbeat()) { |
|
| 472 | + return false; |
|
| 473 | + } |
|
| 474 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 475 | + // $clone = clone( self::$_instance ); |
|
| 476 | + // self::$_instance = NULL; |
|
| 477 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 478 | + $this->_reset_espresso_addon_config(); |
|
| 479 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 480 | + // but BEFORE the actual update occurs |
|
| 481 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 482 | + // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 483 | + $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 484 | + $this->legacy_shortcodes_manager = null; |
|
| 485 | + // now update "ee_config" |
|
| 486 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 487 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 488 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
| 489 | + // if not saved... check if the hook we just added still exists; |
|
| 490 | + // if it does, it means one of two things: |
|
| 491 | + // that update_option bailed at the($value === $old_value) conditional, |
|
| 492 | + // or... |
|
| 493 | + // the db update query returned 0 rows affected |
|
| 494 | + // (probably because the data value was the same from its perspective) |
|
| 495 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 496 | + // but just means no update occurred, so don't display an error to the user. |
|
| 497 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 498 | + // then it means that something truly went wrong |
|
| 499 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 500 | + // remove our action since we don't want it in the system anymore |
|
| 501 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 502 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 503 | + // self::$_instance = $clone; |
|
| 504 | + // unset( $clone ); |
|
| 505 | + // if config remains the same or was updated successfully |
|
| 506 | + if ($saved) { |
|
| 507 | + if ($add_success) { |
|
| 508 | + EE_Error::add_success( |
|
| 509 | + esc_html__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 510 | + __FILE__, |
|
| 511 | + __FUNCTION__, |
|
| 512 | + __LINE__ |
|
| 513 | + ); |
|
| 514 | + } |
|
| 515 | + return true; |
|
| 516 | + } else { |
|
| 517 | + if ($add_error) { |
|
| 518 | + EE_Error::add_error( |
|
| 519 | + esc_html__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 520 | + __FILE__, |
|
| 521 | + __FUNCTION__, |
|
| 522 | + __LINE__ |
|
| 523 | + ); |
|
| 524 | + } |
|
| 525 | + return false; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * _verify_config_params |
|
| 532 | + * |
|
| 533 | + * @access private |
|
| 534 | + * @param string $section |
|
| 535 | + * @param string $name |
|
| 536 | + * @param string $config_class |
|
| 537 | + * @param EE_Config_Base $config_obj |
|
| 538 | + * @param array $tests_to_run |
|
| 539 | + * @param bool $display_errors |
|
| 540 | + * @return bool TRUE on success, FALSE on fail |
|
| 541 | + */ |
|
| 542 | + private function _verify_config_params( |
|
| 543 | + $section = '', |
|
| 544 | + $name = '', |
|
| 545 | + $config_class = '', |
|
| 546 | + $config_obj = null, |
|
| 547 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 548 | + $display_errors = true |
|
| 549 | + ) { |
|
| 550 | + try { |
|
| 551 | + foreach ($tests_to_run as $test) { |
|
| 552 | + switch ($test) { |
|
| 553 | + // TEST #1 : check that section was set |
|
| 554 | + case 1: |
|
| 555 | + if (empty($section)) { |
|
| 556 | + if ($display_errors) { |
|
| 557 | + throw new EE_Error( |
|
| 558 | + sprintf( |
|
| 559 | + esc_html__( |
|
| 560 | + 'No configuration section has been provided while attempting to save "%s".', |
|
| 561 | + 'event_espresso' |
|
| 562 | + ), |
|
| 563 | + $config_class |
|
| 564 | + ) |
|
| 565 | + ); |
|
| 566 | + } |
|
| 567 | + return false; |
|
| 568 | + } |
|
| 569 | + break; |
|
| 570 | + // TEST #2 : check that settings section exists |
|
| 571 | + case 2: |
|
| 572 | + if (! isset($this->{$section})) { |
|
| 573 | + if ($display_errors) { |
|
| 574 | + throw new EE_Error( |
|
| 575 | + sprintf( |
|
| 576 | + esc_html__('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 577 | + $section |
|
| 578 | + ) |
|
| 579 | + ); |
|
| 580 | + } |
|
| 581 | + return false; |
|
| 582 | + } |
|
| 583 | + break; |
|
| 584 | + // TEST #3 : check that section is the proper format |
|
| 585 | + case 3: |
|
| 586 | + if ( |
|
| 587 | + ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 588 | + ) { |
|
| 589 | + if ($display_errors) { |
|
| 590 | + throw new EE_Error( |
|
| 591 | + sprintf( |
|
| 592 | + esc_html__( |
|
| 593 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
| 594 | + 'event_espresso' |
|
| 595 | + ), |
|
| 596 | + $section |
|
| 597 | + ) |
|
| 598 | + ); |
|
| 599 | + } |
|
| 600 | + return false; |
|
| 601 | + } |
|
| 602 | + break; |
|
| 603 | + // TEST #4 : check that config section name has been set |
|
| 604 | + case 4: |
|
| 605 | + if (empty($name)) { |
|
| 606 | + if ($display_errors) { |
|
| 607 | + throw new EE_Error( |
|
| 608 | + esc_html__( |
|
| 609 | + 'No name has been provided for the specific configuration section.', |
|
| 610 | + 'event_espresso' |
|
| 611 | + ) |
|
| 612 | + ); |
|
| 613 | + } |
|
| 614 | + return false; |
|
| 615 | + } |
|
| 616 | + break; |
|
| 617 | + // TEST #5 : check that a config class name has been set |
|
| 618 | + case 5: |
|
| 619 | + if (empty($config_class)) { |
|
| 620 | + if ($display_errors) { |
|
| 621 | + throw new EE_Error( |
|
| 622 | + esc_html__( |
|
| 623 | + 'No class name has been provided for the specific configuration section.', |
|
| 624 | + 'event_espresso' |
|
| 625 | + ) |
|
| 626 | + ); |
|
| 627 | + } |
|
| 628 | + return false; |
|
| 629 | + } |
|
| 630 | + break; |
|
| 631 | + // TEST #6 : verify config class is accessible |
|
| 632 | + case 6: |
|
| 633 | + if (! class_exists($config_class)) { |
|
| 634 | + if ($display_errors) { |
|
| 635 | + throw new EE_Error( |
|
| 636 | + sprintf( |
|
| 637 | + esc_html__( |
|
| 638 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 639 | + 'event_espresso' |
|
| 640 | + ), |
|
| 641 | + $config_class |
|
| 642 | + ) |
|
| 643 | + ); |
|
| 644 | + } |
|
| 645 | + return false; |
|
| 646 | + } |
|
| 647 | + break; |
|
| 648 | + // TEST #7 : check that config has even been set |
|
| 649 | + case 7: |
|
| 650 | + if (! isset($this->{$section}->{$name})) { |
|
| 651 | + if ($display_errors) { |
|
| 652 | + throw new EE_Error( |
|
| 653 | + sprintf( |
|
| 654 | + esc_html__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 655 | + $section, |
|
| 656 | + $name |
|
| 657 | + ) |
|
| 658 | + ); |
|
| 659 | + } |
|
| 660 | + return false; |
|
| 661 | + } else { |
|
| 662 | + // and make sure it's not serialized |
|
| 663 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 664 | + } |
|
| 665 | + break; |
|
| 666 | + // TEST #8 : check that config is the requested type |
|
| 667 | + case 8: |
|
| 668 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 669 | + if ($display_errors) { |
|
| 670 | + throw new EE_Error( |
|
| 671 | + sprintf( |
|
| 672 | + esc_html__( |
|
| 673 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 674 | + 'event_espresso' |
|
| 675 | + ), |
|
| 676 | + $section, |
|
| 677 | + $name, |
|
| 678 | + $config_class |
|
| 679 | + ) |
|
| 680 | + ); |
|
| 681 | + } |
|
| 682 | + return false; |
|
| 683 | + } |
|
| 684 | + break; |
|
| 685 | + // TEST #9 : verify config object |
|
| 686 | + case 9: |
|
| 687 | + if (! $config_obj instanceof EE_Config_Base) { |
|
| 688 | + if ($display_errors) { |
|
| 689 | + throw new EE_Error( |
|
| 690 | + sprintf( |
|
| 691 | + esc_html__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 692 | + print_r($config_obj, true) |
|
| 693 | + ) |
|
| 694 | + ); |
|
| 695 | + } |
|
| 696 | + return false; |
|
| 697 | + } |
|
| 698 | + break; |
|
| 699 | + } |
|
| 700 | + } |
|
| 701 | + } catch (EE_Error $e) { |
|
| 702 | + $e->get_error(); |
|
| 703 | + } |
|
| 704 | + // you have successfully run the gauntlet |
|
| 705 | + return true; |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * _generate_config_option_name |
|
| 711 | + * |
|
| 712 | + * @access protected |
|
| 713 | + * @param string $section |
|
| 714 | + * @param string $name |
|
| 715 | + * @return string |
|
| 716 | + */ |
|
| 717 | + private function _generate_config_option_name($section = '', $name = '') |
|
| 718 | + { |
|
| 719 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * _set_config_class |
|
| 725 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 726 | + * |
|
| 727 | + * @access private |
|
| 728 | + * @param string $config_class |
|
| 729 | + * @param string $name |
|
| 730 | + * @return string |
|
| 731 | + */ |
|
| 732 | + private function _set_config_class($config_class = '', $name = '') |
|
| 733 | + { |
|
| 734 | + return ! empty($config_class) |
|
| 735 | + ? $config_class |
|
| 736 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * @param string $section |
|
| 742 | + * @param string $name |
|
| 743 | + * @param string $config_class |
|
| 744 | + * @param EE_Config_Base|null $config_obj |
|
| 745 | + * @return EE_Config_Base |
|
| 746 | + */ |
|
| 747 | + public function set_config( |
|
| 748 | + string $section = '', |
|
| 749 | + string $name = '', |
|
| 750 | + string $config_class = '', |
|
| 751 | + EE_Config_Base $config_obj = null |
|
| 752 | + ): ?EE_Config_Base { |
|
| 753 | + // ensure config class is set to something |
|
| 754 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 755 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 756 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 757 | + return null; |
|
| 758 | + } |
|
| 759 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 760 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 761 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 762 | + $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 763 | + $this->update_addon_option_names(); |
|
| 764 | + } |
|
| 765 | + // verify the incoming config object but suppress errors |
|
| 766 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 767 | + $config_obj = new $config_class(); |
|
| 768 | + } |
|
| 769 | + if (get_option($config_option_name)) { |
|
| 770 | + EE_Config::log($config_option_name); |
|
| 771 | + try { |
|
| 772 | + update_option($config_option_name, $config_obj); |
|
| 773 | + } catch (Exception $exception) { |
|
| 774 | + throw new DomainException( |
|
| 775 | + sprintf( |
|
| 776 | + esc_html__( |
|
| 777 | + 'The following exception occurred while attempting to update the "%1$s" class for config section "%2$s->%3$s": %4$s', |
|
| 778 | + 'event_espresso' |
|
| 779 | + ), |
|
| 780 | + $config_class, |
|
| 781 | + $section, |
|
| 782 | + $name, |
|
| 783 | + $exception->getMessage() |
|
| 784 | + ) |
|
| 785 | + ); |
|
| 786 | + } |
|
| 787 | + $this->{$section}->{$name} = $config_obj; |
|
| 788 | + return $this->{$section}->{$name}; |
|
| 789 | + } else { |
|
| 790 | + // create a wp-option for this config |
|
| 791 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 792 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 793 | + return $this->{$section}->{$name}; |
|
| 794 | + } else { |
|
| 795 | + EE_Error::add_error( |
|
| 796 | + sprintf(esc_html__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 797 | + __FILE__, |
|
| 798 | + __FUNCTION__, |
|
| 799 | + __LINE__ |
|
| 800 | + ); |
|
| 801 | + return null; |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + |
|
| 807 | + /** |
|
| 808 | + * update_config |
|
| 809 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 810 | + * |
|
| 811 | + * @access public |
|
| 812 | + * @param string $section |
|
| 813 | + * @param string $name |
|
| 814 | + * @param EE_Config_Base|string $config_obj |
|
| 815 | + * @param bool $throw_errors |
|
| 816 | + * @return bool |
|
| 817 | + */ |
|
| 818 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 819 | + { |
|
| 820 | + // don't allow config updates during WP heartbeats |
|
| 821 | + /** @var RequestInterface $request */ |
|
| 822 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 823 | + if ($request->isWordPressHeartbeat()) { |
|
| 824 | + return false; |
|
| 825 | + } |
|
| 826 | + $config_obj = maybe_unserialize($config_obj); |
|
| 827 | + // get class name of the incoming object |
|
| 828 | + $config_class = get_class($config_obj); |
|
| 829 | + // run tests 1-5 and 9 to verify config |
|
| 830 | + if ( |
|
| 831 | + ! $this->_verify_config_params( |
|
| 832 | + $section, |
|
| 833 | + $name, |
|
| 834 | + $config_class, |
|
| 835 | + $config_obj, |
|
| 836 | + array(1, 2, 3, 4, 7, 9) |
|
| 837 | + ) |
|
| 838 | + ) { |
|
| 839 | + return false; |
|
| 840 | + } |
|
| 841 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 842 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 843 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 844 | + // save new config to db |
|
| 845 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 846 | + return true; |
|
| 847 | + } |
|
| 848 | + } else { |
|
| 849 | + // first check if the record already exists |
|
| 850 | + $existing_config = get_option($config_option_name); |
|
| 851 | + $config_obj = serialize($config_obj); |
|
| 852 | + // just return if db record is already up-to-date (NOT type safe comparison) |
|
| 853 | + if ($existing_config == $config_obj) { |
|
| 854 | + $this->{$section}->{$name} = $config_obj; |
|
| 855 | + return true; |
|
| 856 | + } elseif (update_option($config_option_name, $config_obj)) { |
|
| 857 | + EE_Config::log($config_option_name); |
|
| 858 | + // update wp-option for this config class |
|
| 859 | + $this->{$section}->{$name} = $config_obj; |
|
| 860 | + return true; |
|
| 861 | + } elseif ($throw_errors) { |
|
| 862 | + EE_Error::add_error( |
|
| 863 | + sprintf( |
|
| 864 | + esc_html__( |
|
| 865 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 866 | + 'event_espresso' |
|
| 867 | + ), |
|
| 868 | + $config_class, |
|
| 869 | + 'EE_Config->' . $section . '->' . $name |
|
| 870 | + ), |
|
| 871 | + __FILE__, |
|
| 872 | + __FUNCTION__, |
|
| 873 | + __LINE__ |
|
| 874 | + ); |
|
| 875 | + } |
|
| 876 | + } |
|
| 877 | + return false; |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + |
|
| 881 | + /** |
|
| 882 | + * get_config |
|
| 883 | + * |
|
| 884 | + * @access public |
|
| 885 | + * @param string $section |
|
| 886 | + * @param string $name |
|
| 887 | + * @param string $config_class |
|
| 888 | + * @return mixed EE_Config_Base | NULL |
|
| 889 | + */ |
|
| 890 | + public function get_config($section = '', $name = '', $config_class = '') |
|
| 891 | + { |
|
| 892 | + // ensure config class is set to something |
|
| 893 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 894 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 895 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 896 | + return null; |
|
| 897 | + } |
|
| 898 | + // now test if the requested config object exists, but suppress errors |
|
| 899 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 900 | + // config already exists, so pass it back |
|
| 901 | + return $this->{$section}->{$name}; |
|
| 902 | + } |
|
| 903 | + // load config option from db if it exists |
|
| 904 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 905 | + // verify the newly retrieved config object, but suppress errors |
|
| 906 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 907 | + // config is good, so set it and pass it back |
|
| 908 | + $this->{$section}->{$name} = $config_obj; |
|
| 909 | + return $this->{$section}->{$name}; |
|
| 910 | + } |
|
| 911 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 912 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
| 913 | + // verify the newly created config object |
|
| 914 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 915 | + return $this->{$section}->{$name}; |
|
| 916 | + } else { |
|
| 917 | + EE_Error::add_error( |
|
| 918 | + sprintf(esc_html__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 919 | + __FILE__, |
|
| 920 | + __FUNCTION__, |
|
| 921 | + __LINE__ |
|
| 922 | + ); |
|
| 923 | + } |
|
| 924 | + return null; |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * get_config_option |
|
| 930 | + * |
|
| 931 | + * @access public |
|
| 932 | + * @param string $config_option_name |
|
| 933 | + * @return mixed EE_Config_Base | FALSE |
|
| 934 | + */ |
|
| 935 | + public function get_config_option($config_option_name = '') |
|
| 936 | + { |
|
| 937 | + // retrieve the wp-option for this config class. |
|
| 938 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 939 | + if (empty($config_option)) { |
|
| 940 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 941 | + } |
|
| 942 | + return $config_option; |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + |
|
| 946 | + /** |
|
| 947 | + * log |
|
| 948 | + * |
|
| 949 | + * @param string $config_option_name |
|
| 950 | + */ |
|
| 951 | + public static function log($config_option_name = '') |
|
| 952 | + { |
|
| 953 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 954 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 955 | + /** @var RequestParams $request */ |
|
| 956 | + $request = LoaderFactory::getLoader()->getShared(RequestParams::class); |
|
| 957 | + $config_log[ (string) microtime(true) ] = array( |
|
| 958 | + 'config_name' => $config_option_name, |
|
| 959 | + 'request' => $request->requestParams(), |
|
| 960 | + ); |
|
| 961 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 962 | + } |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + |
|
| 966 | + /** |
|
| 967 | + * trim_log |
|
| 968 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 969 | + */ |
|
| 970 | + public static function trim_log() |
|
| 971 | + { |
|
| 972 | + if (! EE_Config::logging_enabled()) { |
|
| 973 | + return; |
|
| 974 | + } |
|
| 975 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 976 | + $log_length = count($config_log); |
|
| 977 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 978 | + ksort($config_log); |
|
| 979 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 980 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 981 | + } |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + |
|
| 985 | + /** |
|
| 986 | + * get_page_for_posts |
|
| 987 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 988 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 989 | + * |
|
| 990 | + * @access public |
|
| 991 | + * @return string |
|
| 992 | + */ |
|
| 993 | + public static function get_page_for_posts() |
|
| 994 | + { |
|
| 995 | + $page_for_posts = get_option('page_for_posts'); |
|
| 996 | + if (! $page_for_posts) { |
|
| 997 | + return 'posts'; |
|
| 998 | + } |
|
| 999 | + global $wpdb; |
|
| 1000 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 1001 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 1002 | + } |
|
| 1003 | + |
|
| 1004 | + |
|
| 1005 | + /** |
|
| 1006 | + * register_shortcodes_and_modules. |
|
| 1007 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 1008 | + * In fact, this is where we give modules a chance to let core know they exist |
|
| 1009 | + * so they can help trigger maintenance mode if it's needed |
|
| 1010 | + * |
|
| 1011 | + * @access public |
|
| 1012 | + * @return void |
|
| 1013 | + */ |
|
| 1014 | + public function register_shortcodes_and_modules() |
|
| 1015 | + { |
|
| 1016 | + // allow modules to set hooks for the rest of the system |
|
| 1017 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + |
|
| 1021 | + /** |
|
| 1022 | + * initialize_shortcodes_and_modules |
|
| 1023 | + * meaning they can start adding their hooks to get stuff done |
|
| 1024 | + * |
|
| 1025 | + * @access public |
|
| 1026 | + * @return void |
|
| 1027 | + */ |
|
| 1028 | + public function initialize_shortcodes_and_modules() |
|
| 1029 | + { |
|
| 1030 | + // allow modules to set hooks for the rest of the system |
|
| 1031 | + $this->_initialize_modules(); |
|
| 1032 | + } |
|
| 1033 | + |
|
| 1034 | + |
|
| 1035 | + /** |
|
| 1036 | + * widgets_init |
|
| 1037 | + * |
|
| 1038 | + * @access private |
|
| 1039 | + * @return void |
|
| 1040 | + */ |
|
| 1041 | + public function widgets_init() |
|
| 1042 | + { |
|
| 1043 | + // only init widgets on admin pages when not in complete maintenance, and |
|
| 1044 | + // on frontend when not in any maintenance mode |
|
| 1045 | + if ( |
|
| 1046 | + MaintenanceStatus::isDisabled() |
|
| 1047 | + || (is_admin() && MaintenanceStatus::isNotFullSite()) |
|
| 1048 | + ) { |
|
| 1049 | + // grab list of installed widgets |
|
| 1050 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1051 | + // filter list of modules to register |
|
| 1052 | + $widgets_to_register = apply_filters( |
|
| 1053 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1054 | + $widgets_to_register |
|
| 1055 | + ); |
|
| 1056 | + if (! empty($widgets_to_register)) { |
|
| 1057 | + // cycle thru widget folders |
|
| 1058 | + foreach ($widgets_to_register as $widget_path) { |
|
| 1059 | + // add to list of installed widget modules |
|
| 1060 | + EE_Config::register_ee_widget($widget_path); |
|
| 1061 | + } |
|
| 1062 | + } |
|
| 1063 | + // filter list of installed modules |
|
| 1064 | + EE_Registry::instance()->widgets = apply_filters( |
|
| 1065 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1066 | + EE_Registry::instance()->widgets |
|
| 1067 | + ); |
|
| 1068 | + } |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + |
|
| 1072 | + /** |
|
| 1073 | + * register_ee_widget - makes core aware of this widget |
|
| 1074 | + * |
|
| 1075 | + * @access public |
|
| 1076 | + * @param string $widget_path - full path up to and including widget folder |
|
| 1077 | + * @return void |
|
| 1078 | + */ |
|
| 1079 | + public static function register_ee_widget($widget_path = null) |
|
| 1080 | + { |
|
| 1081 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1082 | + $widget_ext = '.widget.php'; |
|
| 1083 | + // make all separators match |
|
| 1084 | + $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1085 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1086 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1087 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1088 | + $file_name = explode('.', basename($widget_path)); |
|
| 1089 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1090 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1091 | + // sanitize shortcode directory name |
|
| 1092 | + $widget = sanitize_key($widget); |
|
| 1093 | + // now we need to rebuild the shortcode path |
|
| 1094 | + $widget_path = explode('/', $widget_path); |
|
| 1095 | + // remove last segment |
|
| 1096 | + array_pop($widget_path); |
|
| 1097 | + // glue it back together |
|
| 1098 | + $widget_path = implode(DS, $widget_path); |
|
| 1099 | + } else { |
|
| 1100 | + // grab and sanitize widget directory name |
|
| 1101 | + $widget = sanitize_key(basename($widget_path)); |
|
| 1102 | + } |
|
| 1103 | + // create classname from widget directory name |
|
| 1104 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1105 | + // add class prefix |
|
| 1106 | + $widget_class = 'EEW_' . $widget; |
|
| 1107 | + // does the widget exist ? |
|
| 1108 | + if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1109 | + $msg = sprintf( |
|
| 1110 | + esc_html__( |
|
| 1111 | + 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1112 | + 'event_espresso' |
|
| 1113 | + ), |
|
| 1114 | + $widget_class, |
|
| 1115 | + $widget_path . '/' . $widget_class . $widget_ext |
|
| 1116 | + ); |
|
| 1117 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1118 | + return; |
|
| 1119 | + } |
|
| 1120 | + // load the widget class file |
|
| 1121 | + require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1122 | + // verify that class exists |
|
| 1123 | + if (! class_exists($widget_class)) { |
|
| 1124 | + $msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1125 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1126 | + return; |
|
| 1127 | + } |
|
| 1128 | + register_widget($widget_class); |
|
| 1129 | + // add to array of registered widgets |
|
| 1130 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + |
|
| 1134 | + /** |
|
| 1135 | + * _register_modules |
|
| 1136 | + * |
|
| 1137 | + * @access private |
|
| 1138 | + * @return array |
|
| 1139 | + */ |
|
| 1140 | + private function _register_modules() |
|
| 1141 | + { |
|
| 1142 | + // grab list of installed modules |
|
| 1143 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1144 | + // filter list of modules to register |
|
| 1145 | + $modules_to_register = apply_filters( |
|
| 1146 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1147 | + $modules_to_register |
|
| 1148 | + ); |
|
| 1149 | + if (! empty($modules_to_register)) { |
|
| 1150 | + // loop through folders |
|
| 1151 | + foreach ($modules_to_register as $module_path) { |
|
| 1152 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1153 | + if ( |
|
| 1154 | + $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1155 | + && $module_path !== EE_MODULES . 'gateways' |
|
| 1156 | + ) { |
|
| 1157 | + // add to list of installed modules |
|
| 1158 | + EE_Config::register_module($module_path); |
|
| 1159 | + } |
|
| 1160 | + } |
|
| 1161 | + } |
|
| 1162 | + // filter list of installed modules |
|
| 1163 | + return apply_filters( |
|
| 1164 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1165 | + EE_Registry::instance()->modules |
|
| 1166 | + ); |
|
| 1167 | + } |
|
| 1168 | + |
|
| 1169 | + |
|
| 1170 | + /** |
|
| 1171 | + * register_module - makes core aware of this module |
|
| 1172 | + * |
|
| 1173 | + * @access public |
|
| 1174 | + * @param string $module_path - full path up to and including module folder |
|
| 1175 | + * @return bool |
|
| 1176 | + */ |
|
| 1177 | + public static function register_module($module_path = null) |
|
| 1178 | + { |
|
| 1179 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1180 | + $module_ext = '.module.php'; |
|
| 1181 | + // make all separators match |
|
| 1182 | + $module_path = str_replace(array('\\', '/'), '/', $module_path); |
|
| 1183 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1184 | + if (strpos($module_path, $module_ext) !== false) { |
|
| 1185 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1186 | + $module_file = explode('.', basename($module_path)); |
|
| 1187 | + // now we need to rebuild the shortcode path |
|
| 1188 | + $module_path = explode('/', $module_path); |
|
| 1189 | + // remove last segment |
|
| 1190 | + array_pop($module_path); |
|
| 1191 | + // glue it back together |
|
| 1192 | + $module_path = implode('/', $module_path) . '/'; |
|
| 1193 | + // take first segment from file name pieces and sanitize it |
|
| 1194 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1195 | + // ensure class prefix is added |
|
| 1196 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1197 | + } else { |
|
| 1198 | + // we need to generate the filename based off of the folder name |
|
| 1199 | + // grab and sanitize module name |
|
| 1200 | + $module = strtolower(basename($module_path)); |
|
| 1201 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1202 | + // like trailingslashit() |
|
| 1203 | + $module_path = rtrim($module_path, '/') . '/'; |
|
| 1204 | + // create classname from module directory name |
|
| 1205 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1206 | + // add class prefix |
|
| 1207 | + $module_class = 'EED_' . $module; |
|
| 1208 | + } |
|
| 1209 | + // does the module exist ? |
|
| 1210 | + if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1211 | + $msg = sprintf( |
|
| 1212 | + esc_html__( |
|
| 1213 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1214 | + 'event_espresso' |
|
| 1215 | + ), |
|
| 1216 | + $module |
|
| 1217 | + ); |
|
| 1218 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1219 | + return false; |
|
| 1220 | + } |
|
| 1221 | + // load the module class file |
|
| 1222 | + require_once($module_path . $module_class . $module_ext); |
|
| 1223 | + // verify that class exists |
|
| 1224 | + if (! class_exists($module_class)) { |
|
| 1225 | + $msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1226 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1227 | + return false; |
|
| 1228 | + } |
|
| 1229 | + // add to array of registered modules |
|
| 1230 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1231 | + do_action( |
|
| 1232 | + 'AHEE__EE_Config__register_module__complete', |
|
| 1233 | + $module_class, |
|
| 1234 | + EE_Registry::instance()->modules->{$module_class} |
|
| 1235 | + ); |
|
| 1236 | + return true; |
|
| 1237 | + } |
|
| 1238 | + |
|
| 1239 | + |
|
| 1240 | + /** |
|
| 1241 | + * _initialize_modules |
|
| 1242 | + * allow modules to set hooks for the rest of the system |
|
| 1243 | + * |
|
| 1244 | + * @access private |
|
| 1245 | + * @return void |
|
| 1246 | + */ |
|
| 1247 | + private function _initialize_modules() |
|
| 1248 | + { |
|
| 1249 | + // cycle thru shortcode folders |
|
| 1250 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1251 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1252 | + // which set hooks ? |
|
| 1253 | + if (is_admin() && is_callable([$module_class, 'set_hooks_admin'])) { |
|
| 1254 | + // fire immediately |
|
| 1255 | + call_user_func([$module_class, 'set_hooks_admin']); |
|
| 1256 | + } else { |
|
| 1257 | + // delay until other systems are online |
|
| 1258 | + add_action( |
|
| 1259 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1260 | + array($module_class, 'set_hooks') |
|
| 1261 | + ); |
|
| 1262 | + } |
|
| 1263 | + } |
|
| 1264 | + } |
|
| 1265 | + |
|
| 1266 | + |
|
| 1267 | + /** |
|
| 1268 | + * register_route - adds module method routes to route_map |
|
| 1269 | + * |
|
| 1270 | + * @access public |
|
| 1271 | + * @param string $route - "pretty" public alias for module method |
|
| 1272 | + * @param string $module - module name (classname without EED_ prefix) |
|
| 1273 | + * @param string $method_name - the actual module method to be routed to |
|
| 1274 | + * @param string $key - url param key indicating a route is being called |
|
| 1275 | + * @return bool |
|
| 1276 | + */ |
|
| 1277 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1278 | + { |
|
| 1279 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1280 | + $module = str_replace('EED_', '', $module); |
|
| 1281 | + $module_class = 'EED_' . $module; |
|
| 1282 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1283 | + $msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1284 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1285 | + return false; |
|
| 1286 | + } |
|
| 1287 | + if (empty($route)) { |
|
| 1288 | + $msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1289 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1290 | + return false; |
|
| 1291 | + } |
|
| 1292 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1293 | + $msg = sprintf( |
|
| 1294 | + esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1295 | + $route |
|
| 1296 | + ); |
|
| 1297 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1298 | + return false; |
|
| 1299 | + } |
|
| 1300 | + EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1301 | + return true; |
|
| 1302 | + } |
|
| 1303 | + |
|
| 1304 | + |
|
| 1305 | + /** |
|
| 1306 | + * get_route - get module method route |
|
| 1307 | + * |
|
| 1308 | + * @access public |
|
| 1309 | + * @param string $route - "pretty" public alias for module method |
|
| 1310 | + * @param string $key - url param key indicating a route is being called |
|
| 1311 | + * @return string |
|
| 1312 | + */ |
|
| 1313 | + public static function get_route($route = null, $key = 'ee') |
|
| 1314 | + { |
|
| 1315 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1316 | + $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1317 | + if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1318 | + return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1319 | + } |
|
| 1320 | + return null; |
|
| 1321 | + } |
|
| 1322 | + |
|
| 1323 | + |
|
| 1324 | + /** |
|
| 1325 | + * get_routes - get ALL module method routes |
|
| 1326 | + * |
|
| 1327 | + * @access public |
|
| 1328 | + * @return array |
|
| 1329 | + */ |
|
| 1330 | + public static function get_routes() |
|
| 1331 | + { |
|
| 1332 | + return EE_Config::$_module_route_map; |
|
| 1333 | + } |
|
| 1334 | + |
|
| 1335 | + |
|
| 1336 | + /** |
|
| 1337 | + * register_forward - allows modules to forward request to another module for further processing |
|
| 1338 | + * |
|
| 1339 | + * @access public |
|
| 1340 | + * @param string $route - "pretty" public alias for module method |
|
| 1341 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1342 | + * class, allows different forwards to be served based on status |
|
| 1343 | + * @param array|string $forward - function name or array( class, method ) |
|
| 1344 | + * @param string $key - url param key indicating a route is being called |
|
| 1345 | + * @return bool |
|
| 1346 | + */ |
|
| 1347 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1348 | + { |
|
| 1349 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1350 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1351 | + $msg = sprintf( |
|
| 1352 | + esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1353 | + $route |
|
| 1354 | + ); |
|
| 1355 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1356 | + return false; |
|
| 1357 | + } |
|
| 1358 | + if (empty($forward)) { |
|
| 1359 | + $msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1360 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1361 | + return false; |
|
| 1362 | + } |
|
| 1363 | + if (is_array($forward)) { |
|
| 1364 | + if (! isset($forward[1])) { |
|
| 1365 | + $msg = sprintf( |
|
| 1366 | + esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1367 | + $route |
|
| 1368 | + ); |
|
| 1369 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1370 | + return false; |
|
| 1371 | + } |
|
| 1372 | + if (! method_exists($forward[0], $forward[1])) { |
|
| 1373 | + $msg = sprintf( |
|
| 1374 | + esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1375 | + $forward[1], |
|
| 1376 | + $route |
|
| 1377 | + ); |
|
| 1378 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1379 | + return false; |
|
| 1380 | + } |
|
| 1381 | + } elseif (! function_exists($forward)) { |
|
| 1382 | + $msg = sprintf( |
|
| 1383 | + esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1384 | + $forward, |
|
| 1385 | + $route |
|
| 1386 | + ); |
|
| 1387 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1388 | + return false; |
|
| 1389 | + } |
|
| 1390 | + EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1391 | + return true; |
|
| 1392 | + } |
|
| 1393 | + |
|
| 1394 | + |
|
| 1395 | + /** |
|
| 1396 | + * get_forward - get forwarding route |
|
| 1397 | + * |
|
| 1398 | + * @access public |
|
| 1399 | + * @param string $route - "pretty" public alias for module method |
|
| 1400 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1401 | + * allows different forwards to be served based on status |
|
| 1402 | + * @param string $key - url param key indicating a route is being called |
|
| 1403 | + * @return string |
|
| 1404 | + */ |
|
| 1405 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1406 | + { |
|
| 1407 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1408 | + if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1409 | + return apply_filters( |
|
| 1410 | + 'FHEE__EE_Config__get_forward', |
|
| 1411 | + EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1412 | + $route, |
|
| 1413 | + $status |
|
| 1414 | + ); |
|
| 1415 | + } |
|
| 1416 | + return null; |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + |
|
| 1420 | + /** |
|
| 1421 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1422 | + * results |
|
| 1423 | + * |
|
| 1424 | + * @access public |
|
| 1425 | + * @param string $route - "pretty" public alias for module method |
|
| 1426 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1427 | + * allows different views to be served based on status |
|
| 1428 | + * @param string $view |
|
| 1429 | + * @param string $key - url param key indicating a route is being called |
|
| 1430 | + * @return bool |
|
| 1431 | + */ |
|
| 1432 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1433 | + { |
|
| 1434 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1435 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1436 | + $msg = sprintf( |
|
| 1437 | + esc_html__('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1438 | + $route |
|
| 1439 | + ); |
|
| 1440 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1441 | + return false; |
|
| 1442 | + } |
|
| 1443 | + if (! is_readable($view)) { |
|
| 1444 | + $msg = sprintf( |
|
| 1445 | + esc_html__( |
|
| 1446 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1447 | + 'event_espresso' |
|
| 1448 | + ), |
|
| 1449 | + $view |
|
| 1450 | + ); |
|
| 1451 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1452 | + return false; |
|
| 1453 | + } |
|
| 1454 | + EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1455 | + return true; |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + |
|
| 1459 | + /** |
|
| 1460 | + * get_view - get view for route and status |
|
| 1461 | + * |
|
| 1462 | + * @access public |
|
| 1463 | + * @param string $route - "pretty" public alias for module method |
|
| 1464 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1465 | + * allows different views to be served based on status |
|
| 1466 | + * @param string $key - url param key indicating a route is being called |
|
| 1467 | + * @return string |
|
| 1468 | + */ |
|
| 1469 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1470 | + { |
|
| 1471 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1472 | + if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1473 | + return apply_filters( |
|
| 1474 | + 'FHEE__EE_Config__get_view', |
|
| 1475 | + EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1476 | + $route, |
|
| 1477 | + $status |
|
| 1478 | + ); |
|
| 1479 | + } |
|
| 1480 | + return null; |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + |
|
| 1484 | + public function update_addon_option_names() |
|
| 1485 | + { |
|
| 1486 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1487 | + } |
|
| 1488 | + |
|
| 1489 | + |
|
| 1490 | + public function shutdown() |
|
| 1491 | + { |
|
| 1492 | + $this->update_addon_option_names(); |
|
| 1493 | + } |
|
| 1494 | + |
|
| 1495 | + |
|
| 1496 | + /** |
|
| 1497 | + * @return LegacyShortcodesManager |
|
| 1498 | + */ |
|
| 1499 | + public static function getLegacyShortcodesManager() |
|
| 1500 | + { |
|
| 1501 | + if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1502 | + EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared( |
|
| 1503 | + LegacyShortcodesManager::class |
|
| 1504 | + ); |
|
| 1505 | + } |
|
| 1506 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1507 | + } |
|
| 1508 | + |
|
| 1509 | + |
|
| 1510 | + /** |
|
| 1511 | + * register_shortcode - makes core aware of this shortcode |
|
| 1512 | + * |
|
| 1513 | + * @deprecated 4.9.26 |
|
| 1514 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1515 | + * @return bool |
|
| 1516 | + */ |
|
| 1517 | + public static function register_shortcode($shortcode_path = null) |
|
| 1518 | + { |
|
| 1519 | + EE_Error::doing_it_wrong( |
|
| 1520 | + __METHOD__, |
|
| 1521 | + esc_html__( |
|
| 1522 | + 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1523 | + 'event_espresso' |
|
| 1524 | + ), |
|
| 1525 | + '4.9.26' |
|
| 1526 | + ); |
|
| 1527 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1528 | + } |
|
| 1529 | 1529 | } |
| 1530 | 1530 | |
| 1531 | 1531 | /** |
@@ -1535,98 +1535,98 @@ discard block |
||
| 1535 | 1535 | */ |
| 1536 | 1536 | class EE_Config_Base |
| 1537 | 1537 | { |
| 1538 | - /** |
|
| 1539 | - * Utility function for escaping the value of a property and returning. |
|
| 1540 | - * |
|
| 1541 | - * @param string $property property name (checks to see if exists). |
|
| 1542 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1543 | - * @throws EE_Error |
|
| 1544 | - */ |
|
| 1545 | - public function get_pretty($property) |
|
| 1546 | - { |
|
| 1547 | - if (! property_exists($this, $property)) { |
|
| 1548 | - throw new EE_Error( |
|
| 1549 | - sprintf( |
|
| 1550 | - esc_html__( |
|
| 1551 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1552 | - 'event_espresso' |
|
| 1553 | - ), |
|
| 1554 | - get_class($this), |
|
| 1555 | - $property |
|
| 1556 | - ) |
|
| 1557 | - ); |
|
| 1558 | - } |
|
| 1559 | - // just handling escaping of strings for now. |
|
| 1560 | - if (is_string($this->{$property})) { |
|
| 1561 | - return stripslashes($this->{$property}); |
|
| 1562 | - } |
|
| 1563 | - return $this->{$property}; |
|
| 1564 | - } |
|
| 1565 | - |
|
| 1566 | - |
|
| 1567 | - public function populate() |
|
| 1568 | - { |
|
| 1569 | - // grab defaults via a new instance of this class. |
|
| 1570 | - $class_name = get_class($this); |
|
| 1571 | - $defaults = new $class_name(); |
|
| 1572 | - // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1573 | - // default from our $defaults object. |
|
| 1574 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1575 | - if ($this->{$property} === null) { |
|
| 1576 | - $this->{$property} = $value; |
|
| 1577 | - } |
|
| 1578 | - } |
|
| 1579 | - // cleanup |
|
| 1580 | - unset($defaults); |
|
| 1581 | - } |
|
| 1582 | - |
|
| 1583 | - |
|
| 1584 | - /** |
|
| 1585 | - * __isset |
|
| 1586 | - * |
|
| 1587 | - * @param $a |
|
| 1588 | - * @return bool |
|
| 1589 | - */ |
|
| 1590 | - public function __isset($a) |
|
| 1591 | - { |
|
| 1592 | - return false; |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - |
|
| 1596 | - /** |
|
| 1597 | - * __unset |
|
| 1598 | - * |
|
| 1599 | - * @param $a |
|
| 1600 | - * @return bool |
|
| 1601 | - */ |
|
| 1602 | - public function __unset($a) |
|
| 1603 | - { |
|
| 1604 | - return false; |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - |
|
| 1608 | - /** |
|
| 1609 | - * __clone |
|
| 1610 | - */ |
|
| 1611 | - public function __clone() |
|
| 1612 | - { |
|
| 1613 | - } |
|
| 1614 | - |
|
| 1615 | - |
|
| 1616 | - /** |
|
| 1617 | - * __wakeup |
|
| 1618 | - */ |
|
| 1619 | - public function __wakeup() |
|
| 1620 | - { |
|
| 1621 | - } |
|
| 1622 | - |
|
| 1623 | - |
|
| 1624 | - /** |
|
| 1625 | - * __destruct |
|
| 1626 | - */ |
|
| 1627 | - public function __destruct() |
|
| 1628 | - { |
|
| 1629 | - } |
|
| 1538 | + /** |
|
| 1539 | + * Utility function for escaping the value of a property and returning. |
|
| 1540 | + * |
|
| 1541 | + * @param string $property property name (checks to see if exists). |
|
| 1542 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1543 | + * @throws EE_Error |
|
| 1544 | + */ |
|
| 1545 | + public function get_pretty($property) |
|
| 1546 | + { |
|
| 1547 | + if (! property_exists($this, $property)) { |
|
| 1548 | + throw new EE_Error( |
|
| 1549 | + sprintf( |
|
| 1550 | + esc_html__( |
|
| 1551 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1552 | + 'event_espresso' |
|
| 1553 | + ), |
|
| 1554 | + get_class($this), |
|
| 1555 | + $property |
|
| 1556 | + ) |
|
| 1557 | + ); |
|
| 1558 | + } |
|
| 1559 | + // just handling escaping of strings for now. |
|
| 1560 | + if (is_string($this->{$property})) { |
|
| 1561 | + return stripslashes($this->{$property}); |
|
| 1562 | + } |
|
| 1563 | + return $this->{$property}; |
|
| 1564 | + } |
|
| 1565 | + |
|
| 1566 | + |
|
| 1567 | + public function populate() |
|
| 1568 | + { |
|
| 1569 | + // grab defaults via a new instance of this class. |
|
| 1570 | + $class_name = get_class($this); |
|
| 1571 | + $defaults = new $class_name(); |
|
| 1572 | + // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1573 | + // default from our $defaults object. |
|
| 1574 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1575 | + if ($this->{$property} === null) { |
|
| 1576 | + $this->{$property} = $value; |
|
| 1577 | + } |
|
| 1578 | + } |
|
| 1579 | + // cleanup |
|
| 1580 | + unset($defaults); |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + |
|
| 1584 | + /** |
|
| 1585 | + * __isset |
|
| 1586 | + * |
|
| 1587 | + * @param $a |
|
| 1588 | + * @return bool |
|
| 1589 | + */ |
|
| 1590 | + public function __isset($a) |
|
| 1591 | + { |
|
| 1592 | + return false; |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + |
|
| 1596 | + /** |
|
| 1597 | + * __unset |
|
| 1598 | + * |
|
| 1599 | + * @param $a |
|
| 1600 | + * @return bool |
|
| 1601 | + */ |
|
| 1602 | + public function __unset($a) |
|
| 1603 | + { |
|
| 1604 | + return false; |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + |
|
| 1608 | + /** |
|
| 1609 | + * __clone |
|
| 1610 | + */ |
|
| 1611 | + public function __clone() |
|
| 1612 | + { |
|
| 1613 | + } |
|
| 1614 | + |
|
| 1615 | + |
|
| 1616 | + /** |
|
| 1617 | + * __wakeup |
|
| 1618 | + */ |
|
| 1619 | + public function __wakeup() |
|
| 1620 | + { |
|
| 1621 | + } |
|
| 1622 | + |
|
| 1623 | + |
|
| 1624 | + /** |
|
| 1625 | + * __destruct |
|
| 1626 | + */ |
|
| 1627 | + public function __destruct() |
|
| 1628 | + { |
|
| 1629 | + } |
|
| 1630 | 1630 | } |
| 1631 | 1631 | |
| 1632 | 1632 | /** |
@@ -1634,304 +1634,304 @@ discard block |
||
| 1634 | 1634 | */ |
| 1635 | 1635 | class EE_Core_Config extends EE_Config_Base |
| 1636 | 1636 | { |
| 1637 | - const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1638 | - |
|
| 1639 | - |
|
| 1640 | - public $current_blog_id; |
|
| 1641 | - |
|
| 1642 | - public $ee_ueip_optin; |
|
| 1643 | - |
|
| 1644 | - public $ee_ueip_has_notified; |
|
| 1645 | - |
|
| 1646 | - /** |
|
| 1647 | - * Not to be confused with the 4 critical page variables (See |
|
| 1648 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1649 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1650 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1651 | - * |
|
| 1652 | - * @var array |
|
| 1653 | - */ |
|
| 1654 | - public $post_shortcodes; |
|
| 1655 | - |
|
| 1656 | - public $module_route_map; |
|
| 1657 | - |
|
| 1658 | - public $module_forward_map; |
|
| 1659 | - |
|
| 1660 | - public $module_view_map; |
|
| 1661 | - |
|
| 1662 | - /** |
|
| 1663 | - * The next 4 vars are the IDs of critical EE pages. |
|
| 1664 | - * |
|
| 1665 | - * @var int |
|
| 1666 | - */ |
|
| 1667 | - public $reg_page_id; |
|
| 1668 | - |
|
| 1669 | - public $txn_page_id; |
|
| 1670 | - |
|
| 1671 | - public $thank_you_page_id; |
|
| 1672 | - |
|
| 1673 | - public $cancel_page_id; |
|
| 1674 | - |
|
| 1675 | - /** |
|
| 1676 | - * The next 4 vars are the URLs of critical EE pages. |
|
| 1677 | - * |
|
| 1678 | - * @var int |
|
| 1679 | - */ |
|
| 1680 | - public $reg_page_url; |
|
| 1681 | - |
|
| 1682 | - public $txn_page_url; |
|
| 1683 | - |
|
| 1684 | - public $thank_you_page_url; |
|
| 1685 | - |
|
| 1686 | - public $cancel_page_url; |
|
| 1687 | - |
|
| 1688 | - /** |
|
| 1689 | - * The next vars relate to the custom slugs for EE CPT routes |
|
| 1690 | - */ |
|
| 1691 | - public $event_cpt_slug; |
|
| 1692 | - |
|
| 1693 | - /** |
|
| 1694 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1695 | - * request across blog switches in a multisite context. |
|
| 1696 | - * Avoids extra queries to the db for this option. |
|
| 1697 | - * |
|
| 1698 | - * @var bool |
|
| 1699 | - */ |
|
| 1700 | - public static $ee_ueip_option; |
|
| 1701 | - |
|
| 1702 | - |
|
| 1703 | - /** |
|
| 1704 | - * class constructor |
|
| 1705 | - * |
|
| 1706 | - * @access public |
|
| 1707 | - */ |
|
| 1708 | - public function __construct() |
|
| 1709 | - { |
|
| 1710 | - // set default organization settings |
|
| 1711 | - $this->current_blog_id = get_current_blog_id(); |
|
| 1712 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1713 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1714 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1715 | - $this->post_shortcodes = array(); |
|
| 1716 | - $this->module_route_map = array(); |
|
| 1717 | - $this->module_forward_map = array(); |
|
| 1718 | - $this->module_view_map = array(); |
|
| 1719 | - // critical EE page IDs |
|
| 1720 | - $this->reg_page_id = 0; |
|
| 1721 | - $this->txn_page_id = 0; |
|
| 1722 | - $this->thank_you_page_id = 0; |
|
| 1723 | - $this->cancel_page_id = 0; |
|
| 1724 | - // critical EE page URLs |
|
| 1725 | - $this->reg_page_url = ''; |
|
| 1726 | - $this->txn_page_url = ''; |
|
| 1727 | - $this->thank_you_page_url = ''; |
|
| 1728 | - $this->cancel_page_url = ''; |
|
| 1729 | - // cpt slugs |
|
| 1730 | - $this->event_cpt_slug = esc_html__('events', 'event_espresso'); |
|
| 1731 | - // ueip constant check |
|
| 1732 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1733 | - $this->ee_ueip_optin = false; |
|
| 1734 | - $this->ee_ueip_has_notified = true; |
|
| 1735 | - } |
|
| 1736 | - } |
|
| 1737 | - |
|
| 1738 | - |
|
| 1739 | - /** |
|
| 1740 | - * @return array |
|
| 1741 | - */ |
|
| 1742 | - public function get_critical_pages_array() |
|
| 1743 | - { |
|
| 1744 | - return array( |
|
| 1745 | - $this->reg_page_id, |
|
| 1746 | - $this->txn_page_id, |
|
| 1747 | - $this->thank_you_page_id, |
|
| 1748 | - $this->cancel_page_id, |
|
| 1749 | - ); |
|
| 1750 | - } |
|
| 1751 | - |
|
| 1752 | - |
|
| 1753 | - /** |
|
| 1754 | - * @return array |
|
| 1755 | - */ |
|
| 1756 | - public function get_critical_pages_shortcodes_array() |
|
| 1757 | - { |
|
| 1758 | - return array( |
|
| 1759 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1760 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1761 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1762 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1763 | - ); |
|
| 1764 | - } |
|
| 1765 | - |
|
| 1766 | - |
|
| 1767 | - /** |
|
| 1768 | - * gets/returns URL for EE reg_page |
|
| 1769 | - * |
|
| 1770 | - * @access public |
|
| 1771 | - * @return string |
|
| 1772 | - */ |
|
| 1773 | - public function reg_page_url() |
|
| 1774 | - { |
|
| 1775 | - if (! $this->reg_page_url) { |
|
| 1776 | - $this->reg_page_url = add_query_arg( |
|
| 1777 | - array('uts' => time()), |
|
| 1778 | - get_permalink($this->reg_page_id) |
|
| 1779 | - ) . '#checkout'; |
|
| 1780 | - } |
|
| 1781 | - return $this->reg_page_url; |
|
| 1782 | - } |
|
| 1783 | - |
|
| 1784 | - |
|
| 1785 | - /** |
|
| 1786 | - * gets/returns URL for EE txn_page |
|
| 1787 | - * |
|
| 1788 | - * @param array $query_args like what gets passed to |
|
| 1789 | - * add_query_arg() as the first argument |
|
| 1790 | - * @access public |
|
| 1791 | - * @return string |
|
| 1792 | - */ |
|
| 1793 | - public function txn_page_url($query_args = array()) |
|
| 1794 | - { |
|
| 1795 | - if (! $this->txn_page_url) { |
|
| 1796 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1797 | - } |
|
| 1798 | - if ($query_args) { |
|
| 1799 | - return add_query_arg($query_args, $this->txn_page_url); |
|
| 1800 | - } else { |
|
| 1801 | - return $this->txn_page_url; |
|
| 1802 | - } |
|
| 1803 | - } |
|
| 1804 | - |
|
| 1805 | - |
|
| 1806 | - /** |
|
| 1807 | - * gets/returns URL for EE thank_you_page |
|
| 1808 | - * |
|
| 1809 | - * @param array $query_args like what gets passed to |
|
| 1810 | - * add_query_arg() as the first argument |
|
| 1811 | - * @access public |
|
| 1812 | - * @return string |
|
| 1813 | - */ |
|
| 1814 | - public function thank_you_page_url($query_args = array()) |
|
| 1815 | - { |
|
| 1816 | - if (! $this->thank_you_page_url) { |
|
| 1817 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1818 | - } |
|
| 1819 | - if ($query_args) { |
|
| 1820 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1821 | - } else { |
|
| 1822 | - return $this->thank_you_page_url; |
|
| 1823 | - } |
|
| 1824 | - } |
|
| 1825 | - |
|
| 1826 | - |
|
| 1827 | - /** |
|
| 1828 | - * gets/returns URL for EE cancel_page |
|
| 1829 | - * |
|
| 1830 | - * @access public |
|
| 1831 | - * @return string |
|
| 1832 | - */ |
|
| 1833 | - public function cancel_page_url() |
|
| 1834 | - { |
|
| 1835 | - if (! $this->cancel_page_url) { |
|
| 1836 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1837 | - } |
|
| 1838 | - return $this->cancel_page_url; |
|
| 1839 | - } |
|
| 1840 | - |
|
| 1841 | - |
|
| 1842 | - /** |
|
| 1843 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1844 | - * |
|
| 1845 | - * @since 4.7.5 |
|
| 1846 | - */ |
|
| 1847 | - protected function _reset_urls() |
|
| 1848 | - { |
|
| 1849 | - $this->reg_page_url = ''; |
|
| 1850 | - $this->txn_page_url = ''; |
|
| 1851 | - $this->cancel_page_url = ''; |
|
| 1852 | - $this->thank_you_page_url = ''; |
|
| 1853 | - } |
|
| 1854 | - |
|
| 1855 | - |
|
| 1856 | - /** |
|
| 1857 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1858 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1859 | - * on the main site only. |
|
| 1860 | - * |
|
| 1861 | - * @return bool |
|
| 1862 | - */ |
|
| 1863 | - protected function _get_main_ee_ueip_optin() |
|
| 1864 | - { |
|
| 1865 | - // if this is the main site then we can just bypass our direct query. |
|
| 1866 | - if (is_main_site()) { |
|
| 1867 | - return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1868 | - } |
|
| 1869 | - // is this already cached for this request? If so use it. |
|
| 1870 | - if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1871 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1872 | - } |
|
| 1873 | - global $wpdb; |
|
| 1874 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1875 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1876 | - $option = self::OPTION_NAME_UXIP; |
|
| 1877 | - // set correct table for query |
|
| 1878 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1879 | - // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1880 | - // get_blog_option() does a switch_to_blog and that could cause infinite recursion because EE_Core_Config might be |
|
| 1881 | - // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1882 | - // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1883 | - // for the purpose of caching. |
|
| 1884 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1885 | - if (false !== $pre) { |
|
| 1886 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1887 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1888 | - } |
|
| 1889 | - $row = $wpdb->get_row( |
|
| 1890 | - $wpdb->prepare( |
|
| 1891 | - "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1892 | - $option |
|
| 1893 | - ) |
|
| 1894 | - ); |
|
| 1895 | - if (is_object($row)) { |
|
| 1896 | - $value = $row->option_value; |
|
| 1897 | - } else { // option does not exist so use default. |
|
| 1898 | - EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1899 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1900 | - } |
|
| 1901 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1902 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1903 | - } |
|
| 1904 | - |
|
| 1905 | - |
|
| 1906 | - /** |
|
| 1907 | - * Utility function for escaping the value of a property and returning. |
|
| 1908 | - * |
|
| 1909 | - * @param string $property property name (checks to see if exists). |
|
| 1910 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1911 | - * @throws EE_Error |
|
| 1912 | - */ |
|
| 1913 | - public function get_pretty($property) |
|
| 1914 | - { |
|
| 1915 | - if ($property === self::OPTION_NAME_UXIP) { |
|
| 1916 | - return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1917 | - } |
|
| 1918 | - return parent::get_pretty($property); |
|
| 1919 | - } |
|
| 1920 | - |
|
| 1921 | - |
|
| 1922 | - /** |
|
| 1923 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1924 | - * on the object. |
|
| 1925 | - * |
|
| 1926 | - * @return array |
|
| 1927 | - */ |
|
| 1928 | - public function __sleep() |
|
| 1929 | - { |
|
| 1930 | - // reset all url properties |
|
| 1931 | - $this->_reset_urls(); |
|
| 1932 | - // return what to save to db |
|
| 1933 | - return array_keys(get_object_vars($this)); |
|
| 1934 | - } |
|
| 1637 | + const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1638 | + |
|
| 1639 | + |
|
| 1640 | + public $current_blog_id; |
|
| 1641 | + |
|
| 1642 | + public $ee_ueip_optin; |
|
| 1643 | + |
|
| 1644 | + public $ee_ueip_has_notified; |
|
| 1645 | + |
|
| 1646 | + /** |
|
| 1647 | + * Not to be confused with the 4 critical page variables (See |
|
| 1648 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1649 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1650 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1651 | + * |
|
| 1652 | + * @var array |
|
| 1653 | + */ |
|
| 1654 | + public $post_shortcodes; |
|
| 1655 | + |
|
| 1656 | + public $module_route_map; |
|
| 1657 | + |
|
| 1658 | + public $module_forward_map; |
|
| 1659 | + |
|
| 1660 | + public $module_view_map; |
|
| 1661 | + |
|
| 1662 | + /** |
|
| 1663 | + * The next 4 vars are the IDs of critical EE pages. |
|
| 1664 | + * |
|
| 1665 | + * @var int |
|
| 1666 | + */ |
|
| 1667 | + public $reg_page_id; |
|
| 1668 | + |
|
| 1669 | + public $txn_page_id; |
|
| 1670 | + |
|
| 1671 | + public $thank_you_page_id; |
|
| 1672 | + |
|
| 1673 | + public $cancel_page_id; |
|
| 1674 | + |
|
| 1675 | + /** |
|
| 1676 | + * The next 4 vars are the URLs of critical EE pages. |
|
| 1677 | + * |
|
| 1678 | + * @var int |
|
| 1679 | + */ |
|
| 1680 | + public $reg_page_url; |
|
| 1681 | + |
|
| 1682 | + public $txn_page_url; |
|
| 1683 | + |
|
| 1684 | + public $thank_you_page_url; |
|
| 1685 | + |
|
| 1686 | + public $cancel_page_url; |
|
| 1687 | + |
|
| 1688 | + /** |
|
| 1689 | + * The next vars relate to the custom slugs for EE CPT routes |
|
| 1690 | + */ |
|
| 1691 | + public $event_cpt_slug; |
|
| 1692 | + |
|
| 1693 | + /** |
|
| 1694 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1695 | + * request across blog switches in a multisite context. |
|
| 1696 | + * Avoids extra queries to the db for this option. |
|
| 1697 | + * |
|
| 1698 | + * @var bool |
|
| 1699 | + */ |
|
| 1700 | + public static $ee_ueip_option; |
|
| 1701 | + |
|
| 1702 | + |
|
| 1703 | + /** |
|
| 1704 | + * class constructor |
|
| 1705 | + * |
|
| 1706 | + * @access public |
|
| 1707 | + */ |
|
| 1708 | + public function __construct() |
|
| 1709 | + { |
|
| 1710 | + // set default organization settings |
|
| 1711 | + $this->current_blog_id = get_current_blog_id(); |
|
| 1712 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1713 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1714 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1715 | + $this->post_shortcodes = array(); |
|
| 1716 | + $this->module_route_map = array(); |
|
| 1717 | + $this->module_forward_map = array(); |
|
| 1718 | + $this->module_view_map = array(); |
|
| 1719 | + // critical EE page IDs |
|
| 1720 | + $this->reg_page_id = 0; |
|
| 1721 | + $this->txn_page_id = 0; |
|
| 1722 | + $this->thank_you_page_id = 0; |
|
| 1723 | + $this->cancel_page_id = 0; |
|
| 1724 | + // critical EE page URLs |
|
| 1725 | + $this->reg_page_url = ''; |
|
| 1726 | + $this->txn_page_url = ''; |
|
| 1727 | + $this->thank_you_page_url = ''; |
|
| 1728 | + $this->cancel_page_url = ''; |
|
| 1729 | + // cpt slugs |
|
| 1730 | + $this->event_cpt_slug = esc_html__('events', 'event_espresso'); |
|
| 1731 | + // ueip constant check |
|
| 1732 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1733 | + $this->ee_ueip_optin = false; |
|
| 1734 | + $this->ee_ueip_has_notified = true; |
|
| 1735 | + } |
|
| 1736 | + } |
|
| 1737 | + |
|
| 1738 | + |
|
| 1739 | + /** |
|
| 1740 | + * @return array |
|
| 1741 | + */ |
|
| 1742 | + public function get_critical_pages_array() |
|
| 1743 | + { |
|
| 1744 | + return array( |
|
| 1745 | + $this->reg_page_id, |
|
| 1746 | + $this->txn_page_id, |
|
| 1747 | + $this->thank_you_page_id, |
|
| 1748 | + $this->cancel_page_id, |
|
| 1749 | + ); |
|
| 1750 | + } |
|
| 1751 | + |
|
| 1752 | + |
|
| 1753 | + /** |
|
| 1754 | + * @return array |
|
| 1755 | + */ |
|
| 1756 | + public function get_critical_pages_shortcodes_array() |
|
| 1757 | + { |
|
| 1758 | + return array( |
|
| 1759 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1760 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1761 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1762 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1763 | + ); |
|
| 1764 | + } |
|
| 1765 | + |
|
| 1766 | + |
|
| 1767 | + /** |
|
| 1768 | + * gets/returns URL for EE reg_page |
|
| 1769 | + * |
|
| 1770 | + * @access public |
|
| 1771 | + * @return string |
|
| 1772 | + */ |
|
| 1773 | + public function reg_page_url() |
|
| 1774 | + { |
|
| 1775 | + if (! $this->reg_page_url) { |
|
| 1776 | + $this->reg_page_url = add_query_arg( |
|
| 1777 | + array('uts' => time()), |
|
| 1778 | + get_permalink($this->reg_page_id) |
|
| 1779 | + ) . '#checkout'; |
|
| 1780 | + } |
|
| 1781 | + return $this->reg_page_url; |
|
| 1782 | + } |
|
| 1783 | + |
|
| 1784 | + |
|
| 1785 | + /** |
|
| 1786 | + * gets/returns URL for EE txn_page |
|
| 1787 | + * |
|
| 1788 | + * @param array $query_args like what gets passed to |
|
| 1789 | + * add_query_arg() as the first argument |
|
| 1790 | + * @access public |
|
| 1791 | + * @return string |
|
| 1792 | + */ |
|
| 1793 | + public function txn_page_url($query_args = array()) |
|
| 1794 | + { |
|
| 1795 | + if (! $this->txn_page_url) { |
|
| 1796 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1797 | + } |
|
| 1798 | + if ($query_args) { |
|
| 1799 | + return add_query_arg($query_args, $this->txn_page_url); |
|
| 1800 | + } else { |
|
| 1801 | + return $this->txn_page_url; |
|
| 1802 | + } |
|
| 1803 | + } |
|
| 1804 | + |
|
| 1805 | + |
|
| 1806 | + /** |
|
| 1807 | + * gets/returns URL for EE thank_you_page |
|
| 1808 | + * |
|
| 1809 | + * @param array $query_args like what gets passed to |
|
| 1810 | + * add_query_arg() as the first argument |
|
| 1811 | + * @access public |
|
| 1812 | + * @return string |
|
| 1813 | + */ |
|
| 1814 | + public function thank_you_page_url($query_args = array()) |
|
| 1815 | + { |
|
| 1816 | + if (! $this->thank_you_page_url) { |
|
| 1817 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1818 | + } |
|
| 1819 | + if ($query_args) { |
|
| 1820 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1821 | + } else { |
|
| 1822 | + return $this->thank_you_page_url; |
|
| 1823 | + } |
|
| 1824 | + } |
|
| 1825 | + |
|
| 1826 | + |
|
| 1827 | + /** |
|
| 1828 | + * gets/returns URL for EE cancel_page |
|
| 1829 | + * |
|
| 1830 | + * @access public |
|
| 1831 | + * @return string |
|
| 1832 | + */ |
|
| 1833 | + public function cancel_page_url() |
|
| 1834 | + { |
|
| 1835 | + if (! $this->cancel_page_url) { |
|
| 1836 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1837 | + } |
|
| 1838 | + return $this->cancel_page_url; |
|
| 1839 | + } |
|
| 1840 | + |
|
| 1841 | + |
|
| 1842 | + /** |
|
| 1843 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1844 | + * |
|
| 1845 | + * @since 4.7.5 |
|
| 1846 | + */ |
|
| 1847 | + protected function _reset_urls() |
|
| 1848 | + { |
|
| 1849 | + $this->reg_page_url = ''; |
|
| 1850 | + $this->txn_page_url = ''; |
|
| 1851 | + $this->cancel_page_url = ''; |
|
| 1852 | + $this->thank_you_page_url = ''; |
|
| 1853 | + } |
|
| 1854 | + |
|
| 1855 | + |
|
| 1856 | + /** |
|
| 1857 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1858 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1859 | + * on the main site only. |
|
| 1860 | + * |
|
| 1861 | + * @return bool |
|
| 1862 | + */ |
|
| 1863 | + protected function _get_main_ee_ueip_optin() |
|
| 1864 | + { |
|
| 1865 | + // if this is the main site then we can just bypass our direct query. |
|
| 1866 | + if (is_main_site()) { |
|
| 1867 | + return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1868 | + } |
|
| 1869 | + // is this already cached for this request? If so use it. |
|
| 1870 | + if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1871 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1872 | + } |
|
| 1873 | + global $wpdb; |
|
| 1874 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1875 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1876 | + $option = self::OPTION_NAME_UXIP; |
|
| 1877 | + // set correct table for query |
|
| 1878 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1879 | + // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1880 | + // get_blog_option() does a switch_to_blog and that could cause infinite recursion because EE_Core_Config might be |
|
| 1881 | + // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1882 | + // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1883 | + // for the purpose of caching. |
|
| 1884 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1885 | + if (false !== $pre) { |
|
| 1886 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1887 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1888 | + } |
|
| 1889 | + $row = $wpdb->get_row( |
|
| 1890 | + $wpdb->prepare( |
|
| 1891 | + "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1892 | + $option |
|
| 1893 | + ) |
|
| 1894 | + ); |
|
| 1895 | + if (is_object($row)) { |
|
| 1896 | + $value = $row->option_value; |
|
| 1897 | + } else { // option does not exist so use default. |
|
| 1898 | + EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1899 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1900 | + } |
|
| 1901 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1902 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1903 | + } |
|
| 1904 | + |
|
| 1905 | + |
|
| 1906 | + /** |
|
| 1907 | + * Utility function for escaping the value of a property and returning. |
|
| 1908 | + * |
|
| 1909 | + * @param string $property property name (checks to see if exists). |
|
| 1910 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1911 | + * @throws EE_Error |
|
| 1912 | + */ |
|
| 1913 | + public function get_pretty($property) |
|
| 1914 | + { |
|
| 1915 | + if ($property === self::OPTION_NAME_UXIP) { |
|
| 1916 | + return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1917 | + } |
|
| 1918 | + return parent::get_pretty($property); |
|
| 1919 | + } |
|
| 1920 | + |
|
| 1921 | + |
|
| 1922 | + /** |
|
| 1923 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1924 | + * on the object. |
|
| 1925 | + * |
|
| 1926 | + * @return array |
|
| 1927 | + */ |
|
| 1928 | + public function __sleep() |
|
| 1929 | + { |
|
| 1930 | + // reset all url properties |
|
| 1931 | + $this->_reset_urls(); |
|
| 1932 | + // return what to save to db |
|
| 1933 | + return array_keys(get_object_vars($this)); |
|
| 1934 | + } |
|
| 1935 | 1935 | } |
| 1936 | 1936 | |
| 1937 | 1937 | /** |
@@ -1939,130 +1939,130 @@ discard block |
||
| 1939 | 1939 | */ |
| 1940 | 1940 | class EE_Organization_Config extends EE_Config_Base |
| 1941 | 1941 | { |
| 1942 | - /** |
|
| 1943 | - * @var string $name |
|
| 1944 | - * eg EE4.1 |
|
| 1945 | - */ |
|
| 1946 | - public $name; |
|
| 1947 | - |
|
| 1948 | - /** |
|
| 1949 | - * @var string $address_1 |
|
| 1950 | - * eg 123 Onna Road |
|
| 1951 | - */ |
|
| 1952 | - public $address_1 = ''; |
|
| 1953 | - |
|
| 1954 | - /** |
|
| 1955 | - * @var string $address_2 |
|
| 1956 | - * eg PO Box 123 |
|
| 1957 | - */ |
|
| 1958 | - public $address_2 = ''; |
|
| 1959 | - |
|
| 1960 | - /** |
|
| 1961 | - * @var string $city |
|
| 1962 | - * eg Inna City |
|
| 1963 | - */ |
|
| 1964 | - public $city = ''; |
|
| 1965 | - |
|
| 1966 | - /** |
|
| 1967 | - * @var int $STA_ID |
|
| 1968 | - * eg 4 |
|
| 1969 | - */ |
|
| 1970 | - public $STA_ID = 0; |
|
| 1971 | - |
|
| 1972 | - /** |
|
| 1973 | - * @var string $CNT_ISO |
|
| 1974 | - * eg US |
|
| 1975 | - */ |
|
| 1976 | - public $CNT_ISO = 'US'; |
|
| 1977 | - |
|
| 1978 | - /** |
|
| 1979 | - * @var string $zip |
|
| 1980 | - * eg 12345 or V1A 2B3 |
|
| 1981 | - */ |
|
| 1982 | - public $zip = ''; |
|
| 1983 | - |
|
| 1984 | - /** |
|
| 1985 | - * @var string $email |
|
| 1986 | - * eg [email protected] |
|
| 1987 | - */ |
|
| 1988 | - public $email; |
|
| 1989 | - |
|
| 1990 | - /** |
|
| 1991 | - * @var string $phone |
|
| 1992 | - * eg. 111-111-1111 |
|
| 1993 | - */ |
|
| 1994 | - public $phone = ''; |
|
| 1995 | - |
|
| 1996 | - /** |
|
| 1997 | - * @var string $vat |
|
| 1998 | - * VAT/Tax Number |
|
| 1999 | - */ |
|
| 2000 | - public $vat = ''; |
|
| 2001 | - |
|
| 2002 | - /** |
|
| 2003 | - * @var string $logo_url |
|
| 2004 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 2005 | - */ |
|
| 2006 | - public $logo_url = ''; |
|
| 2007 | - |
|
| 2008 | - /** |
|
| 2009 | - * The below are all various properties for holding links to organization social network profiles |
|
| 2010 | - */ |
|
| 2011 | - /** |
|
| 2012 | - * facebook (facebook.com/profile.name) |
|
| 2013 | - * |
|
| 2014 | - * @var string |
|
| 2015 | - */ |
|
| 2016 | - public $facebook = ''; |
|
| 2017 | - |
|
| 2018 | - /** |
|
| 2019 | - * twitter (twitter.com/twitter_handle) |
|
| 2020 | - * |
|
| 2021 | - * @var string |
|
| 2022 | - */ |
|
| 2023 | - public $twitter = ''; |
|
| 2024 | - |
|
| 2025 | - /** |
|
| 2026 | - * linkedin (linkedin.com/in/profile_name) |
|
| 2027 | - * |
|
| 2028 | - * @var string |
|
| 2029 | - */ |
|
| 2030 | - public $linkedin = ''; |
|
| 2031 | - |
|
| 2032 | - /** |
|
| 2033 | - * pinterest (www.pinterest.com/profile_name) |
|
| 2034 | - * |
|
| 2035 | - * @var string |
|
| 2036 | - */ |
|
| 2037 | - public $pinterest = ''; |
|
| 2038 | - |
|
| 2039 | - /** |
|
| 2040 | - * google+ (google.com/+profileName) |
|
| 2041 | - * |
|
| 2042 | - * @var string |
|
| 2043 | - */ |
|
| 2044 | - public $google = ''; |
|
| 2045 | - |
|
| 2046 | - /** |
|
| 2047 | - * instagram (instagram.com/handle) |
|
| 2048 | - * |
|
| 2049 | - * @var string |
|
| 2050 | - */ |
|
| 2051 | - public $instagram = ''; |
|
| 2052 | - |
|
| 2053 | - |
|
| 2054 | - /** |
|
| 2055 | - * class constructor |
|
| 2056 | - * |
|
| 2057 | - * @access public |
|
| 2058 | - */ |
|
| 2059 | - public function __construct() |
|
| 2060 | - { |
|
| 2061 | - // set default organization settings |
|
| 2062 | - // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2063 | - $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2064 | - $this->email = get_bloginfo('admin_email'); |
|
| 2065 | - } |
|
| 1942 | + /** |
|
| 1943 | + * @var string $name |
|
| 1944 | + * eg EE4.1 |
|
| 1945 | + */ |
|
| 1946 | + public $name; |
|
| 1947 | + |
|
| 1948 | + /** |
|
| 1949 | + * @var string $address_1 |
|
| 1950 | + * eg 123 Onna Road |
|
| 1951 | + */ |
|
| 1952 | + public $address_1 = ''; |
|
| 1953 | + |
|
| 1954 | + /** |
|
| 1955 | + * @var string $address_2 |
|
| 1956 | + * eg PO Box 123 |
|
| 1957 | + */ |
|
| 1958 | + public $address_2 = ''; |
|
| 1959 | + |
|
| 1960 | + /** |
|
| 1961 | + * @var string $city |
|
| 1962 | + * eg Inna City |
|
| 1963 | + */ |
|
| 1964 | + public $city = ''; |
|
| 1965 | + |
|
| 1966 | + /** |
|
| 1967 | + * @var int $STA_ID |
|
| 1968 | + * eg 4 |
|
| 1969 | + */ |
|
| 1970 | + public $STA_ID = 0; |
|
| 1971 | + |
|
| 1972 | + /** |
|
| 1973 | + * @var string $CNT_ISO |
|
| 1974 | + * eg US |
|
| 1975 | + */ |
|
| 1976 | + public $CNT_ISO = 'US'; |
|
| 1977 | + |
|
| 1978 | + /** |
|
| 1979 | + * @var string $zip |
|
| 1980 | + * eg 12345 or V1A 2B3 |
|
| 1981 | + */ |
|
| 1982 | + public $zip = ''; |
|
| 1983 | + |
|
| 1984 | + /** |
|
| 1985 | + * @var string $email |
|
| 1986 | + * eg [email protected] |
|
| 1987 | + */ |
|
| 1988 | + public $email; |
|
| 1989 | + |
|
| 1990 | + /** |
|
| 1991 | + * @var string $phone |
|
| 1992 | + * eg. 111-111-1111 |
|
| 1993 | + */ |
|
| 1994 | + public $phone = ''; |
|
| 1995 | + |
|
| 1996 | + /** |
|
| 1997 | + * @var string $vat |
|
| 1998 | + * VAT/Tax Number |
|
| 1999 | + */ |
|
| 2000 | + public $vat = ''; |
|
| 2001 | + |
|
| 2002 | + /** |
|
| 2003 | + * @var string $logo_url |
|
| 2004 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 2005 | + */ |
|
| 2006 | + public $logo_url = ''; |
|
| 2007 | + |
|
| 2008 | + /** |
|
| 2009 | + * The below are all various properties for holding links to organization social network profiles |
|
| 2010 | + */ |
|
| 2011 | + /** |
|
| 2012 | + * facebook (facebook.com/profile.name) |
|
| 2013 | + * |
|
| 2014 | + * @var string |
|
| 2015 | + */ |
|
| 2016 | + public $facebook = ''; |
|
| 2017 | + |
|
| 2018 | + /** |
|
| 2019 | + * twitter (twitter.com/twitter_handle) |
|
| 2020 | + * |
|
| 2021 | + * @var string |
|
| 2022 | + */ |
|
| 2023 | + public $twitter = ''; |
|
| 2024 | + |
|
| 2025 | + /** |
|
| 2026 | + * linkedin (linkedin.com/in/profile_name) |
|
| 2027 | + * |
|
| 2028 | + * @var string |
|
| 2029 | + */ |
|
| 2030 | + public $linkedin = ''; |
|
| 2031 | + |
|
| 2032 | + /** |
|
| 2033 | + * pinterest (www.pinterest.com/profile_name) |
|
| 2034 | + * |
|
| 2035 | + * @var string |
|
| 2036 | + */ |
|
| 2037 | + public $pinterest = ''; |
|
| 2038 | + |
|
| 2039 | + /** |
|
| 2040 | + * google+ (google.com/+profileName) |
|
| 2041 | + * |
|
| 2042 | + * @var string |
|
| 2043 | + */ |
|
| 2044 | + public $google = ''; |
|
| 2045 | + |
|
| 2046 | + /** |
|
| 2047 | + * instagram (instagram.com/handle) |
|
| 2048 | + * |
|
| 2049 | + * @var string |
|
| 2050 | + */ |
|
| 2051 | + public $instagram = ''; |
|
| 2052 | + |
|
| 2053 | + |
|
| 2054 | + /** |
|
| 2055 | + * class constructor |
|
| 2056 | + * |
|
| 2057 | + * @access public |
|
| 2058 | + */ |
|
| 2059 | + public function __construct() |
|
| 2060 | + { |
|
| 2061 | + // set default organization settings |
|
| 2062 | + // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2063 | + $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2064 | + $this->email = get_bloginfo('admin_email'); |
|
| 2065 | + } |
|
| 2066 | 2066 | } |
| 2067 | 2067 | |
| 2068 | 2068 | /** |
@@ -2070,163 +2070,163 @@ discard block |
||
| 2070 | 2070 | */ |
| 2071 | 2071 | class EE_Currency_Config extends EE_Config_Base |
| 2072 | 2072 | { |
| 2073 | - /** |
|
| 2074 | - * @var string $code |
|
| 2075 | - * eg 'US' |
|
| 2076 | - */ |
|
| 2077 | - public $code; |
|
| 2078 | - |
|
| 2079 | - /** |
|
| 2080 | - * @var string $name |
|
| 2081 | - * eg 'Dollar' |
|
| 2082 | - */ |
|
| 2083 | - public $name; |
|
| 2084 | - |
|
| 2085 | - /** |
|
| 2086 | - * plural name |
|
| 2087 | - * |
|
| 2088 | - * @var string $plural |
|
| 2089 | - * eg 'Dollars' |
|
| 2090 | - */ |
|
| 2091 | - public $plural; |
|
| 2092 | - |
|
| 2093 | - /** |
|
| 2094 | - * currency sign |
|
| 2095 | - * |
|
| 2096 | - * @var string $sign |
|
| 2097 | - * eg '$' |
|
| 2098 | - */ |
|
| 2099 | - public $sign; |
|
| 2100 | - |
|
| 2101 | - /** |
|
| 2102 | - * Whether the currency sign should come before the number or not |
|
| 2103 | - * |
|
| 2104 | - * @var boolean $sign_b4 |
|
| 2105 | - */ |
|
| 2106 | - public $sign_b4; |
|
| 2107 | - |
|
| 2108 | - /** |
|
| 2109 | - * How many digits should come after the decimal place |
|
| 2110 | - * |
|
| 2111 | - * @var int $dec_plc |
|
| 2112 | - */ |
|
| 2113 | - public $dec_plc; |
|
| 2114 | - |
|
| 2115 | - /** |
|
| 2116 | - * Symbol to use for decimal mark |
|
| 2117 | - * |
|
| 2118 | - * @var string $dec_mrk |
|
| 2119 | - * eg '.' |
|
| 2120 | - */ |
|
| 2121 | - public $dec_mrk; |
|
| 2122 | - |
|
| 2123 | - /** |
|
| 2124 | - * Symbol to use for thousands |
|
| 2125 | - * |
|
| 2126 | - * @var string $thsnds |
|
| 2127 | - * eg ',' |
|
| 2128 | - */ |
|
| 2129 | - public $thsnds; |
|
| 2130 | - |
|
| 2131 | - |
|
| 2132 | - /** |
|
| 2133 | - * @param string|null $CNT_ISO |
|
| 2134 | - * @throws EE_Error |
|
| 2135 | - * @throws ReflectionException |
|
| 2136 | - */ |
|
| 2137 | - public function __construct(?string $CNT_ISO = 'US') |
|
| 2138 | - { |
|
| 2139 | - if ($CNT_ISO && $CNT_ISO === $this->code) { |
|
| 2140 | - return; |
|
| 2141 | - } |
|
| 2142 | - // get country code from organization settings or use default |
|
| 2143 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2144 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2145 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2146 | - : 'US'; |
|
| 2147 | - // but override if requested |
|
| 2148 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2149 | - // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2150 | - $this->setCurrency($CNT_ISO); |
|
| 2151 | - // fallback to hardcoded defaults, in case the above failed |
|
| 2152 | - if (empty($this->code)) { |
|
| 2153 | - $this->setFallbackCurrency(); |
|
| 2154 | - } |
|
| 2155 | - } |
|
| 2156 | - |
|
| 2157 | - |
|
| 2158 | - /** |
|
| 2159 | - * @param string|null $CNT_ISO |
|
| 2160 | - * @throws EE_Error |
|
| 2161 | - * @throws ReflectionException |
|
| 2162 | - */ |
|
| 2163 | - public function setCurrency(?string $CNT_ISO = 'US') |
|
| 2164 | - { |
|
| 2165 | - if (empty($CNT_ISO) || DbStatus::isOffline()) { |
|
| 2166 | - return; |
|
| 2167 | - } |
|
| 2168 | - |
|
| 2169 | - /** @var TableAnalysis $table_analysis */ |
|
| 2170 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true); |
|
| 2171 | - if (! $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())) { |
|
| 2172 | - return; |
|
| 2173 | - } |
|
| 2174 | - // retrieve the country settings from the db, just in case they have been customized |
|
| 2175 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2176 | - if (! $country instanceof EE_Country) { |
|
| 2177 | - throw new DomainException( |
|
| 2178 | - sprintf( |
|
| 2179 | - esc_html__('Invalid Country ISO Code: %1$s', 'event_espresso'), |
|
| 2180 | - $CNT_ISO |
|
| 2181 | - ) |
|
| 2182 | - ); |
|
| 2183 | - } |
|
| 2184 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2185 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2186 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2187 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2188 | - $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after |
|
| 2189 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2190 | - $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: ',' = 0,01 or '.' = 0.01 |
|
| 2191 | - $this->thsnds = $country->currency_thousands_separator(); // thousands sep: ',' = 1,000 or '.' = 1.000 |
|
| 2192 | - } |
|
| 2193 | - |
|
| 2194 | - |
|
| 2195 | - private function setFallbackCurrency() |
|
| 2196 | - { |
|
| 2197 | - // set default currency settings |
|
| 2198 | - $this->code = 'USD'; |
|
| 2199 | - $this->name = esc_html__('Dollar', 'event_espresso'); |
|
| 2200 | - $this->plural = esc_html__('Dollars', 'event_espresso'); |
|
| 2201 | - $this->sign = '$'; |
|
| 2202 | - $this->sign_b4 = true; |
|
| 2203 | - $this->dec_plc = 2; |
|
| 2204 | - $this->dec_mrk = '.'; |
|
| 2205 | - $this->thsnds = ','; |
|
| 2206 | - } |
|
| 2207 | - |
|
| 2208 | - |
|
| 2209 | - /** |
|
| 2210 | - * @param string|null $CNT_ISO |
|
| 2211 | - * @return EE_Currency_Config |
|
| 2212 | - * @throws EE_Error |
|
| 2213 | - * @throws ReflectionException |
|
| 2214 | - */ |
|
| 2215 | - public static function getCurrencyConfig(?string $CNT_ISO = ''): EE_Currency_Config |
|
| 2216 | - { |
|
| 2217 | - // if CNT_ISO passed lets try to get currency settings for it. |
|
| 2218 | - $currency_config = ! empty($CNT_ISO) |
|
| 2219 | - ? new EE_Currency_Config($CNT_ISO) |
|
| 2220 | - : null; |
|
| 2221 | - // default currency settings for site if not set |
|
| 2222 | - if ($currency_config instanceof EE_Currency_Config) { |
|
| 2223 | - return $currency_config; |
|
| 2224 | - } |
|
| 2225 | - EE_Config::instance()->currency = EE_Config::instance()->currency instanceof EE_Currency_Config |
|
| 2226 | - ? EE_Config::instance()->currency |
|
| 2227 | - : new EE_Currency_Config(); |
|
| 2228 | - return EE_Config::instance()->currency; |
|
| 2229 | - } |
|
| 2073 | + /** |
|
| 2074 | + * @var string $code |
|
| 2075 | + * eg 'US' |
|
| 2076 | + */ |
|
| 2077 | + public $code; |
|
| 2078 | + |
|
| 2079 | + /** |
|
| 2080 | + * @var string $name |
|
| 2081 | + * eg 'Dollar' |
|
| 2082 | + */ |
|
| 2083 | + public $name; |
|
| 2084 | + |
|
| 2085 | + /** |
|
| 2086 | + * plural name |
|
| 2087 | + * |
|
| 2088 | + * @var string $plural |
|
| 2089 | + * eg 'Dollars' |
|
| 2090 | + */ |
|
| 2091 | + public $plural; |
|
| 2092 | + |
|
| 2093 | + /** |
|
| 2094 | + * currency sign |
|
| 2095 | + * |
|
| 2096 | + * @var string $sign |
|
| 2097 | + * eg '$' |
|
| 2098 | + */ |
|
| 2099 | + public $sign; |
|
| 2100 | + |
|
| 2101 | + /** |
|
| 2102 | + * Whether the currency sign should come before the number or not |
|
| 2103 | + * |
|
| 2104 | + * @var boolean $sign_b4 |
|
| 2105 | + */ |
|
| 2106 | + public $sign_b4; |
|
| 2107 | + |
|
| 2108 | + /** |
|
| 2109 | + * How many digits should come after the decimal place |
|
| 2110 | + * |
|
| 2111 | + * @var int $dec_plc |
|
| 2112 | + */ |
|
| 2113 | + public $dec_plc; |
|
| 2114 | + |
|
| 2115 | + /** |
|
| 2116 | + * Symbol to use for decimal mark |
|
| 2117 | + * |
|
| 2118 | + * @var string $dec_mrk |
|
| 2119 | + * eg '.' |
|
| 2120 | + */ |
|
| 2121 | + public $dec_mrk; |
|
| 2122 | + |
|
| 2123 | + /** |
|
| 2124 | + * Symbol to use for thousands |
|
| 2125 | + * |
|
| 2126 | + * @var string $thsnds |
|
| 2127 | + * eg ',' |
|
| 2128 | + */ |
|
| 2129 | + public $thsnds; |
|
| 2130 | + |
|
| 2131 | + |
|
| 2132 | + /** |
|
| 2133 | + * @param string|null $CNT_ISO |
|
| 2134 | + * @throws EE_Error |
|
| 2135 | + * @throws ReflectionException |
|
| 2136 | + */ |
|
| 2137 | + public function __construct(?string $CNT_ISO = 'US') |
|
| 2138 | + { |
|
| 2139 | + if ($CNT_ISO && $CNT_ISO === $this->code) { |
|
| 2140 | + return; |
|
| 2141 | + } |
|
| 2142 | + // get country code from organization settings or use default |
|
| 2143 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2144 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2145 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2146 | + : 'US'; |
|
| 2147 | + // but override if requested |
|
| 2148 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2149 | + // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2150 | + $this->setCurrency($CNT_ISO); |
|
| 2151 | + // fallback to hardcoded defaults, in case the above failed |
|
| 2152 | + if (empty($this->code)) { |
|
| 2153 | + $this->setFallbackCurrency(); |
|
| 2154 | + } |
|
| 2155 | + } |
|
| 2156 | + |
|
| 2157 | + |
|
| 2158 | + /** |
|
| 2159 | + * @param string|null $CNT_ISO |
|
| 2160 | + * @throws EE_Error |
|
| 2161 | + * @throws ReflectionException |
|
| 2162 | + */ |
|
| 2163 | + public function setCurrency(?string $CNT_ISO = 'US') |
|
| 2164 | + { |
|
| 2165 | + if (empty($CNT_ISO) || DbStatus::isOffline()) { |
|
| 2166 | + return; |
|
| 2167 | + } |
|
| 2168 | + |
|
| 2169 | + /** @var TableAnalysis $table_analysis */ |
|
| 2170 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true); |
|
| 2171 | + if (! $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())) { |
|
| 2172 | + return; |
|
| 2173 | + } |
|
| 2174 | + // retrieve the country settings from the db, just in case they have been customized |
|
| 2175 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2176 | + if (! $country instanceof EE_Country) { |
|
| 2177 | + throw new DomainException( |
|
| 2178 | + sprintf( |
|
| 2179 | + esc_html__('Invalid Country ISO Code: %1$s', 'event_espresso'), |
|
| 2180 | + $CNT_ISO |
|
| 2181 | + ) |
|
| 2182 | + ); |
|
| 2183 | + } |
|
| 2184 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2185 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2186 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2187 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2188 | + $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after |
|
| 2189 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2190 | + $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: ',' = 0,01 or '.' = 0.01 |
|
| 2191 | + $this->thsnds = $country->currency_thousands_separator(); // thousands sep: ',' = 1,000 or '.' = 1.000 |
|
| 2192 | + } |
|
| 2193 | + |
|
| 2194 | + |
|
| 2195 | + private function setFallbackCurrency() |
|
| 2196 | + { |
|
| 2197 | + // set default currency settings |
|
| 2198 | + $this->code = 'USD'; |
|
| 2199 | + $this->name = esc_html__('Dollar', 'event_espresso'); |
|
| 2200 | + $this->plural = esc_html__('Dollars', 'event_espresso'); |
|
| 2201 | + $this->sign = '$'; |
|
| 2202 | + $this->sign_b4 = true; |
|
| 2203 | + $this->dec_plc = 2; |
|
| 2204 | + $this->dec_mrk = '.'; |
|
| 2205 | + $this->thsnds = ','; |
|
| 2206 | + } |
|
| 2207 | + |
|
| 2208 | + |
|
| 2209 | + /** |
|
| 2210 | + * @param string|null $CNT_ISO |
|
| 2211 | + * @return EE_Currency_Config |
|
| 2212 | + * @throws EE_Error |
|
| 2213 | + * @throws ReflectionException |
|
| 2214 | + */ |
|
| 2215 | + public static function getCurrencyConfig(?string $CNT_ISO = ''): EE_Currency_Config |
|
| 2216 | + { |
|
| 2217 | + // if CNT_ISO passed lets try to get currency settings for it. |
|
| 2218 | + $currency_config = ! empty($CNT_ISO) |
|
| 2219 | + ? new EE_Currency_Config($CNT_ISO) |
|
| 2220 | + : null; |
|
| 2221 | + // default currency settings for site if not set |
|
| 2222 | + if ($currency_config instanceof EE_Currency_Config) { |
|
| 2223 | + return $currency_config; |
|
| 2224 | + } |
|
| 2225 | + EE_Config::instance()->currency = EE_Config::instance()->currency instanceof EE_Currency_Config |
|
| 2226 | + ? EE_Config::instance()->currency |
|
| 2227 | + : new EE_Currency_Config(); |
|
| 2228 | + return EE_Config::instance()->currency; |
|
| 2229 | + } |
|
| 2230 | 2230 | } |
| 2231 | 2231 | |
| 2232 | 2232 | /** |
@@ -2234,387 +2234,387 @@ discard block |
||
| 2234 | 2234 | */ |
| 2235 | 2235 | class EE_Registration_Config extends EE_Config_Base |
| 2236 | 2236 | { |
| 2237 | - /** |
|
| 2238 | - * Default registration status |
|
| 2239 | - * |
|
| 2240 | - * @var string $default_STS_ID |
|
| 2241 | - * eg 'RPP' |
|
| 2242 | - */ |
|
| 2243 | - public $default_STS_ID; |
|
| 2244 | - |
|
| 2245 | - /** |
|
| 2246 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2247 | - * registrations) |
|
| 2248 | - * |
|
| 2249 | - * @var int |
|
| 2250 | - */ |
|
| 2251 | - public $default_maximum_number_of_tickets; |
|
| 2252 | - |
|
| 2253 | - /** |
|
| 2254 | - * level of validation to apply to email addresses |
|
| 2255 | - * |
|
| 2256 | - * @var string $email_validation_level |
|
| 2257 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2258 | - */ |
|
| 2259 | - public $email_validation_level; |
|
| 2260 | - |
|
| 2261 | - /** |
|
| 2262 | - * whether to show alternate payment options during the reg process if payment status is pending |
|
| 2263 | - * |
|
| 2264 | - * @var boolean $show_pending_payment_options |
|
| 2265 | - */ |
|
| 2266 | - public $show_pending_payment_options; |
|
| 2267 | - |
|
| 2268 | - /** |
|
| 2269 | - * an array of SPCO reg steps where: |
|
| 2270 | - * the keys denotes the reg step order |
|
| 2271 | - * each element consists of an array with the following elements: |
|
| 2272 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2273 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2274 | - * "slug" => the URL param used to trigger the reg step |
|
| 2275 | - * |
|
| 2276 | - * @var array $reg_steps |
|
| 2277 | - */ |
|
| 2278 | - public $reg_steps; |
|
| 2279 | - |
|
| 2280 | - /** |
|
| 2281 | - * Whether registration confirmation should be the last page of SPCO |
|
| 2282 | - * |
|
| 2283 | - * @var boolean $reg_confirmation_last |
|
| 2284 | - */ |
|
| 2285 | - public $reg_confirmation_last; |
|
| 2286 | - |
|
| 2287 | - /** |
|
| 2288 | - * Whether to enable the EE Bot Trap |
|
| 2289 | - * |
|
| 2290 | - * @var boolean $use_bot_trap |
|
| 2291 | - */ |
|
| 2292 | - public $use_bot_trap; |
|
| 2293 | - |
|
| 2294 | - /** |
|
| 2295 | - * Whether to encrypt some data sent by the EE Bot Trap |
|
| 2296 | - * |
|
| 2297 | - * @var boolean $use_encryption |
|
| 2298 | - */ |
|
| 2299 | - public $use_encryption; |
|
| 2300 | - |
|
| 2301 | - /** |
|
| 2302 | - * Whether to use ReCaptcha |
|
| 2303 | - * |
|
| 2304 | - * @var boolean $use_captcha |
|
| 2305 | - */ |
|
| 2306 | - public $use_captcha; |
|
| 2307 | - |
|
| 2308 | - /** |
|
| 2309 | - * ReCaptcha Theme |
|
| 2310 | - * |
|
| 2311 | - * @var string $recaptcha_theme |
|
| 2312 | - * options: 'dark', 'light', 'invisible' |
|
| 2313 | - */ |
|
| 2314 | - public $recaptcha_theme; |
|
| 2315 | - |
|
| 2316 | - /** |
|
| 2317 | - * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2318 | - * |
|
| 2319 | - * @var string $recaptcha_badge |
|
| 2320 | - * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2321 | - */ |
|
| 2322 | - public $recaptcha_badge; |
|
| 2323 | - |
|
| 2324 | - /** |
|
| 2325 | - * ReCaptcha Type |
|
| 2326 | - * |
|
| 2327 | - * @var string $recaptcha_type |
|
| 2328 | - * options: 'audio', 'image' |
|
| 2329 | - */ |
|
| 2330 | - public $recaptcha_type; |
|
| 2331 | - |
|
| 2332 | - /** |
|
| 2333 | - * ReCaptcha language |
|
| 2334 | - * |
|
| 2335 | - * @var string $recaptcha_language |
|
| 2336 | - * eg 'en' |
|
| 2337 | - */ |
|
| 2338 | - public $recaptcha_language; |
|
| 2339 | - |
|
| 2340 | - /** |
|
| 2341 | - * ReCaptcha public key |
|
| 2342 | - * |
|
| 2343 | - * @var string $recaptcha_publickey |
|
| 2344 | - */ |
|
| 2345 | - public $recaptcha_publickey; |
|
| 2346 | - |
|
| 2347 | - /** |
|
| 2348 | - * ReCaptcha private key |
|
| 2349 | - * |
|
| 2350 | - * @var string $recaptcha_privatekey |
|
| 2351 | - */ |
|
| 2352 | - public $recaptcha_privatekey; |
|
| 2353 | - |
|
| 2354 | - /** |
|
| 2355 | - * array of form names protected by ReCaptcha |
|
| 2356 | - * |
|
| 2357 | - * @var array $recaptcha_protected_forms |
|
| 2358 | - */ |
|
| 2359 | - public $recaptcha_protected_forms; |
|
| 2360 | - |
|
| 2361 | - /** |
|
| 2362 | - * ReCaptcha width |
|
| 2363 | - * |
|
| 2364 | - * @var int $recaptcha_width |
|
| 2365 | - * @deprecated |
|
| 2366 | - */ |
|
| 2367 | - public $recaptcha_width; |
|
| 2368 | - |
|
| 2369 | - /** |
|
| 2370 | - * Whether invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2371 | - * |
|
| 2372 | - * @var boolean $track_invalid_checkout_access |
|
| 2373 | - */ |
|
| 2374 | - protected $track_invalid_checkout_access = true; |
|
| 2375 | - |
|
| 2376 | - /** |
|
| 2377 | - * Whether to show the privacy policy consent checkbox |
|
| 2378 | - * |
|
| 2379 | - * @var bool |
|
| 2380 | - */ |
|
| 2381 | - public $consent_checkbox_enabled; |
|
| 2382 | - |
|
| 2383 | - /** |
|
| 2384 | - * Label text to show on the checkbox |
|
| 2385 | - * |
|
| 2386 | - * @var string |
|
| 2387 | - */ |
|
| 2388 | - public $consent_checkbox_label_text; |
|
| 2389 | - |
|
| 2390 | - /* |
|
| 2237 | + /** |
|
| 2238 | + * Default registration status |
|
| 2239 | + * |
|
| 2240 | + * @var string $default_STS_ID |
|
| 2241 | + * eg 'RPP' |
|
| 2242 | + */ |
|
| 2243 | + public $default_STS_ID; |
|
| 2244 | + |
|
| 2245 | + /** |
|
| 2246 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2247 | + * registrations) |
|
| 2248 | + * |
|
| 2249 | + * @var int |
|
| 2250 | + */ |
|
| 2251 | + public $default_maximum_number_of_tickets; |
|
| 2252 | + |
|
| 2253 | + /** |
|
| 2254 | + * level of validation to apply to email addresses |
|
| 2255 | + * |
|
| 2256 | + * @var string $email_validation_level |
|
| 2257 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2258 | + */ |
|
| 2259 | + public $email_validation_level; |
|
| 2260 | + |
|
| 2261 | + /** |
|
| 2262 | + * whether to show alternate payment options during the reg process if payment status is pending |
|
| 2263 | + * |
|
| 2264 | + * @var boolean $show_pending_payment_options |
|
| 2265 | + */ |
|
| 2266 | + public $show_pending_payment_options; |
|
| 2267 | + |
|
| 2268 | + /** |
|
| 2269 | + * an array of SPCO reg steps where: |
|
| 2270 | + * the keys denotes the reg step order |
|
| 2271 | + * each element consists of an array with the following elements: |
|
| 2272 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2273 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2274 | + * "slug" => the URL param used to trigger the reg step |
|
| 2275 | + * |
|
| 2276 | + * @var array $reg_steps |
|
| 2277 | + */ |
|
| 2278 | + public $reg_steps; |
|
| 2279 | + |
|
| 2280 | + /** |
|
| 2281 | + * Whether registration confirmation should be the last page of SPCO |
|
| 2282 | + * |
|
| 2283 | + * @var boolean $reg_confirmation_last |
|
| 2284 | + */ |
|
| 2285 | + public $reg_confirmation_last; |
|
| 2286 | + |
|
| 2287 | + /** |
|
| 2288 | + * Whether to enable the EE Bot Trap |
|
| 2289 | + * |
|
| 2290 | + * @var boolean $use_bot_trap |
|
| 2291 | + */ |
|
| 2292 | + public $use_bot_trap; |
|
| 2293 | + |
|
| 2294 | + /** |
|
| 2295 | + * Whether to encrypt some data sent by the EE Bot Trap |
|
| 2296 | + * |
|
| 2297 | + * @var boolean $use_encryption |
|
| 2298 | + */ |
|
| 2299 | + public $use_encryption; |
|
| 2300 | + |
|
| 2301 | + /** |
|
| 2302 | + * Whether to use ReCaptcha |
|
| 2303 | + * |
|
| 2304 | + * @var boolean $use_captcha |
|
| 2305 | + */ |
|
| 2306 | + public $use_captcha; |
|
| 2307 | + |
|
| 2308 | + /** |
|
| 2309 | + * ReCaptcha Theme |
|
| 2310 | + * |
|
| 2311 | + * @var string $recaptcha_theme |
|
| 2312 | + * options: 'dark', 'light', 'invisible' |
|
| 2313 | + */ |
|
| 2314 | + public $recaptcha_theme; |
|
| 2315 | + |
|
| 2316 | + /** |
|
| 2317 | + * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2318 | + * |
|
| 2319 | + * @var string $recaptcha_badge |
|
| 2320 | + * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2321 | + */ |
|
| 2322 | + public $recaptcha_badge; |
|
| 2323 | + |
|
| 2324 | + /** |
|
| 2325 | + * ReCaptcha Type |
|
| 2326 | + * |
|
| 2327 | + * @var string $recaptcha_type |
|
| 2328 | + * options: 'audio', 'image' |
|
| 2329 | + */ |
|
| 2330 | + public $recaptcha_type; |
|
| 2331 | + |
|
| 2332 | + /** |
|
| 2333 | + * ReCaptcha language |
|
| 2334 | + * |
|
| 2335 | + * @var string $recaptcha_language |
|
| 2336 | + * eg 'en' |
|
| 2337 | + */ |
|
| 2338 | + public $recaptcha_language; |
|
| 2339 | + |
|
| 2340 | + /** |
|
| 2341 | + * ReCaptcha public key |
|
| 2342 | + * |
|
| 2343 | + * @var string $recaptcha_publickey |
|
| 2344 | + */ |
|
| 2345 | + public $recaptcha_publickey; |
|
| 2346 | + |
|
| 2347 | + /** |
|
| 2348 | + * ReCaptcha private key |
|
| 2349 | + * |
|
| 2350 | + * @var string $recaptcha_privatekey |
|
| 2351 | + */ |
|
| 2352 | + public $recaptcha_privatekey; |
|
| 2353 | + |
|
| 2354 | + /** |
|
| 2355 | + * array of form names protected by ReCaptcha |
|
| 2356 | + * |
|
| 2357 | + * @var array $recaptcha_protected_forms |
|
| 2358 | + */ |
|
| 2359 | + public $recaptcha_protected_forms; |
|
| 2360 | + |
|
| 2361 | + /** |
|
| 2362 | + * ReCaptcha width |
|
| 2363 | + * |
|
| 2364 | + * @var int $recaptcha_width |
|
| 2365 | + * @deprecated |
|
| 2366 | + */ |
|
| 2367 | + public $recaptcha_width; |
|
| 2368 | + |
|
| 2369 | + /** |
|
| 2370 | + * Whether invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2371 | + * |
|
| 2372 | + * @var boolean $track_invalid_checkout_access |
|
| 2373 | + */ |
|
| 2374 | + protected $track_invalid_checkout_access = true; |
|
| 2375 | + |
|
| 2376 | + /** |
|
| 2377 | + * Whether to show the privacy policy consent checkbox |
|
| 2378 | + * |
|
| 2379 | + * @var bool |
|
| 2380 | + */ |
|
| 2381 | + public $consent_checkbox_enabled; |
|
| 2382 | + |
|
| 2383 | + /** |
|
| 2384 | + * Label text to show on the checkbox |
|
| 2385 | + * |
|
| 2386 | + * @var string |
|
| 2387 | + */ |
|
| 2388 | + public $consent_checkbox_label_text; |
|
| 2389 | + |
|
| 2390 | + /* |
|
| 2391 | 2391 | * String describing how long to keep payment logs. Passed into DateTime constructor |
| 2392 | 2392 | * @var string |
| 2393 | 2393 | */ |
| 2394 | - public $gateway_log_lifespan = '1 week'; |
|
| 2395 | - |
|
| 2396 | - /** |
|
| 2397 | - * Enable copy attendee info at form |
|
| 2398 | - * |
|
| 2399 | - * @var boolean $enable_copy_attendee |
|
| 2400 | - */ |
|
| 2401 | - protected $copy_attendee_info = true; |
|
| 2402 | - |
|
| 2403 | - /** |
|
| 2404 | - * @var bool|int|string|null $skip_reg_confirmation |
|
| 2405 | - * @deprecated |
|
| 2406 | - */ |
|
| 2407 | - public $skip_reg_confirmation; |
|
| 2408 | - |
|
| 2409 | - |
|
| 2410 | - |
|
| 2411 | - |
|
| 2412 | - /** |
|
| 2413 | - * class constructor |
|
| 2414 | - * |
|
| 2415 | - * @access public |
|
| 2416 | - */ |
|
| 2417 | - public function __construct() |
|
| 2418 | - { |
|
| 2419 | - // set default registration settings |
|
| 2420 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2421 | - $this->email_validation_level = 'wp_default'; |
|
| 2422 | - $this->show_pending_payment_options = true; |
|
| 2423 | - $this->reg_steps = array(); |
|
| 2424 | - $this->reg_confirmation_last = false; |
|
| 2425 | - $this->use_bot_trap = true; |
|
| 2426 | - $this->use_encryption = true; |
|
| 2427 | - $this->use_captcha = false; |
|
| 2428 | - $this->recaptcha_theme = 'light'; |
|
| 2429 | - $this->recaptcha_badge = 'bottomleft'; |
|
| 2430 | - $this->recaptcha_type = 'image'; |
|
| 2431 | - $this->recaptcha_language = 'en'; |
|
| 2432 | - $this->recaptcha_publickey = null; |
|
| 2433 | - $this->recaptcha_privatekey = null; |
|
| 2434 | - $this->recaptcha_protected_forms = array(); |
|
| 2435 | - $this->recaptcha_width = 500; |
|
| 2436 | - $this->default_maximum_number_of_tickets = 10; |
|
| 2437 | - $this->consent_checkbox_enabled = false; |
|
| 2438 | - $this->consent_checkbox_label_text = ''; |
|
| 2439 | - $this->gateway_log_lifespan = '7 days'; |
|
| 2440 | - $this->copy_attendee_info = true; |
|
| 2441 | - } |
|
| 2442 | - |
|
| 2443 | - |
|
| 2444 | - /** |
|
| 2445 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2446 | - * |
|
| 2447 | - * @since 4.8.8.rc.019 |
|
| 2448 | - */ |
|
| 2449 | - public function do_hooks() |
|
| 2450 | - { |
|
| 2451 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2452 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2453 | - add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2454 | - } |
|
| 2455 | - |
|
| 2456 | - |
|
| 2457 | - /** |
|
| 2458 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2459 | - * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2460 | - */ |
|
| 2461 | - public function set_default_reg_status_on_EEM_Event() |
|
| 2462 | - { |
|
| 2463 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2464 | - } |
|
| 2465 | - |
|
| 2466 | - |
|
| 2467 | - /** |
|
| 2468 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2469 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2470 | - */ |
|
| 2471 | - public function set_default_max_ticket_on_EEM_Event() |
|
| 2472 | - { |
|
| 2473 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2474 | - } |
|
| 2475 | - |
|
| 2476 | - |
|
| 2477 | - /** |
|
| 2478 | - * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2479 | - * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2480 | - * |
|
| 2481 | - * @throws InvalidArgumentException |
|
| 2482 | - * @throws InvalidDataTypeException |
|
| 2483 | - * @throws InvalidInterfaceException |
|
| 2484 | - */ |
|
| 2485 | - public function setDefaultCheckboxLabelText() |
|
| 2486 | - { |
|
| 2487 | - if ( |
|
| 2488 | - $this->getConsentCheckboxLabelText() === null |
|
| 2489 | - || $this->getConsentCheckboxLabelText() === '' |
|
| 2490 | - ) { |
|
| 2491 | - $opening_a_tag = ''; |
|
| 2492 | - $closing_a_tag = ''; |
|
| 2493 | - if (function_exists('get_privacy_policy_url')) { |
|
| 2494 | - $privacy_page_url = get_privacy_policy_url(); |
|
| 2495 | - if (! empty($privacy_page_url)) { |
|
| 2496 | - $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2497 | - $closing_a_tag = '</a>'; |
|
| 2498 | - } |
|
| 2499 | - } |
|
| 2500 | - $loader = LoaderFactory::getLoader(); |
|
| 2501 | - $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2502 | - /** |
|
| 2503 | - * @var $org_config EE_Organization_Config |
|
| 2504 | - */ |
|
| 2505 | - |
|
| 2506 | - $this->setConsentCheckboxLabelText( |
|
| 2507 | - sprintf( |
|
| 2508 | - esc_html__( |
|
| 2509 | - 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2510 | - 'event_espresso' |
|
| 2511 | - ), |
|
| 2512 | - $org_config->name, |
|
| 2513 | - $opening_a_tag, |
|
| 2514 | - $closing_a_tag |
|
| 2515 | - ) |
|
| 2516 | - ); |
|
| 2517 | - } |
|
| 2518 | - } |
|
| 2519 | - |
|
| 2520 | - |
|
| 2521 | - /** |
|
| 2522 | - * @return boolean |
|
| 2523 | - */ |
|
| 2524 | - public function track_invalid_checkout_access() |
|
| 2525 | - { |
|
| 2526 | - return $this->track_invalid_checkout_access; |
|
| 2527 | - } |
|
| 2528 | - |
|
| 2529 | - |
|
| 2530 | - /** |
|
| 2531 | - * @param boolean $track_invalid_checkout_access |
|
| 2532 | - */ |
|
| 2533 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2534 | - { |
|
| 2535 | - $this->track_invalid_checkout_access = filter_var( |
|
| 2536 | - $track_invalid_checkout_access, |
|
| 2537 | - FILTER_VALIDATE_BOOLEAN |
|
| 2538 | - ); |
|
| 2539 | - } |
|
| 2540 | - |
|
| 2541 | - /** |
|
| 2542 | - * @return boolean |
|
| 2543 | - */ |
|
| 2544 | - public function copyAttendeeInfo() |
|
| 2545 | - { |
|
| 2546 | - return $this->copy_attendee_info; |
|
| 2547 | - } |
|
| 2548 | - |
|
| 2549 | - |
|
| 2550 | - /** |
|
| 2551 | - * @param boolean $copy_attendee_info |
|
| 2552 | - */ |
|
| 2553 | - public function setCopyAttendeeInfo($copy_attendee_info) |
|
| 2554 | - { |
|
| 2555 | - $this->copy_attendee_info = filter_var( |
|
| 2556 | - $copy_attendee_info, |
|
| 2557 | - FILTER_VALIDATE_BOOLEAN |
|
| 2558 | - ); |
|
| 2559 | - } |
|
| 2560 | - |
|
| 2561 | - |
|
| 2562 | - /** |
|
| 2563 | - * Gets the options to make available for the gateway log lifespan |
|
| 2564 | - * @return array |
|
| 2565 | - */ |
|
| 2566 | - public function gatewayLogLifespanOptions() |
|
| 2567 | - { |
|
| 2568 | - return (array) apply_filters( |
|
| 2569 | - 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2570 | - array( |
|
| 2571 | - '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2572 | - '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2573 | - '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2574 | - '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2575 | - '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2576 | - ) |
|
| 2577 | - ); |
|
| 2578 | - } |
|
| 2579 | - |
|
| 2580 | - |
|
| 2581 | - /** |
|
| 2582 | - * @return bool |
|
| 2583 | - */ |
|
| 2584 | - public function isConsentCheckboxEnabled() |
|
| 2585 | - { |
|
| 2586 | - return $this->consent_checkbox_enabled; |
|
| 2587 | - } |
|
| 2588 | - |
|
| 2589 | - |
|
| 2590 | - /** |
|
| 2591 | - * @param bool $consent_checkbox_enabled |
|
| 2592 | - */ |
|
| 2593 | - public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2594 | - { |
|
| 2595 | - $this->consent_checkbox_enabled = filter_var( |
|
| 2596 | - $consent_checkbox_enabled, |
|
| 2597 | - FILTER_VALIDATE_BOOLEAN |
|
| 2598 | - ); |
|
| 2599 | - } |
|
| 2600 | - |
|
| 2601 | - |
|
| 2602 | - /** |
|
| 2603 | - * @return string |
|
| 2604 | - */ |
|
| 2605 | - public function getConsentCheckboxLabelText() |
|
| 2606 | - { |
|
| 2607 | - return $this->consent_checkbox_label_text; |
|
| 2608 | - } |
|
| 2609 | - |
|
| 2610 | - |
|
| 2611 | - /** |
|
| 2612 | - * @param string $consent_checkbox_label_text |
|
| 2613 | - */ |
|
| 2614 | - public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2615 | - { |
|
| 2616 | - $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2617 | - } |
|
| 2394 | + public $gateway_log_lifespan = '1 week'; |
|
| 2395 | + |
|
| 2396 | + /** |
|
| 2397 | + * Enable copy attendee info at form |
|
| 2398 | + * |
|
| 2399 | + * @var boolean $enable_copy_attendee |
|
| 2400 | + */ |
|
| 2401 | + protected $copy_attendee_info = true; |
|
| 2402 | + |
|
| 2403 | + /** |
|
| 2404 | + * @var bool|int|string|null $skip_reg_confirmation |
|
| 2405 | + * @deprecated |
|
| 2406 | + */ |
|
| 2407 | + public $skip_reg_confirmation; |
|
| 2408 | + |
|
| 2409 | + |
|
| 2410 | + |
|
| 2411 | + |
|
| 2412 | + /** |
|
| 2413 | + * class constructor |
|
| 2414 | + * |
|
| 2415 | + * @access public |
|
| 2416 | + */ |
|
| 2417 | + public function __construct() |
|
| 2418 | + { |
|
| 2419 | + // set default registration settings |
|
| 2420 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2421 | + $this->email_validation_level = 'wp_default'; |
|
| 2422 | + $this->show_pending_payment_options = true; |
|
| 2423 | + $this->reg_steps = array(); |
|
| 2424 | + $this->reg_confirmation_last = false; |
|
| 2425 | + $this->use_bot_trap = true; |
|
| 2426 | + $this->use_encryption = true; |
|
| 2427 | + $this->use_captcha = false; |
|
| 2428 | + $this->recaptcha_theme = 'light'; |
|
| 2429 | + $this->recaptcha_badge = 'bottomleft'; |
|
| 2430 | + $this->recaptcha_type = 'image'; |
|
| 2431 | + $this->recaptcha_language = 'en'; |
|
| 2432 | + $this->recaptcha_publickey = null; |
|
| 2433 | + $this->recaptcha_privatekey = null; |
|
| 2434 | + $this->recaptcha_protected_forms = array(); |
|
| 2435 | + $this->recaptcha_width = 500; |
|
| 2436 | + $this->default_maximum_number_of_tickets = 10; |
|
| 2437 | + $this->consent_checkbox_enabled = false; |
|
| 2438 | + $this->consent_checkbox_label_text = ''; |
|
| 2439 | + $this->gateway_log_lifespan = '7 days'; |
|
| 2440 | + $this->copy_attendee_info = true; |
|
| 2441 | + } |
|
| 2442 | + |
|
| 2443 | + |
|
| 2444 | + /** |
|
| 2445 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2446 | + * |
|
| 2447 | + * @since 4.8.8.rc.019 |
|
| 2448 | + */ |
|
| 2449 | + public function do_hooks() |
|
| 2450 | + { |
|
| 2451 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2452 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2453 | + add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2454 | + } |
|
| 2455 | + |
|
| 2456 | + |
|
| 2457 | + /** |
|
| 2458 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2459 | + * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2460 | + */ |
|
| 2461 | + public function set_default_reg_status_on_EEM_Event() |
|
| 2462 | + { |
|
| 2463 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2464 | + } |
|
| 2465 | + |
|
| 2466 | + |
|
| 2467 | + /** |
|
| 2468 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2469 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2470 | + */ |
|
| 2471 | + public function set_default_max_ticket_on_EEM_Event() |
|
| 2472 | + { |
|
| 2473 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2474 | + } |
|
| 2475 | + |
|
| 2476 | + |
|
| 2477 | + /** |
|
| 2478 | + * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2479 | + * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2480 | + * |
|
| 2481 | + * @throws InvalidArgumentException |
|
| 2482 | + * @throws InvalidDataTypeException |
|
| 2483 | + * @throws InvalidInterfaceException |
|
| 2484 | + */ |
|
| 2485 | + public function setDefaultCheckboxLabelText() |
|
| 2486 | + { |
|
| 2487 | + if ( |
|
| 2488 | + $this->getConsentCheckboxLabelText() === null |
|
| 2489 | + || $this->getConsentCheckboxLabelText() === '' |
|
| 2490 | + ) { |
|
| 2491 | + $opening_a_tag = ''; |
|
| 2492 | + $closing_a_tag = ''; |
|
| 2493 | + if (function_exists('get_privacy_policy_url')) { |
|
| 2494 | + $privacy_page_url = get_privacy_policy_url(); |
|
| 2495 | + if (! empty($privacy_page_url)) { |
|
| 2496 | + $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2497 | + $closing_a_tag = '</a>'; |
|
| 2498 | + } |
|
| 2499 | + } |
|
| 2500 | + $loader = LoaderFactory::getLoader(); |
|
| 2501 | + $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2502 | + /** |
|
| 2503 | + * @var $org_config EE_Organization_Config |
|
| 2504 | + */ |
|
| 2505 | + |
|
| 2506 | + $this->setConsentCheckboxLabelText( |
|
| 2507 | + sprintf( |
|
| 2508 | + esc_html__( |
|
| 2509 | + 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2510 | + 'event_espresso' |
|
| 2511 | + ), |
|
| 2512 | + $org_config->name, |
|
| 2513 | + $opening_a_tag, |
|
| 2514 | + $closing_a_tag |
|
| 2515 | + ) |
|
| 2516 | + ); |
|
| 2517 | + } |
|
| 2518 | + } |
|
| 2519 | + |
|
| 2520 | + |
|
| 2521 | + /** |
|
| 2522 | + * @return boolean |
|
| 2523 | + */ |
|
| 2524 | + public function track_invalid_checkout_access() |
|
| 2525 | + { |
|
| 2526 | + return $this->track_invalid_checkout_access; |
|
| 2527 | + } |
|
| 2528 | + |
|
| 2529 | + |
|
| 2530 | + /** |
|
| 2531 | + * @param boolean $track_invalid_checkout_access |
|
| 2532 | + */ |
|
| 2533 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2534 | + { |
|
| 2535 | + $this->track_invalid_checkout_access = filter_var( |
|
| 2536 | + $track_invalid_checkout_access, |
|
| 2537 | + FILTER_VALIDATE_BOOLEAN |
|
| 2538 | + ); |
|
| 2539 | + } |
|
| 2540 | + |
|
| 2541 | + /** |
|
| 2542 | + * @return boolean |
|
| 2543 | + */ |
|
| 2544 | + public function copyAttendeeInfo() |
|
| 2545 | + { |
|
| 2546 | + return $this->copy_attendee_info; |
|
| 2547 | + } |
|
| 2548 | + |
|
| 2549 | + |
|
| 2550 | + /** |
|
| 2551 | + * @param boolean $copy_attendee_info |
|
| 2552 | + */ |
|
| 2553 | + public function setCopyAttendeeInfo($copy_attendee_info) |
|
| 2554 | + { |
|
| 2555 | + $this->copy_attendee_info = filter_var( |
|
| 2556 | + $copy_attendee_info, |
|
| 2557 | + FILTER_VALIDATE_BOOLEAN |
|
| 2558 | + ); |
|
| 2559 | + } |
|
| 2560 | + |
|
| 2561 | + |
|
| 2562 | + /** |
|
| 2563 | + * Gets the options to make available for the gateway log lifespan |
|
| 2564 | + * @return array |
|
| 2565 | + */ |
|
| 2566 | + public function gatewayLogLifespanOptions() |
|
| 2567 | + { |
|
| 2568 | + return (array) apply_filters( |
|
| 2569 | + 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2570 | + array( |
|
| 2571 | + '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2572 | + '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2573 | + '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2574 | + '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2575 | + '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2576 | + ) |
|
| 2577 | + ); |
|
| 2578 | + } |
|
| 2579 | + |
|
| 2580 | + |
|
| 2581 | + /** |
|
| 2582 | + * @return bool |
|
| 2583 | + */ |
|
| 2584 | + public function isConsentCheckboxEnabled() |
|
| 2585 | + { |
|
| 2586 | + return $this->consent_checkbox_enabled; |
|
| 2587 | + } |
|
| 2588 | + |
|
| 2589 | + |
|
| 2590 | + /** |
|
| 2591 | + * @param bool $consent_checkbox_enabled |
|
| 2592 | + */ |
|
| 2593 | + public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2594 | + { |
|
| 2595 | + $this->consent_checkbox_enabled = filter_var( |
|
| 2596 | + $consent_checkbox_enabled, |
|
| 2597 | + FILTER_VALIDATE_BOOLEAN |
|
| 2598 | + ); |
|
| 2599 | + } |
|
| 2600 | + |
|
| 2601 | + |
|
| 2602 | + /** |
|
| 2603 | + * @return string |
|
| 2604 | + */ |
|
| 2605 | + public function getConsentCheckboxLabelText() |
|
| 2606 | + { |
|
| 2607 | + return $this->consent_checkbox_label_text; |
|
| 2608 | + } |
|
| 2609 | + |
|
| 2610 | + |
|
| 2611 | + /** |
|
| 2612 | + * @param string $consent_checkbox_label_text |
|
| 2613 | + */ |
|
| 2614 | + public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2615 | + { |
|
| 2616 | + $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2617 | + } |
|
| 2618 | 2618 | } |
| 2619 | 2619 | |
| 2620 | 2620 | /** |
@@ -2622,134 +2622,134 @@ discard block |
||
| 2622 | 2622 | */ |
| 2623 | 2623 | class EE_Admin_Config extends EE_Config_Base |
| 2624 | 2624 | { |
| 2625 | - private $useAdvancedEditor = true; |
|
| 2626 | - |
|
| 2627 | - public $use_remote_logging = false; |
|
| 2628 | - |
|
| 2629 | - public $show_reg_footer = false; |
|
| 2630 | - |
|
| 2631 | - private $is_caffeinated; |
|
| 2632 | - |
|
| 2633 | - public $use_dashboard_widget = false; |
|
| 2634 | - |
|
| 2635 | - public $use_personnel_manager = false; |
|
| 2636 | - |
|
| 2637 | - public $use_event_timezones = false; |
|
| 2638 | - |
|
| 2639 | - /** |
|
| 2640 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2641 | - * but is incompatible with some server configuration errors |
|
| 2642 | - * if you get "500 internal server errors" during registration, try turning this on |
|
| 2643 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2644 | - * |
|
| 2645 | - * @var boolean $encode_session_data |
|
| 2646 | - */ |
|
| 2647 | - private $encode_session_data = false; |
|
| 2648 | - |
|
| 2649 | - public ?string $log_file_name = ''; |
|
| 2650 | - |
|
| 2651 | - public ?string $debug_file_name = ''; |
|
| 2652 | - |
|
| 2653 | - public ?string $remote_logging_url = ''; |
|
| 2654 | - |
|
| 2655 | - public ?string $affiliate_id = 'default'; |
|
| 2656 | - |
|
| 2657 | - /** |
|
| 2658 | - * @var int|null $events_in_dashboard |
|
| 2659 | - * @deprecated |
|
| 2660 | - */ |
|
| 2661 | - public ?int $events_in_dashboard = 30; |
|
| 2662 | - |
|
| 2663 | - |
|
| 2664 | - public function __construct() |
|
| 2665 | - { |
|
| 2666 | - /** @var EventEspresso\core\domain\Domain $domain */ |
|
| 2667 | - $domain = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\Domain'); |
|
| 2668 | - $this->is_caffeinated = $domain->isCaffeinated(); |
|
| 2669 | - |
|
| 2670 | - // set default general admin settings |
|
| 2671 | - $this->show_reg_footer = apply_filters( |
|
| 2672 | - 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
| 2673 | - false |
|
| 2674 | - ); |
|
| 2675 | - } |
|
| 2676 | - |
|
| 2677 | - |
|
| 2678 | - /** |
|
| 2679 | - * @param bool $reset |
|
| 2680 | - * @return string |
|
| 2681 | - */ |
|
| 2682 | - public function log_file_name(bool $reset = false): ?string |
|
| 2683 | - { |
|
| 2684 | - if (empty($this->log_file_name) || $reset) { |
|
| 2685 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2686 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2687 | - } |
|
| 2688 | - return $this->log_file_name; |
|
| 2689 | - } |
|
| 2690 | - |
|
| 2691 | - |
|
| 2692 | - /** |
|
| 2693 | - * @param bool $reset |
|
| 2694 | - * @return string |
|
| 2695 | - */ |
|
| 2696 | - public function debug_file_name(bool $reset = false): ?string |
|
| 2697 | - { |
|
| 2698 | - if (empty($this->debug_file_name) || $reset) { |
|
| 2699 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2700 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2701 | - } |
|
| 2702 | - return $this->debug_file_name; |
|
| 2703 | - } |
|
| 2704 | - |
|
| 2705 | - |
|
| 2706 | - /** |
|
| 2707 | - * @return string |
|
| 2708 | - */ |
|
| 2709 | - public function affiliate_id(): ?string |
|
| 2710 | - { |
|
| 2711 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2712 | - } |
|
| 2713 | - |
|
| 2714 | - |
|
| 2715 | - /** |
|
| 2716 | - * @return boolean |
|
| 2717 | - */ |
|
| 2718 | - public function encode_session_data(): bool |
|
| 2719 | - { |
|
| 2720 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2721 | - } |
|
| 2625 | + private $useAdvancedEditor = true; |
|
| 2722 | 2626 | |
| 2723 | - |
|
| 2724 | - /** |
|
| 2725 | - * @param bool|int|string $encode_session_data |
|
| 2726 | - */ |
|
| 2727 | - public function set_encode_session_data($encode_session_data) |
|
| 2728 | - { |
|
| 2729 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2730 | - } |
|
| 2731 | - |
|
| 2732 | - /** |
|
| 2733 | - * @return boolean |
|
| 2734 | - */ |
|
| 2735 | - public function useAdvancedEditor(): bool |
|
| 2736 | - { |
|
| 2737 | - return $this->useAdvancedEditor && $this->is_caffeinated; |
|
| 2738 | - } |
|
| 2739 | - |
|
| 2740 | - /** |
|
| 2741 | - * @param bool|int|string $use_advanced_editor |
|
| 2742 | - */ |
|
| 2743 | - public function setUseAdvancedEditor($use_advanced_editor = true) |
|
| 2744 | - { |
|
| 2745 | - $this->useAdvancedEditor = filter_var( |
|
| 2746 | - apply_filters( |
|
| 2747 | - 'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor', |
|
| 2748 | - $use_advanced_editor |
|
| 2749 | - ), |
|
| 2750 | - FILTER_VALIDATE_BOOLEAN |
|
| 2751 | - ); |
|
| 2752 | - } |
|
| 2627 | + public $use_remote_logging = false; |
|
| 2628 | + |
|
| 2629 | + public $show_reg_footer = false; |
|
| 2630 | + |
|
| 2631 | + private $is_caffeinated; |
|
| 2632 | + |
|
| 2633 | + public $use_dashboard_widget = false; |
|
| 2634 | + |
|
| 2635 | + public $use_personnel_manager = false; |
|
| 2636 | + |
|
| 2637 | + public $use_event_timezones = false; |
|
| 2638 | + |
|
| 2639 | + /** |
|
| 2640 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2641 | + * but is incompatible with some server configuration errors |
|
| 2642 | + * if you get "500 internal server errors" during registration, try turning this on |
|
| 2643 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2644 | + * |
|
| 2645 | + * @var boolean $encode_session_data |
|
| 2646 | + */ |
|
| 2647 | + private $encode_session_data = false; |
|
| 2648 | + |
|
| 2649 | + public ?string $log_file_name = ''; |
|
| 2650 | + |
|
| 2651 | + public ?string $debug_file_name = ''; |
|
| 2652 | + |
|
| 2653 | + public ?string $remote_logging_url = ''; |
|
| 2654 | + |
|
| 2655 | + public ?string $affiliate_id = 'default'; |
|
| 2656 | + |
|
| 2657 | + /** |
|
| 2658 | + * @var int|null $events_in_dashboard |
|
| 2659 | + * @deprecated |
|
| 2660 | + */ |
|
| 2661 | + public ?int $events_in_dashboard = 30; |
|
| 2662 | + |
|
| 2663 | + |
|
| 2664 | + public function __construct() |
|
| 2665 | + { |
|
| 2666 | + /** @var EventEspresso\core\domain\Domain $domain */ |
|
| 2667 | + $domain = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\Domain'); |
|
| 2668 | + $this->is_caffeinated = $domain->isCaffeinated(); |
|
| 2669 | + |
|
| 2670 | + // set default general admin settings |
|
| 2671 | + $this->show_reg_footer = apply_filters( |
|
| 2672 | + 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
| 2673 | + false |
|
| 2674 | + ); |
|
| 2675 | + } |
|
| 2676 | + |
|
| 2677 | + |
|
| 2678 | + /** |
|
| 2679 | + * @param bool $reset |
|
| 2680 | + * @return string |
|
| 2681 | + */ |
|
| 2682 | + public function log_file_name(bool $reset = false): ?string |
|
| 2683 | + { |
|
| 2684 | + if (empty($this->log_file_name) || $reset) { |
|
| 2685 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2686 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2687 | + } |
|
| 2688 | + return $this->log_file_name; |
|
| 2689 | + } |
|
| 2690 | + |
|
| 2691 | + |
|
| 2692 | + /** |
|
| 2693 | + * @param bool $reset |
|
| 2694 | + * @return string |
|
| 2695 | + */ |
|
| 2696 | + public function debug_file_name(bool $reset = false): ?string |
|
| 2697 | + { |
|
| 2698 | + if (empty($this->debug_file_name) || $reset) { |
|
| 2699 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2700 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2701 | + } |
|
| 2702 | + return $this->debug_file_name; |
|
| 2703 | + } |
|
| 2704 | + |
|
| 2705 | + |
|
| 2706 | + /** |
|
| 2707 | + * @return string |
|
| 2708 | + */ |
|
| 2709 | + public function affiliate_id(): ?string |
|
| 2710 | + { |
|
| 2711 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2712 | + } |
|
| 2713 | + |
|
| 2714 | + |
|
| 2715 | + /** |
|
| 2716 | + * @return boolean |
|
| 2717 | + */ |
|
| 2718 | + public function encode_session_data(): bool |
|
| 2719 | + { |
|
| 2720 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2721 | + } |
|
| 2722 | + |
|
| 2723 | + |
|
| 2724 | + /** |
|
| 2725 | + * @param bool|int|string $encode_session_data |
|
| 2726 | + */ |
|
| 2727 | + public function set_encode_session_data($encode_session_data) |
|
| 2728 | + { |
|
| 2729 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2730 | + } |
|
| 2731 | + |
|
| 2732 | + /** |
|
| 2733 | + * @return boolean |
|
| 2734 | + */ |
|
| 2735 | + public function useAdvancedEditor(): bool |
|
| 2736 | + { |
|
| 2737 | + return $this->useAdvancedEditor && $this->is_caffeinated; |
|
| 2738 | + } |
|
| 2739 | + |
|
| 2740 | + /** |
|
| 2741 | + * @param bool|int|string $use_advanced_editor |
|
| 2742 | + */ |
|
| 2743 | + public function setUseAdvancedEditor($use_advanced_editor = true) |
|
| 2744 | + { |
|
| 2745 | + $this->useAdvancedEditor = filter_var( |
|
| 2746 | + apply_filters( |
|
| 2747 | + 'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor', |
|
| 2748 | + $use_advanced_editor |
|
| 2749 | + ), |
|
| 2750 | + FILTER_VALIDATE_BOOLEAN |
|
| 2751 | + ); |
|
| 2752 | + } |
|
| 2753 | 2753 | } |
| 2754 | 2754 | |
| 2755 | 2755 | /** |
@@ -2757,60 +2757,60 @@ discard block |
||
| 2757 | 2757 | */ |
| 2758 | 2758 | class EE_Template_Config extends EE_Config_Base |
| 2759 | 2759 | { |
| 2760 | - public ?EE_Ticket_Selector_Config $EED_Ticket_Selector; |
|
| 2761 | - |
|
| 2762 | - public ?EE_Event_Single_Config $EED_Event_Single; |
|
| 2763 | - |
|
| 2764 | - public ?EE_Events_Archive_Config $EED_Events_Archive; |
|
| 2765 | - |
|
| 2766 | - /** |
|
| 2767 | - * @var EE_People_Config|null $EED_People_Single |
|
| 2768 | - * @since 5.0.12.p |
|
| 2769 | - */ |
|
| 2770 | - public $EED_People_Single; |
|
| 2771 | - |
|
| 2772 | - public string $current_espresso_theme = ''; |
|
| 2773 | - |
|
| 2774 | - public bool $display_address_in_regform = true; |
|
| 2775 | - |
|
| 2776 | - /** |
|
| 2777 | - * @var bool|int|string|null $enable_default_style |
|
| 2778 | - * @deprecated |
|
| 2779 | - */ |
|
| 2780 | - public $enable_default_style; |
|
| 2781 | - |
|
| 2782 | - /** |
|
| 2783 | - * @var bool|int|string|null $display_description_on_multi_reg_page |
|
| 2784 | - * @deprecated |
|
| 2785 | - */ |
|
| 2786 | - public $display_description_on_multi_reg_page; |
|
| 2787 | - |
|
| 2788 | - /** |
|
| 2789 | - * @var bool|int|string|null $use_custom_templates |
|
| 2790 | - * @deprecated |
|
| 2791 | - */ |
|
| 2792 | - public $use_custom_templates; |
|
| 2793 | - |
|
| 2794 | - /** |
|
| 2795 | - * @var bool|int|string|null $custom_style_sheet |
|
| 2796 | - * @deprecated |
|
| 2797 | - */ |
|
| 2798 | - public $custom_style_sheet; |
|
| 2799 | - |
|
| 2800 | - |
|
| 2801 | - /** |
|
| 2802 | - * class constructor |
|
| 2803 | - * |
|
| 2804 | - * @access public |
|
| 2805 | - */ |
|
| 2806 | - public function __construct() |
|
| 2807 | - { |
|
| 2808 | - // set default template settings |
|
| 2809 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2810 | - $this->EED_Event_Single = null; |
|
| 2811 | - $this->EED_Events_Archive = null; |
|
| 2812 | - $this->EED_Ticket_Selector = null; |
|
| 2813 | - } |
|
| 2760 | + public ?EE_Ticket_Selector_Config $EED_Ticket_Selector; |
|
| 2761 | + |
|
| 2762 | + public ?EE_Event_Single_Config $EED_Event_Single; |
|
| 2763 | + |
|
| 2764 | + public ?EE_Events_Archive_Config $EED_Events_Archive; |
|
| 2765 | + |
|
| 2766 | + /** |
|
| 2767 | + * @var EE_People_Config|null $EED_People_Single |
|
| 2768 | + * @since 5.0.12.p |
|
| 2769 | + */ |
|
| 2770 | + public $EED_People_Single; |
|
| 2771 | + |
|
| 2772 | + public string $current_espresso_theme = ''; |
|
| 2773 | + |
|
| 2774 | + public bool $display_address_in_regform = true; |
|
| 2775 | + |
|
| 2776 | + /** |
|
| 2777 | + * @var bool|int|string|null $enable_default_style |
|
| 2778 | + * @deprecated |
|
| 2779 | + */ |
|
| 2780 | + public $enable_default_style; |
|
| 2781 | + |
|
| 2782 | + /** |
|
| 2783 | + * @var bool|int|string|null $display_description_on_multi_reg_page |
|
| 2784 | + * @deprecated |
|
| 2785 | + */ |
|
| 2786 | + public $display_description_on_multi_reg_page; |
|
| 2787 | + |
|
| 2788 | + /** |
|
| 2789 | + * @var bool|int|string|null $use_custom_templates |
|
| 2790 | + * @deprecated |
|
| 2791 | + */ |
|
| 2792 | + public $use_custom_templates; |
|
| 2793 | + |
|
| 2794 | + /** |
|
| 2795 | + * @var bool|int|string|null $custom_style_sheet |
|
| 2796 | + * @deprecated |
|
| 2797 | + */ |
|
| 2798 | + public $custom_style_sheet; |
|
| 2799 | + |
|
| 2800 | + |
|
| 2801 | + /** |
|
| 2802 | + * class constructor |
|
| 2803 | + * |
|
| 2804 | + * @access public |
|
| 2805 | + */ |
|
| 2806 | + public function __construct() |
|
| 2807 | + { |
|
| 2808 | + // set default template settings |
|
| 2809 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2810 | + $this->EED_Event_Single = null; |
|
| 2811 | + $this->EED_Events_Archive = null; |
|
| 2812 | + $this->EED_Ticket_Selector = null; |
|
| 2813 | + } |
|
| 2814 | 2814 | } |
| 2815 | 2815 | |
| 2816 | 2816 | /** |
@@ -2818,114 +2818,114 @@ discard block |
||
| 2818 | 2818 | */ |
| 2819 | 2819 | class EE_Map_Config extends EE_Config_Base |
| 2820 | 2820 | { |
| 2821 | - /** |
|
| 2822 | - * @var boolean $use_google_maps |
|
| 2823 | - */ |
|
| 2824 | - public $use_google_maps; |
|
| 2825 | - |
|
| 2826 | - /** |
|
| 2827 | - * @var string $api_key |
|
| 2828 | - */ |
|
| 2829 | - public $google_map_api_key; |
|
| 2830 | - |
|
| 2831 | - /** |
|
| 2832 | - * @var int $event_details_map_width |
|
| 2833 | - */ |
|
| 2834 | - public $event_details_map_width; |
|
| 2835 | - |
|
| 2836 | - /** |
|
| 2837 | - * @var int $event_details_map_height |
|
| 2838 | - */ |
|
| 2839 | - public $event_details_map_height; |
|
| 2840 | - |
|
| 2841 | - /** |
|
| 2842 | - * @var int $event_details_map_zoom |
|
| 2843 | - */ |
|
| 2844 | - public $event_details_map_zoom; |
|
| 2845 | - |
|
| 2846 | - /** |
|
| 2847 | - * @var boolean $event_details_display_nav |
|
| 2848 | - */ |
|
| 2849 | - public $event_details_display_nav; |
|
| 2850 | - |
|
| 2851 | - /** |
|
| 2852 | - * @var boolean $event_details_nav_size |
|
| 2853 | - */ |
|
| 2854 | - public $event_details_nav_size; |
|
| 2855 | - |
|
| 2856 | - /** |
|
| 2857 | - * @var string $event_details_control_type |
|
| 2858 | - */ |
|
| 2859 | - public $event_details_control_type; |
|
| 2860 | - |
|
| 2861 | - /** |
|
| 2862 | - * @var string $event_details_map_align |
|
| 2863 | - */ |
|
| 2864 | - public $event_details_map_align; |
|
| 2865 | - |
|
| 2866 | - /** |
|
| 2867 | - * @var int $event_list_map_width |
|
| 2868 | - */ |
|
| 2869 | - public $event_list_map_width; |
|
| 2870 | - |
|
| 2871 | - /** |
|
| 2872 | - * @var int $event_list_map_height |
|
| 2873 | - */ |
|
| 2874 | - public $event_list_map_height; |
|
| 2875 | - |
|
| 2876 | - /** |
|
| 2877 | - * @var int $event_list_map_zoom |
|
| 2878 | - */ |
|
| 2879 | - public $event_list_map_zoom; |
|
| 2880 | - |
|
| 2881 | - /** |
|
| 2882 | - * @var boolean $event_list_display_nav |
|
| 2883 | - */ |
|
| 2884 | - public $event_list_display_nav; |
|
| 2885 | - |
|
| 2886 | - /** |
|
| 2887 | - * @var boolean $event_list_nav_size |
|
| 2888 | - */ |
|
| 2889 | - public $event_list_nav_size; |
|
| 2890 | - |
|
| 2891 | - /** |
|
| 2892 | - * @var string $event_list_control_type |
|
| 2893 | - */ |
|
| 2894 | - public $event_list_control_type; |
|
| 2895 | - |
|
| 2896 | - /** |
|
| 2897 | - * @var string $event_list_map_align |
|
| 2898 | - */ |
|
| 2899 | - public $event_list_map_align; |
|
| 2900 | - |
|
| 2901 | - |
|
| 2902 | - /** |
|
| 2903 | - * class constructor |
|
| 2904 | - * |
|
| 2905 | - * @access public |
|
| 2906 | - */ |
|
| 2907 | - public function __construct() |
|
| 2908 | - { |
|
| 2909 | - // set default map settings |
|
| 2910 | - $this->use_google_maps = true; |
|
| 2911 | - $this->google_map_api_key = ''; |
|
| 2912 | - // for event details pages (reg page) |
|
| 2913 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2914 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2915 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2916 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2917 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2918 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2919 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2920 | - // for event list pages |
|
| 2921 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2922 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2923 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2924 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2925 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2926 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2927 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2928 | - } |
|
| 2821 | + /** |
|
| 2822 | + * @var boolean $use_google_maps |
|
| 2823 | + */ |
|
| 2824 | + public $use_google_maps; |
|
| 2825 | + |
|
| 2826 | + /** |
|
| 2827 | + * @var string $api_key |
|
| 2828 | + */ |
|
| 2829 | + public $google_map_api_key; |
|
| 2830 | + |
|
| 2831 | + /** |
|
| 2832 | + * @var int $event_details_map_width |
|
| 2833 | + */ |
|
| 2834 | + public $event_details_map_width; |
|
| 2835 | + |
|
| 2836 | + /** |
|
| 2837 | + * @var int $event_details_map_height |
|
| 2838 | + */ |
|
| 2839 | + public $event_details_map_height; |
|
| 2840 | + |
|
| 2841 | + /** |
|
| 2842 | + * @var int $event_details_map_zoom |
|
| 2843 | + */ |
|
| 2844 | + public $event_details_map_zoom; |
|
| 2845 | + |
|
| 2846 | + /** |
|
| 2847 | + * @var boolean $event_details_display_nav |
|
| 2848 | + */ |
|
| 2849 | + public $event_details_display_nav; |
|
| 2850 | + |
|
| 2851 | + /** |
|
| 2852 | + * @var boolean $event_details_nav_size |
|
| 2853 | + */ |
|
| 2854 | + public $event_details_nav_size; |
|
| 2855 | + |
|
| 2856 | + /** |
|
| 2857 | + * @var string $event_details_control_type |
|
| 2858 | + */ |
|
| 2859 | + public $event_details_control_type; |
|
| 2860 | + |
|
| 2861 | + /** |
|
| 2862 | + * @var string $event_details_map_align |
|
| 2863 | + */ |
|
| 2864 | + public $event_details_map_align; |
|
| 2865 | + |
|
| 2866 | + /** |
|
| 2867 | + * @var int $event_list_map_width |
|
| 2868 | + */ |
|
| 2869 | + public $event_list_map_width; |
|
| 2870 | + |
|
| 2871 | + /** |
|
| 2872 | + * @var int $event_list_map_height |
|
| 2873 | + */ |
|
| 2874 | + public $event_list_map_height; |
|
| 2875 | + |
|
| 2876 | + /** |
|
| 2877 | + * @var int $event_list_map_zoom |
|
| 2878 | + */ |
|
| 2879 | + public $event_list_map_zoom; |
|
| 2880 | + |
|
| 2881 | + /** |
|
| 2882 | + * @var boolean $event_list_display_nav |
|
| 2883 | + */ |
|
| 2884 | + public $event_list_display_nav; |
|
| 2885 | + |
|
| 2886 | + /** |
|
| 2887 | + * @var boolean $event_list_nav_size |
|
| 2888 | + */ |
|
| 2889 | + public $event_list_nav_size; |
|
| 2890 | + |
|
| 2891 | + /** |
|
| 2892 | + * @var string $event_list_control_type |
|
| 2893 | + */ |
|
| 2894 | + public $event_list_control_type; |
|
| 2895 | + |
|
| 2896 | + /** |
|
| 2897 | + * @var string $event_list_map_align |
|
| 2898 | + */ |
|
| 2899 | + public $event_list_map_align; |
|
| 2900 | + |
|
| 2901 | + |
|
| 2902 | + /** |
|
| 2903 | + * class constructor |
|
| 2904 | + * |
|
| 2905 | + * @access public |
|
| 2906 | + */ |
|
| 2907 | + public function __construct() |
|
| 2908 | + { |
|
| 2909 | + // set default map settings |
|
| 2910 | + $this->use_google_maps = true; |
|
| 2911 | + $this->google_map_api_key = ''; |
|
| 2912 | + // for event details pages (reg page) |
|
| 2913 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2914 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2915 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2916 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2917 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2918 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2919 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2920 | + // for event list pages |
|
| 2921 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2922 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2923 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2924 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2925 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2926 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2927 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2928 | + } |
|
| 2929 | 2929 | } |
| 2930 | 2930 | |
| 2931 | 2931 | /** |
@@ -2933,46 +2933,46 @@ discard block |
||
| 2933 | 2933 | */ |
| 2934 | 2934 | class EE_Events_Archive_Config extends EE_Config_Base |
| 2935 | 2935 | { |
| 2936 | - public $display_status_banner; |
|
| 2936 | + public $display_status_banner; |
|
| 2937 | 2937 | |
| 2938 | - public $display_description; |
|
| 2938 | + public $display_description; |
|
| 2939 | 2939 | |
| 2940 | - public $display_ticket_selector; |
|
| 2940 | + public $display_ticket_selector; |
|
| 2941 | 2941 | |
| 2942 | - public $display_datetimes; |
|
| 2942 | + public $display_datetimes; |
|
| 2943 | 2943 | |
| 2944 | - public $display_venue; |
|
| 2944 | + public $display_venue; |
|
| 2945 | 2945 | |
| 2946 | - public $display_expired_events; |
|
| 2946 | + public $display_expired_events; |
|
| 2947 | 2947 | |
| 2948 | - public $use_sortable_display_order; |
|
| 2948 | + public $use_sortable_display_order; |
|
| 2949 | 2949 | |
| 2950 | - public $display_order_tickets; |
|
| 2950 | + public $display_order_tickets; |
|
| 2951 | 2951 | |
| 2952 | - public $display_order_datetimes; |
|
| 2952 | + public $display_order_datetimes; |
|
| 2953 | 2953 | |
| 2954 | - public $display_order_event; |
|
| 2954 | + public $display_order_event; |
|
| 2955 | 2955 | |
| 2956 | - public $display_order_venue; |
|
| 2956 | + public $display_order_venue; |
|
| 2957 | 2957 | |
| 2958 | 2958 | |
| 2959 | - /** |
|
| 2960 | - * class constructor |
|
| 2961 | - */ |
|
| 2962 | - public function __construct() |
|
| 2963 | - { |
|
| 2964 | - $this->display_status_banner = 0; |
|
| 2965 | - $this->display_description = 1; |
|
| 2966 | - $this->display_ticket_selector = 0; |
|
| 2967 | - $this->display_datetimes = 1; |
|
| 2968 | - $this->display_venue = 0; |
|
| 2969 | - $this->display_expired_events = 0; |
|
| 2970 | - $this->use_sortable_display_order = false; |
|
| 2971 | - $this->display_order_tickets = 100; |
|
| 2972 | - $this->display_order_datetimes = 110; |
|
| 2973 | - $this->display_order_event = 120; |
|
| 2974 | - $this->display_order_venue = 130; |
|
| 2975 | - } |
|
| 2959 | + /** |
|
| 2960 | + * class constructor |
|
| 2961 | + */ |
|
| 2962 | + public function __construct() |
|
| 2963 | + { |
|
| 2964 | + $this->display_status_banner = 0; |
|
| 2965 | + $this->display_description = 1; |
|
| 2966 | + $this->display_ticket_selector = 0; |
|
| 2967 | + $this->display_datetimes = 1; |
|
| 2968 | + $this->display_venue = 0; |
|
| 2969 | + $this->display_expired_events = 0; |
|
| 2970 | + $this->use_sortable_display_order = false; |
|
| 2971 | + $this->display_order_tickets = 100; |
|
| 2972 | + $this->display_order_datetimes = 110; |
|
| 2973 | + $this->display_order_event = 120; |
|
| 2974 | + $this->display_order_venue = 130; |
|
| 2975 | + } |
|
| 2976 | 2976 | } |
| 2977 | 2977 | |
| 2978 | 2978 | /** |
@@ -2980,34 +2980,34 @@ discard block |
||
| 2980 | 2980 | */ |
| 2981 | 2981 | class EE_Event_Single_Config extends EE_Config_Base |
| 2982 | 2982 | { |
| 2983 | - public $display_status_banner_single; |
|
| 2983 | + public $display_status_banner_single; |
|
| 2984 | 2984 | |
| 2985 | - public $display_venue; |
|
| 2985 | + public $display_venue; |
|
| 2986 | 2986 | |
| 2987 | - public $use_sortable_display_order; |
|
| 2987 | + public $use_sortable_display_order; |
|
| 2988 | 2988 | |
| 2989 | - public $display_order_tickets; |
|
| 2989 | + public $display_order_tickets; |
|
| 2990 | 2990 | |
| 2991 | - public $display_order_datetimes; |
|
| 2991 | + public $display_order_datetimes; |
|
| 2992 | 2992 | |
| 2993 | - public $display_order_event; |
|
| 2993 | + public $display_order_event; |
|
| 2994 | 2994 | |
| 2995 | - public $display_order_venue; |
|
| 2995 | + public $display_order_venue; |
|
| 2996 | 2996 | |
| 2997 | 2997 | |
| 2998 | - /** |
|
| 2999 | - * class constructor |
|
| 3000 | - */ |
|
| 3001 | - public function __construct() |
|
| 3002 | - { |
|
| 3003 | - $this->display_status_banner_single = 0; |
|
| 3004 | - $this->display_venue = 1; |
|
| 3005 | - $this->use_sortable_display_order = false; |
|
| 3006 | - $this->display_order_tickets = 100; |
|
| 3007 | - $this->display_order_datetimes = 110; |
|
| 3008 | - $this->display_order_event = 120; |
|
| 3009 | - $this->display_order_venue = 130; |
|
| 3010 | - } |
|
| 2998 | + /** |
|
| 2999 | + * class constructor |
|
| 3000 | + */ |
|
| 3001 | + public function __construct() |
|
| 3002 | + { |
|
| 3003 | + $this->display_status_banner_single = 0; |
|
| 3004 | + $this->display_venue = 1; |
|
| 3005 | + $this->use_sortable_display_order = false; |
|
| 3006 | + $this->display_order_tickets = 100; |
|
| 3007 | + $this->display_order_datetimes = 110; |
|
| 3008 | + $this->display_order_event = 120; |
|
| 3009 | + $this->display_order_venue = 130; |
|
| 3010 | + } |
|
| 3011 | 3011 | } |
| 3012 | 3012 | |
| 3013 | 3013 | /** |
@@ -3015,172 +3015,172 @@ discard block |
||
| 3015 | 3015 | */ |
| 3016 | 3016 | class EE_Ticket_Selector_Config extends EE_Config_Base |
| 3017 | 3017 | { |
| 3018 | - /** |
|
| 3019 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 3020 | - */ |
|
| 3021 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 3022 | - |
|
| 3023 | - /** |
|
| 3024 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 3025 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 3026 | - */ |
|
| 3027 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 3028 | - |
|
| 3029 | - /** |
|
| 3030 | - * @var boolean $show_ticket_sale_columns |
|
| 3031 | - */ |
|
| 3032 | - public $show_ticket_sale_columns; |
|
| 3033 | - |
|
| 3034 | - /** |
|
| 3035 | - * @var boolean $show_ticket_details |
|
| 3036 | - */ |
|
| 3037 | - public $show_ticket_details; |
|
| 3038 | - |
|
| 3039 | - /** |
|
| 3040 | - * @var boolean $show_expired_tickets |
|
| 3041 | - */ |
|
| 3042 | - public $show_expired_tickets; |
|
| 3043 | - |
|
| 3044 | - /** |
|
| 3045 | - * whether to display a dropdown box populated with event datetimes |
|
| 3046 | - * that toggles which tickets are displayed for a ticket selector. |
|
| 3047 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 3048 | - * |
|
| 3049 | - * @var string $show_datetime_selector |
|
| 3050 | - */ |
|
| 3051 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
| 3052 | - |
|
| 3053 | - /** |
|
| 3054 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 3055 | - * |
|
| 3056 | - * @var int $datetime_selector_threshold |
|
| 3057 | - */ |
|
| 3058 | - private $datetime_selector_threshold = 3; |
|
| 3059 | - |
|
| 3060 | - /** |
|
| 3061 | - * determines the maximum number of "checked" dates in the date and time filter |
|
| 3062 | - * |
|
| 3063 | - * @var int $datetime_selector_checked |
|
| 3064 | - */ |
|
| 3065 | - private $datetime_selector_max_checked = 10; |
|
| 3066 | - |
|
| 3067 | - |
|
| 3068 | - /** |
|
| 3069 | - * class constructor |
|
| 3070 | - */ |
|
| 3071 | - public function __construct() |
|
| 3072 | - { |
|
| 3073 | - $this->show_ticket_sale_columns = true; |
|
| 3074 | - $this->show_ticket_details = true; |
|
| 3075 | - $this->show_expired_tickets = true; |
|
| 3076 | - $this->show_datetime_selector = EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3077 | - $this->datetime_selector_threshold = 3; |
|
| 3078 | - $this->datetime_selector_max_checked = 10; |
|
| 3079 | - } |
|
| 3080 | - |
|
| 3081 | - |
|
| 3082 | - /** |
|
| 3083 | - * returns true if a datetime selector should be displayed |
|
| 3084 | - * |
|
| 3085 | - * @param array $datetimes |
|
| 3086 | - * @return bool |
|
| 3087 | - */ |
|
| 3088 | - public function showDatetimeSelector(array $datetimes) |
|
| 3089 | - { |
|
| 3090 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3091 | - return ! ( |
|
| 3092 | - $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3093 | - || ( |
|
| 3094 | - $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3095 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3096 | - ) |
|
| 3097 | - ); |
|
| 3098 | - } |
|
| 3099 | - |
|
| 3100 | - |
|
| 3101 | - /** |
|
| 3102 | - * @return string |
|
| 3103 | - */ |
|
| 3104 | - public function getShowDatetimeSelector() |
|
| 3105 | - { |
|
| 3106 | - return $this->show_datetime_selector; |
|
| 3107 | - } |
|
| 3108 | - |
|
| 3109 | - |
|
| 3110 | - /** |
|
| 3111 | - * @param bool $keys_only |
|
| 3112 | - * @return array |
|
| 3113 | - */ |
|
| 3114 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3115 | - { |
|
| 3116 | - return $keys_only |
|
| 3117 | - ? array( |
|
| 3118 | - EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3119 | - EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3120 | - ) |
|
| 3121 | - : array( |
|
| 3122 | - EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3123 | - 'Do not show date & time filter', |
|
| 3124 | - 'event_espresso' |
|
| 3125 | - ), |
|
| 3126 | - EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3127 | - 'Maybe show date & time filter', |
|
| 3128 | - 'event_espresso' |
|
| 3129 | - ), |
|
| 3130 | - ); |
|
| 3131 | - } |
|
| 3132 | - |
|
| 3133 | - |
|
| 3134 | - /** |
|
| 3135 | - * @param string $show_datetime_selector |
|
| 3136 | - */ |
|
| 3137 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3138 | - { |
|
| 3139 | - $this->show_datetime_selector = in_array( |
|
| 3140 | - $show_datetime_selector, |
|
| 3141 | - $this->getShowDatetimeSelectorOptions(), |
|
| 3142 | - true |
|
| 3143 | - ) |
|
| 3144 | - ? $show_datetime_selector |
|
| 3145 | - : EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3146 | - } |
|
| 3147 | - |
|
| 3148 | - |
|
| 3149 | - /** |
|
| 3150 | - * @return int |
|
| 3151 | - */ |
|
| 3152 | - public function getDatetimeSelectorThreshold() |
|
| 3153 | - { |
|
| 3154 | - return $this->datetime_selector_threshold; |
|
| 3155 | - } |
|
| 3156 | - |
|
| 3157 | - |
|
| 3158 | - /** |
|
| 3159 | - * @param int $datetime_selector_threshold |
|
| 3160 | - */ |
|
| 3161 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3162 | - { |
|
| 3163 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3164 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3165 | - } |
|
| 3166 | - |
|
| 3167 | - |
|
| 3168 | - /** |
|
| 3169 | - * @return int |
|
| 3170 | - */ |
|
| 3171 | - public function getDatetimeSelectorMaxChecked() |
|
| 3172 | - { |
|
| 3173 | - return $this->datetime_selector_max_checked; |
|
| 3174 | - } |
|
| 3175 | - |
|
| 3176 | - |
|
| 3177 | - /** |
|
| 3178 | - * @param int $datetime_selector_max_checked |
|
| 3179 | - */ |
|
| 3180 | - public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
| 3181 | - { |
|
| 3182 | - $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
| 3183 | - } |
|
| 3018 | + /** |
|
| 3019 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 3020 | + */ |
|
| 3021 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 3022 | + |
|
| 3023 | + /** |
|
| 3024 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 3025 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 3026 | + */ |
|
| 3027 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 3028 | + |
|
| 3029 | + /** |
|
| 3030 | + * @var boolean $show_ticket_sale_columns |
|
| 3031 | + */ |
|
| 3032 | + public $show_ticket_sale_columns; |
|
| 3033 | + |
|
| 3034 | + /** |
|
| 3035 | + * @var boolean $show_ticket_details |
|
| 3036 | + */ |
|
| 3037 | + public $show_ticket_details; |
|
| 3038 | + |
|
| 3039 | + /** |
|
| 3040 | + * @var boolean $show_expired_tickets |
|
| 3041 | + */ |
|
| 3042 | + public $show_expired_tickets; |
|
| 3043 | + |
|
| 3044 | + /** |
|
| 3045 | + * whether to display a dropdown box populated with event datetimes |
|
| 3046 | + * that toggles which tickets are displayed for a ticket selector. |
|
| 3047 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 3048 | + * |
|
| 3049 | + * @var string $show_datetime_selector |
|
| 3050 | + */ |
|
| 3051 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
| 3052 | + |
|
| 3053 | + /** |
|
| 3054 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 3055 | + * |
|
| 3056 | + * @var int $datetime_selector_threshold |
|
| 3057 | + */ |
|
| 3058 | + private $datetime_selector_threshold = 3; |
|
| 3059 | + |
|
| 3060 | + /** |
|
| 3061 | + * determines the maximum number of "checked" dates in the date and time filter |
|
| 3062 | + * |
|
| 3063 | + * @var int $datetime_selector_checked |
|
| 3064 | + */ |
|
| 3065 | + private $datetime_selector_max_checked = 10; |
|
| 3066 | + |
|
| 3067 | + |
|
| 3068 | + /** |
|
| 3069 | + * class constructor |
|
| 3070 | + */ |
|
| 3071 | + public function __construct() |
|
| 3072 | + { |
|
| 3073 | + $this->show_ticket_sale_columns = true; |
|
| 3074 | + $this->show_ticket_details = true; |
|
| 3075 | + $this->show_expired_tickets = true; |
|
| 3076 | + $this->show_datetime_selector = EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3077 | + $this->datetime_selector_threshold = 3; |
|
| 3078 | + $this->datetime_selector_max_checked = 10; |
|
| 3079 | + } |
|
| 3080 | + |
|
| 3081 | + |
|
| 3082 | + /** |
|
| 3083 | + * returns true if a datetime selector should be displayed |
|
| 3084 | + * |
|
| 3085 | + * @param array $datetimes |
|
| 3086 | + * @return bool |
|
| 3087 | + */ |
|
| 3088 | + public function showDatetimeSelector(array $datetimes) |
|
| 3089 | + { |
|
| 3090 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3091 | + return ! ( |
|
| 3092 | + $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3093 | + || ( |
|
| 3094 | + $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3095 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3096 | + ) |
|
| 3097 | + ); |
|
| 3098 | + } |
|
| 3099 | + |
|
| 3100 | + |
|
| 3101 | + /** |
|
| 3102 | + * @return string |
|
| 3103 | + */ |
|
| 3104 | + public function getShowDatetimeSelector() |
|
| 3105 | + { |
|
| 3106 | + return $this->show_datetime_selector; |
|
| 3107 | + } |
|
| 3108 | + |
|
| 3109 | + |
|
| 3110 | + /** |
|
| 3111 | + * @param bool $keys_only |
|
| 3112 | + * @return array |
|
| 3113 | + */ |
|
| 3114 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3115 | + { |
|
| 3116 | + return $keys_only |
|
| 3117 | + ? array( |
|
| 3118 | + EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3119 | + EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3120 | + ) |
|
| 3121 | + : array( |
|
| 3122 | + EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3123 | + 'Do not show date & time filter', |
|
| 3124 | + 'event_espresso' |
|
| 3125 | + ), |
|
| 3126 | + EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3127 | + 'Maybe show date & time filter', |
|
| 3128 | + 'event_espresso' |
|
| 3129 | + ), |
|
| 3130 | + ); |
|
| 3131 | + } |
|
| 3132 | + |
|
| 3133 | + |
|
| 3134 | + /** |
|
| 3135 | + * @param string $show_datetime_selector |
|
| 3136 | + */ |
|
| 3137 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3138 | + { |
|
| 3139 | + $this->show_datetime_selector = in_array( |
|
| 3140 | + $show_datetime_selector, |
|
| 3141 | + $this->getShowDatetimeSelectorOptions(), |
|
| 3142 | + true |
|
| 3143 | + ) |
|
| 3144 | + ? $show_datetime_selector |
|
| 3145 | + : EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3146 | + } |
|
| 3147 | + |
|
| 3148 | + |
|
| 3149 | + /** |
|
| 3150 | + * @return int |
|
| 3151 | + */ |
|
| 3152 | + public function getDatetimeSelectorThreshold() |
|
| 3153 | + { |
|
| 3154 | + return $this->datetime_selector_threshold; |
|
| 3155 | + } |
|
| 3156 | + |
|
| 3157 | + |
|
| 3158 | + /** |
|
| 3159 | + * @param int $datetime_selector_threshold |
|
| 3160 | + */ |
|
| 3161 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3162 | + { |
|
| 3163 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3164 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3165 | + } |
|
| 3166 | + |
|
| 3167 | + |
|
| 3168 | + /** |
|
| 3169 | + * @return int |
|
| 3170 | + */ |
|
| 3171 | + public function getDatetimeSelectorMaxChecked() |
|
| 3172 | + { |
|
| 3173 | + return $this->datetime_selector_max_checked; |
|
| 3174 | + } |
|
| 3175 | + |
|
| 3176 | + |
|
| 3177 | + /** |
|
| 3178 | + * @param int $datetime_selector_max_checked |
|
| 3179 | + */ |
|
| 3180 | + public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
| 3181 | + { |
|
| 3182 | + $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
| 3183 | + } |
|
| 3184 | 3184 | } |
| 3185 | 3185 | |
| 3186 | 3186 | /** |
@@ -3192,79 +3192,79 @@ discard block |
||
| 3192 | 3192 | */ |
| 3193 | 3193 | class EE_Environment_Config extends EE_Config_Base |
| 3194 | 3194 | { |
| 3195 | - /** |
|
| 3196 | - * Hold any php environment variables that we want to track. |
|
| 3197 | - * |
|
| 3198 | - * @var stdClass; |
|
| 3199 | - */ |
|
| 3200 | - public $php; |
|
| 3201 | - |
|
| 3202 | - |
|
| 3203 | - /** |
|
| 3204 | - * constructor |
|
| 3205 | - */ |
|
| 3206 | - public function __construct() |
|
| 3207 | - { |
|
| 3208 | - $this->php = new stdClass(); |
|
| 3209 | - $this->_set_php_values(); |
|
| 3210 | - } |
|
| 3211 | - |
|
| 3212 | - |
|
| 3213 | - /** |
|
| 3214 | - * This sets the php environment variables. |
|
| 3215 | - * |
|
| 3216 | - * @since 4.4.0 |
|
| 3217 | - * @return void |
|
| 3218 | - */ |
|
| 3219 | - protected function _set_php_values() |
|
| 3220 | - { |
|
| 3221 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3222 | - $this->php->version = phpversion(); |
|
| 3223 | - } |
|
| 3224 | - |
|
| 3225 | - |
|
| 3226 | - /** |
|
| 3227 | - * helper method for determining whether input_count is |
|
| 3228 | - * reaching the potential maximum the server can handle |
|
| 3229 | - * according to max_input_vars |
|
| 3230 | - * |
|
| 3231 | - * @param int $input_count the count of input vars. |
|
| 3232 | - * @return string error message |
|
| 3233 | - */ |
|
| 3234 | - public function max_input_vars_limit_check($input_count = 0) |
|
| 3235 | - { |
|
| 3236 | - if ( |
|
| 3237 | - ! empty($this->php->max_input_vars) |
|
| 3238 | - && ($input_count >= $this->php->max_input_vars) |
|
| 3239 | - ) { |
|
| 3240 | - // check the server setting because the config value could be stale |
|
| 3241 | - $max_input_vars = ini_get('max_input_vars'); |
|
| 3242 | - if ($input_count >= $max_input_vars) { |
|
| 3243 | - return sprintf( |
|
| 3244 | - esc_html__( |
|
| 3245 | - 'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.', |
|
| 3246 | - 'event_espresso' |
|
| 3247 | - ), |
|
| 3248 | - '<br>', |
|
| 3249 | - $input_count, |
|
| 3250 | - $max_input_vars |
|
| 3251 | - ); |
|
| 3252 | - } |
|
| 3253 | - } |
|
| 3254 | - return ''; |
|
| 3255 | - } |
|
| 3256 | - |
|
| 3257 | - |
|
| 3258 | - /** |
|
| 3259 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3260 | - * |
|
| 3261 | - * @since 4.4.1 |
|
| 3262 | - * @return void |
|
| 3263 | - */ |
|
| 3264 | - public function recheck_values() |
|
| 3265 | - { |
|
| 3266 | - $this->_set_php_values(); |
|
| 3267 | - } |
|
| 3195 | + /** |
|
| 3196 | + * Hold any php environment variables that we want to track. |
|
| 3197 | + * |
|
| 3198 | + * @var stdClass; |
|
| 3199 | + */ |
|
| 3200 | + public $php; |
|
| 3201 | + |
|
| 3202 | + |
|
| 3203 | + /** |
|
| 3204 | + * constructor |
|
| 3205 | + */ |
|
| 3206 | + public function __construct() |
|
| 3207 | + { |
|
| 3208 | + $this->php = new stdClass(); |
|
| 3209 | + $this->_set_php_values(); |
|
| 3210 | + } |
|
| 3211 | + |
|
| 3212 | + |
|
| 3213 | + /** |
|
| 3214 | + * This sets the php environment variables. |
|
| 3215 | + * |
|
| 3216 | + * @since 4.4.0 |
|
| 3217 | + * @return void |
|
| 3218 | + */ |
|
| 3219 | + protected function _set_php_values() |
|
| 3220 | + { |
|
| 3221 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3222 | + $this->php->version = phpversion(); |
|
| 3223 | + } |
|
| 3224 | + |
|
| 3225 | + |
|
| 3226 | + /** |
|
| 3227 | + * helper method for determining whether input_count is |
|
| 3228 | + * reaching the potential maximum the server can handle |
|
| 3229 | + * according to max_input_vars |
|
| 3230 | + * |
|
| 3231 | + * @param int $input_count the count of input vars. |
|
| 3232 | + * @return string error message |
|
| 3233 | + */ |
|
| 3234 | + public function max_input_vars_limit_check($input_count = 0) |
|
| 3235 | + { |
|
| 3236 | + if ( |
|
| 3237 | + ! empty($this->php->max_input_vars) |
|
| 3238 | + && ($input_count >= $this->php->max_input_vars) |
|
| 3239 | + ) { |
|
| 3240 | + // check the server setting because the config value could be stale |
|
| 3241 | + $max_input_vars = ini_get('max_input_vars'); |
|
| 3242 | + if ($input_count >= $max_input_vars) { |
|
| 3243 | + return sprintf( |
|
| 3244 | + esc_html__( |
|
| 3245 | + 'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.', |
|
| 3246 | + 'event_espresso' |
|
| 3247 | + ), |
|
| 3248 | + '<br>', |
|
| 3249 | + $input_count, |
|
| 3250 | + $max_input_vars |
|
| 3251 | + ); |
|
| 3252 | + } |
|
| 3253 | + } |
|
| 3254 | + return ''; |
|
| 3255 | + } |
|
| 3256 | + |
|
| 3257 | + |
|
| 3258 | + /** |
|
| 3259 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3260 | + * |
|
| 3261 | + * @since 4.4.1 |
|
| 3262 | + * @return void |
|
| 3263 | + */ |
|
| 3264 | + public function recheck_values() |
|
| 3265 | + { |
|
| 3266 | + $this->_set_php_values(); |
|
| 3267 | + } |
|
| 3268 | 3268 | } |
| 3269 | 3269 | |
| 3270 | 3270 | /** |
@@ -3276,21 +3276,21 @@ discard block |
||
| 3276 | 3276 | */ |
| 3277 | 3277 | class EE_Tax_Config extends EE_Config_Base |
| 3278 | 3278 | { |
| 3279 | - /* |
|
| 3279 | + /* |
|
| 3280 | 3280 | * flag to indicate whether to display ticket prices with the taxes included |
| 3281 | 3281 | * |
| 3282 | 3282 | * @var boolean $prices_displayed_including_taxes |
| 3283 | 3283 | */ |
| 3284 | - public $prices_displayed_including_taxes; |
|
| 3284 | + public $prices_displayed_including_taxes; |
|
| 3285 | 3285 | |
| 3286 | 3286 | |
| 3287 | - /** |
|
| 3288 | - * class constructor |
|
| 3289 | - */ |
|
| 3290 | - public function __construct() |
|
| 3291 | - { |
|
| 3292 | - $this->prices_displayed_including_taxes = true; |
|
| 3293 | - } |
|
| 3287 | + /** |
|
| 3288 | + * class constructor |
|
| 3289 | + */ |
|
| 3290 | + public function __construct() |
|
| 3291 | + { |
|
| 3292 | + $this->prices_displayed_including_taxes = true; |
|
| 3293 | + } |
|
| 3294 | 3294 | } |
| 3295 | 3295 | |
| 3296 | 3296 | /** |
@@ -3303,19 +3303,19 @@ discard block |
||
| 3303 | 3303 | */ |
| 3304 | 3304 | class EE_Messages_Config extends EE_Config_Base |
| 3305 | 3305 | { |
| 3306 | - /** |
|
| 3307 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3308 | - * A value of 0 represents never deleting. Default is 0. |
|
| 3309 | - * |
|
| 3310 | - * @var integer |
|
| 3311 | - */ |
|
| 3312 | - public $delete_threshold; |
|
| 3313 | - |
|
| 3314 | - |
|
| 3315 | - public function __construct() |
|
| 3316 | - { |
|
| 3317 | - $this->delete_threshold = 0; |
|
| 3318 | - } |
|
| 3306 | + /** |
|
| 3307 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3308 | + * A value of 0 represents never deleting. Default is 0. |
|
| 3309 | + * |
|
| 3310 | + * @var integer |
|
| 3311 | + */ |
|
| 3312 | + public $delete_threshold; |
|
| 3313 | + |
|
| 3314 | + |
|
| 3315 | + public function __construct() |
|
| 3316 | + { |
|
| 3317 | + $this->delete_threshold = 0; |
|
| 3318 | + } |
|
| 3319 | 3319 | } |
| 3320 | 3320 | |
| 3321 | 3321 | /** |
@@ -3325,31 +3325,31 @@ discard block |
||
| 3325 | 3325 | */ |
| 3326 | 3326 | class EE_Gateway_Config extends EE_Config_Base |
| 3327 | 3327 | { |
| 3328 | - /** |
|
| 3329 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3330 | - * with any config info the gateway wants to store |
|
| 3331 | - * |
|
| 3332 | - * @var array |
|
| 3333 | - */ |
|
| 3334 | - public $payment_settings; |
|
| 3335 | - |
|
| 3336 | - /** |
|
| 3337 | - * Where keys are gateway slugs, and values are booleans indicating whether |
|
| 3338 | - * the gateway is stored in the uploads directory |
|
| 3339 | - * |
|
| 3340 | - * @var array |
|
| 3341 | - */ |
|
| 3342 | - public $active_gateways; |
|
| 3343 | - |
|
| 3344 | - |
|
| 3345 | - /** |
|
| 3346 | - * class constructor |
|
| 3347 | - * |
|
| 3348 | - * @deprecated |
|
| 3349 | - */ |
|
| 3350 | - public function __construct() |
|
| 3351 | - { |
|
| 3352 | - $this->payment_settings = array(); |
|
| 3353 | - $this->active_gateways = array('Invoice' => false); |
|
| 3354 | - } |
|
| 3328 | + /** |
|
| 3329 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3330 | + * with any config info the gateway wants to store |
|
| 3331 | + * |
|
| 3332 | + * @var array |
|
| 3333 | + */ |
|
| 3334 | + public $payment_settings; |
|
| 3335 | + |
|
| 3336 | + /** |
|
| 3337 | + * Where keys are gateway slugs, and values are booleans indicating whether |
|
| 3338 | + * the gateway is stored in the uploads directory |
|
| 3339 | + * |
|
| 3340 | + * @var array |
|
| 3341 | + */ |
|
| 3342 | + public $active_gateways; |
|
| 3343 | + |
|
| 3344 | + |
|
| 3345 | + /** |
|
| 3346 | + * class constructor |
|
| 3347 | + * |
|
| 3348 | + * @deprecated |
|
| 3349 | + */ |
|
| 3350 | + public function __construct() |
|
| 3351 | + { |
|
| 3352 | + $this->payment_settings = array(); |
|
| 3353 | + $this->active_gateways = array('Invoice' => false); |
|
| 3354 | + } |
|
| 3355 | 3355 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | public static function instance() |
| 153 | 153 | { |
| 154 | 154 | // check if class object is instantiated, and instantiated properly |
| 155 | - if (! self::$_instance instanceof EE_Config) { |
|
| 155 | + if ( ! self::$_instance instanceof EE_Config) { |
|
| 156 | 156 | self::$_instance = new self(); |
| 157 | 157 | } |
| 158 | 158 | return self::$_instance; |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | $this |
| 295 | 295 | ); |
| 296 | 296 | if (is_object($settings) && property_exists($this, $config)) { |
| 297 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 297 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__'.$config, $settings); |
|
| 298 | 298 | // call configs populate method to ensure any defaults are set for empty values. |
| 299 | 299 | if (method_exists($settings, 'populate')) { |
| 300 | 300 | $this->{$config}->populate(); |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | break; |
| 570 | 570 | // TEST #2 : check that settings section exists |
| 571 | 571 | case 2: |
| 572 | - if (! isset($this->{$section})) { |
|
| 572 | + if ( ! isset($this->{$section})) { |
|
| 573 | 573 | if ($display_errors) { |
| 574 | 574 | throw new EE_Error( |
| 575 | 575 | sprintf( |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | break; |
| 631 | 631 | // TEST #6 : verify config class is accessible |
| 632 | 632 | case 6: |
| 633 | - if (! class_exists($config_class)) { |
|
| 633 | + if ( ! class_exists($config_class)) { |
|
| 634 | 634 | if ($display_errors) { |
| 635 | 635 | throw new EE_Error( |
| 636 | 636 | sprintf( |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | break; |
| 648 | 648 | // TEST #7 : check that config has even been set |
| 649 | 649 | case 7: |
| 650 | - if (! isset($this->{$section}->{$name})) { |
|
| 650 | + if ( ! isset($this->{$section}->{$name})) { |
|
| 651 | 651 | if ($display_errors) { |
| 652 | 652 | throw new EE_Error( |
| 653 | 653 | sprintf( |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | break; |
| 666 | 666 | // TEST #8 : check that config is the requested type |
| 667 | 667 | case 8: |
| 668 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 668 | + if ( ! $this->{$section}->{$name} instanceof $config_class) { |
|
| 669 | 669 | if ($display_errors) { |
| 670 | 670 | throw new EE_Error( |
| 671 | 671 | sprintf( |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | break; |
| 685 | 685 | // TEST #9 : verify config object |
| 686 | 686 | case 9: |
| 687 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 687 | + if ( ! $config_obj instanceof EE_Config_Base) { |
|
| 688 | 688 | if ($display_errors) { |
| 689 | 689 | throw new EE_Error( |
| 690 | 690 | sprintf( |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | */ |
| 717 | 717 | private function _generate_config_option_name($section = '', $name = '') |
| 718 | 718 | { |
| 719 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 719 | + return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
@@ -733,7 +733,7 @@ discard block |
||
| 733 | 733 | { |
| 734 | 734 | return ! empty($config_class) |
| 735 | 735 | ? $config_class |
| 736 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 736 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config'; |
|
| 737 | 737 | } |
| 738 | 738 | |
| 739 | 739 | |
@@ -753,17 +753,17 @@ discard block |
||
| 753 | 753 | // ensure config class is set to something |
| 754 | 754 | $config_class = $this->_set_config_class($config_class, $name); |
| 755 | 755 | // run tests 1-4, 6, and 7 to verify all config params are set and valid |
| 756 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 756 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 757 | 757 | return null; |
| 758 | 758 | } |
| 759 | 759 | $config_option_name = $this->_generate_config_option_name($section, $name); |
| 760 | 760 | // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
| 761 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 762 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 761 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 762 | + $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 763 | 763 | $this->update_addon_option_names(); |
| 764 | 764 | } |
| 765 | 765 | // verify the incoming config object but suppress errors |
| 766 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 766 | + if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 767 | 767 | $config_obj = new $config_class(); |
| 768 | 768 | } |
| 769 | 769 | if (get_option($config_option_name)) { |
@@ -840,7 +840,7 @@ discard block |
||
| 840 | 840 | } |
| 841 | 841 | $config_option_name = $this->_generate_config_option_name($section, $name); |
| 842 | 842 | // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
| 843 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 843 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 844 | 844 | // save new config to db |
| 845 | 845 | if ($this->set_config($section, $name, $config_class, $config_obj)) { |
| 846 | 846 | return true; |
@@ -866,7 +866,7 @@ discard block |
||
| 866 | 866 | 'event_espresso' |
| 867 | 867 | ), |
| 868 | 868 | $config_class, |
| 869 | - 'EE_Config->' . $section . '->' . $name |
|
| 869 | + 'EE_Config->'.$section.'->'.$name |
|
| 870 | 870 | ), |
| 871 | 871 | __FILE__, |
| 872 | 872 | __FUNCTION__, |
@@ -892,7 +892,7 @@ discard block |
||
| 892 | 892 | // ensure config class is set to something |
| 893 | 893 | $config_class = $this->_set_config_class($config_class, $name); |
| 894 | 894 | // run tests 1-4, 6 and 7 to verify that all params have been set |
| 895 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 895 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 896 | 896 | return null; |
| 897 | 897 | } |
| 898 | 898 | // now test if the requested config object exists, but suppress errors |
@@ -937,7 +937,7 @@ discard block |
||
| 937 | 937 | // retrieve the wp-option for this config class. |
| 938 | 938 | $config_option = maybe_unserialize(get_option($config_option_name, array())); |
| 939 | 939 | if (empty($config_option)) { |
| 940 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 940 | + EE_Config::log($config_option_name.'-NOT-FOUND'); |
|
| 941 | 941 | } |
| 942 | 942 | return $config_option; |
| 943 | 943 | } |
@@ -954,7 +954,7 @@ discard block |
||
| 954 | 954 | $config_log = get_option(EE_Config::LOG_NAME, array()); |
| 955 | 955 | /** @var RequestParams $request */ |
| 956 | 956 | $request = LoaderFactory::getLoader()->getShared(RequestParams::class); |
| 957 | - $config_log[ (string) microtime(true) ] = array( |
|
| 957 | + $config_log[(string) microtime(true)] = array( |
|
| 958 | 958 | 'config_name' => $config_option_name, |
| 959 | 959 | 'request' => $request->requestParams(), |
| 960 | 960 | ); |
@@ -969,7 +969,7 @@ discard block |
||
| 969 | 969 | */ |
| 970 | 970 | public static function trim_log() |
| 971 | 971 | { |
| 972 | - if (! EE_Config::logging_enabled()) { |
|
| 972 | + if ( ! EE_Config::logging_enabled()) { |
|
| 973 | 973 | return; |
| 974 | 974 | } |
| 975 | 975 | $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
@@ -993,7 +993,7 @@ discard block |
||
| 993 | 993 | public static function get_page_for_posts() |
| 994 | 994 | { |
| 995 | 995 | $page_for_posts = get_option('page_for_posts'); |
| 996 | - if (! $page_for_posts) { |
|
| 996 | + if ( ! $page_for_posts) { |
|
| 997 | 997 | return 'posts'; |
| 998 | 998 | } |
| 999 | 999 | global $wpdb; |
@@ -1047,13 +1047,13 @@ discard block |
||
| 1047 | 1047 | || (is_admin() && MaintenanceStatus::isNotFullSite()) |
| 1048 | 1048 | ) { |
| 1049 | 1049 | // grab list of installed widgets |
| 1050 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1050 | + $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR); |
|
| 1051 | 1051 | // filter list of modules to register |
| 1052 | 1052 | $widgets_to_register = apply_filters( |
| 1053 | 1053 | 'FHEE__EE_Config__register_widgets__widgets_to_register', |
| 1054 | 1054 | $widgets_to_register |
| 1055 | 1055 | ); |
| 1056 | - if (! empty($widgets_to_register)) { |
|
| 1056 | + if ( ! empty($widgets_to_register)) { |
|
| 1057 | 1057 | // cycle thru widget folders |
| 1058 | 1058 | foreach ($widgets_to_register as $widget_path) { |
| 1059 | 1059 | // add to list of installed widget modules |
@@ -1103,31 +1103,31 @@ discard block |
||
| 1103 | 1103 | // create classname from widget directory name |
| 1104 | 1104 | $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
| 1105 | 1105 | // add class prefix |
| 1106 | - $widget_class = 'EEW_' . $widget; |
|
| 1106 | + $widget_class = 'EEW_'.$widget; |
|
| 1107 | 1107 | // does the widget exist ? |
| 1108 | - if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1108 | + if ( ! is_readable($widget_path.'/'.$widget_class.$widget_ext)) { |
|
| 1109 | 1109 | $msg = sprintf( |
| 1110 | 1110 | esc_html__( |
| 1111 | 1111 | 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
| 1112 | 1112 | 'event_espresso' |
| 1113 | 1113 | ), |
| 1114 | 1114 | $widget_class, |
| 1115 | - $widget_path . '/' . $widget_class . $widget_ext |
|
| 1115 | + $widget_path.'/'.$widget_class.$widget_ext |
|
| 1116 | 1116 | ); |
| 1117 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1117 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1118 | 1118 | return; |
| 1119 | 1119 | } |
| 1120 | 1120 | // load the widget class file |
| 1121 | - require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1121 | + require_once($widget_path.'/'.$widget_class.$widget_ext); |
|
| 1122 | 1122 | // verify that class exists |
| 1123 | - if (! class_exists($widget_class)) { |
|
| 1123 | + if ( ! class_exists($widget_class)) { |
|
| 1124 | 1124 | $msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
| 1125 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1125 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1126 | 1126 | return; |
| 1127 | 1127 | } |
| 1128 | 1128 | register_widget($widget_class); |
| 1129 | 1129 | // add to array of registered widgets |
| 1130 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1130 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path.'/'.$widget_class.$widget_ext; |
|
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | 1133 | |
@@ -1140,19 +1140,19 @@ discard block |
||
| 1140 | 1140 | private function _register_modules() |
| 1141 | 1141 | { |
| 1142 | 1142 | // grab list of installed modules |
| 1143 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1143 | + $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR); |
|
| 1144 | 1144 | // filter list of modules to register |
| 1145 | 1145 | $modules_to_register = apply_filters( |
| 1146 | 1146 | 'FHEE__EE_Config__register_modules__modules_to_register', |
| 1147 | 1147 | $modules_to_register |
| 1148 | 1148 | ); |
| 1149 | - if (! empty($modules_to_register)) { |
|
| 1149 | + if ( ! empty($modules_to_register)) { |
|
| 1150 | 1150 | // loop through folders |
| 1151 | 1151 | foreach ($modules_to_register as $module_path) { |
| 1152 | 1152 | /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
| 1153 | 1153 | if ( |
| 1154 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1155 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1154 | + $module_path !== EE_MODULES.'zzz-copy-this-module-template' |
|
| 1155 | + && $module_path !== EE_MODULES.'gateways' |
|
| 1156 | 1156 | ) { |
| 1157 | 1157 | // add to list of installed modules |
| 1158 | 1158 | EE_Config::register_module($module_path); |
@@ -1189,25 +1189,25 @@ discard block |
||
| 1189 | 1189 | // remove last segment |
| 1190 | 1190 | array_pop($module_path); |
| 1191 | 1191 | // glue it back together |
| 1192 | - $module_path = implode('/', $module_path) . '/'; |
|
| 1192 | + $module_path = implode('/', $module_path).'/'; |
|
| 1193 | 1193 | // take first segment from file name pieces and sanitize it |
| 1194 | 1194 | $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
| 1195 | 1195 | // ensure class prefix is added |
| 1196 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1196 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module; |
|
| 1197 | 1197 | } else { |
| 1198 | 1198 | // we need to generate the filename based off of the folder name |
| 1199 | 1199 | // grab and sanitize module name |
| 1200 | 1200 | $module = strtolower(basename($module_path)); |
| 1201 | 1201 | $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
| 1202 | 1202 | // like trailingslashit() |
| 1203 | - $module_path = rtrim($module_path, '/') . '/'; |
|
| 1203 | + $module_path = rtrim($module_path, '/').'/'; |
|
| 1204 | 1204 | // create classname from module directory name |
| 1205 | 1205 | $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
| 1206 | 1206 | // add class prefix |
| 1207 | - $module_class = 'EED_' . $module; |
|
| 1207 | + $module_class = 'EED_'.$module; |
|
| 1208 | 1208 | } |
| 1209 | 1209 | // does the module exist ? |
| 1210 | - if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1210 | + if ( ! is_readable($module_path.'/'.$module_class.$module_ext)) { |
|
| 1211 | 1211 | $msg = sprintf( |
| 1212 | 1212 | esc_html__( |
| 1213 | 1213 | 'The requested %s module file could not be found or is not readable due to file permissions.', |
@@ -1215,19 +1215,19 @@ discard block |
||
| 1215 | 1215 | ), |
| 1216 | 1216 | $module |
| 1217 | 1217 | ); |
| 1218 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1218 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1219 | 1219 | return false; |
| 1220 | 1220 | } |
| 1221 | 1221 | // load the module class file |
| 1222 | - require_once($module_path . $module_class . $module_ext); |
|
| 1222 | + require_once($module_path.$module_class.$module_ext); |
|
| 1223 | 1223 | // verify that class exists |
| 1224 | - if (! class_exists($module_class)) { |
|
| 1224 | + if ( ! class_exists($module_class)) { |
|
| 1225 | 1225 | $msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
| 1226 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1226 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1227 | 1227 | return false; |
| 1228 | 1228 | } |
| 1229 | 1229 | // add to array of registered modules |
| 1230 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1230 | + EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext; |
|
| 1231 | 1231 | do_action( |
| 1232 | 1232 | 'AHEE__EE_Config__register_module__complete', |
| 1233 | 1233 | $module_class, |
@@ -1278,26 +1278,26 @@ discard block |
||
| 1278 | 1278 | { |
| 1279 | 1279 | do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
| 1280 | 1280 | $module = str_replace('EED_', '', $module); |
| 1281 | - $module_class = 'EED_' . $module; |
|
| 1282 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1281 | + $module_class = 'EED_'.$module; |
|
| 1282 | + if ( ! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1283 | 1283 | $msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module); |
| 1284 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1284 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1285 | 1285 | return false; |
| 1286 | 1286 | } |
| 1287 | 1287 | if (empty($route)) { |
| 1288 | 1288 | $msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route); |
| 1289 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1289 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1290 | 1290 | return false; |
| 1291 | 1291 | } |
| 1292 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1292 | + if ( ! method_exists('EED_'.$module, $method_name)) { |
|
| 1293 | 1293 | $msg = sprintf( |
| 1294 | 1294 | esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
| 1295 | 1295 | $route |
| 1296 | 1296 | ); |
| 1297 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1297 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1298 | 1298 | return false; |
| 1299 | 1299 | } |
| 1300 | - EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1300 | + EE_Config::$_module_route_map[(string) $key][(string) $route] = array('EED_'.$module, $method_name); |
|
| 1301 | 1301 | return true; |
| 1302 | 1302 | } |
| 1303 | 1303 | |
@@ -1314,8 +1314,8 @@ discard block |
||
| 1314 | 1314 | { |
| 1315 | 1315 | do_action('AHEE__EE_Config__get_route__begin', $route); |
| 1316 | 1316 | $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
| 1317 | - if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1318 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1317 | + if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1318 | + return EE_Config::$_module_route_map[$key][$route]; |
|
| 1319 | 1319 | } |
| 1320 | 1320 | return null; |
| 1321 | 1321 | } |
@@ -1347,47 +1347,47 @@ discard block |
||
| 1347 | 1347 | public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
| 1348 | 1348 | { |
| 1349 | 1349 | do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
| 1350 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1350 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1351 | 1351 | $msg = sprintf( |
| 1352 | 1352 | esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'), |
| 1353 | 1353 | $route |
| 1354 | 1354 | ); |
| 1355 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1355 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1356 | 1356 | return false; |
| 1357 | 1357 | } |
| 1358 | 1358 | if (empty($forward)) { |
| 1359 | 1359 | $msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route); |
| 1360 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1360 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1361 | 1361 | return false; |
| 1362 | 1362 | } |
| 1363 | 1363 | if (is_array($forward)) { |
| 1364 | - if (! isset($forward[1])) { |
|
| 1364 | + if ( ! isset($forward[1])) { |
|
| 1365 | 1365 | $msg = sprintf( |
| 1366 | 1366 | esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
| 1367 | 1367 | $route |
| 1368 | 1368 | ); |
| 1369 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1369 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1370 | 1370 | return false; |
| 1371 | 1371 | } |
| 1372 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1372 | + if ( ! method_exists($forward[0], $forward[1])) { |
|
| 1373 | 1373 | $msg = sprintf( |
| 1374 | 1374 | esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
| 1375 | 1375 | $forward[1], |
| 1376 | 1376 | $route |
| 1377 | 1377 | ); |
| 1378 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1378 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1379 | 1379 | return false; |
| 1380 | 1380 | } |
| 1381 | - } elseif (! function_exists($forward)) { |
|
| 1381 | + } elseif ( ! function_exists($forward)) { |
|
| 1382 | 1382 | $msg = sprintf( |
| 1383 | 1383 | esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
| 1384 | 1384 | $forward, |
| 1385 | 1385 | $route |
| 1386 | 1386 | ); |
| 1387 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1387 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1388 | 1388 | return false; |
| 1389 | 1389 | } |
| 1390 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1390 | + EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1391 | 1391 | return true; |
| 1392 | 1392 | } |
| 1393 | 1393 | |
@@ -1405,10 +1405,10 @@ discard block |
||
| 1405 | 1405 | public static function get_forward($route = null, $status = 0, $key = 'ee') |
| 1406 | 1406 | { |
| 1407 | 1407 | do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
| 1408 | - if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1408 | + if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1409 | 1409 | return apply_filters( |
| 1410 | 1410 | 'FHEE__EE_Config__get_forward', |
| 1411 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1411 | + EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1412 | 1412 | $route, |
| 1413 | 1413 | $status |
| 1414 | 1414 | ); |
@@ -1432,15 +1432,15 @@ discard block |
||
| 1432 | 1432 | public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
| 1433 | 1433 | { |
| 1434 | 1434 | do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
| 1435 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1435 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1436 | 1436 | $msg = sprintf( |
| 1437 | 1437 | esc_html__('The module route %s for this view has not been registered.', 'event_espresso'), |
| 1438 | 1438 | $route |
| 1439 | 1439 | ); |
| 1440 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1440 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1441 | 1441 | return false; |
| 1442 | 1442 | } |
| 1443 | - if (! is_readable($view)) { |
|
| 1443 | + if ( ! is_readable($view)) { |
|
| 1444 | 1444 | $msg = sprintf( |
| 1445 | 1445 | esc_html__( |
| 1446 | 1446 | 'The %s view file could not be found or is not readable due to file permissions.', |
@@ -1448,10 +1448,10 @@ discard block |
||
| 1448 | 1448 | ), |
| 1449 | 1449 | $view |
| 1450 | 1450 | ); |
| 1451 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1451 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1452 | 1452 | return false; |
| 1453 | 1453 | } |
| 1454 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1454 | + EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1455 | 1455 | return true; |
| 1456 | 1456 | } |
| 1457 | 1457 | |
@@ -1469,10 +1469,10 @@ discard block |
||
| 1469 | 1469 | public static function get_view($route = null, $status = 0, $key = 'ee') |
| 1470 | 1470 | { |
| 1471 | 1471 | do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
| 1472 | - if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1472 | + if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1473 | 1473 | return apply_filters( |
| 1474 | 1474 | 'FHEE__EE_Config__get_view', |
| 1475 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1475 | + EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1476 | 1476 | $route, |
| 1477 | 1477 | $status |
| 1478 | 1478 | ); |
@@ -1498,7 +1498,7 @@ discard block |
||
| 1498 | 1498 | */ |
| 1499 | 1499 | public static function getLegacyShortcodesManager() |
| 1500 | 1500 | { |
| 1501 | - if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1501 | + if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1502 | 1502 | EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared( |
| 1503 | 1503 | LegacyShortcodesManager::class |
| 1504 | 1504 | ); |
@@ -1544,7 +1544,7 @@ discard block |
||
| 1544 | 1544 | */ |
| 1545 | 1545 | public function get_pretty($property) |
| 1546 | 1546 | { |
| 1547 | - if (! property_exists($this, $property)) { |
|
| 1547 | + if ( ! property_exists($this, $property)) { |
|
| 1548 | 1548 | throw new EE_Error( |
| 1549 | 1549 | sprintf( |
| 1550 | 1550 | esc_html__( |
@@ -1772,11 +1772,11 @@ discard block |
||
| 1772 | 1772 | */ |
| 1773 | 1773 | public function reg_page_url() |
| 1774 | 1774 | { |
| 1775 | - if (! $this->reg_page_url) { |
|
| 1775 | + if ( ! $this->reg_page_url) { |
|
| 1776 | 1776 | $this->reg_page_url = add_query_arg( |
| 1777 | 1777 | array('uts' => time()), |
| 1778 | 1778 | get_permalink($this->reg_page_id) |
| 1779 | - ) . '#checkout'; |
|
| 1779 | + ).'#checkout'; |
|
| 1780 | 1780 | } |
| 1781 | 1781 | return $this->reg_page_url; |
| 1782 | 1782 | } |
@@ -1792,7 +1792,7 @@ discard block |
||
| 1792 | 1792 | */ |
| 1793 | 1793 | public function txn_page_url($query_args = array()) |
| 1794 | 1794 | { |
| 1795 | - if (! $this->txn_page_url) { |
|
| 1795 | + if ( ! $this->txn_page_url) { |
|
| 1796 | 1796 | $this->txn_page_url = get_permalink($this->txn_page_id); |
| 1797 | 1797 | } |
| 1798 | 1798 | if ($query_args) { |
@@ -1813,7 +1813,7 @@ discard block |
||
| 1813 | 1813 | */ |
| 1814 | 1814 | public function thank_you_page_url($query_args = array()) |
| 1815 | 1815 | { |
| 1816 | - if (! $this->thank_you_page_url) { |
|
| 1816 | + if ( ! $this->thank_you_page_url) { |
|
| 1817 | 1817 | $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
| 1818 | 1818 | } |
| 1819 | 1819 | if ($query_args) { |
@@ -1832,7 +1832,7 @@ discard block |
||
| 1832 | 1832 | */ |
| 1833 | 1833 | public function cancel_page_url() |
| 1834 | 1834 | { |
| 1835 | - if (! $this->cancel_page_url) { |
|
| 1835 | + if ( ! $this->cancel_page_url) { |
|
| 1836 | 1836 | $this->cancel_page_url = get_permalink($this->cancel_page_id); |
| 1837 | 1837 | } |
| 1838 | 1838 | return $this->cancel_page_url; |
@@ -1875,13 +1875,13 @@ discard block |
||
| 1875 | 1875 | $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
| 1876 | 1876 | $option = self::OPTION_NAME_UXIP; |
| 1877 | 1877 | // set correct table for query |
| 1878 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1878 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options'; |
|
| 1879 | 1879 | // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
| 1880 | 1880 | // get_blog_option() does a switch_to_blog and that could cause infinite recursion because EE_Core_Config might be |
| 1881 | 1881 | // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
| 1882 | 1882 | // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
| 1883 | 1883 | // for the purpose of caching. |
| 1884 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1884 | + $pre = apply_filters('pre_option_'.$option, false, $option); |
|
| 1885 | 1885 | if (false !== $pre) { |
| 1886 | 1886 | EE_Core_Config::$ee_ueip_option = $pre; |
| 1887 | 1887 | return EE_Core_Config::$ee_ueip_option; |
@@ -1895,10 +1895,10 @@ discard block |
||
| 1895 | 1895 | if (is_object($row)) { |
| 1896 | 1896 | $value = $row->option_value; |
| 1897 | 1897 | } else { // option does not exist so use default. |
| 1898 | - EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1898 | + EE_Core_Config::$ee_ueip_option = apply_filters('default_option_'.$option, false, $option); |
|
| 1899 | 1899 | return EE_Core_Config::$ee_ueip_option; |
| 1900 | 1900 | } |
| 1901 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1901 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option); |
|
| 1902 | 1902 | return EE_Core_Config::$ee_ueip_option; |
| 1903 | 1903 | } |
| 1904 | 1904 | |
@@ -2168,12 +2168,12 @@ discard block |
||
| 2168 | 2168 | |
| 2169 | 2169 | /** @var TableAnalysis $table_analysis */ |
| 2170 | 2170 | $table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true); |
| 2171 | - if (! $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())) { |
|
| 2171 | + if ( ! $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())) { |
|
| 2172 | 2172 | return; |
| 2173 | 2173 | } |
| 2174 | 2174 | // retrieve the country settings from the db, just in case they have been customized |
| 2175 | 2175 | $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
| 2176 | - if (! $country instanceof EE_Country) { |
|
| 2176 | + if ( ! $country instanceof EE_Country) { |
|
| 2177 | 2177 | throw new DomainException( |
| 2178 | 2178 | sprintf( |
| 2179 | 2179 | esc_html__('Invalid Country ISO Code: %1$s', 'event_espresso'), |
@@ -2181,14 +2181,14 @@ discard block |
||
| 2181 | 2181 | ) |
| 2182 | 2182 | ); |
| 2183 | 2183 | } |
| 2184 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2185 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2186 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2187 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2188 | - $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after |
|
| 2189 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2190 | - $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: ',' = 0,01 or '.' = 0.01 |
|
| 2191 | - $this->thsnds = $country->currency_thousands_separator(); // thousands sep: ',' = 1,000 or '.' = 1.000 |
|
| 2184 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2185 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2186 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2187 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2188 | + $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after |
|
| 2189 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2190 | + $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: ',' = 0,01 or '.' = 0.01 |
|
| 2191 | + $this->thsnds = $country->currency_thousands_separator(); // thousands sep: ',' = 1,000 or '.' = 1.000 |
|
| 2192 | 2192 | } |
| 2193 | 2193 | |
| 2194 | 2194 | |
@@ -2492,8 +2492,8 @@ discard block |
||
| 2492 | 2492 | $closing_a_tag = ''; |
| 2493 | 2493 | if (function_exists('get_privacy_policy_url')) { |
| 2494 | 2494 | $privacy_page_url = get_privacy_policy_url(); |
| 2495 | - if (! empty($privacy_page_url)) { |
|
| 2496 | - $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2495 | + if ( ! empty($privacy_page_url)) { |
|
| 2496 | + $opening_a_tag = '<a href="'.$privacy_page_url.'" target="_blank">'; |
|
| 2497 | 2497 | $closing_a_tag = '</a>'; |
| 2498 | 2498 | } |
| 2499 | 2499 | } |
@@ -2682,7 +2682,7 @@ discard block |
||
| 2682 | 2682 | public function log_file_name(bool $reset = false): ?string |
| 2683 | 2683 | { |
| 2684 | 2684 | if (empty($this->log_file_name) || $reset) { |
| 2685 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2685 | + $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt'; |
|
| 2686 | 2686 | EE_Config::instance()->update_espresso_config(false, false); |
| 2687 | 2687 | } |
| 2688 | 2688 | return $this->log_file_name; |
@@ -2696,7 +2696,7 @@ discard block |
||
| 2696 | 2696 | public function debug_file_name(bool $reset = false): ?string |
| 2697 | 2697 | { |
| 2698 | 2698 | if (empty($this->debug_file_name) || $reset) { |
| 2699 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2699 | + $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt'; |
|
| 2700 | 2700 | EE_Config::instance()->update_espresso_config(false, false); |
| 2701 | 2701 | } |
| 2702 | 2702 | return $this->debug_file_name; |
@@ -2910,21 +2910,21 @@ discard block |
||
| 2910 | 2910 | $this->use_google_maps = true; |
| 2911 | 2911 | $this->google_map_api_key = ''; |
| 2912 | 2912 | // for event details pages (reg page) |
| 2913 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2914 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2915 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2916 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2917 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2918 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2919 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2913 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2914 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2915 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2916 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2917 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2918 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2919 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2920 | 2920 | // for event list pages |
| 2921 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2922 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2923 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2924 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2925 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2926 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2927 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2921 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2922 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2923 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2924 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2925 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2926 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2927 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2928 | 2928 | } |
| 2929 | 2929 | } |
| 2930 | 2930 | |