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( esc_attr__( '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 // input var okay. ); } else { update_option( WPDA::FRONTEND_OPTIONNAME_DATABASE_ACCESS . $database, isset( $_REQUEST['table_access'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['table_access'] ) ) : null // input var okay. ); } $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( esc_attr__( '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_ADD_PROJECTS_TO_TOOLBAR, isset( $_REQUEST['add_projects_to_toolbar'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['add_projects_to_toolbar'] ) ) : 'off' // input var okay. ); } 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_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; } } $add_projects_to_toolbar = WPDA::get_option( WPDA::OPTION_FE_ADD_PROJECTS_TO_TOOLBAR ); ?>