mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
- Update plugin version to 1.0.0 and bump dependency requirements (WP 6.3+, PHP 8.1+, WC 9.0+, WPGraphQL 2.0+) - Update README.md, README.txt, and docs with v1.0.0 features - Add building-a-woocommerce-admin-app.md documenting WC Settings API, product CRUD, product attribute management, and refund operations - Update settings.md with new v1.0.0 settings documentation - Update installation.md with version prerequisites - Remove obsolete toc.md (replaced by docs/README.md) - Update @since tags from TBD to 1.0.0
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* Label utility functions for GraphQL name formatting.
|
|
*
|
|
* @package WPGraphQL\WooCommerce\Utils
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
namespace WPGraphQL\WooCommerce\Utils;
|
|
|
|
use WPGraphQL\Type\WPEnumType;
|
|
|
|
/**
|
|
* Class Label
|
|
*/
|
|
class Label {
|
|
/**
|
|
* Returns a safe GraphQL enum name for the given value, optionally
|
|
* transliterating non-latin characters when the setting is enabled.
|
|
*
|
|
* Falls back to WPEnumType::get_safe_name() and returns null when
|
|
* the result contains no alphanumeric characters (i.e. is meaningless).
|
|
*
|
|
* @param string $value The raw value to convert to a safe enum name.
|
|
*
|
|
* @return string|null The safe name, or null if the value cannot produce a valid GraphQL name.
|
|
*/
|
|
public static function get_safe_enum_name( string $value ): ?string {
|
|
if (
|
|
'on' === woographql_setting( 'enable_transliteration', 'off' )
|
|
&& function_exists( 'transliterator_transliterate' )
|
|
&& preg_match( '/[^\x20-\x7E]/', $value )
|
|
) {
|
|
$value = transliterator_transliterate( 'Any-Latin; Latin-ASCII', $value );
|
|
}
|
|
|
|
if ( empty( $value ) ) {
|
|
return null;
|
|
}
|
|
|
|
$safe_name = WPEnumType::get_safe_name( $value );
|
|
|
|
if ( ! preg_match( '/[A-Za-z0-9]/', $safe_name ) ) {
|
|
return null;
|
|
}
|
|
|
|
return $safe_name;
|
|
}
|
|
}
|