$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'] ) . '