upgrade.php
| 1 | <?php |
| 2 | |
| 3 | /*-------------------------------------------------------------------------------------- |
| 4 | * |
| 5 | * Update - Ajax Functions |
| 6 | * |
| 7 | * @author Elliot Condon |
| 8 | * @since 3.0.0 |
| 9 | * |
| 10 | *-------------------------------------------------------------------------------------*/ |
| 11 | |
| 12 | $version = get_option('acf_version','1.0.5'); |
| 13 | $next = false; |
| 14 | |
| 15 | // list of starting points |
| 16 | if(version_compare($version,'3.0.0') < 0) |
| 17 | { |
| 18 | $next = '3.0.0'; |
| 19 | } |
| 20 | ?> |
| 21 | |
| 22 | <script type="text/javascript"> |
| 23 | (function($){ |
| 24 | |
| 25 | function add_message(messaage) |
| 26 | { |
| 27 | $('#wpbody-content').append('<p>' + messaage + '</p>'); |
| 28 | } |
| 29 | |
| 30 | function run_upgrade(version) |
| 31 | { |
| 32 | $.ajax({ |
| 33 | url: ajaxurl, |
| 34 | data: { action : 'acf_upgrade', version : version }, |
| 35 | type: 'post', |
| 36 | dataType: 'json', |
| 37 | success: function(json){ |
| 38 | |
| 39 | if(json) |
| 40 | { |
| 41 | if(json.status) |
| 42 | { |
| 43 | add_message(json.message); |
| 44 | |
| 45 | // next update? |
| 46 | if(json.next) |
| 47 | { |
| 48 | run_upgrade(json.next); |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | // all done |
| 53 | add_message('Upgrade Complete! <a href="<?php echo admin_url(); ?>edit.php?post_type=acf">Continue to ACF »</a>'); |
| 54 | } |
| 55 | } |
| 56 | else |
| 57 | { |
| 58 | // error! |
| 59 | add_message('Error: ' + json.message); |
| 60 | } |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | // major error! |
| 65 | add_message('Sorry. Something went wrong during the upgrade process. Please report this on the support forum'); |
| 66 | } |
| 67 | } |
| 68 | }); |
| 69 | } |
| 70 | |
| 71 | <?php if($next){ echo 'run_upgrade("' . $next . '");'; } ?> |
| 72 | |
| 73 | })(jQuery); |
| 74 | </script> |
| 75 | <style type="text/css"> |
| 76 | #message { |
| 77 | display: none; |
| 78 | } |
| 79 | </style> |
| 80 | <?php |
| 81 | |
| 82 | if(!$next) |
| 83 | { |
| 84 | echo '<p>No Upgrade Required</p>'; |
| 85 | } |
| 86 | |
| 87 | ?> |