PluginProbe
Advanced Custom Fields (ACF®) / 5.9.8
Advanced Custom Fields (ACF®) v5.9.8
6.8.9 6.8.8 6.8.7 6.8.6 6.8.5 6.8.4 6.8.3 6.8.2 6.8.1 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.2 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 All 230 releases
advanced-custom-fields / includes / admin / admin-upgrade.php
admin-upgrade.php
244 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5 if( ! class_exists('ACF_Admin_Upgrade') ) :
6
7 class ACF_Admin_Upgrade {
8
9 /**
10 * __construct
11 *
12 * Sets up the class functionality.
13 *
14 * @date 31/7/18
15 * @since 5.7.2
16 *
17 * @param void
18 * @return void
19 */
20 function __construct() {
21
22 // actions
23 add_action( 'admin_menu', array($this,'admin_menu'), 20 );
24 if( is_multisite() ) {
25 add_action( 'network_admin_menu', array($this,'network_admin_menu'), 20 );
26 }
27 }
28
29 /**
30 * admin_menu
31 *
32 * Setus up logic if DB Upgrade is needed on a single site.
33 *
34 * @date 24/8/18
35 * @since 5.7.4
36 *
37 * @param void
38 * @return void
39 */
40 function admin_menu() {
41
42 // check if upgrade is avaialble
43 if( acf_has_upgrade() ) {
44
45 // add notice
46 add_action('admin_notices', array($this, 'admin_notices'));
47
48 // add page
49 $page = add_submenu_page('index.php', __('Upgrade Database','acf'), __('Upgrade Database','acf'), acf_get_setting('capability'), 'acf-upgrade', array($this,'admin_html') );
50
51 // actions
52 add_action('load-' . $page, array($this,'admin_load'));
53 }
54 }
55
56 /**
57 * network_admin_menu
58 *
59 * Sets up admin logic if DB Upgrade is required on a multi site.
60 *
61 * @date 24/8/18
62 * @since 5.7.4
63 *
64 * @param void
65 * @return void
66 */
67 function network_admin_menu() {
68
69 // Vars.
70 $upgrade = false;
71
72 // Loop over sites and check for upgrades.
73 $sites = get_sites( array( 'number' => 0 ) );
74 if( $sites ) {
75
76 // Unhook action to avoid memory issue (as seen in wp-includes/ms-site.php).
77 remove_action( 'switch_blog', 'wp_switch_roles_and_user', 1 );
78 foreach( $sites as $site ) {
79
80 // Switch site.
81 switch_to_blog( $site->blog_id );
82
83 // Check for upgrade.
84 $site_upgrade = acf_has_upgrade();
85
86 // Restore site.
87 // Ideally, we would switch back to the original site at after looping, however,
88 // the restore_current_blog() is needed to modify global vars.
89 restore_current_blog();
90
91 // Check if upgrade was found.
92 if( $site_upgrade ) {
93 $upgrade = true;
94 break;
95 }
96 }
97 add_action( 'switch_blog', 'wp_switch_roles_and_user', 1, 2 );
98 }
99
100 // Bail early if no upgrade is needed.
101 if( !$upgrade ) {
102 return;
103 }
104
105 // Add notice.
106 add_action('network_admin_notices', array($this, 'network_admin_notices'));
107
108 // Add page.
109 $page = add_submenu_page(
110 'index.php',
111 __('Upgrade Database','acf'),
112 __('Upgrade Database','acf'),
113 acf_get_setting('capability'),
114 'acf-upgrade-network',
115 array( $this,'network_admin_html' )
116 );
117 add_action( "load-$page", array( $this, 'network_admin_load' ) );
118 }
119
120 /**
121 * admin_load
122 *
123 * Runs during the loading of the admin page.
124 *
125 * @date 24/8/18
126 * @since 5.7.4
127 *
128 * @param type $var Description. Default.
129 * @return type Description.
130 */
131 function admin_load() {
132
133 // remove prompt
134 remove_action('admin_notices', array($this, 'admin_notices'));
135
136 // Enqueue core script.
137 acf_enqueue_script( 'acf' );
138 }
139
140 /**
141 * network_admin_load
142 *
143 * Runs during the loading of the network admin page.
144 *
145 * @date 24/8/18
146 * @since 5.7.4
147 *
148 * @param type $var Description. Default.
149 * @return type Description.
150 */
151 function network_admin_load() {
152
153 // remove prompt
154 remove_action('network_admin_notices', array($this, 'network_admin_notices'));
155
156 // Enqueue core script.
157 acf_enqueue_script( 'acf' );
158 }
159
160 /**
161 * admin_notices
162 *
163 * Displays the DB Upgrade prompt.
164 *
165 * @date 23/8/18
166 * @since 5.7.3
167 *
168 * @param void
169 * @return void
170 */
171 function admin_notices() {
172
173 // vars
174 $view = array(
175 'button_text' => __("Upgrade Database", 'acf'),
176 'button_url' => admin_url('index.php?page=acf-upgrade'),
177 'confirm' => true
178 );
179
180 // view
181 acf_get_view('html-notice-upgrade', $view);
182 }
183
184 /**
185 * network_admin_notices
186 *
187 * Displays the DB Upgrade prompt on a multi site.
188 *
189 * @date 23/8/18
190 * @since 5.7.3
191 *
192 * @param void
193 * @return void
194 */
195 function network_admin_notices() {
196
197 // vars
198 $view = array(
199 'button_text' => __("Review sites & upgrade", 'acf'),
200 'button_url' => network_admin_url('index.php?page=acf-upgrade-network'),
201 'confirm' => false
202 );
203
204 // view
205 acf_get_view('html-notice-upgrade', $view);
206 }
207
208 /**
209 * admin_html
210 *
211 * Displays the HTML for the admin page.
212 *
213 * @date 24/8/18
214 * @since 5.7.4
215 *
216 * @param void
217 * @return void
218 */
219 function admin_html() {
220 acf_get_view('html-admin-page-upgrade');
221 }
222
223 /**
224 * network_admin_html
225 *
226 * Displays the HTML for the network upgrade admin page.
227 *
228 * @date 24/8/18
229 * @since 5.7.4
230 *
231 * @param void
232 * @return void
233 */
234 function network_admin_html() {
235 acf_get_view('html-admin-page-upgrade-network');
236 }
237 }
238
239 // instantiate
240 acf_new_instance('ACF_Admin_Upgrade');
241
242 endif; // class_exists check
243
244 ?>