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

161 lines 6.5 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 * 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
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 }
108
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 }
126
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 }
156
157 private static function flush_rewrite_rules() {
158 }
159
160 }
161