upgrade.php
97 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Admin Database Upgrade |
| 4 | * |
| 5 | * Shows the database upgrade process. |
| 6 | * |
| 7 | * @package wordpress/secure-custom-fields |
| 8 | */ |
| 9 | |
| 10 | ?> |
| 11 | <style type="text/css"> |
| 12 | |
| 13 | /* hide steps */ |
| 14 | .step-1, |
| 15 | .step-2, |
| 16 | .step-3 { |
| 17 | display: none; |
| 18 | } |
| 19 | |
| 20 | </style> |
| 21 | <div id="acf-upgrade-wrap" class="wrap"> |
| 22 | |
| 23 | <h1><?php esc_html_e( 'Upgrade Database', 'secure-custom-fields' ); ?></h1> |
| 24 | |
| 25 | <?php if ( acf_has_upgrade() ) : ?> |
| 26 | |
| 27 | <p><?php esc_html_e( 'Reading upgrade tasks...', 'secure-custom-fields' ); ?></p> |
| 28 | <?php /* translators: %s the new ACF version */ ?> |
| 29 | <p class="step-1"><i class="acf-loading"></i> <?php echo esc_html( sprintf( __( 'Upgrading data to version %s', 'secure-custom-fields' ), ACF_VERSION ) ); ?></p> |
| 30 | <p class="step-2"></p> |
| 31 | <?php /* translators: %s the url to the field group page. */ ?> |
| 32 | <p class="step-3"><?php echo acf_esc_html( sprintf( __( 'Database upgrade complete. <a href="%s">See what\'s new</a>', 'secure-custom-fields' ), esc_url( admin_url( 'edit.php?post_type=acf-field-group' ) ) ) ); ?></p> |
| 33 | |
| 34 | <script type="text/javascript"> |
| 35 | (function($) { |
| 36 | |
| 37 | var upgrader = new acf.Model({ |
| 38 | initialize: function(){ |
| 39 | |
| 40 | // allow user to read message for 1 second |
| 41 | this.setTimeout( this.upgrade, 1000 ); |
| 42 | }, |
| 43 | upgrade: function(){ |
| 44 | |
| 45 | // show step 1 |
| 46 | $('.step-1').show(); |
| 47 | |
| 48 | // vars |
| 49 | var response = ''; |
| 50 | var success = false; |
| 51 | |
| 52 | // send ajax request to upgrade DB |
| 53 | $.ajax({ |
| 54 | url: acf.get('ajaxurl'), |
| 55 | dataType: 'json', |
| 56 | type: 'post', |
| 57 | data: acf.prepareForAjax({ |
| 58 | action: 'acf/ajax/upgrade' |
| 59 | }), |
| 60 | success: function( json ){ |
| 61 | success = true; |
| 62 | }, |
| 63 | error: function( jqXHR, textStatus, errorThrown ){ |
| 64 | response = '<?php esc_attr_e( 'Upgrade failed.', 'secure-custom-fields' ); ?>'; |
| 65 | if( error = acf.getXhrError(jqXHR) ) { |
| 66 | response += ' <code>' + error + '</code>'; |
| 67 | } |
| 68 | }, |
| 69 | complete: this.proxy(function(){ |
| 70 | |
| 71 | // remove spinner |
| 72 | $('.acf-loading').hide(); |
| 73 | |
| 74 | // display response |
| 75 | if( response ) { |
| 76 | $('.step-2').show().html( response ); |
| 77 | } |
| 78 | |
| 79 | // display success |
| 80 | if( success ) { |
| 81 | $('.step-3').show(); |
| 82 | } |
| 83 | }) |
| 84 | }); |
| 85 | } |
| 86 | }); |
| 87 | |
| 88 | })(jQuery); |
| 89 | </script> |
| 90 | |
| 91 | <?php else : ?> |
| 92 | |
| 93 | <p><?php esc_html_e( 'No updates available.', 'secure-custom-fields' ); ?></p> |
| 94 | |
| 95 | <?php endif; ?> |
| 96 | </div> |
| 97 |