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