PluginProbe
Polylang / 3.8.11
Polylang v3.8.11
3.8.11 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 All 235 releases
← All changes | src/Model/Languages.php +15 -3 3.8.4 → 3.8.11 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()`.
@@ -963,9 +975,9 @@
963 975 if ( ! empty( $args['lang_id'] ) ) {
964 976 $language_term = get_term( (int) $args['lang_id'] );
965 977
966 978 if ( $language_term instanceof WP_Term ) {
967 - $old_data = maybe_unserialize( $language_term->description );
979 + $old_data = pll_maybe_unserialize( $language_term->description );
968 980 }
969 981 }
970 982
971 983 if ( empty( $old_data ) || ! is_array( $old_data ) ) {
@@ -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.
@@ -1104,9 +1116,9 @@
1104 1116
1105 1117 if ( is_array( $terms ) ) {
1106 1118 foreach ( $terms as $term ) {
1107 1119 $term_ids[ $term->taxonomy ][] = $term->term_id;
1108 - $tr = maybe_unserialize( $term->description );
1120 + $tr = pll_maybe_unserialize( $term->description );
1109 1121 $tr = is_array( $tr ) ? $tr : array();
1110 1122
1111 1123 /**
1112 1124 * Filters the unserialized translation group description before it is