PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.12
Code Manager v1.0.12
1.0.47 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
code-manager / includes / class-code-manager-switch.php
code-manager / includes Last commit date
class-code-manager-i18n.php 4 years ago class-code-manager-loader.php 4 years ago class-code-manager-switch.php 4 years ago class-code-manager.php 4 years ago
class-code-manager-switch.php
109 lines
1 <?php
2
3 use Code_Manager\Code_Manager_Model;
4
5 /**
6 * Class Code_Manager_Switch
7 *
8 * Switch to:
9 * + activate plugin {@see Code_Manager_Switch::activate()}
10 * + deactive plugin {@see Code_Manager_Switch::deactivate()}
11 *
12 * @author Peter Schulz
13 * @since 1.0.0
14 *
15 * @see Code_Manager_Switch::activate()
16 * @see Code_Manager_Switch::deactivate()
17 */
18 class Code_Manager_Switch {
19
20 /**
21 * Activate Code Manager
22 *
23 * The user must have the appropriate privileges to perform this operation.
24 *
25 * For single site installation {@see Code_Manager_Switch::activate_blog()} will be called. For multi site
26 * installations {@see Code_Manager_Switch::activate_blog()} must be called for every blog.
27 *
28 * IMPORTANT!!!
29 *
30 * For blogs installed on multi site installations after activation of the plugin, activation of the plugin for
31 * that blog will not be performed if the plugin is network activated. In that case the admin user of the blog
32 * will receive a message when viewing a plugin page with an option to follow these steps manually.
33 *
34 * @since 1.0.0
35 *
36 * @see Code_Manager_Switch::activate_blog()
37 */
38 public static function activate() {
39 if ( current_user_can( 'activate_plugins' ) ) {
40 // Activate plugin.
41 if ( is_multisite() ) {
42 global $wpdb;
43 // Multisite installation.
44 $blogids = $wpdb->get_col( "select blog_id from $wpdb->blogs" ); // db call ok; no-cache ok.
45 foreach ( $blogids as $blog_id ) {
46 // Uninstall blog.
47 switch_to_blog( $blog_id );
48 self::activate_blog();
49 restore_current_blog();
50 }
51 } else {
52 // Single site installation.
53 self::activate_blog();
54 }
55 }
56 }
57
58 /**
59 * Activate blog
60 *
61 * The user must have the appropriate privileges to perform this operation.
62 *
63 * Creates plugin table (if not found) and updates plugin version. This action is performed on the
64 * 'active WordPress blog'. On single site there is only one blog. On multisite installations it must be
65 * executed for every blog.
66 *
67 * @since 1.0.0
68 */
69 protected static function activate_blog() {
70 if ( current_user_can( 'activate_plugins' ) ) {
71 if ( CODE_MANAGER_VERSION !== get_option( 'code_manager_version' ) ) {
72 $code_manager_model = new Code_Manager_Model();
73 if ( ! $code_manager_model::table_exists() ) {
74 global $wpdb;
75
76 $create_table =
77 "CREATE TABLE {wp_prefix}code_manager
78 ( code_id mediumint(9) NOT NULL AUTO_INCREMENT
79 , code_name varchar(100) NOT NULL
80 , code_type varchar(30) NOT NULL
81 , code_enabled tinyint(1) NOT NULL DEFAULT 0
82 , code text
83 , code_author varchar(100)
84 , code_description text
85 , PRIMARY KEY (code_id)
86 , UNIQUE KEY (code_name)
87 )";
88 $wpdb->query( str_replace( '{wp_prefix}', $wpdb->prefix, $create_table ) );
89 }
90
91 update_option( 'code_manager_version', CODE_MANAGER_VERSION );
92 }
93 }
94 }
95
96 /**
97 * Deactivate plugin WP Data Access
98 *
99 * On deactivation we leave the repository and options as they are in case the user wants to reactivate the
100 * plugin later again. Tables and options are deleted when the plugin is uninstalled.
101 *
102 * @since 1.0.0
103 */
104 public static function deactivate() {
105 // Add future deactivation code here
106 }
107
108 }
109