PluginProbe
Code Snippets / 2.12.0
Code Snippets v2.12.0
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 3.0.1 All 64 releases
code-snippets / php / upgrade.php

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

84 lines 2.7 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 $db = code_snippets()->db;
19
20 /* Get the current plugin version from the database */
21 $prev_version = get_option( 'code_snippets_version' );
22
23 /* Check if we have upgraded from an older version */
24 if ( version_compare( $prev_version, CODE_SNIPPETS_VERSION, '<' ) ) {
25
26 /* Upgrade the database tables */
27 $db->create_tables( true );
28
29 /* Update the plugin version stored in the database */
30 update_option( 'code_snippets_version', CODE_SNIPPETS_VERSION );
31
32 /* Update the scope column of the database */
33 if ( version_compare( $prev_version, '2.10.0', '<' ) ) {
34 $wpdb->query( "UPDATE {$wpdb->snippets} SET scope = 'global' WHERE scope = 0" );
35 $wpdb->query( "UPDATE {$wpdb->snippets} SET scope = 'admin' WHERE scope = 1" );
36 $wpdb->query( "UPDATE {$wpdb->snippets} SET scope = 'front-end' WHERE scope = 2" );
37 }
38
39 /* Custom capabilities were removed after version 2.9.5 */
40 if ( version_compare( $prev_version, '2.9.5', '<=' ) ) {
41 $role = get_role( apply_filters( 'code_snippets_role', 'administrator' ) );
42 $role->remove_cap( apply_filters( 'code_snippets_cap', 'manage_snippets' ) );
43 }
44 }
45
46 if ( false === $prev_version ) {
47 $db->create_sample_content();
48 }
49
50 /* Run multisite-only upgrades */
51
52 if ( is_multisite() && is_main_site() ) {
53
54 /* Get the current plugin version from the database */
55 $prev_ms_version = get_site_option( 'code_snippets_version' );
56
57 /* Check if we have upgraded from an older version */
58 if ( version_compare( $prev_ms_version, CODE_SNIPPETS_VERSION, '<' ) ) {
59
60 /* Update the plugin version stored in the database */
61 update_site_option( 'code_snippets_version', CODE_SNIPPETS_VERSION );
62
63 /* Update the scope column of the database */
64 if ( version_compare( $prev_version, '2.10.0', '<' ) ) {
65 $wpdb->query( "UPDATE {$wpdb->ms_snippets} SET scope = 'global' WHERE scope = 0" );
66 $wpdb->query( "UPDATE {$wpdb->ms_snippets} SET scope = 'admin' WHERE scope = 1" );
67 $wpdb->query( "UPDATE {$wpdb->ms_snippets} SET scope = 'front-end' WHERE scope = 2" );
68 }
69
70 /* Custom capabilities were removed after version 2.9.5 */
71 if ( version_compare( $prev_ms_version, '2.9.5', '<=' ) ) {
72 $network_cap = apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' );
73
74 foreach ( get_super_admins() as $admin ) {
75 $user = new WP_User( 0, $admin );
76 $user->remove_cap( $network_cap );
77 }
78 }
79 }
80 }
81 }
82
83 add_action( 'plugins_loaded', 'code_snippets_upgrader', 0 );
84