network.php
206 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package ACF |
| 4 | * @author WP Engine |
| 5 | * |
| 6 | * © 2026 Advanced Custom Fields (ACF®). All rights reserved. |
| 7 | * "ACF" is a trademark of WP Engine. |
| 8 | * Licensed under the GNU General Public License v2 or later. |
| 9 | * https://www.gnu.org/licenses/gpl-2.0.html |
| 10 | */ |
| 11 | ?> |
| 12 | <style type="text/css"> |
| 13 | |
| 14 | /* hide steps */ |
| 15 | .show-on-complete { |
| 16 | display: none; |
| 17 | } |
| 18 | |
| 19 | </style> |
| 20 | <div id="acf-upgrade-wrap" class="wrap"> |
| 21 | |
| 22 | <h1><?php esc_html_e( 'Upgrade Database', 'acf' ); ?></h1> |
| 23 | |
| 24 | <?php // translators: %s The button label name, translated seperately ?> |
| 25 | <p><?php printf( esc_html__( 'The following sites require a DB upgrade. Check the ones you want to update and then click %s.', 'acf' ), '"' . esc_html__( 'Upgrade Sites', 'acf' ) . '"' ); ?></p> |
| 26 | <p><input type="submit" name="upgrade" value="<?php esc_attr_e( 'Upgrade Sites', 'acf' ); ?>" class="button" id="upgrade-sites"></p> |
| 27 | |
| 28 | <table class="wp-list-table widefat"> |
| 29 | <thead> |
| 30 | <tr> |
| 31 | <td class="manage-column check-column" scope="col"> |
| 32 | <input type="checkbox" id="sites-select-all"> |
| 33 | </td> |
| 34 | <th class="manage-column" scope="col" style="width:33%;"> |
| 35 | <label for="sites-select-all"><?php esc_html_e( 'Site', 'acf' ); ?></label> |
| 36 | </th> |
| 37 | <th><?php esc_html_e( 'Description', 'acf' ); ?></th> |
| 38 | </tr> |
| 39 | </thead> |
| 40 | <tfoot> |
| 41 | <tr> |
| 42 | <td class="manage-column check-column" scope="col"> |
| 43 | <input type="checkbox" id="sites-select-all-2"> |
| 44 | </td> |
| 45 | <th class="manage-column" scope="col"> |
| 46 | <label for="sites-select-all-2"><?php esc_html_e( 'Site', 'acf' ); ?></label> |
| 47 | </th> |
| 48 | <th><?php esc_html_e( 'Description', 'acf' ); ?></th> |
| 49 | </tr> |
| 50 | </tfoot> |
| 51 | <tbody id="the-list"> |
| 52 | <?php |
| 53 | |
| 54 | $sites = acf_get_sites(); |
| 55 | if ( $sites ) : |
| 56 | foreach ( $sites as $i => $site ) : |
| 57 | |
| 58 | // switch blog |
| 59 | switch_to_blog( $site['blog_id'] ); |
| 60 | |
| 61 | ?> |
| 62 | <tr |
| 63 | <?php |
| 64 | if ( $i % 2 == 0 ) : |
| 65 | ?> |
| 66 | class="alternate"<?php endif; ?>> |
| 67 | <th class="check-column" scope="row"> |
| 68 | <?php if ( acf_has_upgrade() ) : ?> |
| 69 | <input type="checkbox" value="<?php echo esc_attr( $site['blog_id'] ); ?>" name="checked[]"> |
| 70 | <?php endif; ?> |
| 71 | </th> |
| 72 | <td> |
| 73 | <strong><?php echo esc_html( get_bloginfo( 'name' ) ); ?></strong><br /><?php echo esc_url( home_url() ); ?> |
| 74 | </td> |
| 75 | <td> |
| 76 | <?php if ( acf_has_upgrade() ) : ?> |
| 77 | <span class="response"> |
| 78 | <?php |
| 79 | printf( |
| 80 | /* translators: %1$s current db version, %2$s available db version */ |
| 81 | esc_html__( 'Site requires database upgrade from %1$s to %2$s', 'acf' ), |
| 82 | esc_html( acf_get_db_version() ), |
| 83 | esc_html( ACF_VERSION ) |
| 84 | ); |
| 85 | ?> |
| 86 | </span> |
| 87 | <?php else : ?> |
| 88 | <?php esc_html_e( 'Site is up to date', 'acf' ); ?> |
| 89 | <?php endif; ?> |
| 90 | </td> |
| 91 | </tr> |
| 92 | <?php |
| 93 | |
| 94 | // restore |
| 95 | restore_current_blog(); |
| 96 | endforeach; |
| 97 | endif; |
| 98 | |
| 99 | ?> |
| 100 | </tbody> |
| 101 | </table> |
| 102 | |
| 103 | <p><input type="submit" name="upgrade" value="<?php esc_attr_e( 'Upgrade Sites', 'acf' ); ?>" class="button" id="upgrade-sites-2"></p> |
| 104 | <?php // translators: %s admin dashboard url page ?> |
| 105 | <p class="show-on-complete"><?php echo acf_esc_html( sprintf( __( 'Database Upgrade complete. <a href="%s">Return to network dashboard</a>', 'acf' ), esc_url( network_admin_url() ) ) ); ?></p> |
| 106 | |
| 107 | <script type="text/javascript"> |
| 108 | (function($) { |
| 109 | |
| 110 | var upgrader = new acf.Model({ |
| 111 | events: { |
| 112 | 'click #upgrade-sites': 'onClick', |
| 113 | 'click #upgrade-sites-2': 'onClick' |
| 114 | }, |
| 115 | $inputs: function(){ |
| 116 | return $('#the-list input:checked'); |
| 117 | }, |
| 118 | onClick: function( e, $el ){ |
| 119 | |
| 120 | // prevent default |
| 121 | e.preventDefault(); |
| 122 | |
| 123 | // bail early if no selection |
| 124 | if( !this.$inputs().length ) { |
| 125 | return alert('<?php esc_attr_e( 'Please select at least one site to upgrade.', 'acf' ); ?>'); |
| 126 | } |
| 127 | |
| 128 | // confirm action |
| 129 | if( !confirm("<?php esc_attr_e( 'It is strongly recommended that you backup your database before proceeding. Are you sure you wish to run the updater now?', 'acf' ); ?>") ) { |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | // upgrade |
| 134 | this.upgrade(); |
| 135 | }, |
| 136 | upgrade: function(){ |
| 137 | |
| 138 | // vars |
| 139 | var $inputs = this.$inputs(); |
| 140 | |
| 141 | // bail early if no sites selected |
| 142 | if( !$inputs.length ) { |
| 143 | return this.complete(); |
| 144 | } |
| 145 | |
| 146 | // disable buttons |
| 147 | $('.button').prop('disabled', true); |
| 148 | |
| 149 | // vars |
| 150 | var $input = $inputs.first(); |
| 151 | var $row = $input.closest('tr'); |
| 152 | var text = ''; |
| 153 | var success = false; |
| 154 | |
| 155 | // show loading |
| 156 | <?php // translators: %s the version being upgraded to. ?> |
| 157 | $row.find('.response').html('<i class="acf-loading"></i></span> <?php printf( esc_attr__( 'Upgrading data to version %s', 'acf' ), esc_attr( ACF_VERSION ) ); ?>'); |
| 158 | |
| 159 | // send ajax request to upgrade DB |
| 160 | $.ajax({ |
| 161 | url: acf.get('ajaxurl'), |
| 162 | dataType: 'json', |
| 163 | type: 'post', |
| 164 | data: acf.prepareForAjax({ |
| 165 | action: 'acf/ajax/upgrade', |
| 166 | blog_id: $input.val() |
| 167 | }), |
| 168 | success: function( json ){ |
| 169 | success = true; |
| 170 | $input.remove(); |
| 171 | text = '<?php esc_attr_e( 'Upgrade complete.', 'acf' ); ?>'; |
| 172 | }, |
| 173 | error: function( jqXHR, textStatus, errorThrown ){ |
| 174 | text = '<?php esc_attr_e( 'Upgrade failed.', 'acf' ); ?>'; |
| 175 | if( error = acf.getXhrError(jqXHR) ) { |
| 176 | text += ' <code>' + error + '</code>'; |
| 177 | } |
| 178 | }, |
| 179 | complete: this.proxy(function(){ |
| 180 | |
| 181 | // display text |
| 182 | $row.find('.response').html( text ); |
| 183 | |
| 184 | // if successful upgrade, proceed to next site. Otherwise, skip to complete. |
| 185 | if( success ) { |
| 186 | this.upgrade(); |
| 187 | } else { |
| 188 | this.complete(); |
| 189 | } |
| 190 | }) |
| 191 | }); |
| 192 | }, |
| 193 | complete: function(){ |
| 194 | |
| 195 | // enable buttons |
| 196 | $('.button').prop('disabled', false); |
| 197 | |
| 198 | // show message |
| 199 | $('.show-on-complete').show(); |
| 200 | } |
| 201 | }); |
| 202 | |
| 203 | })(jQuery); |
| 204 | </script> |
| 205 | </div> |
| 206 |