$value) { // If the value is an array, assume it's a notification and process accordingly if (is_array($value)) { foreach ($value as $key => $val) { // Sanitization logic per field if ( 'atk_email_to' === $key ) { // 1) Reverse slashes & sanitize the raw input $raw_email = isset( $val ) ? wp_unslash( $val ) : ''; $email = sanitize_email( $raw_email ); // 2) Validate as a proper email address if ( false !== is_email( $email ) ) { $new_input[ $index ][ $key ] = $email; } // else: invalid email → simply drop it (or set to empty string if you prefer) } else { // Default sanitization for all other fields $raw_val = isset( $val ) ? wp_unslash( $val ) : ''; $new_input[ $index ][ $key ] = sanitize_text_field( $raw_val ); } } } else { if (is_numeric($value)) { // If the value is numeric, convert it to either an integer or a float, as appropriate $new_input[$index] = $value + 0; // This will automatically convert to int or float based on the value } else { // For non-numeric values, use sanitize_text_field to ensure safe text $new_input[$index] = sanitize_text_field($value); } } } } return $new_input; } public function atk_register_settings() { $args = array( 'type' => 'string', 'sanitize_callback' => array( $this, 'atk_sanitize_options' ), 'default' => NULL, ); register_setting('atk_settings', 'atk_options', $args ); } public function atk_register_notifications() { $args = array( 'type' => 'string', 'sanitize_callback' => array( $this, 'atk_sanitize_options' ), 'default' => NULL, ); register_setting('atk_notifications', 'atk_notification', $args ); } public function atk_admin_notices() { if (!isset($_GET['page']) || ($_GET['page'] !== 'atk-notifications' && $_GET['page'] !== 'atk-settings')) { return; } // Fetch settings errors registered by add_settings_error() $settings_errors = get_settings_errors(); // Check if there are any errors if (!empty($settings_errors)) { foreach ( $settings_errors as $error ) { // Define the class for the notice based on the type $class = 'notice'; if ($error['type'] === 'error') { $class .= ' notice-error'; } elseif ($error['type'] === 'success') { $class .= ' notice-success'; // Customize message based on the page if (isset($_GET['page'])) { if ($_GET['page'] === 'atk-notifications') { $error['message'] = "Notification saved."; } elseif ($_GET['page'] === 'atk-settings') { $error['message'] = "Settings saved."; } } } elseif ($error['type'] === 'warning') { $class .= ' notice-warning'; } // Display the notice echo '

' . wp_kses_post( $error['message'] ) . '

'; } // Clear the settings errors to prevent duplicates settings_errors('', false, true); } } public function atk_delete_all_logs_callback() { global $wpdb; if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( [ 'message' => 'Unauthorized' ], 403 ); } // 1) Pull & sanitize the incoming nonce $nonce = sanitize_text_field( wp_unslash( $_POST['nonce'] ?? '' ) ); // 2) Verify it if ( ! wp_verify_nonce( $nonce, 'atk_del_all' ) ) { wp_send_json_error( [ 'message' => 'Nonce verification failed' ], 200 ); } $result = $wpdb->query( sprintf( 'TRUNCATE TABLE `%s`', esc_sql( $wpdb->prefix . 'atk_ai_logs' ) ) ); if ( false !== $result && get_option( 'atk_security_db_version' ) ) { $result = $wpdb->query( $wpdb->prepare( 'TRUNCATE TABLE %i', $wpdb->prefix . 'atk_security_events' ) ); } if ( false === $result ) { wp_send_json_error( [ 'message' => 'There was an error deleting the records' ], 200 ); } wp_send_json_success( [ 'message' => 'All logs have been deleted successfully' ], 200 ); } } new ATKAI_Admin_Settings();