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 +116 -82 5.5.415.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.41' );
55 - const OPTION_WPDA_CLIENT_VERSION = array( 'wpda_client_version', '1.0.41' );
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 */
@@ -126,8 +128,11 @@
126 128 const OPTION_PLUGIN_TIME_FORMAT = array( 'wpda_plugin_time_format', 'H:i');
127 129 const OPTION_PLUGIN_TIME_PLACEHOLDER = array( 'wpda_plugin_time_placeholder', 'hh:mi');
128 130 const OPTION_PLUGIN_SET_FORMAT = array( 'wpda_plugin_set_format', 'csv');
129 131
132 + // App options
133 + const OPTION_APPS_SCROLL_OFFSET = array( 'wpda_apps_scroll_offset', '120');
134 +
130 135 // Plugin debug mode
131 136 const OPTION_PLUGIN_DEBUG = array( 'wpda_plugin_debug', 'off');
132 137
133 138 // Back-end options.
@@ -341,8 +346,9 @@
341 346 WP_Data_Access_Admin::PAGE_PUBLISHER,
342 347 WP_Data_Access_Admin::PAGE_DESIGNER,
343 348 WP_Data_Access_Admin::PAGE_MY_TABLES,
344 349 WP_Data_Access_Admin::PAGE_CHARTS,
350 + WP_Data_Access_Admin::PAGE_TABLE,
345 351 WPDP::PAGE_MAIN,
346 352 WPDP::PAGE_TEMPLATES,
347 353 );
348 354
@@ -351,9 +357,9 @@
351 357 is_scalar( $page ) &&
352 358 (
353 359 'wpda_wpdp_' === substr( $page, 0, 10 ) ||
354 360 WP_Data_Access_Admin::PAGE_EXPLORER === substr( $page, 0, 13 ) ||
355 - in_array( $page, self::$plugin_pages) //phpcs:ignore - 8.1 proof
361 + in_array( $page, self::$plugin_pages) // phpcs:ignore -- 8.1 proof
356 362 )
357 363 );
358 364 }
359 365
@@ -426,9 +432,9 @@
426 432 public static function clear_all_options() {
427 433
428 434 global $wpdb;
429 435
430 - $wpdb->query(
436 + $wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
431 437 "
432 438 DELETE FROM wp_options
433 439 WHERE option_name LIKE 'wpda_%'
434 440 "
@@ -444,9 +450,9 @@
444 450 * @since 1.1.0
445 451 */
446 452 public static function load_wp_tables() {
447 453
448 - if ( 0 === count( self::$wp_tables ) ) {//phpcs:ignore - 8.1 proof
454 + if ( 0 === count( self::$wp_tables ) ) { // phpcs:ignore -- 8.1 proof
449 455 try {
450 456 global $wpdb;
451 457
452 458 if ( ! is_multisite() ) {
@@ -454,11 +460,11 @@
454 460 self::$wp_tables[ $table ] = $table;
455 461 }
456 462 } else {
457 463 $query = "select blog_id from {$wpdb->blogs}";
458 - $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
459 465 foreach ( $blogs as $blog ) {
460 - 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
461 467 self::$wp_tables[ $table ] = $table;
462 468 }
463 469 }
464 470 }
@@ -464,12 +470,14 @@
464 470 }
465 471
466 472 return true;
467 473 } catch ( \Exception $e ) {
468 - wp_die( 'ERROR: ' . $e->getMessage() );
474 + wp_die( esc_attr( 'ERROR: ' . $e->getMessage() ) );
469 475 }
470 476 }
471 477
478 + return false;
479 +
472 480 }
473 481
474 482 /**
475 483 * Checks if a table is a WordPress table
@@ -483,9 +491,9 @@
483 491 public static function is_wp_table( $table_name ) {
484 492
485 493 self::load_wp_tables();
486 494
487 - if ( 0 === count( self::$wp_tables ) ) {//phpcs:ignore - 8.1 proof
495 + if ( 0 === count( self::$wp_tables ) ) { // phpcs:ignore -- 8.1 proof
488 496 return false;
489 497 }
490 498
491 499 return isset( self::$wp_tables[ $table_name ] );
@@ -502,10 +510,10 @@
502 510 public static function get_wp_tables() {
503 511
504 512 self::load_wp_tables();
505 513
506 - if ( 0 === count( self::$wp_tables ) ) {//phpcs:ignore - 8.1 proof
507 - 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' ) );
508 516 }
509 517
510 518 return self::$wp_tables;
511 519
@@ -539,9 +547,9 @@
539 547 *
540 548 * @return bool
541 549 */
542 550 public static function column_is_schema_name( $table_name, $column_name ) {
543 - if ( 0 === count( self::$wpda_tables ) ) {//phpcs:ignore - 8.1 proof
551 + if ( 0 === count( self::$wpda_tables ) ) { // phpcs:ignore -- 8.1 proof
544 552 // Cache schema names
545 553 global $wpdb;
546 554 self::$wpda_tables[$wpdb->prefix . 'wpda_media.media_schema_name' ] = true;
547 555 self::$wpda_tables[$wpdb->prefix . 'wpda_project_page.page_schema_name' ] = true;
@@ -719,13 +727,13 @@
719 727 *
720 728 * @return array
721 729 */
722 730 public static function array_insert_after( $array, $key, $new ) {
723 - $keys = array_keys( (array) $array ); //phpcs:ignore - 8.1 proof
724 - $index = array_search( $key, $keys ); //phpcs:ignore - 8.1 proof
725 - $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
726 734
727 - 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
728 736 }
729 737
730 738 /**
731 739 * Log a message in the database
@@ -751,9 +759,9 @@
751 759 , $log_id
752 760 , $log_type
753 761 , $log_msg
754 762 );
755 - $wpdb->query( $sql );
763 + $wpdb->query( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
756 764
757 765 }
758 766
759 767 /**
@@ -787,9 +795,9 @@
787 795 if ( is_user_logged_in() ) {
788 796 $user = wp_get_current_user();
789 797 $allcaps = array();
790 798 foreach ( $user->allcaps as $key => $val ) {
791 - array_push( $allcaps, $key );//phpcs:ignore - 8.1 proof
799 + array_push( $allcaps, $key ); // phpcs:ignore -- 8.1 proof
792 800 }
793 801
794 802 return $allcaps[0];
795 803 } else {
@@ -815,15 +823,12 @@
815 823 } else if ( $matches[2] == 'K' ) {
816 824 return $matches[1] * 1024;
817 825 }
818 826 }
827 + return '';
819 828 }
820 829
821 - public static function get_current_user_id( $is_anonymous = false ) {
822 - if ( $is_anonymous ) {
823 - return -1;
824 - }
825 -
830 + public static function get_current_user_id() {
826 831 global $current_user;
827 832 if ( isset( $current_user->ID ) ) {
828 833 return $current_user->ID;
829 834 } else {
@@ -831,12 +836,12 @@
831 836 $wp_user = wp_get_current_user();
832 837 if ( isset( $wp_user->ID ) ) {
833 838 return $wp_user->ID;
834 839 } else {
835 - return - 1;
840 + return -1;
836 841 }
837 842 } else {
838 - return - 1;
843 + return -1;
839 844 }
840 845 }
841 846 }
842 847
@@ -926,9 +931,9 @@
926 931 * $columns['column_default'] => information_schema.tables.column_default
927 932 *
928 933 * @param string $schema_name Schema name (optional)
929 934 * @param string $table_name Table name (optional)
930 - * @param string $columns Array containing table columns
935 + * @param array $columns Array containing table columns
931 936 * @param string $search Search string entered by user
932 937 * @param boolean $is_case_sensitive Case-sensitive search (default = false)
933 938 * @param boolean $is_dt_request Always skip filter for DataTable requests (default = false)
934 939 *
@@ -986,22 +991,22 @@
986 991 $where_columns = array();
987 992
988 993 foreach ( $columns as $column ) {
989 994 if ( 'string' === WPDA::get_type( $column['data_type'] ) ) {
990 - $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
991 996 }
992 997
993 998 if ( $is_dt_request ) {
994 999 // Handle numeric and date queries for DataTables.
995 1000 if ( 'number' === WPDA::get_type( $column['data_type'] ) && ( is_numeric( $search ) ) ) {
996 - $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
997 1002 } elseif ( 'date' === WPDA::get_type( $column['data_type'] ) ) {
998 - $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
999 1004 }
1000 1005 }
1001 1006 }
1002 1007
1003 - if ( 0 === count( $where_columns ) ) {//phpcs:ignore - 8.1 proof
1008 + if ( 0 === count( $where_columns ) ) { // phpcs:ignore -- 8.1 proof
1004 1009 return '' === $where_search_args ? ' (1=2) ' : $where_search_args;
1005 1010 }
1006 1011
1007 1012 if ( '' === $where_search_args ) {
@@ -1015,11 +1020,11 @@
1015 1020 $where_columns = array();
1016 1021
1017 1022 if ( is_array( $columns ) ) {
1018 1023 global $wpdb;
1019 - $request = array_change_key_case( $_REQUEST ); //phpcs:ignore - 8.1 proof
1024 + $request = array_change_key_case( $_REQUEST ); // phpcs:ignore -- 8.1 proof
1020 1025 foreach ( $columns as $column ) {
1021 - $column_name = str_replace( '`', '', $column['column_name'] );
1026 + $column_name = str_replace( '`', '', $column['column_name'] ?? '' );
1022 1027 $column_name_lwr = strtolower( $column_name );
1023 1028 if ( isset( $request["wpda_search_column_{$column_name_lwr}"] ) ) {
1024 1029 if ( is_array( $request["wpda_search_column_{$column_name_lwr}"] ) ) {
1025 1030 // Handle multiple values for same column with OR
@@ -1028,16 +1033,16 @@
1028 1033 $column_date_type = $column['data_type'];
1029 1034 $column_value = wp_strip_all_tags( wp_unslash( $value ) ); // input var okay.
1030 1035 if ( '' !== $column_value ) {
1031 1036 if ( 'string' === WPDA::get_type( $column_date_type ) ) {
1032 - $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
1033 1038 } elseif ( 'number' === WPDA::get_type( $column_date_type ) ) {
1034 - $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
1035 1040 }
1036 1041 }
1037 1042 }
1038 - if ( count( $where_columns_arr ) > 0 ) {//phpcs:ignore - 8.1 proof
1039 - $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
1040 1045 }
1041 1046 } else {
1042 1047 // Handle single value
1043 1048 $column_date_type = $column['data_type'];
@@ -1043,11 +1048,11 @@
1043 1048 $column_date_type = $column['data_type'];
1044 1049 $column_value = wp_strip_all_tags( wp_unslash( $request[ "wpda_search_column_{$column_name_lwr}" ] ) );
1045 1050 if ( '' !== $column_value ) {
1046 1051 if ( 'string' === WPDA::get_type( $column_date_type ) ) {
1047 - $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
1048 1053 } elseif ( 'number' === WPDA::get_type( $column_date_type ) ) {
1049 - $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
1050 1055 }
1051 1056 }
1052 1057 }
1053 1058 }
@@ -1053,14 +1058,13 @@
1053 1058 }
1054 1059 }
1055 1060 }
1056 1061
1057 - if ( 0 === count( $where_columns ) ) {//phpcs:ignore - 8.1 proof
1062 + if ( 0 === count( $where_columns ) ) { // phpcs:ignore -- 8.1 proof
1058 1063 return '';
1059 1064 } else {
1060 1065 $operator =
1061 - isset( $_REQUEST['wpda_search_column_operator'] ) &&
1062 - 'or' === strtolower( $_REQUEST['wpda_search_column_operator'] )
1066 + isset( $_REQUEST['wpda_search_column_operator'] ) && 'or' === strtolower( $_REQUEST['wpda_search_column_operator'] ) // phpcs:ignore
1063 1067 ? 'or' : 'and';
1064 1068 return ' (' . implode( " $operator ", $where_columns ) . ') ';
1065 1069 }
1066 1070 }
@@ -1093,15 +1097,18 @@
1093 1097 return false;
1094 1098 }
1095 1099 if ( method_exists( $wpdadb, 'is_connected' ) ) {
1096 1100 if ( ! $wpdadb->is_connected() ) {
1101 + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
1097 1102 $msg = new WPDA_Message_Box(
1098 1103 [
1099 - '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 ),
1100 1106 'message_type' => 'error',
1101 1107 'message_is_dismissible' => false,
1102 1108 ]
1103 1109 );
1110 + // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment
1104 1111 $msg->box();
1105 1112
1106 1113 return false;
1107 1114 }
@@ -1115,9 +1122,9 @@
1115 1122 $wpdadb->dbname,
1116 1123 ]
1117 1124 )
1118 1125 ); // db call ok; no-cache ok.
1119 - $wpdadb->get_results(); // phpcs:ignore Standard.Category.SniffName.ErrorCode
1126 + $wpdadb->get_results();
1120 1127
1121 1128 return 1 === $wpdadb->num_rows;
1122 1129 }
1123 1130
@@ -1144,23 +1151,28 @@
1144 1151 jQuery(function() {
1145 1152 var clipboard = new ClipboardJS('.wpda_shortcode_clipboard');
1146 1153 });
1147 1154 </script>
1148 - <style type="text/css">
1155 + <style>
1156 + /* noinspection CssUnusedSymbol */
1149 1157 .wpda_shortcode_content {
1150 1158 padding: 0 20px;
1151 1159 }
1160 + /* noinspection CssUnusedSymbol */
1152 1161 .wpda_shortcode_text {
1153 1162 text-align: center;
1154 1163 font-size: 105%;
1155 1164 white-space: nowrap;
1156 1165 }
1166 + /* noinspection CssUnusedSymbol */
1157 1167 .wpda_shortcode_buttons {
1158 1168 text-align: center;
1159 1169 }
1170 + /* noinspection CssUnusedSymbol */
1160 1171 .button.wpda_shortcode_button {
1161 1172 width: 100px !important;
1162 1173 }
1174 + /* noinspection CssUnusedSymbol */
1163 1175 .wpda_shortcode_link {
1164 1176 text-decoration: none;
1165 1177 font-weight: bold;
1166 1178 }
@@ -1189,9 +1201,9 @@
1189 1201 * @return array
1190 1202 */
1191 1203 public static function get_post_types() {
1192 1204 global $wpdb;
1193 - $rows = $wpdb->get_results(
1205 + $rows = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1194 1206 "select distinct post_type from {$wpdb->posts}",
1195 1207 'ARRAY_N'
1196 1208 );
1197 1209
@@ -1204,9 +1216,9 @@
1204 1216 }
1205 1217
1206 1218 public static function get_table_engine( $schema_name, $table_name ) {
1207 1219 $table_info = WPDA::get_table_values( $schema_name, $table_name );
1208 - //phpcs:ignore - 8.1 proof
1220 + // phpcs:ignore -- 8.1 proof
1209 1221 return (
1210 1222 1 === count( $table_info ) &&
1211 1223 'connect' === strtolower( $table_info[0]['engine'] )
1212 1224 ) ? 'connect' : '';
@@ -1235,13 +1247,13 @@
1235 1247
1236 1248 /**
1237 1249 * Get estimated number of rows in a table
1238 1250 *
1239 - * @param $schema_name Schema name
1240 - * @param $table_name Table name
1241 - * @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)
1242 1254 *
1243 - * @return int row count estimate or -1 if no estimate available
1255 + * @return array row count estimate or -1 if no estimate available
1244 1256 */
1245 1257 public static function get_row_count_estimate( $schema_name, $table_name, $wpda_table_settings ) {
1246 1258 $row_count = null;
1247 1259 $is_estimate = null;
@@ -1246,9 +1258,9 @@
1246 1258 $row_count = null;
1247 1259 $is_estimate = null;
1248 1260 $do_real_count = null;
1249 1261 $table_info = self::get_table_values( $schema_name, $table_name );
1250 - if ( 1 === count( $table_info ) ) {//phpcs:ignore - 8.1 proof
1262 + if ( 1 === count( $table_info ) ) { // phpcs:ignore -- 8.1 proof
1251 1263 $row_count = $table_info[0]['table_rows'];
1252 1264
1253 1265 $system_row_count_estimate = null;
1254 1266 $row_count_estimate_value = null;
@@ -1303,9 +1315,9 @@
1303 1315 }
1304 1316 } elseif ( 'connect' === strtolower( $table_info[0]['engine'] ) ) {
1305 1317 $getpk = WPDA_List_Columns_Cache::get_list_columns( $schema_name, $table_name );
1306 1318 $pk = $getpk->get_table_primary_key();
1307 - 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
1308 1320 $sql_rowcount_sql =
1309 1321 'select count(*) from `' . str_replace( '`', '', $table_name ) .
1310 1322 '` where `' . $pk[0] . '` not in ' .
1311 1323 '(select null from `' . str_replace( '`', '', $table_name ) . '` where 1=2)';
@@ -1310,9 +1322,9 @@
1310 1322 '` where `' . $pk[0] . '` not in ' .
1311 1323 '(select null from `' . str_replace( '`', '', $table_name ) . '` where 1=2)';
1312 1324 $wpdadb = WPDADB::get_db_connection( $schema_name );
1313 1325 $sql_rowcount = $wpdadb->get_results( $sql_rowcount_sql, 'ARRAY_N' );
1314 - if ( count( $sql_rowcount ) === 1 ) {//phpcs:ignore - 8.1 proof
1326 + if ( count( $sql_rowcount ) === 1 ) { // phpcs:ignore -- 8.1 proof
1315 1327 $row_count = $sql_rowcount[0][0];
1316 1328 $is_estimate = false;
1317 1329 $do_real_count = false;
1318 1330 } else {
@@ -1359,11 +1371,11 @@
1359 1371 }
1360 1372
1361 1373 if ( null === $column_names ) {
1362 1374 $columns = WPDA_Dictionary_Lists::get_table_columns( $table_name, $schema_name );
1363 - $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
1364 1376 }
1365 - if ( count( $column_names ) === 0 ) {//phpcs:ignore - 8.1 proof
1377 + if ( count( $column_names ) === 0 ) { // phpcs:ignore -- 8.1 proof
1366 1378 return self::validate_name_np();
1367 1379 }
1368 1380
1369 1381 $is_valid = true;
@@ -1390,9 +1402,9 @@
1390 1402
1391 1403 public static function validate_name_failed() {
1392 1404 $title = __( 'Schema, table or column name(s) restricting plugin features (click to read more and fix)', 'wp-data-access' );
1393 1405 $warning = "
1394 - <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'>
1395 1407 <span class='dashicons dashicons-flag wpda_tooltip' style='color:red;padding-left:5px' title='$title'></span>
1396 1408 </a>";
1397 1409 return $warning;
1398 1410 }
@@ -1399,9 +1411,9 @@
1399 1411
1400 1412 public static function validate_name_np() {
1401 1413 $title = __( 'Schema, table or column name validation not possible (click to read more and fix)', 'wp-data-access' );
1402 1414 $warning = "
1403 - <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'>
1404 1416 <span class='dashicons dashicons-warning wpda_tooltip' style='padding-left:5px' title='$title'></span>
1405 1417 </a>";
1406 1418 return $warning;
1407 1419 }
@@ -1464,9 +1476,22 @@
1464 1476 $encrypt_method = 'AES-256-CBC';
1465 1477 $key = hash( 'sha256', WPDA::get_option( WPDA::OPTION_PLUGIN_SECRET_KEY ) );
1466 1478 $iv = substr( hash( 'sha256', WPDA::get_option( WPDA::OPTION_PLUGIN_SECRET_IV ) ), 0, 16 );
1467 1479
1468 - 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 + );
1469 1494 }
1470 1495
1471 1496 public static function wpda_create_sonce( $action = 'undefined' ) {
1472 1497 $token = self::get_sonce_token();
@@ -1489,15 +1514,14 @@
1489 1514
1490 1515 public static function wpda_create_content_folder() {
1491 1516 $upload_dir = WPDA::get_plugin_upload_dir();
1492 1517 if ( ! file_exists( $upload_dir ) ) {
1493 - mkdir( $upload_dir, 0755, true );
1494 -
1495 - $fw = fopen( $upload_dir . ".htaccess", 'w' );
1518 + mkdir( $upload_dir, 0755, true ); // phpcs:ignore
1519 + $fw = fopen( $upload_dir . ".htaccess", 'w' ); // phpcs:ignore
1496 1520 if ( false !== $fw ) {
1497 - fwrite( $fw, "IndexIgnore *" );
1521 + fwrite( $fw, "IndexIgnore *" ); // phpcs:ignore
1498 1522 }
1499 - fclose( $fw );
1523 + fclose( $fw ); // phpcs:ignore
1500 1524 }
1501 1525 }
1502 1526
1503 1527 public static function wpda_delete_content_folder() {
@@ -1504,13 +1528,12 @@
1504 1528 $upload_dir = WPDA::get_plugin_upload_dir();
1505 1529 if ( file_exists( $upload_dir ) ) {
1506 1530 $files = glob( $upload_dir . '*', GLOB_MARK );
1507 1531 foreach ( $files as $file ) {
1508 - unlink( $file );
1532 + unlink( $file ); // phpcs:ignore
1509 1533 }
1510 - unlink( $upload_dir . '.htaccess' );
1511 -
1512 - rmdir( $upload_dir );
1534 + unlink( $upload_dir . '.htaccess' ); // phpcs:ignore
1535 + rmdir( $upload_dir ); // phpcs:ignore
1513 1536 }
1514 1537 }
1515 1538
1516 1539 public static function sent_header( $content_type, $cors = null, $attachment = null ) {
@@ -1531,12 +1554,12 @@
1531 1554
1532 1555 public static function sent_msg( $status, $msg ) {
1533 1556 echo json_encode(
1534 1557 array(
1535 - 'status' => $status,
1536 - 'msg' => $msg,
1558 + 'status' => esc_attr( $status ),
1559 + 'msg' => $msg, // phpcs:ignore
1537 1560 ), true
1538 - ); // phpcs:ignore - 8.1 proof
1561 + ); // phpcs:ignore
1539 1562 }
1540 1563
1541 1564 public static function is_post() {
1542 1565 global $post;
@@ -1552,9 +1575,9 @@
1552 1575 $user_id = get_current_user_id();
1553 1576
1554 1577 $wpda_hide_manage_link = get_option( 'wpda_hide_manage_link' );
1555 1578 if ( is_array( $wpda_hide_manage_link ) ) {
1556 - $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
1557 1580 } else {
1558 1581 $wpda_hide_manage_list = array();
1559 1582 }
1560 1583
@@ -1600,11 +1623,11 @@
1600 1623 * @return mixed|string
1601 1624 */
1602 1625 public static function get_server_address() {
1603 1626 if ( isset( $_SERVER['SERVER_ADDR'] ) ) {
1604 - return $_SERVER['SERVER_ADDR'];
1627 + return sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) );
1605 1628 } elseif ( isset( $_SERVER['LOCAL_ADDR'] ) ) {
1606 - return $_SERVER['LOCAL_ADDR'];
1629 + return sanitize_text_field( wp_unslash( $_SERVER['LOCAL_ADDR'] ) );
1607 1630 } else {
1608 1631 return 'UNKNOWN';
1609 1632 }
1610 1633 }
@@ -1619,9 +1642,9 @@
1619 1642 return WPDA::get_current_user_email();
1620 1643 case '$$NOW$$':
1621 1644 case '$$NOWDT$$':
1622 1645 global $wpdb;
1623 - $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
1624 1647 $db_format = WPDA::DB_DATETIME_FORMAT;
1625 1648 $convert_date = \DateTime::createFromFormat( $db_format, $now_db );
1626 1649 if ( false !== $convert_date ) {
1627 1650 $date_format = WPDA::get_option( WPDA::OPTION_PLUGIN_DATE_FORMAT );
@@ -1645,20 +1668,22 @@
1645 1668 * @param string $errmsg Error message
1646 1669 * @return void
1647 1670 */
1648 1671 public static function wpda_log_wp_error( $errmsg ) {
1649 - $dbt = debug_backtrace();
1650 - $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
1651 1674
1675 + // phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
1652 1676 error_log( "WP Data Access error in {$clr['file']}:{$clr['line']}" );
1653 1677 error_log( print_r( $errmsg, true ) );
1678 + // phpcs:enable WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
1654 1679 }
1655 1680
1656 1681 /**
1657 1682 * Get the column data types from a custom query
1658 1683 *
1659 - * @param $database Database (schema) name
1660 - * @param $query Custom query
1684 + * @param $database string Database (schema) name
1685 + * @param $query string Custom query
1661 1686 * @return array|null Column data type array or null if the query does not return any columns
1662 1687 */
1663 1688 public static function get_columns_from_query( $database, $query ) {
1664 1689 $wpdadb = WPDADB::get_db_connection( $database );
@@ -1666,9 +1691,9 @@
1666 1691 return null;
1667 1692 }
1668 1693
1669 1694 $wpdadb->suppress_errors( true );
1670 - $table_name = 'custom' . mt_rand(0, time());
1695 + $table_name = 'custom' . wp_rand(0, time());
1671 1696
1672 1697 // Create temporary table.
1673 1698 $wpdadb->query(
1674 1699 "CREATE TEMPORARY TABLE `{$table_name}` AS (select * from (" . $query . ') as t limit 0)'
@@ -1688,9 +1713,18 @@
1688 1713 return $rows;
1689 1714 }
1690 1715
1691 1716 public static function current_user_is_admin() {
1692 - return current_user_can( 'manage_options' );
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;
1693 1727 }
1694 1728
1695 1729 }
1696 1730