PluginProbe
Polylang / 3.8.10
Polylang v3.8.10
3.8.10 3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 All 234 releases
← All changes | src/Model/Languages.php +13 -1 3.8.4 → 3.8.10 View file →
@@ -928,8 +928,20 @@
928 928 return new Languages_Proxies( $this, $this->proxies, $key );
929 929 }
930 930
931 931 /**
932 + * Checks if a given value matches the locale format.
933 + *
934 + * @since 3.8.5
935 + *
936 + * @param string $value The value to check.
937 + * @return bool
938 + */
939 + public static function is_locale( $value ): bool {
940 + return is_string( $value ) && (bool) preg_match( '#' . self::LOCALE_PATTERN . '#', $value );
941 + }
942 +
943 + /**
932 944 * Builds the language metas into an array and serializes it, to be stored in the term description.
933 945 *
934 946 * @since 3.4
935 947 * @since 3.7 Moved from `PLL_Admin_Model::build_language_metas()` to `WP_Syntex\Polylang\Model\Languages::build_metas()`.
@@ -1036,9 +1048,9 @@
1036 1048 protected function validate_lang( $args, ?PLL_Language $lang = null ): WP_Error {
1037 1049 $errors = new WP_Error();
1038 1050
1039 1051 // Validate locale with the same pattern as WP 4.3. See #28303.
1040 - if ( empty( $args['locale'] ) || ! preg_match( '#' . self::LOCALE_PATTERN . '#', $args['locale'], $matches ) ) {
1052 + if ( empty( $args['locale'] ) || ! self::is_locale( $args['locale'] ) ) {
1041 1053 $errors->add( 'pll_invalid_locale', __( 'Enter a valid WordPress locale', 'polylang' ) );
1042 1054 }
1043 1055
1044 1056 // Validate slug characters.