PluginProbe
Code Snippets / 2.10.0
Code Snippets v2.10.0
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / php / upgrade.php

upgrade.php in Code Snippets 2.10.0, at php/upgrade.php

79 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file manages upgrades to the database between plugin versions
5 */
6
7 /* Bail on direct access */
8 if ( ! defined( 'ABSPATH' ) ) {
9 return;
10 }
11
12 /**
13 * Preform upgrade tasks such as deleting and updating options
14 * @since 2.0
15 */
16 function code_snippets_upgrader() {
17 global $wpdb;
18
19 /* Get the current plugin version from the database */
20 $prev_version = get_option( 'code_snippets_version' );
21
22 /* Check if we have upgraded from an older version */
23 if ( version_compare( $prev_version, CODE_SNIPPETS_VERSION, '<' ) ) {
24
25 /* Upgrade the database tables */
26 code_snippets()->db->create_tables( true );
27
28 /* Update the plugin version stored in the database */
29 update_option( 'code_snippets_version', CODE_SNIPPETS_VERSION );
30
31 /* Update the scope column of the database */
32 if ( version_compare( $prev_version, '2.10.0', '<' ) ) {
33 $wpdb->query( "UPDATE {$wpdb->snippets} SET scope = 'global' WHERE scope = 0" );
34 $wpdb->query( "UPDATE {$wpdb->snippets} SET scope = 'admin' WHERE scope = 1" );
35 $wpdb->query( "UPDATE {$wpdb->snippets} SET scope = 'front-end' WHERE scope = 2" );
36 }
37
38 /* Custom capabilities were removed after version 2.9.5 */
39 if ( version_compare( $prev_version, '2.9.5', '<=' ) ) {
40 $role = get_role( apply_filters( 'code_snippets_role', 'administrator' ) );
41 $role->remove_cap( apply_filters( 'code_snippets_cap', 'manage_snippets' ) );
42 }
43 }
44
45 /* Run multisite-only upgrades */
46
47 if ( is_multisite() && is_main_site() ) {
48
49 /* Get the current plugin version from the database */
50 $prev_ms_version = get_site_option( 'code_snippets_version' );
51
52 /* Check if we have upgraded from an older version */
53 if ( version_compare( $prev_ms_version, CODE_SNIPPETS_VERSION, '<' ) ) {
54
55 /* Update the plugin version stored in the database */
56 update_site_option( 'code_snippets_version', CODE_SNIPPETS_VERSION );
57
58 /* Update the scope column of the database */
59 if ( version_compare( $prev_version, '2.10.0', '<' ) ) {
60 $wpdb->query( "UPDATE {$wpdb->ms_snippets} SET scope = 'global' WHERE scope = 0" );
61 $wpdb->query( "UPDATE {$wpdb->ms_snippets} SET scope = 'admin' WHERE scope = 1" );
62 $wpdb->query( "UPDATE {$wpdb->ms_snippets} SET scope = 'front-end' WHERE scope = 2" );
63 }
64
65 /* Custom capabilities were removed after version 2.9.5 */
66 if ( version_compare( $prev_ms_version, '2.9.5', '<=' ) ) {
67 $network_cap = apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' );
68
69 foreach ( get_super_admins() as $admin ) {
70 $user = new WP_User( 0, $admin );
71 $user->remove_cap( $network_cap );
72 }
73 }
74 }
75 }
76 }
77
78 add_action( 'plugins_loaded', 'code_snippets_upgrader', 0 );
79