PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 2.0.13
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v2.0.13
5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 5.5.43 All 159 releases
wp-data-access / includes / class-wp-data-access-switch.php

class-wp-data-access-switch.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 2.0.13, at includes/class-wp-data-access-switch.php

127 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Suppress "error - 0 - No summary was found for this file" on phpdoc generation
4 *
5 * @package plugin\includes
6 */
7
8 use WPDataAccess\Utilities\WPDA_Repository;
9 use WPDataAccess\WPDA;
10
11 /**
12 * Class WP_Data_Access_Switch
13 *
14 * Switch to:
15 * + activate plugin {@see WP_Data_Access_Switch::activate()}
16 * + deactive plugin {@see WP_Data_Access_Switch::deactivate()}
17 *
18 * @package plugin\includes
19 * @author Peter Schulz
20 * @since 1.0.0
21 *
22 * @see WP_Data_Access_Switch::activate()
23 * @see WP_Data_Access_Switch::deactivate()
24 */
25 class WP_Data_Access_Switch {
26
27 /**
28 * Activate plugin WP Data Access
29 *
30 * The user must have the appropriate privileges to perform this operation.
31 *
32 * For single site installation {@see WP_Data_Access_Switch::activate_blog()} will be called. For multi site
33 * installations {@see WP_Data_Access_Switch::activate_blog()} must be called for every blog.
34 *
35 * IMPORTANT!!!
36 *
37 * For blogs installed on multi site installations after activation of the plugin, activation of the plugin for
38 * that blog will not be performed if the plugin is network activated. In that case the admin user of the blog
39 * will receive a message when viewing a plugin page with an option to follow these steps manually.
40 *
41 * @since 1.0.0
42 *
43 * @see WP_Data_Access_Switch::activate_blog()
44 */
45 public static function activate() {
46 if ( current_user_can( 'activate_plugins' ) ) {
47 // Activate plugin.
48 if ( is_multisite() ) {
49 global $wpdb;
50 // Multisite installation.
51 $blogids = $wpdb->get_col( "select blog_id from $wpdb->blogs" ); // db call ok; no-cache ok.
52 foreach ( $blogids as $blog_id ) {
53 // Uninstall blog.
54 switch_to_blog( $blog_id );
55 self::activate_blog();
56 restore_current_blog();
57 }
58 } else {
59 // Single site installation.
60 self::activate_blog();
61 }
62 } else {
63 // Is this blocking the site on unattended plugin update? (support topic 11472418 - tjgorman)
64 // wp_die( esc_html__( 'ERROR: Not authorized', 'wp-data-access' ) );
65 }
66 }
67
68 /**
69 * Activate blog
70 *
71 * The user must have the appropriate privileges to perform this operation.
72 *
73 * On activation this method checks whether there has previously been a version of the plugin installed. For this
74 * purpose the wp_options table read directly (usually done via class WPDA). If a value is found, this method
75 * checks if the version number in wp_options is the same as the plugin version. If these are equal, no action is
76 * needed. If they are not equal, this method will check if there is an upgrade or downgrade for the delta
77 * between these releases.
78 *
79 * This action is performed on the 'active WordPress blog'. On single site there is only one blog. On multisite
80 * installations it must be executed for every blog.
81 *
82 * On a fresh installation the following actions are performed:
83 * + save plugin version number in wp_options {@see WPDA::set_option()}
84 * + (re)create plugin repository {@see WPDA_Repository::recreate()}
85 *
86 * @since 1.0.0
87 *
88 * @see WPDA::set_option()
89 * @see WPDA_Repository::create()
90 */
91 protected static function activate_blog() {
92 if ( current_user_can( 'activate_plugins' ) ) {
93 // (re)create plugin repository
94 // If no repository is found, a new one is created
95 // If a repository is found, the table structures are update and the data transferred
96 $wpda_repository = new WPDA_Repository();
97 $wpda_repository->recreate();
98
99 // Save plugin version
100 WPDA::set_option( WPDA::OPTION_WPDA_VERSION );
101
102 // Show link to "What's New?" page on plugin pages in WordPress dashboard.
103 WPDA::set_option( WPDA::OPTION_WPDA_SHOW_WHATS_NEW, 'on' );
104 } else {
105 // Is this blocking the site on unattended plugin update? (support topic 11472418 - tjgorman)
106 // wp_die( esc_html__( 'ERROR: Not authorized', 'wp-data-access' ) );
107 }
108 }
109
110 /**
111 * Deactivate plugin WP Data Access
112 *
113 * On deactivation we leave the repository and options as they are in case the user wants to reactivate the
114 * plugin later again. Tables and options are deleted when the plugin is uninstalled. To keep tables and options
115 * on uninstall change plugin settings (see uninstall settings).
116 *
117 * @since 1.0.0
118 */
119 public static function deactivate() {
120 if ( ! current_user_can( 'activate_plugins' ) ) {
121 // Is this blocking the site on unattended plugin update? (support topic 11472418 - tjgorman)
122 // wp_die( esc_html__( 'ERROR: Not authorized', 'wp-data-access' ) );
123 }
124 }
125
126 }
127