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