PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.2.1
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.2.1
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 5.5.45 All 158 releases
wp-data-access / wp-data-access.php

wp-data-access.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.2.1, at wp-data-access.php

280 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: WP Data Access
5 * Plugin URI: https://wpdataaccess.com/
6 * Description: Local and remote data administration, publication and app development tool available directly from the WordPress dashboard.
7 * Version: 5.2.1
8 * Author: Passionate Programmers B.V.
9 * Author URI: https://wpdataaccess.com/
10 * Text Domain: wp-data-access
11 * License: GPL-2.0+
12 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
13 * Domain Path: /languages
14 *
15 *
16 * @package plugin
17 * @author Peter Schulz
18 * @since 1.0.0
19 */
20 use WPDataAccess\WPDA ;
21 if ( !defined( 'WPINC' ) ) {
22 die;
23 }
24 if ( !defined( 'ABSPATH' ) ) {
25 exit;
26 }
27 // Add freemius to WP Data Access.
28
29 if ( function_exists( 'wpda_freemius' ) ) {
30 wpda_freemius()->set_basename( false, __FILE__ );
31 } else {
32 // Load WPDataAccess namespace.
33 require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
34 /**
35 * Create a helper function for easy SDK access
36 *
37 * @return Freemius
38 */
39 function wpda_freemius()
40 {
41 global $wpda_freemius ;
42
43 if ( !isset( $wpda_freemius ) ) {
44 // Include Freemius SDK.
45 require_once dirname( __FILE__ ) . '/freemius/start.php';
46 $wpda_freemius = fs_dynamic_init( array(
47 'id' => '6189',
48 'slug' => 'wp-data-access',
49 'type' => 'plugin',
50 'public_key' => 'pk_fc2d1714ca61c930152f6e326b575',
51 'is_premium' => false,
52 'premium_suffix' => 'Premium',
53 'has_addons' => false,
54 'has_paid_plans' => true,
55 'trial' => array(
56 'days' => 14,
57 'is_require_payment' => false,
58 ),
59 'menu' => array(
60 'slug' => 'wpda',
61 'contact' => false,
62 'network' => true,
63 ),
64 'is_live' => true,
65 ) );
66 }
67
68 return $wpda_freemius;
69 }
70
71 // Init Freemius.
72 wpda_freemius();
73 // Signal that SDK was initiated.
74 do_action( 'wpda_freemius_loaded' );
75 /**
76 * Change plugin settings info
77 *
78 * @param mixed $links Links.
79 * @param mixed $file File.
80 * @return mixed
81 */
82 function wpda_row_meta( $links, $file )
83 {
84
85 if ( strpos( $file, plugin_basename( __FILE__ ) ) !== false ) {
86 // Add settings link.
87 $settings_url = admin_url( 'options-general.php' ) . '?page=wpdataaccess';
88 $settings_link = "<a href='{$settings_url}'>Settings</a>";
89 array_push( $links, $settings_link );
90 }
91
92 return $links;
93 }
94
95 add_filter(
96 'plugin_row_meta',
97 'wpda_row_meta',
98 10,
99 2
100 );
101 /**
102 * Activate plugin
103 *
104 * @author Peter Schulz
105 * @since 1.0.0
106 */
107 function activate_wp_data_access()
108 {
109 require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-data-access-switch.php';
110 WP_Data_Access_Switch::activate();
111 }
112
113 register_activation_hook( __FILE__, 'activate_wp_data_access' );
114 /**
115 * Deactivate plugin
116 *
117 * @author Peter Schulz
118 * @since 1.0.0
119 */
120 function deactivate_wp_data_access()
121 {
122 require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-data-access-switch.php';
123 WP_Data_Access_Switch::deactivate();
124 }
125
126 register_deactivation_hook( __FILE__, 'deactivate_wp_data_access' );
127 /**
128 * Check if database needs to be updated
129 *
130 * @author Peter Schulz
131 * @since 1.5.2
132 */
133 function wpda_update_db_check()
134 {
135 if ( get_option( WPDataAccess\WPDA::OPTION_WPDA_VERSION[0] ) !== WPDataAccess\WPDA::OPTION_WPDA_VERSION[1] ) {
136 activate_wp_data_access();
137 }
138 }
139
140 add_action( 'plugins_loaded', 'wpda_update_db_check' );
141 /**
142 * Uninstall blog
143 *
144 * This functions is called when the plugin is uninstalled. The following actions are performed:
145 * + Drop plugin tables (unless settings indicate not to)
146 * + Delete plugin options from $wpdb->options (unless settings indicate not to)
147 *
148 * Actions are processed on the current blog and are repeated for every blog on a multisite installation. Must be
149 * called from the dashboard (WP_UNINSTALL_PLUGIN defined). User must have the proper privileges (activate_plugins).
150 *
151 * @author Peter Schulz
152 * @since 1.0.0
153 */
154 function wpda_uninstall_blog()
155 {
156 global $wpdb ;
157 $drop_tables = get_option( 'wpda_uninstall_tables' );
158
159 if ( 'on' === $drop_tables ) {
160 // Get all plugin table names (without WP prefix).
161 $plugin_tables = WPDataAccess\WPDA::get_wpda_tables();
162 foreach ( $plugin_tables as $plugin_table ) {
163 // Loop through plugin tables.
164 // Drop plugin table.
165 $wpdb->query( $wpdb->prepare(
166 'DROP TABLE IF EXISTS `%1s`',
167 // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders, WordPress.DB.DirectDatabaseQuery.SchemaChange
168 WPDataAccess\WPDA::remove_backticks( $plugin_table )
169 ) );
170 // db call ok; no-cache ok.
171 // Get plugin backup tables (if applicable).
172 $backup_tables = $wpdb->get_results( $wpdb->prepare( '
173 select table_name as table_name from information_schema.tables
174 where table_schema = %s
175 and table_name like %s
176 ', array( $wpdb->dbname, "{$plugin_table}_BACKUP_%" ) ), 'ARRAY_A' );
177 // db call ok; no-cache ok.
178 foreach ( $backup_tables as $backup_table ) {
179 // Drop plugin backup table.
180 $wpdb->query( $wpdb->prepare(
181 'DROP TABLE IF EXISTS `%1s`',
182 // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders, WordPress.DB.DirectDatabaseQuery.SchemaChange
183 WPDataAccess\WPDA::remove_backticks( $backup_table['table_name'] )
184 ) );
185 // db call ok; no-cache ok.
186 }
187 }
188 }
189
190 $delete_options = get_option( 'wpda_uninstall_options' );
191
192 if ( 'on' === $delete_options ) {
193 // Delete all options from wp_options.
194 $wpdb->query( "\n\t\t\t\t\tDELETE FROM {$wpdb->options}\n\t\t\t\t\tWHERE option_name LIKE 'wpda%'\n\t\t\t\t" );
195 // db call ok; no-cache ok.
196 $wpdb->query( "\n\t\t\t\t\tDELETE FROM {$wpdb->usermeta}\n\t\t\t\t\tWHERE meta_key LIKE 'wpda%'\n\t\t\t\t\t OR meta_key LIKE '%wp-data-access%'\n\t\t\t\t" );
197 // db call ok; no-cache ok.
198 }
199
200 }
201
202 /**
203 * Uninstall WP Data Access tables, options and meta keys
204 *
205 * @return void
206 */
207 function wpda_uninstall()
208 {
209
210 if ( is_multisite() ) {
211 global $wpdb ;
212 // Uninstall plugin for alll blogs one by one (will fail silently for blogs having no plugin tables/options).
213 $blogids = $wpdb->get_col( "select blog_id from {$wpdb->blogs}" );
214 // db call ok; no-cache ok.
215 foreach ( $blogids as $blog_id ) {
216 // Uninstall blog.
217 switch_to_blog( $blog_id );
218 wpda_uninstall_blog();
219 restore_current_blog();
220 }
221 } else {
222 // Uninstall on single site installation.
223 wpda_uninstall_blog();
224 }
225
226 WPDA::wpda_delete_content_folder();
227 }
228
229 wpda_freemius()->add_action( 'after_uninstall', 'wpda_uninstall' );
230 /**
231 * Add WP Data Access icon to freemius
232 *
233 * @return string
234 */
235 function wpda_freemius_icon()
236 {
237 return dirname( __FILE__ ) . '/freemius/assets/img/wpda.png';
238 }
239
240 wpda_freemius()->add_filter( 'plugin_icon', 'wpda_freemius_icon' );
241 /**
242 * Handle freemius menu items
243 *
244 * @param boolean $is_visible Visibility.
245 * @param string $submenu_id Sub menu ID.
246 * @return false|mixed
247 */
248 function wpda_freemius_menu_visible( $is_visible, $submenu_id )
249 {
250 // Support, account, contact, pricing.
251 if ( 'dashboard' === WPDA::get_option( WPDA::OPTION_PLUGIN_NAVIGATION ) ) {
252 if ( 'support' === $submenu_id || 'account' === $submenu_id ) {
253 $is_visible = false;
254 }
255 }
256 return $is_visible;
257 }
258
259 wpda_freemius()->add_filter(
260 'is_submenu_visible',
261 'wpda_freemius_menu_visible',
262 10,
263 2
264 );
265 /**
266 * Start plugin
267 *
268 * @author Peter Schulz
269 * @since 1.0.0
270 */
271 function run_wp_data_access()
272 {
273 require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-data-access.php';
274 $wpdataaccess = new WP_Data_Access();
275 $wpdataaccess->run();
276 }
277
278 run_wp_data_access();
279 }
280