$value ) { set_theme_mod( 'oribi_' . $key, $value ); } } else { // Sanitize & save each setting. foreach ( $defaults as $key => $default ) { $posted = isset( $_POST[ 'oribi_' . $key ] ) ? wp_unslash( $_POST[ 'oribi_' . $key ] ) // phpcs:ignore : $default; // Determine sanitisation method by key prefix/type. if ( strpos( $key, 'color_' ) === 0 || strpos( $key, 'dark_' ) === 0 ) { // Colour values (hex or rgba). $posted = oribi_sanitize_color( $posted ); } elseif ( strpos( $key, 'font_' ) === 0 ) { $posted = sanitize_text_field( $posted ); } elseif ( strpos( $key, 'radius_' ) === 0 || strpos( $key, 'container_' ) === 0 || $key === 'wide_size' ) { $posted = sanitize_text_field( $posted ); } else { $posted = sanitize_text_field( $posted ); } set_theme_mod( 'oribi_' . $key, $posted ); } } // Regenerate CSS. $result = oribi_write_generated_css(); if ( is_wp_error( $result ) ) { add_settings_error( 'oribi_settings', 'css_error', $result->get_error_message(), 'error' ); } else { $msg = 'reset' === $action ? __( 'Settings reset to defaults. CSS regenerated.', 'ots-theme' ) : __( 'Settings saved. CSS regenerated.', 'ots-theme' ); add_settings_error( 'oribi_settings', 'saved', $msg, 'success' ); } // Store errors/notices in transient so they survive the redirect. set_transient( 'oribi_settings_notices', get_settings_errors( 'oribi_settings' ), 30 ); // PRG redirect. wp_safe_redirect( admin_url( 'themes.php?page=oribi-theme-settings' ) ); exit; } ); /** * Sanitize a colour value (hex or rgba). * * @param string $value Raw colour value. * @return string Sanitized colour. */ function oribi_sanitize_color( $value ) { $value = trim( $value ); // Allow rgba(...) values (used for dark mode light tints). if ( preg_match( '/^rgba?\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*(,\s*[\d.]+\s*)?\)$/', $value ) ) { return $value; } // Standard hex. return sanitize_hex_color( $value ) ?? '#000000'; } /* ── Render the settings page ──────────────────────────────────── */ function oribi_render_settings_page() { // Seed defaults on first visit. oribi_maybe_seed_defaults(); // Show any saved notices. $notices = get_transient( 'oribi_settings_notices' ); if ( $notices ) { delete_transient( 'oribi_settings_notices' ); foreach ( $notices as $notice ) { printf( '
%s