PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 2.4
Admin Columns v2.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 / upgrade.php
codepress-admin-columns / classes Last commit date
column 11 years ago storage_model 11 years ago addons.php 11 years ago column.php 11 years ago settings.php 11 years ago storage_model.php 11 years ago third_party.php 11 years ago upgrade.php 11 years ago utility.php 11 years ago
upgrade.php
411 lines
1 <?php
2 /**
3 * Upgrade
4 *
5 * Class largely based on code from ACF ( thanks to Elliot Condon )
6 *
7 * @since 2.0
8 */
9 class CPAC_Upgrade {
10
11 /**
12 * CPAC class
13 */
14 private $cpac;
15
16 public $update_prevented = false;
17
18 /**
19 * @since 2.0
20 */
21 function __construct( $cpac ) {
22
23 $this->cpac = $cpac;
24
25 // Hooks
26 add_action( 'admin_init', array( $this, 'init' ) );
27 add_action( 'admin_menu', array( $this, 'admin_menu' ), 11 );
28 add_action( 'admin_head', array( $this, 'admin_head' ) );
29 add_action( 'wp_ajax_cpac_upgrade', array( $this, 'ajax_upgrade' ) );
30
31 if ( ! $this->allow_upgrade() ) {
32 add_action( 'cpac_messages', array( $this, 'proaddon_notice' ) );
33 }
34 }
35
36 /**
37 * Admin CSS to hide upgrade menu and place icon
38 *
39 * @since 2.2.7
40 */
41 public function admin_head() {
42 ?>
43 <style type="text/css">
44 #menu-settings a[href="options-general.php?page=cpac-upgrade"] { display: none; }
45 </style>
46 <?php
47 }
48
49 /**
50 * Display a notice about the deprecated pro add-on
51 *
52 * @since 2.2
53 */
54 public function proaddon_notice() {
55
56 if ( apply_filters( 'cpac/suppress_proaddon_notice', false ) ) {
57 return;
58 }
59 ?>
60 <div class="message error">
61 <p>
62 <?php _e( '<strong>Important:</strong> We&#39;ve noticed that you&#39;re using the <em>Pro add-on</em>, which is no longer supported by Admin Columns 2.2+. However, a free license of <strong>Admin Columns Pro</strong> <a href="http://www.admincolumns.com/pro-addon-information/" target="_blank">is available</a>, which features a bunch of cool new features, including Direct Inline Editing!', 'cpac' ); ?>
63 <a href="http://www.admincolumns.com/pro-addon-information/" target="_blank"><?php _e( 'Learn more', 'cpac' ); ?></a>
64 </p>
65 </div>
66 <?php
67 }
68
69 /**
70 * Whether upgrading is allowed
71 *
72 * @since 2.1.5
73 *
74 * @return bool Whether plugin upgrading is allowed
75 */
76 public function allow_upgrade() {
77
78 require_once ABSPATH . 'wp-admin/includes/plugin.php';
79
80 return ! is_plugin_active( 'cac-addon-pro/cac-addon-pro.php' );
81 }
82
83 /**
84 * Add submenu page & scripts
85 *
86 * @since 2.0
87 */
88 public function admin_menu() {
89
90 // Don't run on plugin activate
91 if ( isset( $_GET['action'] ) && 'activate-plugin' === $_GET['action'] ) {
92 return;
93 }
94
95 $upgrade_page = add_submenu_page( 'options-general.php', __( 'Upgrade', 'cpac' ), __( 'Upgrade', 'cpac' ), 'manage_options', 'cpac-upgrade', array( $this, 'start_upgrade' ) );
96 add_action( "admin_print_scripts-{$upgrade_page}", array( $this, 'admin_scripts' ) );
97 }
98
99 /**
100 * @since 2.0
101 */
102 public function init() {
103
104 // @dev_only delete_option( 'cpac_version' ); set_transient( 'cpac_show_welcome', 'display' );
105 $version = get_option( 'cpac_version', false );
106
107 // Maybe version pre 2.0.0 was used
108 if ( ! $version && get_option( 'cpac_options' ) ) {
109 $version = '1.0.0';
110 }
111
112 // @dev_only if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) echo "--------- CPAC DEBUG: START ---------<br/>\n" . $version . "<br/>\n" . CPAC_VERSION . "<br/>\n" . CPAC_UPGRADE_VERSION . "<br/>\n" . get_transient( 'cpac_show_welcome' ) . "<br/>\n" . "--------- CPAC DEBUG: END ---------<br/>\n";
113
114 // Maybe upgrade?
115 if ( $version ) {
116
117 // run every upgrade
118 if ( $version < CPAC_VERSION ) {
119 // nothing yet
120 }
121
122 // run only when updating from v1 to v2
123 if ( $version < '2.0.0' ) {
124
125 // show welcome screen
126 set_transient( 'cpac_show_welcome', 'display' );
127 }
128
129 // run only when database upgrade is needed
130 if ( $version < CPAC_UPGRADE_VERSION ) {
131
132 // display upgrade message on every page except upgrade page itself
133 if ( ! ( isset( $_REQUEST['page'] ) && 'cpac-upgrade' === $_REQUEST['page'] ) ) {
134
135 $message = __( 'Admin Columns', 'cpac' ) . ' v' . CPAC_VERSION . ' ' .
136 __( 'requires a database upgrade','cpac' ) .
137 ' (<a class="thickbox" href="' . admin_url() .
138 'plugin-install.php?tab=plugin-information&plugin=codepress-admin-columns&section=changelog&TB_iframe=true&width=640&height=559">' .
139 __( 'why?', 'cpac' ) .'</a>). ' .
140 __( "Please", 'cpac' ) .' <a href="http://codex.wordpress.org/Backing_Up_Your_Database">' .
141 __( "backup your database", 'cpac' ) .'</a>, '.
142 __( "then click", 'cpac' ) . ' <a href="' . admin_url() . 'options-general.php?page=cpac-upgrade" class="button">' .
143 __( "Upgrade Database", 'cpac' ) . '</a>';
144
145 cpac_admin_message( $message, 'updated' );
146 }
147 }
148
149 // run when NO upgrade is needed
150 elseif ( $version < CPAC_VERSION ) {
151
152 update_option( 'cpac_version', CPAC_VERSION );
153 }
154 }
155
156 // Fresh install
157 else {
158
159 update_option( 'cpac_version', CPAC_VERSION );
160 }
161 }
162
163 /**
164 * Init Upgrade Process
165 *
166 * @since 2.0
167 */
168 public function ajax_upgrade() {
169
170 // vars
171 $return = array(
172 'status' => false,
173 'message' => "",
174 'next' => false,
175 );
176
177 $version = $_POST['version'];
178
179 // versions
180 switch ( $version ) {
181
182 case '2.0.0' :
183
184 $old_settings = get_option( 'cpac_options' );
185
186 // old settings
187 if ( ! empty( $old_settings['columns'] ) ) {
188
189 foreach ( $old_settings['columns'] as $storage_key => $old_columns ){
190
191 $columns = array();
192
193 if ( $old_columns ) {
194
195 // used to determine clone ID
196 $tax_count = null;
197 $post_count = null;
198 $meta_count = null;
199
200 foreach ( $old_columns as $old_column_name => $old_column_settings ) {
201
202 // only active columns
203 if ( isset( $old_column_settings['state'] ) && 'on' !== $old_column_settings['state'] )
204 continue;
205
206 // convert old settings to new
207 $settings = array_merge( $old_column_settings, array(
208 'type' => $old_column_name,
209 'clone' => ''
210 ) );
211
212 // set name
213 $name = $old_column_name;
214
215 // convert: Users
216 if ( 'wp-users' == $storage_key ) {
217
218 // is user postcount?
219 if ( strpos( $old_column_name, 'column-user_postcount-' ) !== false ) {
220 $settings['type'] = 'column-user_postcount';
221 $settings['clone'] = $post_count;
222 $settings['post_type'] = str_replace( 'column-user_postcount-', '', $old_column_name );
223
224 $name = $post_count ? $settings['type'] . '-' . $settings['clone'] : $settings['type'];
225 $post_count++;
226 }
227 }
228
229 // convert: Media
230 elseif ( 'wp-media' == $storage_key ) {
231
232 if ( 'column-filesize' == $old_column_name ) {
233 $name = 'column-file_size';
234 $settings['type'] = $name;
235 }
236 // is EXIF data?
237 elseif ( strpos( $old_column_name, 'column-image-' ) !== false ) {
238 $name = 'column-exif_data';
239 $settings['type'] = $name;
240 $settings['exif_datatype'] = str_replace( 'column-image-', '', $old_column_name );
241 }
242 elseif ( 'column-file_paths' == $old_column_name ) {
243 $name = 'column-available_sizes';
244 $settings['type'] = $name;
245 }
246 }
247
248 // convert: Comments
249 elseif ( 'wp-comments' == $storage_key ) {
250
251 if ( 'column-author_author' == $old_column_name ) {
252 $name = 'column-author';
253 $settings['type'] = $name;
254 }
255 }
256
257 // convert: Posts
258 else {
259
260 if ( 'column-attachment-count' == $old_column_name ) {
261 $name = 'column-attachment_count';
262 $settings['type'] = $name;
263 }
264 elseif ( 'column-author-name' == $old_column_name ) {
265 $name = 'column-author_name';
266 $settings['type'] = $name;
267 $settings['display_author_as'] = $old_column_settings['display_as'];
268 }
269 elseif ( 'column-before-moretag' == $old_column_name ) {
270 $name = 'column-before_moretag';
271 $settings['type'] = $name;
272 }
273 elseif ( 'column-comment-count' == $old_column_name ) {
274 $name = 'column-comment_count';
275 $settings['type'] = $name;
276 $settings['comment_status'] = 'total_comments';
277 }
278 elseif ( 'column-comment-status' == $old_column_name ) {
279 $name = 'column-comment_status';
280 $settings['type'] = $name;
281 }
282 elseif ( 'column-ping-status' == $old_column_name ) {
283 $name = 'column-ping_status';
284 $settings['type'] = $name;
285 }
286 elseif ( 'column-page-slug' == $old_column_name ) {
287 $name = 'column-slug';
288 $settings['type'] = $name;
289 }
290 elseif ( 'column-page-template' == $old_column_name ) {
291 $name = 'column-page_template';
292 $settings['type'] = $name;
293 }
294 }
295
296 // convert: Applies to all storage types
297
298 // is taxonomy?
299 if ( strpos( $old_column_name, 'column-taxonomy-' ) !== false ) {
300 $settings['type'] = 'column-taxonomy';
301 $settings['clone'] = $tax_count;
302 $settings['taxonomy'] = str_replace( 'column-taxonomy-', '', $old_column_name );
303
304 $name = $tax_count ? $settings['type'] . '-' . $settings['clone'] : $settings['type'];
305 $tax_count++;
306 }
307 // is custom field?
308 elseif ( strpos( $old_column_name, 'column-meta-' ) !== false ) {
309
310 $settings['type'] = 'column-meta';
311 //$settings['clone'] = str_replace( 'column-meta-', '', $old_column_name );
312 $settings['clone'] = $meta_count;
313
314 $name = $meta_count ? $settings['type'] . '-' . $settings['clone'] : $settings['type'];
315 $meta_count++;
316 }
317 elseif ( 'column-word-count' == $old_column_name ) {
318 $name = 'column-word_count';
319 $settings['type'] = $name;
320 }
321
322 // add to column set
323 $columns[ $name ] = $settings;
324
325 // reorder so that active column are at the top of the pile.
326 $active = $inactive = array();
327 foreach ( $columns as $name => $_settings ) {
328 if ( 'on' === $_settings['state'] ) {
329 $active[ $name ] = $_settings;
330 }
331 else {
332 $inactive[ $name ] = $_settings;
333 }
334 }
335 $columns = array_merge( $active, $inactive );
336 }
337
338 // store column settings
339 if ( ! get_option( "cpac_options_{$storage_key}" ) ) {
340 update_option( "cpac_options_{$storage_key}", $columns );
341 }
342 }
343 }
344 }
345
346 // update version
347 update_option( 'cpac_version', $version );
348
349 $return = array(
350 'status' => true,
351 'message' => __( "Migrating Column Settings", 'cpac' ) . '...',
352 'next' => false,
353 );
354
355 break;
356 }
357
358 // return json
359 echo json_encode( $return );
360 die;
361 }
362
363 /*
364 * Starting points of the upgrade process
365 *
366 * @since 2.0
367 */
368 public function start_upgrade() {
369
370 $version = get_option( 'cpac_version', '1.0.0' );
371 $next = false;
372
373 // list of starting points
374 if( $version < '2.0.0' ) {
375 $next = '2.0.0';
376 }
377
378 // Run upgrade?
379 if( $next ) : ?>
380 <script type="text/javascript">
381 run_upgrade("<?php echo $next; ?>");
382 </script>
383 <?php
384
385 // No update required
386 else : ?>
387 <p><?php _e( 'No Upgrade Required', 'cpac' ); ?></p>
388 <a href="<?php echo admin_url('options-general.php'); ?>?page=codepress-admin-columns&amp;info"><?php _e( 'Return to welcome screen.', 'cpac' ); ?></a>
389 <?php
390 endif;
391 }
392
393 /**
394 * Scripts
395 *
396 * @since 2.0
397 */
398 public function admin_scripts() {
399 wp_enqueue_script( 'cpac-upgrade', CPAC_URL . 'assets/js/upgrade.js', array( 'jquery' ), CPAC_VERSION );
400
401 // CSS
402 wp_enqueue_style( 'cpac-admin', CPAC_URL . 'assets/css/admin-column.css', array(), CPAC_VERSION, 'all' );
403
404 // javascript translations
405 wp_localize_script( 'cpac-upgrade', 'cpac_upgrade_i18n', array(
406 'complete' => __( 'Upgrade Complete!', 'cpac' ) . '</p><p><a href="' . admin_url('options-general.php') . '?page=codepress-admin-columns&info">' . __( 'Return to settings.', 'cpac' ) . "</a>" ,
407 'error' => __( 'Error', 'cpac' ),
408 'major_error' => __( 'Sorry. Something went wrong during the upgrade process. Please report this on the support forum.', 'cpac' )
409 ));
410 }
411 }