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 +94 -53 5.5.415.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,10 @@
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' );
179 164 // Mail service.
180 165 $wpda_mail_server = \WPDataAccess\Utilities\WPDA_Mail::get_option();
181 166 if ( isset(
182 167 $wpda_mail_server['host'],
@@ -189,8 +174,13 @@
189 174 ) ) {
190 175 add_action(
191 176 'phpmailer_init',
192 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 + }
193 183 $phpmailer->isSMTP();
194 184 $phpmailer->isHTML( false );
195 185 $phpmailer->SMTPDebug = $wpda_mail_server['debug'] ?? 0;
196 186 $phpmailer->Host = $wpda_mail_server['host'];
@@ -228,14 +218,12 @@
228 218 $this->loader->add_action( 'wp_ajax_wpda_widget_pub_add', WPDA_Widget_Publication::class, 'ajax_widget' );
229 219 $this->loader->add_action( 'wp_ajax_wpda_widget_chart_add', WPDA_Widget_Google_Chart::class, 'ajax_widget' );
230 220 $this->loader->add_action( 'wp_ajax_wpda_widget_chart_refresh', WPDA_Widget_Google_Chart::class, 'ajax_refresh' );
231 221 // Add/remove favourites.
222 + // ???
232 223 $plugin_favourites = new WPDA_Favourites();
233 224 $this->loader->add_action( 'admin_action_wpda_add_favourite', $plugin_favourites, 'add' );
234 225 $this->loader->add_action( 'admin_action_wpda_rem_favourite', $plugin_favourites, 'rem' );
235 - // Show tables actions.
236 - $plugin_table_actions = new WPDA_Table_Actions();
237 - $this->loader->add_action( 'admin_action_wpda_show_table_actions', $plugin_table_actions, 'show' );
238 226 $plugin_dictionary_list = new WPDA_Dictionary_Lists();
239 227 // Get tables for a specific database.
240 228 $this->loader->add_action( 'admin_action_wpda_get_tables', $plugin_dictionary_list, 'get_tables_ajax' );
241 229 // Get columns for a specific table.
@@ -242,9 +230,9 @@
242 230 $this->loader->add_action( 'admin_action_wpda_get_columns', $plugin_dictionary_list, 'get_columns' );
243 231 // Get row count for a specific table.
244 232 $this->loader->add_action( 'admin_action_wpda_get_table_row_count', $plugin_dictionary_list, 'get_table_row_count_ajax' );
245 233 // Get table widget info.
246 - $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' );
247 235 // Global database search and replace.
248 236 $this->loader->add_action( 'wp_ajax_wpda_global_search', \WPDataAccess\Global_Search\WPDA_Global_Search::class, 'search' );
249 237 $this->loader->add_action( 'wp_ajax_wpda_global_replace', \WPDataAccess\Global_Search\WPDA_Global_Search::class, 'replace' );
250 238 // Export project.
@@ -279,27 +267,24 @@
279 267 'wp_ajax_wpda_dbinit_admin',
280 268 function () {
281 269 if ( !isset( $_POST['wpnonce'], $_POST['wpdaschema_name'] ) ) {
282 270 WPDA::sent_header( 'application/json' );
283 - echo WPDA::sent_msg( 'ERROR', 'Invalid arguments' );
284 - // phpcs:ignore WordPress.Security.EscapeOutput
271 + WPDA::sent_msg( 'ERROR', 'Invalid arguments' );
285 272 wp_die();
286 273 }
274 + // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotValidated
287 275 $wpnonce = sanitize_text_field( wp_unslash( $_REQUEST['wpnonce'] ) );
288 - // input var okay.
289 276 if ( !WPDA::current_user_is_admin() || !wp_verify_nonce( $wpnonce, 'wpda_dbinit_admin_' . WPDA::get_current_user_login() ) ) {
290 277 WPDA::sent_header( 'application/json' );
291 - echo WPDA::sent_msg( 'ERROR', 'Not authorized' );
292 - // phpcs:ignore WordPress.Security.EscapeOutput
278 + WPDA::sent_msg( 'ERROR', 'Not authorized' );
293 279 wp_die();
294 280 }
295 281 $wpdaschema_name = sanitize_text_field( wp_unslash( $_REQUEST['wpdaschema_name'] ) );
296 - // input var okay.
282 + // phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotValidated
297 283 $wpdadb = WPDADB::get_db_connection( $wpdaschema_name );
298 284 if ( null === $wpdadb ) {
299 285 WPDA::sent_header( 'application/json' );
300 - echo WPDA::sent_msg( 'ERROR', 'Cannot connect to database' );
301 - // phpcs:ignore WordPress.Security.EscapeOutput
286 + WPDA::sent_msg( 'ERROR', 'Cannot connect to database' );
302 287 wp_die();
303 288 }
304 289 $suppress_errors = $wpdadb->suppress_errors( true );
305 290 $wpdadb->query( 'create function wpda_get_wp_user_id() returns integer deterministic no sql return @wpda_wp_user_id' );
@@ -305,14 +290,12 @@
305 290 $wpdadb->query( 'create function wpda_get_wp_user_id() returns integer deterministic no sql return @wpda_wp_user_id' );
306 291 $error = $wpdadb->last_error;
307 292 $wpdadb->suppress_errors( $suppress_errors );
308 293 if ( '' === $error ) {
309 - //phpcs:ignore - 8.1 proof
310 - echo WPDA::sent_msg( 'OK', '' );
311 - // phpcs:ignore WordPress.Security.EscapeOutput
294 + // phpcs:ignore -- 8.1 proof
295 + WPDA::sent_msg( 'OK', '' );
312 296 } else {
313 - echo WPDA::sent_msg( 'ERROR', "Function not created [{$error}]" );
314 - // phpcs:ignore WordPress.Security.EscapeOutput
297 + WPDA::sent_msg( 'ERROR', "Function not created [{$error}]" );
315 298 }
316 299 wp_die();
317 300 },
318 301 10,
@@ -361,8 +344,32 @@
361 344 },
362 345 10,
363 346 1
364 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 + );
365 372 }
366 373
367 374 /**
368 375 * Needed for JDT to support IE
@@ -373,10 +380,11 @@
373 380 * @return mixed|string
374 381 */
375 382 public function add_id_to_script( $tag, $handle, $src ) {
376 383 if ( 'wpda_datatables' === $handle ) {
384 + // phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript
377 385 $tag = '<script id="wpda_datatables" src="' . $src . '"></script>';
378 - // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
386 + // phpcs:enable WordPress.WP.EnqueuedResources.NonEnqueuedScript
379 387 }
380 388 return $tag;
381 389 }
382 390
@@ -438,11 +446,49 @@
438 446 *
439 447 * @since 1.0.0
440 448 */
441 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' );
442 452 $this->loader->run();
443 453 }
444 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 +
445 491 /**
446 492 * Add plugin settings page
447 493 */
448 494 public function wpdataaccess_register_settings_page() {
@@ -460,10 +506,12 @@
460 506 */
461 507 public function wpdataaccess_settings_page() {
462 508 WPDA_Dashboard::add_dashboard();
463 509 $current_tab = ( isset( $_REQUEST['tab'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) ) : 'plugin' );
464 - // phpcs:ignore WordPress.Security.NonceVerification
465 510 switch ( $current_tab ) {
511 + case 'apps':
512 + $wpda_settings_class_name = 'WPDA_Settings_Apps';
513 + break;
466 514 case 'backend':
467 515 $wpda_settings_class_name = 'WPDA_Settings_BackEnd';
468 516 break;
469 517 case 'frontend':
@@ -471,20 +519,8 @@
471 519 break;
472 520 case 'pds':
473 521 $wpda_settings_class_name = 'WPDA_Settings_PDS';
474 522 break;
475 - case 'dashboard':
476 - $wpda_settings_class_name = 'WPDA_Settings_Dashboard';
477 - break;
478 - case 'datatables':
479 - $wpda_settings_class_name = 'WPDA_Settings_DataTables';
480 - break;
481 - case 'dataforms':
482 - $wpda_settings_class_name = 'WPDA_Settings_DataForms';
483 - break;
484 - case 'databackup':
485 - $wpda_settings_class_name = 'WPDA_Settings_DataBackup';
486 - break;
487 523 case 'uninstall':
488 524 $wpda_settings_class_name = 'WPDA_Settings_Uninstall';
489 525 break;
490 526 case 'repository':
@@ -489,11 +525,8 @@
489 525 break;
490 526 case 'repository':
491 527 $wpda_settings_class_name = 'WPDA_Settings_ManageRepository';
492 528 break;
493 - case 'roles':
494 - $wpda_settings_class_name = 'WPDA_Settings_ManageRoles';
495 - break;
496 529 case 'system':
497 530 $wpda_settings_class_name = 'WPDA_Settings_SystemInfo';
498 531 break;
499 532 case 'mail':
@@ -498,8 +531,14 @@
498 531 break;
499 532 case 'mail':
500 533 $wpda_settings_class_name = 'WPDA_Settings_Mail';
501 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;
502 541 default:
503 542 $wpda_settings_class_name = 'WPDA_Settings_Plugin';
504 543 }
505 544 $wpda_settings_class_name = '\\WPDataAccess\\Settings\\' . $wpda_settings_class_name;
@@ -507,4 +546,6 @@
507 546 $wpda_settings->show();
508 547 }
509 548
510 549 }
550 +
551 +// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing