PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.2
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.2
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 5.2, at includes/class-wp-data-access-switch.php

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