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-front-end-settings-' . WPDA::get_current_user_login() ) ) { wp_die( __( 'ERROR: Not authorized', 'wp-data-access' ) ); } if ( 'save' === $action ) { if ( $is_wp_database ) { WPDA::set_option( WPDA::OPTION_FE_TABLE_ACCESS, ( isset( $_REQUEST['table_access'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['table_access'] ) ) : null ) ); } else { update_option( WPDA::FRONTEND_OPTIONNAME_DATABASE_ACCESS . $database, ( isset( $_REQUEST['table_access'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['table_access'] ) ) : null ) ); } $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, 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: Table not found', 'wp-data-access' ) ); } } } else { $table_access_selected_new_value_checked = ''; } if ( $is_wp_database ) { WPDA::set_option( WPDA::OPTION_FE_TABLE_ACCESS_SELECTED, $table_access_selected_new_value_checked ); } else { update_option( WPDA::FRONTEND_OPTIONNAME_DATABASE_SELECTED . $database, $table_access_selected_new_value_checked ); } WPDA::set_option( WPDA::OPTION_FE_PAGINATION, ( isset( $_REQUEST['pagination'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['pagination'] ) ) : null ) ); if ( isset( $_REQUEST['ui_theme'] ) ) { WPDA::set_option( WPDA::WPDA_DT_UI_THEME_DEFAULT, sanitize_text_field( wp_unslash( $_REQUEST['ui_theme'] ) ) ); } WPDA::set_option( WPDA::OPTION_FE_ADD_PROJECTS_TO_TOOLBAR, ( isset( $_REQUEST['add_projects_to_toolbar'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['add_projects_to_toolbar'] ) ) : 'off' ) ); } elseif ( 'setdefaults' === $action ) { // Set all front-end settings back to default if ( $is_wp_database ) { WPDA::set_option( WPDA::OPTION_FE_TABLE_ACCESS ); WPDA::set_option( WPDA::OPTION_FE_TABLE_ACCESS_SELECTED ); } else { update_option( WPDA::FRONTEND_OPTIONNAME_DATABASE_ACCESS . $database, 'select' ); update_option( WPDA::FRONTEND_OPTIONNAME_DATABASE_SELECTED . $database, '' ); } WPDA::set_option( WPDA::OPTION_FE_PAGINATION ); WPDA::set_option( WPDA::WPDA_DT_UI_THEME_DEFAULT ); WPDA::set_option( WPDA::OPTION_FE_ADD_PROJECTS_TO_TOOLBAR ); } $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_FE_TABLE_ACCESS ); $table_access_selected = WPDA::get_option( WPDA::OPTION_FE_TABLE_ACCESS_SELECTED ); } else { $table_access = get_option( WPDA::FRONTEND_OPTIONNAME_DATABASE_ACCESS . $database ); if ( false === $table_access ) { $table_access = 'select'; } $table_access_selected = get_option( WPDA::FRONTEND_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; } } $pagination = WPDA::get_option( WPDA::OPTION_FE_PAGINATION ); $ui_theme_default = WPDA::get_option( WPDA::WPDA_DT_UI_THEME_DEFAULT ); $add_projects_to_toolbar = WPDA::get_option( WPDA::OPTION_FE_ADD_PROJECTS_TO_TOOLBAR ); ?>