PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.84
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.84
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.php +135 -53 5.5.355.5.84 View file →
@@ -8,9 +8,9 @@
8 8 use WPDataAccess\Connection\WPDADB;
9 9 use WPDataAccess\Cookies\WPDA_Cookies;
10 10 use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Lists;
11 11 use WPDataAccess\Data_Tables\WPDA_Data_Tables;
12 -use WPDataAccess\Utilities\WPDA_Table_Actions;
12 +use WPDataAccess\Plugin_Table_Models\WPDA_Table_Settings_Model;
13 13 use WPDataAccess\Utilities\WPDA_Export;
14 14 use WPDataAccess\Utilities\WPDA_Favourites;
15 15 use WPDataAccess\WPDA;
16 16 use WPDataProjects\Utilities\WPDP_Export_Project;
@@ -19,9 +19,8 @@
19 19 use WPDataRoles\WPDA_Roles;
20 20 use WPDataAccess\Utilities\WPDA_Autocomplete;
21 21 use WPDataAccess\Premium\WPDAPRO_Geo_Location\WPDAPRO_Geo_Location_WS;
22 22 use WPDataAccess\Premium\WPDAPRO_Geo_Location\WPDAPRO_Geo_Location;
23 -use WPDataAccess\Query_Builder\WPDA_Query_Builder;
24 23 use WPDataAccess\Dashboard\WPDA_Dashboard;
25 24 use WPDataAccess\Dashboard\WPDA_Widget_Code;
26 25 use WPDataAccess\Dashboard\WPDA_Widget_Publication;
27 26 use WPDataAccess\Dashboard\WPDA_Widget_Dbms;
@@ -43,8 +42,9 @@
43 42 * @see WP_Data_Access_Public
44 43 * @see WP_Data_Access_I18n
45 44 * @see WP_Data_Access_Loader
46 45 */
46 +// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- verified on page
47 47 class WP_Data_Access {
48 48 /**
49 49 * Reference to plugin loader
50 50 *
@@ -80,11 +80,9 @@
80 80 * @see WP_Data_Access::define_public_hooks()
81 81 */
82 82 public function __construct() {
83 83 if ( isset( $_REQUEST['page'] ) ) {
84 - // phpcs:ignore WordPress.Security.NonceVerification
85 84 $this->page = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) );
86 - // phpcs:ignore WordPress.Security.NonceVerification
87 85 }
88 86 $this->load_dependencies();
89 87 $this->set_locale();
90 88 $this->define_admin_hooks();
@@ -152,14 +150,8 @@
152 150 $this->loader->add_action( 'admin_init', $wpda_cookies, 'handle_plugin_cookies' );
153 151 }
154 152 // Admin menu.
155 153 $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_menu_items' );
156 - $this->loader->add_action(
157 - 'admin_menu',
158 - $plugin_admin,
159 - 'add_menu_my_tables',
160 - 11
161 - );
162 154 $this->loader->add_filter( 'submenu_file', $plugin_admin, 'wpda_submenu_filter' );
163 155 // Admin scripts.
164 156 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
165 157 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
@@ -166,17 +158,53 @@
166 158 $this->loader->add_action( 'in_admin_header', $plugin_admin, 'user_admin_notices' );
167 159 $this->loader->add_action( 'admin_head', $plugin_admin, 'remove_icons' );
168 160 // Add settings page.
169 161 $this->loader->add_action( 'admin_menu', $this, 'wpdataaccess_register_settings_page' );
170 - // Query Builder.
171 - $query_builder = new WPDA_Query_Builder();
172 - $this->loader->add_action( 'admin_action_wpda_query_builder_execute_sql', $query_builder, 'execute' );
173 - $this->loader->add_action( 'admin_action_wpda_query_builder_save_sql', $query_builder, 'save' );
174 - $this->loader->add_action( 'admin_action_wpda_query_builder_open_sql', $query_builder, 'open' );
175 - $this->loader->add_action( 'admin_action_wpda_query_builder_delete_sql', $query_builder, 'delete' );
176 - $this->loader->add_action( 'admin_action_wpda_query_builder_get_db_hints', $query_builder, 'get_db_hints' );
177 - $this->loader->add_action( 'admin_action_wpda_query_builder_set_db_hints', $query_builder, 'set_db_hints' );
178 - $this->loader->add_action( 'admin_action_wpda_query_builder_get_vqb', $query_builder, 'get_visual_query' );
162 + // Run unattended scheduled export
163 + $this->loader->add_action( \WPDataAccess\Utilities\WPDA_Export_Scheduler::SCHEDULER_HOOK_NAME, \WPDataAccess\Utilities\WPDA_Export_Scheduler::class, 'run_scheduled_export' );
164 + // Mail service.
165 + $wpda_mail_server = \WPDataAccess\Utilities\WPDA_Mail::get_option();
166 + if ( isset(
167 + $wpda_mail_server['host'],
168 + $wpda_mail_server['port'],
169 + $wpda_mail_server['authenticate'],
170 + $wpda_mail_server['encryption'],
171 + $wpda_mail_server['skip_verify'],
172 + $wpda_mail_server['username'],
173 + $wpda_mail_server['password']
174 + ) ) {
175 + add_action(
176 + 'phpmailer_init',
177 + function ( $phpmailer ) use($wpda_mail_server) {
178 + // Only run if mail WPDA requests.
179 + if ( !did_action( 'wpda_sending_mail' ) ) {
180 + return;
181 + // Allow other plugins/themes to overwrite.
182 + }
183 + $phpmailer->isSMTP();
184 + $phpmailer->isHTML( false );
185 + $phpmailer->SMTPDebug = $wpda_mail_server['debug'] ?? 0;
186 + $phpmailer->Host = $wpda_mail_server['host'];
187 + $phpmailer->Port = $wpda_mail_server['port'];
188 + $phpmailer->SMTPAuth = 'on' === $wpda_mail_server['authenticate'];
189 + $phpmailer->SMTPSecure = $wpda_mail_server['encryption'];
190 + if ( 'on' === $wpda_mail_server['skip_verify'] ) {
191 + $phpmailer->SMTPOptions = array(
192 + 'ssl' => array(
193 + 'verify_peer' => false,
194 + 'verify_peer_name' => false,
195 + 'allow_self_signed' => true,
196 + ),
197 + );
198 + }
199 + $phpmailer->Username = $wpda_mail_server['username'];
200 + $phpmailer->Password = $wpda_mail_server['password'];
201 + $phpmailer->From = $wpda_mail_server['username'];
202 + },
203 + 10,
204 + 1
205 + );
206 + }
179 207 // Export action.
180 208 $this->loader->add_action( 'admin_action_wpda_export', WPDA_Export::class, 'export' );
181 209 // Dashboard and widgets.
182 210 $this->loader->add_action( 'wp_ajax_wpda_save_dashboard', WPDA_Dashboard::class, 'save' );
@@ -190,14 +218,12 @@
190 218 $this->loader->add_action( 'wp_ajax_wpda_widget_pub_add', WPDA_Widget_Publication::class, 'ajax_widget' );
191 219 $this->loader->add_action( 'wp_ajax_wpda_widget_chart_add', WPDA_Widget_Google_Chart::class, 'ajax_widget' );
192 220 $this->loader->add_action( 'wp_ajax_wpda_widget_chart_refresh', WPDA_Widget_Google_Chart::class, 'ajax_refresh' );
193 221 // Add/remove favourites.
222 + // ???
194 223 $plugin_favourites = new WPDA_Favourites();
195 224 $this->loader->add_action( 'admin_action_wpda_add_favourite', $plugin_favourites, 'add' );
196 225 $this->loader->add_action( 'admin_action_wpda_rem_favourite', $plugin_favourites, 'rem' );
197 - // Show tables actions.
198 - $plugin_table_actions = new WPDA_Table_Actions();
199 - $this->loader->add_action( 'admin_action_wpda_show_table_actions', $plugin_table_actions, 'show' );
200 226 $plugin_dictionary_list = new WPDA_Dictionary_Lists();
201 227 // Get tables for a specific database.
202 228 $this->loader->add_action( 'admin_action_wpda_get_tables', $plugin_dictionary_list, 'get_tables_ajax' );
203 229 // Get columns for a specific table.
@@ -204,9 +230,9 @@
204 230 $this->loader->add_action( 'admin_action_wpda_get_columns', $plugin_dictionary_list, 'get_columns' );
205 231 // Get row count for a specific table.
206 232 $this->loader->add_action( 'admin_action_wpda_get_table_row_count', $plugin_dictionary_list, 'get_table_row_count_ajax' );
207 233 // Get table widget info.
208 - $this->loader->add_action( 'admin_action_wpda_get_table_widget_info', $plugin_dictionary_list, 'get_table_widget_info' );
234 + $this->loader->add_action( 'admin_action_wpda_get_table_widget_info', $plugin_dictionary_list, 'get_table_widget_info_ajax' );
209 235 // Global database search and replace.
210 236 $this->loader->add_action( 'wp_ajax_wpda_global_search', \WPDataAccess\Global_Search\WPDA_Global_Search::class, 'search' );
211 237 $this->loader->add_action( 'wp_ajax_wpda_global_replace', \WPDataAccess\Global_Search\WPDA_Global_Search::class, 'replace' );
212 238 // Export project.
@@ -241,27 +267,24 @@
241 267 'wp_ajax_wpda_dbinit_admin',
242 268 function () {
243 269 if ( !isset( $_POST['wpnonce'], $_POST['wpdaschema_name'] ) ) {
244 270 WPDA::sent_header( 'application/json' );
245 - echo WPDA::sent_msg( 'ERROR', 'Invalid arguments' );
246 - // phpcs:ignore WordPress.Security.EscapeOutput
271 + WPDA::sent_msg( 'ERROR', 'Invalid arguments' );
247 272 wp_die();
248 273 }
274 + // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotValidated
249 275 $wpnonce = sanitize_text_field( wp_unslash( $_REQUEST['wpnonce'] ) );
250 - // input var okay.
251 276 if ( !WPDA::current_user_is_admin() || !wp_verify_nonce( $wpnonce, 'wpda_dbinit_admin_' . WPDA::get_current_user_login() ) ) {
252 277 WPDA::sent_header( 'application/json' );
253 - echo WPDA::sent_msg( 'ERROR', 'Not authorized' );
254 - // phpcs:ignore WordPress.Security.EscapeOutput
278 + WPDA::sent_msg( 'ERROR', 'Not authorized' );
255 279 wp_die();
256 280 }
257 281 $wpdaschema_name = sanitize_text_field( wp_unslash( $_REQUEST['wpdaschema_name'] ) );
258 - // input var okay.
282 + // phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotValidated
259 283 $wpdadb = WPDADB::get_db_connection( $wpdaschema_name );
260 284 if ( null === $wpdadb ) {
261 285 WPDA::sent_header( 'application/json' );
262 - echo WPDA::sent_msg( 'ERROR', 'Cannot connect to database' );
263 - // phpcs:ignore WordPress.Security.EscapeOutput
286 + WPDA::sent_msg( 'ERROR', 'Cannot connect to database' );
264 287 wp_die();
265 288 }
266 289 $suppress_errors = $wpdadb->suppress_errors( true );
267 290 $wpdadb->query( 'create function wpda_get_wp_user_id() returns integer deterministic no sql return @wpda_wp_user_id' );
@@ -267,14 +290,12 @@
267 290 $wpdadb->query( 'create function wpda_get_wp_user_id() returns integer deterministic no sql return @wpda_wp_user_id' );
268 291 $error = $wpdadb->last_error;
269 292 $wpdadb->suppress_errors( $suppress_errors );
270 293 if ( '' === $error ) {
271 - //phpcs:ignore - 8.1 proof
272 - echo WPDA::sent_msg( 'OK', '' );
273 - // phpcs:ignore WordPress.Security.EscapeOutput
294 + // phpcs:ignore -- 8.1 proof
295 + WPDA::sent_msg( 'OK', '' );
274 296 } else {
275 - echo WPDA::sent_msg( 'ERROR', "Function not created [{$error}]" );
276 - // phpcs:ignore WordPress.Security.EscapeOutput
297 + WPDA::sent_msg( 'ERROR', "Function not created [{$error}]" );
277 298 }
278 299 wp_die();
279 300 },
280 301 10,
@@ -323,8 +344,32 @@
323 344 },
324 345 10,
325 346 1
326 347 );
348 + add_action(
349 + 'wpda_set_hard_row_count',
350 + function ( $dbs, $tbl ) {
351 + // Only admins and super admins.
352 + if ( WPDA::current_user_is_admin() ) {
353 + // Get actual row count.
354 + $count = \WPDataAccess\API\WPDA_Actions::get_row_count( $dbs, $tbl );
355 + // Get table settings.
356 + $settings_db = WPDA_Table_Settings_Model::query( $tbl, $dbs );
357 + if ( isset( $settings_db[0]['wpda_table_settings'] ) ) {
358 + // Convert string to JSON.
359 + $settings = json_decode( $settings_db[0]['wpda_table_settings'], true );
360 + if ( isset( $settings['table_settings']['row_count_estimate_value_hard'] ) ) {
361 + // Store actual row count as hard estimate.
362 + $settings['table_settings']['row_count_estimate_value_hard'] = $count;
363 + // Save new hard row count.
364 + WPDA_Table_Settings_Model::update( $tbl, json_encode( $settings ), $dbs );
365 + }
366 + }
367 + }
368 + },
369 + 10,
370 + 2
371 + );
327 372 }
328 373
329 374 /**
330 375 * Needed for JDT to support IE
@@ -335,10 +380,11 @@
335 380 * @return mixed|string
336 381 */
337 382 public function add_id_to_script( $tag, $handle, $src ) {
338 383 if ( 'wpda_datatables' === $handle ) {
384 + // phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript
339 385 $tag = '<script id="wpda_datatables" src="' . $src . '"></script>';
340 - // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
386 + // phpcs:enable WordPress.WP.EnqueuedResources.NonEnqueuedScript
341 387 }
342 388 return $tag;
343 389 }
344 390
@@ -400,11 +446,49 @@
400 446 *
401 447 * @since 1.0.0
402 448 */
403 449 public function run() {
450 + $this->loader->add_action( 'init', $this, 'register_blocks' );
451 + $this->loader->add_action( 'enqueue_block_assets', $this, 'enqueue_block_assets' );
404 452 $this->loader->run();
405 453 }
406 454
455 + public function register_blocks() {
456 + register_block_type( plugin_dir_path( dirname( __FILE__ ) ) . 'assets/gtb', array(
457 + 'render_callback' => array($this, 'render_wp_data_access_app_block'),
458 + ) );
459 + }
460 +
461 + public function enqueue_block_assets() {
462 + wp_enqueue_style( 'dashicons' );
463 + }
464 +
465 + public function render_wp_data_access_app_block( $attributes ) {
466 + $appid = ( isset( $attributes['appid'] ) ? sanitize_text_field( $attributes['appid'] ) : '' );
467 + $feedback = filter_var( $attributes['feedback'] ?? false, FILTER_VALIDATE_BOOLEAN );
468 + $builders = filter_var( $attributes['builders'] ?? false, FILTER_VALIDATE_BOOLEAN );
469 + $hidetitlebar = filter_var( $attributes['hidetitlebar'] ?? false, FILTER_VALIDATE_BOOLEAN );
470 + $fullscreen = filter_var( $attributes['fullscreen'] ?? false, FILTER_VALIDATE_BOOLEAN );
471 + if ( empty( $appid ) ) {
472 + return null;
473 + }
474 + if ( !shortcode_exists( 'wpda_app' ) ) {
475 + return 'Shortcode wpda_app is not registered.';
476 + }
477 + $shortcode = sprintf(
478 + '[wpda_app app_id="%s" builders="%s" feedback="%s" hidetitlebar="%s" fullscreen="%s"]',
479 + esc_attr( $appid ),
480 + ( $builders ? 'false' : 'true' ),
481 + ( $feedback ? 'true' : 'false' ),
482 + ( $hidetitlebar ? 'true' : 'false' ),
483 + ( $fullscreen ? 'true' : 'false' )
484 + );
485 + $wrapper_attributes = get_block_wrapper_attributes( array(
486 + 'class' => 'wpda-wp-data-access-app',
487 + ) );
488 + return sprintf( '<div %s>%s</div>', $wrapper_attributes, do_shortcode( $shortcode ) );
489 + }
490 +
407 491 /**
408 492 * Add plugin settings page
409 493 */
410 494 public function wpdataaccess_register_settings_page() {
@@ -422,10 +506,12 @@
422 506 */
423 507 public function wpdataaccess_settings_page() {
424 508 WPDA_Dashboard::add_dashboard();
425 509 $current_tab = ( isset( $_REQUEST['tab'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) ) : 'plugin' );
426 - // phpcs:ignore WordPress.Security.NonceVerification
427 510 switch ( $current_tab ) {
511 + case 'apps':
512 + $wpda_settings_class_name = 'WPDA_Settings_Apps';
513 + break;
428 514 case 'backend':
429 515 $wpda_settings_class_name = 'WPDA_Settings_BackEnd';
430 516 break;
431 517 case 'frontend':
@@ -433,20 +519,8 @@
433 519 break;
434 520 case 'pds':
435 521 $wpda_settings_class_name = 'WPDA_Settings_PDS';
436 522 break;
437 - case 'dashboard':
438 - $wpda_settings_class_name = 'WPDA_Settings_Dashboard';
439 - break;
440 - case 'datatables':
441 - $wpda_settings_class_name = 'WPDA_Settings_DataTables';
442 - break;
443 - case 'dataforms':
444 - $wpda_settings_class_name = 'WPDA_Settings_DataForms';
445 - break;
446 - case 'databackup':
447 - $wpda_settings_class_name = 'WPDA_Settings_DataBackup';
448 - break;
449 523 case 'uninstall':
450 524 $wpda_settings_class_name = 'WPDA_Settings_Uninstall';
451 525 break;
452 526 case 'repository':
@@ -451,14 +525,20 @@
451 525 break;
452 526 case 'repository':
453 527 $wpda_settings_class_name = 'WPDA_Settings_ManageRepository';
454 528 break;
455 - case 'roles':
456 - $wpda_settings_class_name = 'WPDA_Settings_ManageRoles';
457 - break;
458 529 case 'system':
459 530 $wpda_settings_class_name = 'WPDA_Settings_SystemInfo';
460 531 break;
532 + case 'mail':
533 + $wpda_settings_class_name = 'WPDA_Settings_Mail';
534 + break;
535 + case 'drives':
536 + $wpda_settings_class_name = 'WPDA_Settings_Drives';
537 + break;
538 + case 'legacy':
539 + $wpda_settings_class_name = 'WPDA_Settings_Legacy';
540 + break;
461 541 default:
462 542 $wpda_settings_class_name = 'WPDA_Settings_Plugin';
463 543 }
464 544 $wpda_settings_class_name = '\\WPDataAccess\\Settings\\' . $wpda_settings_class_name;
@@ -466,4 +546,6 @@
466 546 $wpda_settings->show();
467 547 }
468 548
469 549 }
550 +
551 +// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing