post-types
5 months ago
tools
6 months ago
views
1 month ago
admin-email-opt-in-banner.php
1 month ago
admin-internal-post-type-list.php
6 months ago
admin-internal-post-type.php
6 months ago
admin-notices.php
6 months ago
admin-options-pages-preview.php
6 months ago
admin-tools.php
6 months ago
admin-upgrade.php
6 months ago
admin.php
1 month ago
index.php
2 years ago
admin-upgrade.php
303 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 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; // Exit if accessed directly |
| 14 | } |
| 15 | |
| 16 | if ( ! class_exists( 'ACF_Admin_Upgrade' ) ) : |
| 17 | |
| 18 | class ACF_Admin_Upgrade { |
| 19 | |
| 20 | /** |
| 21 | * The name of the transient to store the network update check status. |
| 22 | * |
| 23 | * @var string |
| 24 | */ |
| 25 | public $network_upgrade_needed_transient; |
| 26 | |
| 27 | /** |
| 28 | * __construct |
| 29 | * |
| 30 | * Sets up the class functionality. |
| 31 | * |
| 32 | * @date 31/7/18 |
| 33 | * @since 5.7.2 |
| 34 | * |
| 35 | * @param void |
| 36 | * @return void |
| 37 | */ |
| 38 | function __construct() { |
| 39 | |
| 40 | $this->network_upgrade_needed_transient = 'acf_network_upgrade_needed_' . ACF_UPGRADE_VERSION; |
| 41 | |
| 42 | add_action( 'admin_menu', array( $this, 'admin_menu' ), 20 ); |
| 43 | if ( is_multisite() ) { |
| 44 | add_action( 'network_admin_menu', array( $this, 'network_admin_menu' ), 20 ); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * admin_menu |
| 50 | * |
| 51 | * Setus up logic if DB Upgrade is needed on a single site. |
| 52 | * |
| 53 | * @date 24/8/18 |
| 54 | * @since 5.7.4 |
| 55 | * |
| 56 | * @param void |
| 57 | * @return void |
| 58 | */ |
| 59 | function admin_menu() { |
| 60 | |
| 61 | // check if upgrade is avaialble |
| 62 | if ( acf_has_upgrade() ) { |
| 63 | |
| 64 | // add notice |
| 65 | add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
| 66 | |
| 67 | // add page |
| 68 | $page = add_submenu_page( 'index.php', __( 'Upgrade Database', 'acf' ), __( 'Upgrade Database', 'acf' ), acf_get_setting( 'capability' ), 'acf-upgrade', array( $this, 'admin_html' ) ); |
| 69 | |
| 70 | // actions |
| 71 | add_action( 'load-' . $page, array( $this, 'admin_load' ) ); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Displays a “Database Upgrade Required” network admin notice and adds |
| 77 | * the “Upgrade Database” submenu under the “Dashboard” network admin |
| 78 | * menu item if an ACF upgrade needs to run on any network site. |
| 79 | * |
| 80 | * @since 5.7.4 |
| 81 | * @since 6.0.0 Reduce memory usage, cache network upgrade checks. |
| 82 | */ |
| 83 | function network_admin_menu() { |
| 84 | $network_upgrade_needed = get_site_transient( $this->network_upgrade_needed_transient ); |
| 85 | |
| 86 | // No transient value exists, so run the upgrade check. |
| 87 | if ( $network_upgrade_needed === false ) { |
| 88 | $network_upgrade_needed = $this->check_for_network_upgrades(); |
| 89 | } |
| 90 | |
| 91 | if ( $network_upgrade_needed === 'no' ) { |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | add_action( 'network_admin_notices', array( $this, 'network_admin_notices' ) ); |
| 96 | |
| 97 | $page = add_submenu_page( |
| 98 | 'index.php', |
| 99 | __( 'Upgrade Database', 'acf' ), |
| 100 | __( 'Upgrade Database', 'acf' ), |
| 101 | acf_get_setting( 'capability' ), |
| 102 | 'acf-upgrade-network', |
| 103 | array( $this, 'network_admin_html' ) |
| 104 | ); |
| 105 | |
| 106 | add_action( "load-$page", array( $this, 'network_admin_load' ) ); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Checks if an ACF database upgrade is required on any site in the |
| 111 | * multisite network. |
| 112 | * |
| 113 | * Stores the result in `$this->network_upgrade_needed_transient`, |
| 114 | * which is version-linked to ACF_UPGRADE_VERSION: the highest ACF |
| 115 | * version that requires an upgrade function to run. Bumping |
| 116 | * ACF_UPGRADE_VERSION will trigger new upgrade checks but incrementing |
| 117 | * ACF_VERSION alone will not. |
| 118 | * |
| 119 | * @since 6.0.0 |
| 120 | * @return string 'yes' if any site in the network requires an upgrade, |
| 121 | * otherwise 'no'. String instead of boolean so that |
| 122 | * `false` returned from a get_site_transient check can |
| 123 | * denote that an upgrade check is needed. |
| 124 | */ |
| 125 | public function check_for_network_upgrades() { |
| 126 | $network_upgrade_needed = 'no'; |
| 127 | |
| 128 | $sites = get_sites( |
| 129 | array( |
| 130 | 'number' => 0, |
| 131 | 'fields' => 'ids', // Reduces PHP memory usage. |
| 132 | ) |
| 133 | ); |
| 134 | |
| 135 | if ( $sites ) { |
| 136 | // Reduces memory usage (same pattern used in wp-includes/ms-site.php). |
| 137 | remove_action( 'switch_blog', 'wp_switch_roles_and_user', 1 ); |
| 138 | |
| 139 | foreach ( $sites as $site_id ) { |
| 140 | switch_to_blog( $site_id ); |
| 141 | |
| 142 | $site_needs_upgrade = acf_has_upgrade(); |
| 143 | |
| 144 | restore_current_blog(); // Restores global vars. |
| 145 | |
| 146 | if ( $site_needs_upgrade ) { |
| 147 | $network_upgrade_needed = 'yes'; |
| 148 | break; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | add_action( 'switch_blog', 'wp_switch_roles_and_user', 1, 2 ); |
| 153 | } |
| 154 | |
| 155 | set_site_transient( |
| 156 | $this->network_upgrade_needed_transient, |
| 157 | $network_upgrade_needed, |
| 158 | 3 * MONTH_IN_SECONDS |
| 159 | ); |
| 160 | |
| 161 | return $network_upgrade_needed; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * admin_load |
| 166 | * |
| 167 | * Runs during the loading of the admin page. |
| 168 | * |
| 169 | * @date 24/8/18 |
| 170 | * @since 5.7.4 |
| 171 | * |
| 172 | * @param type $var Description. Default. |
| 173 | * @return type Description. |
| 174 | */ |
| 175 | function admin_load() { |
| 176 | |
| 177 | add_action( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
| 178 | |
| 179 | // remove prompt |
| 180 | remove_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
| 181 | |
| 182 | // Enqueue core script. |
| 183 | acf_enqueue_script( 'acf' ); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * network_admin_load |
| 188 | * |
| 189 | * Runs during the loading of the network admin page. |
| 190 | * |
| 191 | * @date 24/8/18 |
| 192 | * @since 5.7.4 |
| 193 | * |
| 194 | * @param type $var Description. Default. |
| 195 | * @return type Description. |
| 196 | */ |
| 197 | function network_admin_load() { |
| 198 | |
| 199 | add_action( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
| 200 | |
| 201 | // remove prompt |
| 202 | remove_action( 'network_admin_notices', array( $this, 'network_admin_notices' ) ); |
| 203 | |
| 204 | // Enqueue core script. |
| 205 | acf_enqueue_script( 'acf' ); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Modifies the admin body class. |
| 210 | * |
| 211 | * @since 6.0.0 |
| 212 | * |
| 213 | * @param string $classes Space-separated list of CSS classes. |
| 214 | * @return string |
| 215 | */ |
| 216 | public function admin_body_class( $classes ) { |
| 217 | $classes .= ' acf-admin-page'; |
| 218 | return $classes; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * admin_notices |
| 223 | * |
| 224 | * Displays the DB Upgrade prompt. |
| 225 | * |
| 226 | * @date 23/8/18 |
| 227 | * @since 5.7.3 |
| 228 | * |
| 229 | * @param void |
| 230 | * @return void |
| 231 | */ |
| 232 | function admin_notices() { |
| 233 | |
| 234 | // vars |
| 235 | $view = array( |
| 236 | 'button_text' => __( 'Upgrade Database', 'acf' ), |
| 237 | 'button_url' => admin_url( 'index.php?page=acf-upgrade' ), |
| 238 | 'confirm' => true, |
| 239 | ); |
| 240 | |
| 241 | // view |
| 242 | acf_get_view( 'upgrade/notice', $view ); |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * network_admin_notices |
| 247 | * |
| 248 | * Displays the DB Upgrade prompt on a multi site. |
| 249 | * |
| 250 | * @date 23/8/18 |
| 251 | * @since 5.7.3 |
| 252 | * |
| 253 | * @param void |
| 254 | * @return void |
| 255 | */ |
| 256 | function network_admin_notices() { |
| 257 | |
| 258 | // vars |
| 259 | $view = array( |
| 260 | 'button_text' => __( 'Review sites & upgrade', 'acf' ), |
| 261 | 'button_url' => network_admin_url( 'index.php?page=acf-upgrade-network' ), |
| 262 | 'confirm' => false, |
| 263 | ); |
| 264 | |
| 265 | // view |
| 266 | acf_get_view( 'upgrade/notice', $view ); |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * admin_html |
| 271 | * |
| 272 | * Displays the HTML for the admin page. |
| 273 | * |
| 274 | * @date 24/8/18 |
| 275 | * @since 5.7.4 |
| 276 | * |
| 277 | * @param void |
| 278 | * @return void |
| 279 | */ |
| 280 | function admin_html() { |
| 281 | acf_get_view( 'upgrade/upgrade' ); |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * network_admin_html |
| 286 | * |
| 287 | * Displays the HTML for the network upgrade admin page. |
| 288 | * |
| 289 | * @date 24/8/18 |
| 290 | * @since 5.7.4 |
| 291 | * |
| 292 | * @param void |
| 293 | * @return void |
| 294 | */ |
| 295 | function network_admin_html() { |
| 296 | acf_get_view( 'upgrade/network' ); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | // instantiate |
| 301 | acf_new_instance( 'ACF_Admin_Upgrade' ); |
| 302 | endif; // class_exists check |
| 303 |