PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 3.0.5
Admin Columns v3.0.5
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Admin / Page / Upgrade.php
codepress-admin-columns / classes / Admin / Page Last commit date
Addons.php 8 years ago Columns.php 8 years ago Help.php 8 years ago Settings.php 8 years ago Upgrade.php 8 years ago Welcome.php 8 years ago
Upgrade.php
373 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * Upgrade
9 *
10 * Class largely based on code from ACF ( props to Elliot )
11 *
12 * @since 2.0
13 */
14 class AC_Admin_Page_Upgrade extends AC_Admin_Page {
15
16 const VERSION_KEY = 'cpac_version';
17
18 public $update_prevented = false;
19
20 /**
21 * @since 2.0
22 */
23 function __construct() {
24 $this
25 ->set_slug( 'upgrade' )
26 ->set_label( __( 'Upgrade', 'codepress-admin-columns' ) )
27 ->set_show_in_menu( false );
28
29 add_action( 'wp_ajax_cpac_upgrade', array( $this, 'ajax_upgrade' ) );
30
31 if ( ! $this->allow_upgrade() ) {
32 add_action( 'ac/settings/after_menu', array( $this, 'proaddon_notice' ) );
33 }
34
35 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
36 }
37
38 /**
39 * Display a notice about the deprecated pro add-on
40 *
41 * @since 2.2
42 */
43 public function proaddon_notice() { ?>
44 <div class="message error">
45 <p>
46 <?php _e( 'The pro add-on is no longer supported. Please login to your account and download Admin Columns Pro', 'codepress-admin-columns' ); ?>
47 <a href="<?php echo ac_get_site_utm_url( 'pro-addon-information', 'pro-notice' ); ?>" target="_blank"><?php _e( 'Learn more', 'codepress-admin-columns' ); ?></a>
48 </p>
49 </div>
50 <?php
51 }
52
53 /**
54 * Whether upgrading is allowed
55 *
56 * @since 2.1.5
57 *
58 * @return bool Whether plugin upgrading is allowed
59 */
60 public function allow_upgrade() {
61 require_once ABSPATH . 'wp-admin/includes/plugin.php';
62
63 return ! is_plugin_active( 'cac-addon-pro/cac-addon-pro.php' );
64 }
65
66 /**
67 * Init Upgrade Process
68 *
69 * @since 2.0
70 */
71 public function ajax_upgrade() {
72
73 // vars
74 $return = array(
75 'status' => false,
76 'message' => "",
77 'next' => false,
78 );
79
80 $version = $_POST['version'];
81
82 // versions
83 switch ( $version ) {
84
85 case '2.0.0' :
86
87 $old_settings = get_option( 'cpac_options' );
88
89 // old settings
90 if ( ! empty( $old_settings['columns'] ) ) {
91
92 foreach ( $old_settings['columns'] as $storage_key => $old_columns ) {
93
94 $columns = array();
95
96 if ( $old_columns ) {
97
98 // used to determine clone ID
99 $tax_count = null;
100 $post_count = null;
101 $meta_count = null;
102
103 foreach ( $old_columns as $old_column_name => $old_column_settings ) {
104
105 // only active columns
106 if ( isset( $old_column_settings['state'] ) && 'on' !== $old_column_settings['state'] ) {
107 continue;
108 }
109
110 // convert old settings to new
111 $settings = array_merge( $old_column_settings, array(
112 'type' => $old_column_name,
113 'clone' => '',
114 ) );
115
116 // set name
117 $name = $old_column_name;
118
119 // convert: Users
120 if ( 'wp-users' == $storage_key ) {
121
122 // is user post count?
123 if ( strpos( $old_column_name, 'column-user_postcount-' ) !== false ) {
124 $settings['type'] = 'column-user_postcount';
125 $settings['clone'] = $post_count;
126 $settings['post_type'] = str_replace( 'column-user_postcount-', '', $old_column_name );
127
128 $name = $post_count ? $settings['type'] . '-' . $settings['clone'] : $settings['type'];
129 $post_count++;
130 }
131 }
132
133 // convert: Media
134 elseif ( 'wp-media' == $storage_key ) {
135
136 if ( 'column-filesize' == $old_column_name ) {
137 $name = 'column-file_size';
138 $settings['type'] = $name;
139 }
140 // is EXIF data?
141 elseif ( strpos( $old_column_name, 'column-image-' ) !== false ) {
142 $name = 'column-exif_data';
143 $settings['type'] = $name;
144 $settings['exif_datatype'] = str_replace( 'column-image-', '', $old_column_name );
145 }
146 elseif ( 'column-file_paths' == $old_column_name ) {
147 $name = 'column-available_sizes';
148 $settings['type'] = $name;
149 }
150 }
151
152 // convert: Comments
153 elseif ( 'wp-comments' == $storage_key ) {
154
155 if ( 'column-author_author' == $old_column_name ) {
156 $name = 'column-author';
157 $settings['type'] = $name;
158 }
159 }
160
161 // convert: Posts
162 else {
163
164 if ( 'column-attachment-count' == $old_column_name ) {
165 $name = 'column-attachment_count';
166 $settings['type'] = $name;
167 }
168 elseif ( 'column-author-name' == $old_column_name ) {
169 $name = 'column-author_name';
170 $settings['type'] = $name;
171 $settings['display_author_as'] = $old_column_settings['display_as'];
172 }
173 elseif ( 'column-before-moretag' == $old_column_name ) {
174 $name = 'column-before_moretag';
175 $settings['type'] = $name;
176 }
177 elseif ( 'column-comment-count' == $old_column_name ) {
178 $name = 'column-comment_count';
179 $settings['type'] = $name;
180 $settings['comment_status'] = 'total_comments';
181 }
182 elseif ( 'column-comment-status' == $old_column_name ) {
183 $name = 'column-comment_status';
184 $settings['type'] = $name;
185 }
186 elseif ( 'column-ping-status' == $old_column_name ) {
187 $name = 'column-ping_status';
188 $settings['type'] = $name;
189 }
190 elseif ( 'column-page-slug' == $old_column_name ) {
191 $name = 'column-slug';
192 $settings['type'] = $name;
193 }
194 elseif ( 'column-page-template' == $old_column_name ) {
195 $name = 'column-page_template';
196 $settings['type'] = $name;
197 }
198 }
199
200 // convert: Applies to all storage types
201
202 // is taxonomy?
203 if ( strpos( $old_column_name, 'column-taxonomy-' ) !== false ) {
204 $settings['type'] = 'column-taxonomy';
205 $settings['clone'] = $tax_count;
206 $settings['taxonomy'] = str_replace( 'column-taxonomy-', '', $old_column_name );
207
208 $name = $tax_count ? $settings['type'] . '-' . $settings['clone'] : $settings['type'];
209 $tax_count++;
210 }
211 // is custom field?
212 elseif ( strpos( $old_column_name, 'column-meta-' ) !== false ) {
213
214 $settings['type'] = 'column-meta';
215 //$settings['clone'] = str_replace( 'column-meta-', '', $old_column_name );
216 $settings['clone'] = $meta_count;
217
218 $name = $meta_count ? $settings['type'] . '-' . $settings['clone'] : $settings['type'];
219 $meta_count++;
220 }
221 elseif ( 'column-word-count' == $old_column_name ) {
222 $name = 'column-word_count';
223 $settings['type'] = $name;
224 }
225
226 // add to column set
227 $columns[ $name ] = $settings;
228
229 // reorder so that active column are at the top of the pile.
230 $active = $inactive = array();
231 foreach ( $columns as $name => $_settings ) {
232 if ( 'on' === $_settings['state'] ) {
233 $active[ $name ] = $_settings;
234 }
235 else {
236 $inactive[ $name ] = $_settings;
237 }
238 }
239 $columns = array_merge( $active, $inactive );
240 }
241
242 // store column settings
243 if ( ! get_option( "cpac_options_{$storage_key}" ) ) {
244 update_option( "cpac_options_{$storage_key}", $columns );
245 }
246 }
247 }
248 }
249
250 // update version
251 update_option( self::VERSION_KEY, $version );
252
253 $return = array(
254 'status' => true,
255 'message' => __( "Migrating Column Settings", 'codepress-admin-columns' ) . '...',
256 'next' => false,
257 );
258
259 break;
260 }
261
262 // return json
263 echo json_encode( $return );
264 die;
265 }
266
267 /*
268 * Starting points of the upgrade process
269 *
270 * @since 2.0
271 */
272 public function start_upgrade() {
273
274 $version = get_option( self::VERSION_KEY, '1.0.0' );
275 $next = false;
276
277 // list of starting points
278 if ( $version < '2.0.0' ) {
279 $next = '2.0.0';
280 }
281
282 // Run upgrade?
283 if ( $next ) : ?>
284 <script type="text/javascript">
285 run_upgrade( "<?php echo $next; ?>" );
286 </script>
287 <?php
288
289 // No update required
290 else : ?>
291 <p><?php _e( 'No Upgrade Required', 'codepress-admin-columns' ); ?></p>
292 <?php echo ac_helper()->html->link( AC()->admin()->get_link( 'welcome' ), __( 'Return to welcome screen.', 'codepress-admin-columns' ) );
293 endif;
294 }
295
296 /**
297 * Scripts
298 *
299 * @since 2.0
300 */
301 public function admin_scripts() {
302 if ( ! $this->is_current_screen() ) {
303 return;
304 }
305
306 wp_enqueue_script( 'ac-upgrade', AC()->get_plugin_url() . 'assets/js/upgrade.js', array( 'jquery' ), AC()->get_version() );
307 wp_localize_script( 'ac-upgrade', 'cpac_upgrade_i18n', array(
308 'complete' => __( 'Upgrade Complete!', 'codepress-admin-columns' ) . '</p><p><a href="' . esc_url( AC()->admin()->get_link( 'welcome' ) ) . '">' . __( 'Return to settings.', 'codepress-admin-columns' ) . "</a>",
309 'error' => __( 'Error', 'codepress-admin-columns' ),
310 'major_error' => __( 'Sorry. Something went wrong during the upgrade process. Please report this on the support forum.', 'codepress-admin-columns' ),
311 ) );
312 }
313
314 /**
315 * @since 2.0
316 */
317 public function display() {
318 ?>
319 <h1><?php _e( 'Upgrade', 'codepress-admin-columns' ); ?></h1>
320 <?php
321
322 $version = get_option( self::VERSION_KEY, false );
323
324 // Maybe version pre 2.0.0 was used
325 if ( ! $version && get_option( 'cpac_options' ) ) {
326 $version = '1.0.0';
327 }
328
329 // Maybe upgrade?
330 if ( $version ) {
331
332 // run every upgrade
333 if ( $version < AC()->get_version() ) {
334 // nothing yet
335 }
336
337 // run only when updating from v1 to v2
338 if ( $version < '2.0.0' ) {
339
340 // show welcome screen
341 wp_safe_redirect( AC()->admin()->get_link( 'welcome' ) );
342 exit;
343 }
344
345 // run only when database upgrade is needed
346 if ( $version < AC()->get_upgrade_version() ) {
347
348 // display upgrade message on every page except upgrade page itself
349 if ( ! ( isset( $_REQUEST['page'] ) && 'upgrade' === $_REQUEST['page'] ) ) {
350
351 $message = sprintf( "Admin Columns %s requires a database upgrade.", AC()->get_version() );
352 $message .= sprintf( "Please %s, then click %s.", ac_helper()->html->link( 'http://codex.wordpress.org/Backing_Up_Your_Database', 'backup your database' ), ac_helper()->html->link( $this->get_link(), 'Upgrade Database' ) );
353
354 AC()->notice( $message, 'updated' );
355 }
356 }
357
358 // run when NO upgrade is needed
359 elseif ( $version < AC()->get_version() ) {
360
361 update_option( self::VERSION_KEY, AC()->get_version() );
362 }
363 }
364
365 // Fresh install
366 else {
367
368 update_option( self::VERSION_KEY, AC()->get_version() );
369 }
370 }
371
372 }
373