dbname; } $is_wp_database = $database === $wpdb->dbname; if ( isset( $_REQUEST['action'] ) ) { $action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); // input var okay. // Security check. $wp_nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; // input var okay. if ( ! wp_verify_nonce( $wp_nonce, 'wpda-back-end-settings' ) ) { wp_die( __( 'ERROR: Not authorized', 'wp-data-access' ) ); } if ( 'save' === $action ) { // Save options. if ( $is_wp_database ) { WPDA::set_option( WPDA::OPTION_BE_TABLE_ACCESS, isset( $_REQUEST['table_access'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['table_access'] ) ) : null // input var okay. ); } else { update_option( WPDA::BACKEND_OPTIONNAME_DATABASE_ACCESS . $database, isset( $_REQUEST['table_access'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['table_access'] ) ) : null // input var okay. );} $wpda_hide_manage_link = array(); if ( isset( $_REQUEST['wpda_hide_manage_link'] ) ) { foreach ( $_REQUEST['wpda_hide_manage_link'] as $userid ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput if ( is_numeric( $userid ) ) { $wpda_hide_manage_link[] = sanitize_text_field( wp_unslash( $userid ) ); } } } update_option( 'wpda_hide_manage_link', $wpda_hide_manage_link ); $table_access_selected_new_value = isset( $_REQUEST['table_access_selected'] ) ? WPDA::sanitize_text_field_array( $_REQUEST['table_access_selected'] ) : null; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput if ( is_array( $table_access_selected_new_value ) ) { // Check the requested table names for sql injection. This is simply done by checking if the table // name exists in our WordPress database. $table_access_selected_new_value_checked = array(); foreach ( $table_access_selected_new_value as $key => $value ) { $wpda_dictionary_checks = new WPDA_Dictionary_Exist( $database, $value ); if ( $wpda_dictionary_checks->table_exists( false ) ) { // Add existing table to list. $table_access_selected_new_value_checked[ $key ] = $value; } else { // An invalid table name was provided. Might be an sql injection attack or an invalid state. wp_die( __( 'ERROR: Invalid table name', 'wp-data-access' ) ); } } } else { $table_access_selected_new_value_checked = ''; } if ( $is_wp_database ) { WPDA::set_option( WPDA::OPTION_BE_TABLE_ACCESS_SELECTED, $table_access_selected_new_value_checked ); } else { update_option( WPDA::BACKEND_OPTIONNAME_DATABASE_SELECTED . $database, $table_access_selected_new_value_checked ); } WPDA::set_option( WPDA::OPTION_BE_VIEW_LINK, isset( $_REQUEST['view_link'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['view_link'] ) ) : 'off' // input var okay. ); WPDA::set_option( WPDA::OPTION_BE_ALLOW_INSERT, isset( $_REQUEST['allow_insert'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['allow_insert'] ) ) : 'off' // input var okay. ); WPDA::set_option( WPDA::OPTION_BE_ALLOW_UPDATE, isset( $_REQUEST['allow_update'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['allow_update'] ) ) : 'off' // input var okay. ); WPDA::set_option( WPDA::OPTION_BE_ALLOW_DELETE, isset( $_REQUEST['allow_delete'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['allow_delete'] ) ) : 'off' // input var okay. ); WPDA::set_option( WPDA::OPTION_BE_EXPORT_ROWS, isset( $_REQUEST['export_rows'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['export_rows'] ) ) : 'off' // input var okay. ); WPDA::set_option( WPDA::OPTION_BE_EXPORT_VARIABLE_PREFIX, isset( $_REQUEST['export_variable_rows'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['export_variable_rows'] ) ) : 'off' // input var okay. ); WPDA::set_option( WPDA::OPTION_BE_ALLOW_IMPORTS, isset( $_REQUEST['allow_imports'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['allow_imports'] ) ) : 'off' // input var okay. ); WPDA::set_option( WPDA::OPTION_BE_CONFIRM_EXPORT, isset( $_REQUEST['confirm_export'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['confirm_export'] ) ) : 'off' // input var okay. ); WPDA::set_option( WPDA::OPTION_BE_CONFIRM_VIEW, isset( $_REQUEST['confirm_view'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['confirm_view'] ) ) : 'off' // input var okay. ); WPDA::set_option( WPDA::OPTION_BE_PAGINATION, isset( $_REQUEST['pagination'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['pagination'] ) ) : null // input var okay. ); WPDA::set_option( WPDA::OPTION_BE_REMEMBER_SEARCH, isset( $_REQUEST['remember_search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['remember_search'] ) ) : 'off' // input var okay. ); WPDA::set_option( WPDA::OPTION_BE_INNODB_COUNT, isset( $_REQUEST['innodb_count'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['innodb_count'] ) ) : 100000 // input var okay. ); WPDA::set_option( WPDA::OPTION_BE_DESIGN_MODE, isset( $_REQUEST['design_mode'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['design_mode'] ) ) : 'basic' // input var okay. ); WPDA::set_option( WPDA::OPTION_BE_TEXT_WRAP_SWITCH, isset( $_REQUEST['text_wrap_switch'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['text_wrap_switch'] ) ) : 'off' // input var okay. ); WPDA::set_option( WPDA::OPTION_BE_TEXT_WRAP, isset( $_REQUEST['text_wrap'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['text_wrap'] ) ) : 400 // input var okay. ); if ( isset( $_REQUEST['wpda_default_user'] ) && isset( $_REQUEST['wpda_default_database'] ) && '' !== $_REQUEST['wpda_default_user'] && '' !== $_REQUEST['wpda_default_database'] ) { $default_databases = get_option( 'wpda_default_database' ); if ( false === $default_databases ) { $default_databases = array(); } $wpda_default_user = sanitize_text_field( wp_unslash( $_REQUEST['wpda_default_user'] ) ); // input var okay. $wpda_default_database = sanitize_text_field( wp_unslash( $_REQUEST['wpda_default_database'] ) ); // input var okay. $default_databases[ $wpda_default_user ] = $wpda_default_database; update_option( 'wpda_default_database', $default_databases ); } WPDA::set_option( WPDA::OPTION_BE_HIDE_BUTTON_ICONS, isset( $_REQUEST['hide_button_icons'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['hide_button_icons'] ) ) : 'off' // input var okay. ); } elseif ( 'setdefaults' === $action ) { // Set all back-end settings back to default. if ( $is_wp_database ) { WPDA::set_option( WPDA::OPTION_BE_TABLE_ACCESS ); WPDA::set_option( WPDA::OPTION_BE_TABLE_ACCESS_SELECTED ); } else { update_option( WPDA::BACKEND_OPTIONNAME_DATABASE_ACCESS . $database, 'show' ); update_option( WPDA::BACKEND_OPTIONNAME_DATABASE_SELECTED . $database, '' ); } update_option( 'wpda_hide_manage_link', array() ); WPDA::set_option( WPDA::OPTION_BE_VIEW_LINK ); WPDA::set_option( WPDA::OPTION_BE_ALLOW_INSERT ); WPDA::set_option( WPDA::OPTION_BE_ALLOW_UPDATE ); WPDA::set_option( WPDA::OPTION_BE_ALLOW_DELETE ); WPDA::set_option( WPDA::OPTION_BE_EXPORT_ROWS ); WPDA::set_option( WPDA::OPTION_BE_EXPORT_VARIABLE_PREFIX ); WPDA::set_option( WPDA::OPTION_BE_ALLOW_IMPORTS ); WPDA::set_option( WPDA::OPTION_BE_CONFIRM_EXPORT ); WPDA::set_option( WPDA::OPTION_BE_CONFIRM_VIEW ); WPDA::set_option( WPDA::OPTION_BE_PAGINATION ); WPDA::set_option( WPDA::OPTION_BE_REMEMBER_SEARCH ); WPDA::set_option( WPDA::OPTION_BE_INNODB_COUNT ); WPDA::set_option( WPDA::OPTION_BE_DESIGN_MODE ); WPDA::set_option( WPDA::OPTION_BE_TEXT_WRAP_SWITCH ); WPDA::set_option( WPDA::OPTION_BE_TEXT_WRAP ); update_option( 'wpda_default_database', array() ); WPDA::set_option( WPDA::OPTION_BE_HIDE_BUTTON_ICONS ); } elseif ( 'delete_default_user_database' === $action ) { if ( isset( $_REQUEST['wpda_default_database_delete'] ) ) { $delete_user_id = sanitize_text_field( wp_unslash( $_REQUEST['wpda_default_database_delete'] ) ); // input var okay. $default_databases = get_option( 'wpda_default_database' ); if ( false !== $default_databases && isset( $default_databases[ $delete_user_id ] ) ) { unset( $default_databases[ $delete_user_id ] ); update_option( 'wpda_default_database', $default_databases ); } } } $msg = new WPDA_Message_Box( array( 'message_text' => __( 'Settings saved', 'wp-data-access' ), ) ); $msg->box(); } // Get options. if ( $is_wp_database ) { $table_access = WPDA::get_option( WPDA::OPTION_BE_TABLE_ACCESS ); $table_access_selected = WPDA::get_option( WPDA::OPTION_BE_TABLE_ACCESS_SELECTED ); } else { $table_access = get_option( WPDA::BACKEND_OPTIONNAME_DATABASE_ACCESS . $database ); if ( false === $table_access ) { $table_access = 'show'; } $table_access_selected = get_option( WPDA::BACKEND_OPTIONNAME_DATABASE_SELECTED . $database ); if ( false === $table_access_selected ) { $table_access_selected = ''; } } if ( is_array( $table_access_selected ) ) { // Convert table for simple access. $table_access_selected_by_name = array(); foreach ( $table_access_selected as $key => $value ) { $table_access_selected_by_name[ $value ] = true; } } $wpda_hide_manage_link = get_option( 'wpda_hide_manage_link' ); if ( is_array( $wpda_hide_manage_link ) ) { $wpda_hide_manage_list = array_flip( $wpda_hide_manage_link ); //phpcs:ignore - 8.1 proof } else { $wpda_hide_manage_list = array(); } $view_link = WPDA::get_option( WPDA::OPTION_BE_VIEW_LINK ); $allow_insert = WPDA::get_option( WPDA::OPTION_BE_ALLOW_INSERT ); $allow_update = WPDA::get_option( WPDA::OPTION_BE_ALLOW_UPDATE ); $allow_delete = WPDA::get_option( WPDA::OPTION_BE_ALLOW_DELETE ); $export_rows = WPDA::get_option( WPDA::OPTION_BE_EXPORT_ROWS ); $export_variable_rows = WPDA::get_option( WPDA::OPTION_BE_EXPORT_VARIABLE_PREFIX ); $allow_imports = WPDA::get_option( WPDA::OPTION_BE_ALLOW_IMPORTS ); $confirm_export = WPDA::get_option( WPDA::OPTION_BE_CONFIRM_EXPORT ); $confirm_view = WPDA::get_option( WPDA::OPTION_BE_CONFIRM_VIEW ); $pagination = WPDA::get_option( WPDA::OPTION_BE_PAGINATION ); $remember_search = WPDA::get_option( WPDA::OPTION_BE_REMEMBER_SEARCH ); $innodb_count = WPDA::get_option( WPDA::OPTION_BE_INNODB_COUNT ); $design_mode = WPDA::get_option( WPDA::OPTION_BE_DESIGN_MODE ); $text_wrap_switch = WPDA::get_option( WPDA::OPTION_BE_TEXT_WRAP_SWITCH ); $text_wrap = WPDA::get_option( WPDA::OPTION_BE_TEXT_WRAP ); $hide_button_icons = WPDA::get_option( WPDA::OPTION_BE_HIDE_BUTTON_ICONS ); ?>