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.84 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 All 160 releases
← All changes | includes/class-wp-data-access-switch.php +98 -132 5.5.42.0.13 View file →
@@ -1,22 +1,14 @@
1 1 <?php
2 -
3 2 /**
4 3 * Suppress "error - 0 - No summary was found for this file" on phpdoc generation
5 4 *
6 5 * @package plugin\includes
7 6 */
8 -use WPDataAccess\Plugin_Table_Models\WPDA_Design_Table_Model;
9 -use WPDataAccess\Plugin_Table_Models\WPDA_Logging_Model;
10 -use WPDataAccess\Plugin_Table_Models\WPDA_Media_Model;
11 -use WPDataAccess\Plugin_Table_Models\WPDA_Publisher_Model;
12 -use WPDataAccess\Plugin_Table_Models\WPDA_Table_Settings_Model;
13 -use WPDataAccess\Plugin_Table_Models\WPDA_User_Menus_Model;
14 -use WPDataAccess\Plugin_Table_Models\WPDP_Page_Model;
15 -use WPDataAccess\Plugin_Table_Models\WPDP_Project_Model;
16 -use WPDataAccess\Plugin_Table_Models\WPDP_Project_Design_Table_Model;
7 +
17 8 use WPDataAccess\Utilities\WPDA_Repository;
18 9 use WPDataAccess\WPDA;
10 +
19 11 /**
20 12 * Class WP_Data_Access_Switch
21 13 *
22 14 * Switch to:
@@ -22,8 +14,9 @@
22 14 * Switch to:
23 15 * + activate plugin {@see WP_Data_Access_Switch::activate()}
24 16 * + deactive plugin {@see WP_Data_Access_Switch::deactivate()}
25 17 *
18 + * @package plugin\includes
26 19 * @author Peter Schulz
27 20 * @since 1.0.0
28 21 *
29 22 * @see WP_Data_Access_Switch::activate()
@@ -29,132 +22,105 @@
29 22 * @see WP_Data_Access_Switch::activate()
30 23 * @see WP_Data_Access_Switch::deactivate()
31 24 */
32 25 class WP_Data_Access_Switch {
33 - /**
34 - * Activate plugin WP Data Access
35 - *
36 - * The user must have the appropriate privileges to perform this operation.
37 - *
38 - * For single site installation {@see WP_Data_Access_Switch::activate_blog()} will be called. For multi site
39 - * installations {@see WP_Data_Access_Switch::activate_blog()} must be called for every blog.
40 - *
41 - * IMPORTANT!!!
42 - *
43 - * For blogs installed on multi site installations after activation of the plugin, activation of the plugin for
44 - * that blog will not be performed if the plugin is network activated. In that case the admin user of the blog
45 - * will receive a message when viewing a plugin page with an option to follow these steps manually.
46 - *
47 - * @since 1.0.0
48 - *
49 - * @see WP_Data_Access_Switch::activate_blog()
50 - */
51 - public static function activate() {
52 - if ( current_user_can( 'activate_plugins' ) ) {
53 - // Activate plugin.
54 - if ( is_multisite() ) {
55 - global $wpdb;
56 - // Multisite installation.
57 - $blogids = $wpdb->get_col( "select blog_id from {$wpdb->blogs}" );
58 - // db call ok; no-cache ok.
59 - foreach ( $blogids as $blog_id ) {
60 - // Activate blog.
61 - switch_to_blog( $blog_id );
62 - self::activate_blog();
63 - restore_current_blog();
64 - }
65 - } else {
66 - // Single site installation.
67 - self::activate_blog();
68 - }
69 - }
70 - }
71 26
72 - /**
73 - * Activate blog
74 - *
75 - * The user must have the appropriate privileges to perform this operation.
76 - *
77 - * On activation this method checks whether there has previously been a version of the plugin installed. For this
78 - * purpose the wp_options table read directly (usually done via class WPDA). If a value is found, this method
79 - * checks if the version number in wp_options is the same as the plugin version. If these are equal, no action is
80 - * needed. If they are not equal, this method will check if there is an upgrade or downgrade for the delta
81 - * between these releases.
82 - *
83 - * This action is performed on the 'active WordPress blog'. On single site there is only one blog. On multisite
84 - * installations it must be executed for every blog.
85 - *
86 - * On a fresh installation the following actions are performed:
87 - * + save plugin version number in wp_options {@see WPDA::set_option()}
88 - * + (re)create plugin repository {@see WPDA_Repository::recreate()}
89 - *
90 - * @since 1.0.0
91 - *
92 - * @see WPDA::set_option()
93 - * @see WPDA_Repository::create()
94 - */
95 - protected static function activate_blog() {
96 - if ( current_user_can( 'activate_plugins' ) ) {
97 - if ( get_option( WPDataAccess\WPDA::OPTION_WPDA_VERSION[0] ) !== WPDataAccess\WPDA::OPTION_WPDA_VERSION[1] ) {
98 - self::recreate_repository();
99 - } elseif ( !WPDA_User_Menus_Model::table_exists() || !WPDA_Design_Table_Model::table_exists() || !WPDP_Project_Design_Table_Model::table_exists() || !WPDA_Publisher_Model::table_exists() || !WPDA_Logging_Model::table_exists() || !WPDA_Media_Model::table_exists() || !WPDP_Project_Model::table_exists() || !WPDP_Page_Model::table_exists() || !WPDA_Table_Settings_Model::table_exists() ) {
100 - self::recreate_repository();
101 - }
102 - if ( wpda_freemius()->is_free_plan() ) {
103 - update_option( 'wpda_fulltext_support', 'off' );
104 - }
105 - self::flush_rewrite_rules();
106 - }
107 - }
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 + }
108 67
109 - /**
110 - * (re)create plugin repository
111 - *
112 - * If no repository is found, a new one is created
113 - * If a repository is found, the table structures are update and the data transferred
114 - */
115 - protected static function recreate_repository() {
116 - $wpda_repository = new WPDA_Repository();
117 - $wpda_repository->recreate();
118 - // Save (new) plugin version.
119 - WPDA::set_option( WPDA::OPTION_WPDA_VERSION );
120 - // Create content folder to store CSV and cache files.
121 - WPDA::wpda_create_content_folder();
122 - // Generate new sonce seed on every update.
123 - WPDA::set_option( WPDA::OPTION_PLUGIN_SONCE_SEED, bin2hex( openssl_random_pseudo_bytes( wp_rand( 40, 60 ) ) ) );
124 - WPDA::set_option( WPDA::OPTION_WPDA_UPGRADED, true );
125 - }
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();
126 98
127 - /**
128 - * Deactivate plugin WP Data Access
129 - *
130 - * On deactivation we leave the repository and options as they are in case the user wants to reactivate the
131 - * plugin later again. Tables and options are deleted when the plugin is uninstalled. To keep tables and options
132 - * on uninstall change plugin settings (see uninstall settings).
133 - *
134 - * @since 1.0.0
135 - */
136 - public static function deactivate() {
137 - if ( current_user_can( 'activate_plugins' ) ) {
138 - // Deactivate plugin.
139 - if ( is_multisite() ) {
140 - global $wpdb;
141 - // Multisite installation.
142 - $blogids = $wpdb->get_col( "select blog_id from {$wpdb->blogs}" );
143 - // db call ok; no-cache ok.
144 - foreach ( $blogids as $blog_id ) {
145 - // Deactivate blog.
146 - switch_to_blog( $blog_id );
147 - self::flush_rewrite_rules();
148 - restore_current_blog();
149 - }
150 - } else {
151 - // Single site installation.
152 - self::flush_rewrite_rules();
153 - }
154 - }
155 - }
99 + // Save plugin version
100 + WPDA::set_option( WPDA::OPTION_WPDA_VERSION );
156 101
157 - private static function flush_rewrite_rules() {
158 - }
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 + }
159 125
160 126 }