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 | WPDataAccess/WPDA.php +137 -83 5.5.35.5.84 View file →
@@ -19,9 +19,9 @@
19 19 * Class WPDA
20 20 *
21 21 * Plugin default values and settings are managed through this class. Every plugin option has a default value
22 22 * which is maintained in an array together with the option name. Options are only saved in $wpdb->options when
23 - * they are changed. Otherwise the default values are used. After reading option values from $wpdb->options the
23 + * they are changed. Otherwise, the default values are used. After reading option values from $wpdb->options the
24 24 * values are cached as many of them are used in multiple
25 25 * values are cached as many of them are used in multiple
26 26 * places during the processing of a request.
27 27 *
@@ -27,10 +27,12 @@
27 27 *
28 28 * @author Peter Schulz
29 29 * @since 1.0.0
30 30 */
31 - class WPDA {
32 31
32 + // phpcs:disable PluginCheck.CodeAnalysis.Offloading.OffloadedContent
33 + class WPDA {
34 +
33 35 // SAVING SPACE - According to the plugin guidelines it is allowed to include external fonts:
34 36 // https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/#8-plugins-may-not-send-executable-code-via-third-party-systems
35 37 const CDN_FONTAWESOME = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/';
36 38 const GOOGLE_CHARTS = 'https://www.gstatic.com/charts/loader.js';
@@ -50,10 +52,10 @@
50 52 // Application options.
51 53 /**
52 54 * Option wpda_version and it's default value
53 55 */
54 - const OPTION_WPDA_VERSION = array( 'wpda_version', '5.5.3' );
55 - const OPTION_WPDA_CLIENT_VERSION = array( 'wpda_client_version', '1.0.4' );
56 + const OPTION_WPDA_VERSION = array( 'wpda_version', '5.5.84' );
57 + const OPTION_WPDA_CLIENT_VERSION = array( 'wpda_client_version', '1.0.82' );
56 58 const OPTION_WPDA_UPGRADED = array( 'wpda_upgraded', false );
57 59 /**
58 60 * Option wpda_setup_error and it's default value
59 61 */
@@ -86,8 +88,21 @@
86 88
87 89 const OPTION_PLUGIN_SECRET_KEY_DEFAULT = 'enter-your-secret-key-here';
88 90 const OPTION_PLUGIN_SECRET_IV_DEFAULT = 'enter-your-secret-iv-here';
89 91
92 + const OPTION_PLUGIN_LEGACY_TOOLS =
93 + array(
94 + 'wpda_plugin_legacy_tools',
95 + array(
96 + 'tables' => array(false, 0),
97 + 'forms' => array(false, 0),
98 + 'templates' => array(false, 0),
99 + 'designer' => array(false, 0),
100 + 'dashboards' => array(false, 0),
101 + 'charts' => array(false, 0),
102 + )
103 + );
104 +
90 105 const OPTION_PLUGIN_SECRET_KEY = array( 'wpda_plugin_secret_key', self::OPTION_PLUGIN_SECRET_KEY_DEFAULT);
91 106 const OPTION_PLUGIN_SECRET_IV = array( 'wpda_plugin_secret_iv', self::OPTION_PLUGIN_SECRET_IV_DEFAULT);
92 107
93 108 const OPTION_PLUGIN_SONCE_SEED = array( 'wpda_plugin_sonce_seed', 'ALSKDFHIUWEALDSKNCNKSDJAKDJHSFAKSDFGFKOJHORITIHGMRTGHMHL');
@@ -113,8 +128,11 @@
113 128 const OPTION_PLUGIN_TIME_FORMAT = array( 'wpda_plugin_time_format', 'H:i');
114 129 const OPTION_PLUGIN_TIME_PLACEHOLDER = array( 'wpda_plugin_time_placeholder', 'hh:mi');
115 130 const OPTION_PLUGIN_SET_FORMAT = array( 'wpda_plugin_set_format', 'csv');
116 131
132 + // App options
133 + const OPTION_APPS_SCROLL_OFFSET = array( 'wpda_apps_scroll_offset', '120');
134 +
117 135 // Plugin debug mode
118 136 const OPTION_PLUGIN_DEBUG = array( 'wpda_plugin_debug', 'off');
119 137
120 138 // Back-end options.
@@ -278,19 +296,21 @@
278 296 /**
279 297 * List of plugin tables
280 298 */
281 299 const WPDA_TABLES = array(
300 + 'wpda_app' => true,
301 + 'wpda_app_container' => true,
302 + 'wpda_app_apps' => true,
282 303 'wpda_logging' => true,
283 304 'wpda_menus' => true,
284 305 'wpda_table_settings' => true,
285 306 'wpda_table_design' => true,
286 - 'wpda_publisher' => true, // Old plugin table name: do NOT change!
307 + 'wpda_publisher' => true,
287 308 'wpda_media' => true,
288 309 'wpda_project' => true,
289 310 'wpda_project_page' => true,
290 311 'wpda_project_table' => true,
291 312 'wpda_csv_uploads' => true,
292 - 'wpda_pro_reports' => true,
293 313 );
294 314
295 315 /**
296 316 * List containing all plugin tables
@@ -316,8 +336,9 @@
316 336 static protected $wp_tables = array();
317 337
318 338 static protected $plugin_pages = array(
319 339 WP_Data_Access_Admin::PAGE_MAIN,
340 + WP_Data_Access_Admin::PAGE_NAVI,
320 341 WP_Data_Access_Admin::PAGE_APPS,
321 342 WP_Data_Access_Admin::PAGE_DASHBOARD,
322 343 WP_Data_Access_Admin::PAGE_SETTINGS,
323 344 WP_Data_Access_Admin::PAGE_EXPLORER,
@@ -325,8 +346,9 @@
325 346 WP_Data_Access_Admin::PAGE_PUBLISHER,
326 347 WP_Data_Access_Admin::PAGE_DESIGNER,
327 348 WP_Data_Access_Admin::PAGE_MY_TABLES,
328 349 WP_Data_Access_Admin::PAGE_CHARTS,
350 + WP_Data_Access_Admin::PAGE_TABLE,
329 351 WPDP::PAGE_MAIN,
330 352 WPDP::PAGE_TEMPLATES,
331 353 );
332 354
@@ -335,9 +357,9 @@
335 357 is_scalar( $page ) &&
336 358 (
337 359 'wpda_wpdp_' === substr( $page, 0, 10 ) ||
338 360 WP_Data_Access_Admin::PAGE_EXPLORER === substr( $page, 0, 13 ) ||
339 - in_array( $page, self::$plugin_pages) //phpcs:ignore - 8.1 proof
361 + in_array( $page, self::$plugin_pages) // phpcs:ignore -- 8.1 proof
340 362 )
341 363 );
342 364 }
343 365
@@ -410,9 +432,9 @@
410 432 public static function clear_all_options() {
411 433
412 434 global $wpdb;
413 435
414 - $wpdb->query(
436 + $wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
415 437 "
416 438 DELETE FROM wp_options
417 439 WHERE option_name LIKE 'wpda_%'
418 440 "
@@ -428,9 +450,9 @@
428 450 * @since 1.1.0
429 451 */
430 452 public static function load_wp_tables() {
431 453
432 - if ( 0 === count( self::$wp_tables ) ) {//phpcs:ignore - 8.1 proof
454 + if ( 0 === count( self::$wp_tables ) ) { // phpcs:ignore -- 8.1 proof
433 455 try {
434 456 global $wpdb;
435 457
436 458 if ( ! is_multisite() ) {
@@ -438,11 +460,11 @@
438 460 self::$wp_tables[ $table ] = $table;
439 461 }
440 462 } else {
441 463 $query = "select blog_id from {$wpdb->blogs}";
442 - $blogs = $wpdb->get_results( $query, 'ARRAY_N' );
464 + $blogs = $wpdb->get_results( $query, 'ARRAY_N' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
443 465 foreach ( $blogs as $blog ) {
444 - foreach ( $wpdb->tables( $blog === reset( $blogs ) ? 'all' : 'blog', true, $blog[0] ) as $table ) {//phpcs:ignore - 8.1 proof
466 + foreach ( $wpdb->tables( $blog === reset( $blogs ) ? 'all' : 'blog', true, $blog[0] ) as $table ) { // phpcs:ignore -- 8.1 proof
445 467 self::$wp_tables[ $table ] = $table;
446 468 }
447 469 }
448 470 }
@@ -448,12 +470,14 @@
448 470 }
449 471
450 472 return true;
451 473 } catch ( \Exception $e ) {
452 - wp_die( 'ERROR: ' . $e->getMessage() );
474 + wp_die( esc_attr( 'ERROR: ' . $e->getMessage() ) );
453 475 }
454 476 }
455 477
478 + return false;
479 +
456 480 }
457 481
458 482 /**
459 483 * Checks if a table is a WordPress table
@@ -467,9 +491,9 @@
467 491 public static function is_wp_table( $table_name ) {
468 492
469 493 self::load_wp_tables();
470 494
471 - if ( 0 === count( self::$wp_tables ) ) {//phpcs:ignore - 8.1 proof
495 + if ( 0 === count( self::$wp_tables ) ) { // phpcs:ignore -- 8.1 proof
472 496 return false;
473 497 }
474 498
475 499 return isset( self::$wp_tables[ $table_name ] );
@@ -486,10 +510,10 @@
486 510 public static function get_wp_tables() {
487 511
488 512 self::load_wp_tables();
489 513
490 - if ( 0 === count( self::$wp_tables ) ) {//phpcs:ignore - 8.1 proof
491 - wp_die( __( 'ERROR: No WordPress table found', 'wp-data-access' ) );
514 + if ( 0 === count( self::$wp_tables ) ) { // phpcs:ignore -- 8.1 proof
515 + wp_die( esc_attr__( 'ERROR: No WordPress table found', 'wp-data-access' ) );
492 516 }
493 517
494 518 return self::$wp_tables;
495 519
@@ -523,9 +547,9 @@
523 547 *
524 548 * @return bool
525 549 */
526 550 public static function column_is_schema_name( $table_name, $column_name ) {
527 - if ( 0 === count( self::$wpda_tables ) ) {//phpcs:ignore - 8.1 proof
551 + if ( 0 === count( self::$wpda_tables ) ) { // phpcs:ignore -- 8.1 proof
528 552 // Cache schema names
529 553 global $wpdb;
530 554 self::$wpda_tables[$wpdb->prefix . 'wpda_media.media_schema_name' ] = true;
531 555 self::$wpda_tables[$wpdb->prefix . 'wpda_project_page.page_schema_name' ] = true;
@@ -703,13 +727,13 @@
703 727 *
704 728 * @return array
705 729 */
706 730 public static function array_insert_after( $array, $key, $new ) {
707 - $keys = array_keys( (array) $array ); //phpcs:ignore - 8.1 proof
708 - $index = array_search( $key, $keys ); //phpcs:ignore - 8.1 proof
709 - $pos = false === $index ? count( $array ) : $index + 1; //phpcs:ignore - 8.1 proof
731 + $keys = array_keys( (array) $array ); // phpcs:ignore -- 8.1 proof
732 + $index = array_search( $key, $keys ); // phpcs:ignore -- 8.1 proof
733 + $pos = false === $index ? count( $array ) : $index + 1; // phpcs:ignore -- 8.1 proof
710 734
711 - return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) ); //phpcs:ignore - 8.1 proof
735 + return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) ); // phpcs:ignore -- 8.1 proof
712 736 }
713 737
714 738 /**
715 739 * Log a message in the database
@@ -735,9 +759,9 @@
735 759 , $log_id
736 760 , $log_type
737 761 , $log_msg
738 762 );
739 - $wpdb->query( $sql );
763 + $wpdb->query( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
740 764
741 765 }
742 766
743 767 /**
@@ -771,9 +795,9 @@
771 795 if ( is_user_logged_in() ) {
772 796 $user = wp_get_current_user();
773 797 $allcaps = array();
774 798 foreach ( $user->allcaps as $key => $val ) {
775 - array_push( $allcaps, $key );//phpcs:ignore - 8.1 proof
799 + array_push( $allcaps, $key ); // phpcs:ignore -- 8.1 proof
776 800 }
777 801
778 802 return $allcaps[0];
779 803 } else {
@@ -799,15 +823,12 @@
799 823 } else if ( $matches[2] == 'K' ) {
800 824 return $matches[1] * 1024;
801 825 }
802 826 }
827 + return '';
803 828 }
804 829
805 - public static function get_current_user_id( $is_anonymous = false ) {
806 - if ( $is_anonymous ) {
807 - return -1;
808 - }
809 -
830 + public static function get_current_user_id() {
810 831 global $current_user;
811 832 if ( isset( $current_user->ID ) ) {
812 833 return $current_user->ID;
813 834 } else {
@@ -815,12 +836,12 @@
815 836 $wp_user = wp_get_current_user();
816 837 if ( isset( $wp_user->ID ) ) {
817 838 return $wp_user->ID;
818 839 } else {
819 - return - 1;
840 + return -1;
820 841 }
821 842 } else {
822 - return - 1;
843 + return -1;
823 844 }
824 845 }
825 846 }
826 847
@@ -910,9 +931,9 @@
910 931 * $columns['column_default'] => information_schema.tables.column_default
911 932 *
912 933 * @param string $schema_name Schema name (optional)
913 934 * @param string $table_name Table name (optional)
914 - * @param string $columns Array containing table columns
935 + * @param array $columns Array containing table columns
915 936 * @param string $search Search string entered by user
916 937 * @param boolean $is_case_sensitive Case-sensitive search (default = false)
917 938 * @param boolean $is_dt_request Always skip filter for DataTable requests (default = false)
918 939 *
@@ -970,22 +991,22 @@
970 991 $where_columns = array();
971 992
972 993 foreach ( $columns as $column ) {
973 994 if ( 'string' === WPDA::get_type( $column['data_type'] ) ) {
974 - $where_columns[] = $wpdb->prepare( "`" . str_replace( '`', '', $column['column_name'] ) . "` like {$case_sensitive} '%s'", '%' . esc_sql( $search ) . '%' ); // phpcs:ignore Standard.Category.SniffName.ErrorCode
995 + $where_columns[] = $wpdb->prepare( "`" . str_replace( '`', '', $column['column_name'] ) . "` like {$case_sensitive} '%s'", '%' . esc_sql( $search ) . '%' ); // phpcs:ignore
975 996 }
976 997
977 998 if ( $is_dt_request ) {
978 999 // Handle numeric and date queries for DataTables.
979 1000 if ( 'number' === WPDA::get_type( $column['data_type'] ) && ( is_numeric( $search ) ) ) {
980 - $where_columns[] = $wpdb->prepare( "`" . str_replace( '`', '', $column['column_name'] ) . "` = '%s'", esc_sql( $search ) ); // phpcs:ignore Standard.Category.SniffName.ErrorCode
1001 + $where_columns[] = $wpdb->prepare( "`" . str_replace( '`', '', $column['column_name'] ) . "` = '%s'", esc_sql( $search ) ); // phpcs:ignore
981 1002 } elseif ( 'date' === WPDA::get_type( $column['data_type'] ) ) {
982 - $where_columns[] = $wpdb->prepare( "`" . str_replace( '`', '', $column['column_name'] ) . "` like '%s'", esc_sql( $search ) . '%' ); // phpcs:ignore Standard.Category.SniffName.ErrorCode
1003 + $where_columns[] = $wpdb->prepare( "`" . str_replace( '`', '', $column['column_name'] ) . "` like '%s'", esc_sql( $search ) . '%' ); // phpcs:ignore
983 1004 }
984 1005 }
985 1006 }
986 1007
987 - if ( 0 === count( $where_columns ) ) {//phpcs:ignore - 8.1 proof
1008 + if ( 0 === count( $where_columns ) ) { // phpcs:ignore -- 8.1 proof
988 1009 return '' === $where_search_args ? ' (1=2) ' : $where_search_args;
989 1010 }
990 1011
991 1012 if ( '' === $where_search_args ) {
@@ -999,11 +1020,11 @@
999 1020 $where_columns = array();
1000 1021
1001 1022 if ( is_array( $columns ) ) {
1002 1023 global $wpdb;
1003 - $request = array_change_key_case( $_REQUEST ); //phpcs:ignore - 8.1 proof
1024 + $request = array_change_key_case( $_REQUEST ); // phpcs:ignore -- 8.1 proof
1004 1025 foreach ( $columns as $column ) {
1005 - $column_name = str_replace( '`', '', $column['column_name'] );
1026 + $column_name = str_replace( '`', '', $column['column_name'] ?? '' );
1006 1027 $column_name_lwr = strtolower( $column_name );
1007 1028 if ( isset( $request["wpda_search_column_{$column_name_lwr}"] ) ) {
1008 1029 if ( is_array( $request["wpda_search_column_{$column_name_lwr}"] ) ) {
1009 1030 // Handle multiple values for same column with OR
@@ -1012,16 +1033,16 @@
1012 1033 $column_date_type = $column['data_type'];
1013 1034 $column_value = wp_strip_all_tags( wp_unslash( $value ) ); // input var okay.
1014 1035 if ( '' !== $column_value ) {
1015 1036 if ( 'string' === WPDA::get_type( $column_date_type ) ) {
1016 - $where_columns_arr[] = $wpdb->prepare( "`{$column_name}` like '%s'", esc_sql( $column_value ) ); // phpcs:ignore Standard.Category.SniffName.ErrorCode
1037 + $where_columns_arr[] = $wpdb->prepare( "`{$column_name}` like '%s'", esc_sql( $column_value ) ); // phpcs:ignore
1017 1038 } elseif ( 'number' === WPDA::get_type( $column_date_type ) ) {
1018 - $where_columns_arr[] = $wpdb->prepare( "`{$column_name}` = '%d'", esc_sql( $column_value ) ); // phpcs:ignore Standard.Category.SniffName.ErrorCode
1039 + $where_columns_arr[] = $wpdb->prepare( "`{$column_name}` = '%d'", esc_sql( $column_value ) ); // phpcs:ignore
1019 1040 }
1020 1041 }
1021 1042 }
1022 - if ( count( $where_columns_arr ) > 0 ) {//phpcs:ignore - 8.1 proof
1023 - $where_columns[] = ' (' . implode( ' or ', $where_columns_arr ) . ') ';//phpcs:ignore - 8.1 proof
1043 + if ( count( $where_columns_arr ) > 0 ) { // phpcs:ignore -- 8.1 proof
1044 + $where_columns[] = ' (' . implode( ' or ', $where_columns_arr ) . ') '; // phpcs:ignore -- 8.1 proof
1024 1045 }
1025 1046 } else {
1026 1047 // Handle single value
1027 1048 $column_date_type = $column['data_type'];
@@ -1027,11 +1048,11 @@
1027 1048 $column_date_type = $column['data_type'];
1028 1049 $column_value = wp_strip_all_tags( wp_unslash( $request[ "wpda_search_column_{$column_name_lwr}" ] ) );
1029 1050 if ( '' !== $column_value ) {
1030 1051 if ( 'string' === WPDA::get_type( $column_date_type ) ) {
1031 - $where_columns[] = $wpdb->prepare( "`{$column_name}` like '%s'", esc_sql( $column_value ) ); // phpcs:ignore Standard.Category.SniffName.ErrorCode
1052 + $where_columns[] = $wpdb->prepare( "`{$column_name}` like '%s'", esc_sql( $column_value ) ); // phpcs:ignore
1032 1053 } elseif ( 'number' === WPDA::get_type( $column_date_type ) ) {
1033 - $where_columns[] = $wpdb->prepare( "`{$column_name}` = '%d'", esc_sql( $column_value ) ); // phpcs:ignore Standard.Category.SniffName.ErrorCode
1054 + $where_columns[] = $wpdb->prepare( "`{$column_name}` = '%d'", esc_sql( $column_value ) ); // phpcs:ignore
1034 1055 }
1035 1056 }
1036 1057 }
1037 1058 }
@@ -1037,14 +1058,13 @@
1037 1058 }
1038 1059 }
1039 1060 }
1040 1061
1041 - if ( 0 === count( $where_columns ) ) {//phpcs:ignore - 8.1 proof
1062 + if ( 0 === count( $where_columns ) ) { // phpcs:ignore -- 8.1 proof
1042 1063 return '';
1043 1064 } else {
1044 1065 $operator =
1045 - isset( $_REQUEST['wpda_search_column_operator'] ) &&
1046 - 'or' === strtolower( $_REQUEST['wpda_search_column_operator'] )
1066 + isset( $_REQUEST['wpda_search_column_operator'] ) && 'or' === strtolower( $_REQUEST['wpda_search_column_operator'] ) // phpcs:ignore
1047 1067 ? 'or' : 'and';
1048 1068 return ' (' . implode( " $operator ", $where_columns ) . ') ';
1049 1069 }
1050 1070 }
@@ -1077,15 +1097,18 @@
1077 1097 return false;
1078 1098 }
1079 1099 if ( method_exists( $wpdadb, 'is_connected' ) ) {
1080 1100 if ( ! $wpdadb->is_connected() ) {
1101 + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
1081 1102 $msg = new WPDA_Message_Box(
1082 1103 [
1083 - 'message_text' => __( "Remote database '{$schema_name}' not available [check connection: Settings > WP Data Access]", 'wp-data-access' ),
1104 + /* translators: %s = database name */
1105 + 'message_text' => sprintf( __( 'Remote database "%s" not available [check connection: Settings > WP Data Access]', 'wp-data-access' ), $schema_name ),
1084 1106 'message_type' => 'error',
1085 1107 'message_is_dismissible' => false,
1086 1108 ]
1087 1109 );
1110 + // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment
1088 1111 $msg->box();
1089 1112
1090 1113 return false;
1091 1114 }
@@ -1099,9 +1122,9 @@
1099 1122 $wpdadb->dbname,
1100 1123 ]
1101 1124 )
1102 1125 ); // db call ok; no-cache ok.
1103 - $wpdadb->get_results(); // phpcs:ignore Standard.Category.SniffName.ErrorCode
1126 + $wpdadb->get_results();
1104 1127
1105 1128 return 1 === $wpdadb->num_rows;
1106 1129 }
1107 1130
@@ -1128,23 +1151,28 @@
1128 1151 jQuery(function() {
1129 1152 var clipboard = new ClipboardJS('.wpda_shortcode_clipboard');
1130 1153 });
1131 1154 </script>
1132 - <style type="text/css">
1155 + <style>
1156 + /* noinspection CssUnusedSymbol */
1133 1157 .wpda_shortcode_content {
1134 1158 padding: 0 20px;
1135 1159 }
1160 + /* noinspection CssUnusedSymbol */
1136 1161 .wpda_shortcode_text {
1137 1162 text-align: center;
1138 1163 font-size: 105%;
1139 1164 white-space: nowrap;
1140 1165 }
1166 + /* noinspection CssUnusedSymbol */
1141 1167 .wpda_shortcode_buttons {
1142 1168 text-align: center;
1143 1169 }
1170 + /* noinspection CssUnusedSymbol */
1144 1171 .button.wpda_shortcode_button {
1145 1172 width: 100px !important;
1146 1173 }
1174 + /* noinspection CssUnusedSymbol */
1147 1175 .wpda_shortcode_link {
1148 1176 text-decoration: none;
1149 1177 font-weight: bold;
1150 1178 }
@@ -1173,9 +1201,9 @@
1173 1201 * @return array
1174 1202 */
1175 1203 public static function get_post_types() {
1176 1204 global $wpdb;
1177 - $rows = $wpdb->get_results(
1205 + $rows = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1178 1206 "select distinct post_type from {$wpdb->posts}",
1179 1207 'ARRAY_N'
1180 1208 );
1181 1209
@@ -1188,9 +1216,9 @@
1188 1216 }
1189 1217
1190 1218 public static function get_table_engine( $schema_name, $table_name ) {
1191 1219 $table_info = WPDA::get_table_values( $schema_name, $table_name );
1192 - //phpcs:ignore - 8.1 proof
1220 + // phpcs:ignore -- 8.1 proof
1193 1221 return (
1194 1222 1 === count( $table_info ) &&
1195 1223 'connect' === strtolower( $table_info[0]['engine'] )
1196 1224 ) ? 'connect' : '';
@@ -1219,13 +1247,13 @@
1219 1247
1220 1248 /**
1221 1249 * Get estimated number of rows in a table
1222 1250 *
1223 - * @param $schema_name Schema name
1224 - * @param $table_name Table name
1225 - * @param $wpda_table_settings Table settings (query WPDA_Table_Settings_Model)
1251 + * @param $schema_name string Schema name
1252 + * @param $table_name string Table name
1253 + * @param $wpda_table_settings string Table settings (query WPDA_Table_Settings_Model)
1226 1254 *
1227 - * @return int row count estimate or -1 if no estimate available
1255 + * @return array row count estimate or -1 if no estimate available
1228 1256 */
1229 1257 public static function get_row_count_estimate( $schema_name, $table_name, $wpda_table_settings ) {
1230 1258 $row_count = null;
1231 1259 $is_estimate = null;
@@ -1230,9 +1258,9 @@
1230 1258 $row_count = null;
1231 1259 $is_estimate = null;
1232 1260 $do_real_count = null;
1233 1261 $table_info = self::get_table_values( $schema_name, $table_name );
1234 - if ( 1 === count( $table_info ) ) {//phpcs:ignore - 8.1 proof
1262 + if ( 1 === count( $table_info ) ) { // phpcs:ignore -- 8.1 proof
1235 1263 $row_count = $table_info[0]['table_rows'];
1236 1264
1237 1265 $system_row_count_estimate = null;
1238 1266 $row_count_estimate_value = null;
@@ -1287,9 +1315,9 @@
1287 1315 }
1288 1316 } elseif ( 'connect' === strtolower( $table_info[0]['engine'] ) ) {
1289 1317 $getpk = WPDA_List_Columns_Cache::get_list_columns( $schema_name, $table_name );
1290 1318 $pk = $getpk->get_table_primary_key();
1291 - if ( is_array( $pk ) && count( $pk ) > 0 ) {//phpcs:ignore - 8.1 proof
1319 + if ( is_array( $pk ) && count( $pk ) > 0 ) { // phpcs:ignore -- 8.1 proof
1292 1320 $sql_rowcount_sql =
1293 1321 'select count(*) from `' . str_replace( '`', '', $table_name ) .
1294 1322 '` where `' . $pk[0] . '` not in ' .
1295 1323 '(select null from `' . str_replace( '`', '', $table_name ) . '` where 1=2)';
@@ -1294,9 +1322,9 @@
1294 1322 '` where `' . $pk[0] . '` not in ' .
1295 1323 '(select null from `' . str_replace( '`', '', $table_name ) . '` where 1=2)';
1296 1324 $wpdadb = WPDADB::get_db_connection( $schema_name );
1297 1325 $sql_rowcount = $wpdadb->get_results( $sql_rowcount_sql, 'ARRAY_N' );
1298 - if ( count( $sql_rowcount ) === 1 ) {//phpcs:ignore - 8.1 proof
1326 + if ( count( $sql_rowcount ) === 1 ) { // phpcs:ignore -- 8.1 proof
1299 1327 $row_count = $sql_rowcount[0][0];
1300 1328 $is_estimate = false;
1301 1329 $do_real_count = false;
1302 1330 } else {
@@ -1343,11 +1371,11 @@
1343 1371 }
1344 1372
1345 1373 if ( null === $column_names ) {
1346 1374 $columns = WPDA_Dictionary_Lists::get_table_columns( $table_name, $schema_name );
1347 - $column_names = array_column( $columns, 'column_name' ); //phpcs:ignore - 8.1 proof
1375 + $column_names = array_column( $columns, 'column_name' ); // phpcs:ignore -- 8.1 proof
1348 1376 }
1349 - if ( count( $column_names ) === 0 ) {//phpcs:ignore - 8.1 proof
1377 + if ( count( $column_names ) === 0 ) { // phpcs:ignore -- 8.1 proof
1350 1378 return self::validate_name_np();
1351 1379 }
1352 1380
1353 1381 $is_valid = true;
@@ -1374,9 +1402,9 @@
1374 1402
1375 1403 public static function validate_name_failed() {
1376 1404 $title = __( 'Schema, table or column name(s) restricting plugin features (click to read more and fix)', 'wp-data-access' );
1377 1405 $warning = "
1378 - <a href='https://wpdataaccess.com/docs/data-explorer/naming-conventions/' target='_blank' style='text-decoration:none'>
1406 + <a href='https://docs.legacy.wpdataaccess.com/docs/naming-conventions/' target='_blank' style='text-decoration:none'>
1379 1407 <span class='dashicons dashicons-flag wpda_tooltip' style='color:red;padding-left:5px' title='$title'></span>
1380 1408 </a>";
1381 1409 return $warning;
1382 1410 }
@@ -1383,9 +1411,9 @@
1383 1411
1384 1412 public static function validate_name_np() {
1385 1413 $title = __( 'Schema, table or column name validation not possible (click to read more and fix)', 'wp-data-access' );
1386 1414 $warning = "
1387 - <a href='https://wpdataaccess.com/docs/data-explorer/naming-conventions/' target='_blank'>
1415 + <a href='https://docs.legacy.wpdataaccess.com/docs/naming-conventions/' target='_blank'>
1388 1416 <span class='dashicons dashicons-warning wpda_tooltip' style='padding-left:5px' title='$title'></span>
1389 1417 </a>";
1390 1418 return $warning;
1391 1419 }
@@ -1448,9 +1476,22 @@
1448 1476 $encrypt_method = 'AES-256-CBC';
1449 1477 $key = hash( 'sha256', WPDA::get_option( WPDA::OPTION_PLUGIN_SECRET_KEY ) );
1450 1478 $iv = substr( hash( 'sha256', WPDA::get_option( WPDA::OPTION_PLUGIN_SECRET_IV ) ), 0, 16 );
1451 1479
1452 - return base64_encode( openssl_encrypt( WPDA::get_option( WPDA::OPTION_PLUGIN_SONCE_SEED ) . $_SERVER['REMOTE_ADDR'], $encrypt_method, $key, 0, $iv ) );
1480 + return base64_encode(
1481 + openssl_encrypt( WPDA::get_option(
1482 + WPDA::OPTION_PLUGIN_SONCE_SEED ) .
1483 + (
1484 + isset( $_SERVER['REMOTE_ADDR'] )
1485 + ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) )
1486 + : ''
1487 + ),
1488 + $encrypt_method,
1489 + $key,
1490 + 0,
1491 + $iv
1492 + )
1493 + );
1453 1494 }
1454 1495
1455 1496 public static function wpda_create_sonce( $action = 'undefined' ) {
1456 1497 $token = self::get_sonce_token();
@@ -1473,15 +1514,14 @@
1473 1514
1474 1515 public static function wpda_create_content_folder() {
1475 1516 $upload_dir = WPDA::get_plugin_upload_dir();
1476 1517 if ( ! file_exists( $upload_dir ) ) {
1477 - mkdir( $upload_dir, 0755, true );
1478 -
1479 - $fw = fopen( $upload_dir . ".htaccess", 'w' );
1518 + mkdir( $upload_dir, 0755, true ); // phpcs:ignore
1519 + $fw = fopen( $upload_dir . ".htaccess", 'w' ); // phpcs:ignore
1480 1520 if ( false !== $fw ) {
1481 - fwrite( $fw, "IndexIgnore *" );
1521 + fwrite( $fw, "IndexIgnore *" ); // phpcs:ignore
1482 1522 }
1483 - fclose( $fw );
1523 + fclose( $fw ); // phpcs:ignore
1484 1524 }
1485 1525 }
1486 1526
1487 1527 public static function wpda_delete_content_folder() {
@@ -1488,13 +1528,12 @@
1488 1528 $upload_dir = WPDA::get_plugin_upload_dir();
1489 1529 if ( file_exists( $upload_dir ) ) {
1490 1530 $files = glob( $upload_dir . '*', GLOB_MARK );
1491 1531 foreach ( $files as $file ) {
1492 - unlink( $file );
1532 + unlink( $file ); // phpcs:ignore
1493 1533 }
1494 - unlink( $upload_dir . '.htaccess' );
1495 -
1496 - rmdir( $upload_dir );
1534 + unlink( $upload_dir . '.htaccess' ); // phpcs:ignore
1535 + rmdir( $upload_dir ); // phpcs:ignore
1497 1536 }
1498 1537 }
1499 1538
1500 1539 public static function sent_header( $content_type, $cors = null, $attachment = null ) {
@@ -1515,12 +1554,12 @@
1515 1554
1516 1555 public static function sent_msg( $status, $msg ) {
1517 1556 echo json_encode(
1518 1557 array(
1519 - 'status' => $status,
1520 - 'msg' => $msg,
1558 + 'status' => esc_attr( $status ),
1559 + 'msg' => $msg, // phpcs:ignore
1521 1560 ), true
1522 - ); // phpcs:ignore - 8.1 proof
1561 + ); // phpcs:ignore
1523 1562 }
1524 1563
1525 1564 public static function is_post() {
1526 1565 global $post;
@@ -1536,9 +1575,9 @@
1536 1575 $user_id = get_current_user_id();
1537 1576
1538 1577 $wpda_hide_manage_link = get_option( 'wpda_hide_manage_link' );
1539 1578 if ( is_array( $wpda_hide_manage_link ) ) {
1540 - $wpda_hide_manage_list = array_flip( $wpda_hide_manage_link ); //phpcs:ignore - 8.1 proof
1579 + $wpda_hide_manage_list = array_flip( $wpda_hide_manage_link ); // phpcs:ignore -- 8.1 proof
1541 1580 } else {
1542 1581 $wpda_hide_manage_list = array();
1543 1582 }
1544 1583
@@ -1584,11 +1623,11 @@
1584 1623 * @return mixed|string
1585 1624 */
1586 1625 public static function get_server_address() {
1587 1626 if ( isset( $_SERVER['SERVER_ADDR'] ) ) {
1588 - return $_SERVER['SERVER_ADDR'];
1627 + return sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) );
1589 1628 } elseif ( isset( $_SERVER['LOCAL_ADDR'] ) ) {
1590 - return $_SERVER['LOCAL_ADDR'];
1629 + return sanitize_text_field( wp_unslash( $_SERVER['LOCAL_ADDR'] ) );
1591 1630 } else {
1592 1631 return 'UNKNOWN';
1593 1632 }
1594 1633 }
@@ -1603,9 +1642,9 @@
1603 1642 return WPDA::get_current_user_email();
1604 1643 case '$$NOW$$':
1605 1644 case '$$NOWDT$$':
1606 1645 global $wpdb;
1607 - $now_db = $wpdb->get_var( 'select now()' );
1646 + $now_db = $wpdb->get_var( 'select now()' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1608 1647 $db_format = WPDA::DB_DATETIME_FORMAT;
1609 1648 $convert_date = \DateTime::createFromFormat( $db_format, $now_db );
1610 1649 if ( false !== $convert_date ) {
1611 1650 $date_format = WPDA::get_option( WPDA::OPTION_PLUGIN_DATE_FORMAT );
@@ -1629,20 +1668,22 @@
1629 1668 * @param string $errmsg Error message
1630 1669 * @return void
1631 1670 */
1632 1671 public static function wpda_log_wp_error( $errmsg ) {
1633 - $dbt = debug_backtrace();
1634 - $clr = array_shift( $dbt );//phpcs:ignore - 8.1 proof
1672 + $dbt = debug_backtrace(); // phpcs:ignore
1673 + $clr = array_shift( $dbt ); // phpcs:ignore -- 8.1 proof
1635 1674
1675 + // phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
1636 1676 error_log( "WP Data Access error in {$clr['file']}:{$clr['line']}" );
1637 1677 error_log( print_r( $errmsg, true ) );
1678 + // phpcs:enable WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
1638 1679 }
1639 1680
1640 1681 /**
1641 1682 * Get the column data types from a custom query
1642 1683 *
1643 - * @param $database Database (schema) name
1644 - * @param $query Custom query
1684 + * @param $database string Database (schema) name
1685 + * @param $query string Custom query
1645 1686 * @return array|null Column data type array or null if the query does not return any columns
1646 1687 */
1647 1688 public static function get_columns_from_query( $database, $query ) {
1648 1689 $wpdadb = WPDADB::get_db_connection( $database );
@@ -1650,9 +1691,9 @@
1650 1691 return null;
1651 1692 }
1652 1693
1653 1694 $wpdadb->suppress_errors( true );
1654 - $table_name = 'custom' . mt_rand(0, time());
1695 + $table_name = 'custom' . wp_rand(0, time());
1655 1696
1656 1697 // Create temporary table.
1657 1698 $wpdadb->query(
1658 1699 "CREATE TEMPORARY TABLE `{$table_name}` AS (select * from (" . $query . ') as t limit 0)'
@@ -1670,8 +1711,21 @@
1670 1711 }
1671 1712
1672 1713 return $rows;
1673 1714 }
1715 +
1716 + public static function current_user_is_admin() {
1717 + if (current_user_can( 'manage_options' ) || is_super_admin()) {
1718 + return true;
1719 + }
1720 +
1721 + $user = wp_get_current_user();
1722 + if ( in_array( 'administrator', $user->roles ) ) {
1723 + return true;
1724 + }
1725 +
1726 + return false;
1727 + }
1674 1728
1675 1729 }
1676 1730
1677 1731 }