label map of allowed values. * choices array For 'checkboxes': key => label map. * min/max int For 'number': enforced bounds. * default mixed Fallback when option is not set. * label string Human-readable field label. * description string Help text shown below the field. * * @param string $context One of self::contexts(). * @return array> */ public static function get_fields_for_context( string $context ): array { return PRAutoBlogger_Pipeline_Settings_Option_Fields_Data::fields_for( $context ); } /** * Sanitize a raw POST value for a single field. * * Handles each field type independently: textarea → sanitize_textarea_field, * select → key validated against the options allowlist, number → absint + * bounds clamp, toggle → '0'|'1', checkboxes → JSON array of allowed keys. * * @param mixed $value Raw value from $_POST. * @param array $field Field definition from get_fields_for_context(). * @return mixed Sanitized value ready for update_option(). */ public static function sanitize_option( mixed $value, array $field ): mixed { $type = (string) ( $field['type'] ?? 'textarea' ); switch ( $type ) { case 'textarea': return sanitize_textarea_field( (string) $value ); case 'toggle': return ( '1' === (string) $value ) ? '1' : '0'; case 'number': $int = absint( $value ); if ( isset( $field['min'] ) && $int < (int) $field['min'] ) { $int = (int) $field['min']; } if ( isset( $field['max'] ) && $int > (int) $field['max'] ) { $int = (int) $field['max']; } return $int; case 'select': $key = sanitize_key( (string) $value ); $allowed = array_keys( (array) ( $field['options'] ?? array() ) ); return in_array( $key, $allowed, true ) ? $key : (string) ( $field['default'] ?? '' ); case 'checkboxes': if ( ! is_array( $value ) ) { $value = array(); } $allowed = array_keys( (array) ( $field['choices'] ?? array() ) ); $filtered = array(); foreach ( $value as $item ) { $item = sanitize_key( (string) $item ); if ( in_array( $item, $allowed, true ) ) { $filtered[] = $item; } } return wp_json_encode( $filtered ); default: return sanitize_text_field( (string) $value ); } } }