WP_Font_Face::validate_font_face_declarations()
Validates each font-face declaration (property and value pairing).
Метод класса: WP_Font_Face{}
Хуков нет.
Возвращает
Массив|false
. Validated font-face on success, or false on failure.
Использование
// private - только в коде основоного (родительского) класса $result = $this->validate_font_face_declarations( $font_face );
- $font_face(массив) (обязательный)
- Font face property and value pairings to validate.
Список изменений
С версии 6.4.0 | Введена. |
Код WP_Font_Face::validate_font_face_declarations() WP Font Face::validate font face declarations WP 6.7.1
private function validate_font_face_declarations( array $font_face ) { $font_face = wp_parse_args( $font_face, $this->font_face_property_defaults ); // Check the font-family. if ( empty( $font_face['font-family'] ) || ! is_string( $font_face['font-family'] ) ) { // @todo replace with `wp_trigger_error()`. _doing_it_wrong( __METHOD__, __( 'Font font-family must be a non-empty string.' ), '6.4.0' ); return false; } // Make sure that local fonts have 'src' defined. if ( empty( $font_face['src'] ) || ( ! is_string( $font_face['src'] ) && ! is_array( $font_face['src'] ) ) ) { // @todo replace with `wp_trigger_error()`. _doing_it_wrong( __METHOD__, __( 'Font src must be a non-empty string or an array of strings.' ), '6.4.0' ); return false; } // Validate the 'src' property. foreach ( (array) $font_face['src'] as $src ) { if ( empty( $src ) || ! is_string( $src ) ) { // @todo replace with `wp_trigger_error()`. _doing_it_wrong( __METHOD__, __( 'Each font src must be a non-empty string.' ), '6.4.0' ); return false; } } // Check the font-weight. if ( ! is_string( $font_face['font-weight'] ) && ! is_int( $font_face['font-weight'] ) ) { // @todo replace with `wp_trigger_error()`. _doing_it_wrong( __METHOD__, __( 'Font font-weight must be a properly formatted string or integer.' ), '6.4.0' ); return false; } // Check the font-display. if ( ! in_array( $font_face['font-display'], $this->valid_font_display, true ) ) { $font_face['font-display'] = $this->font_face_property_defaults['font-display']; } // Remove invalid properties. foreach ( $font_face as $property => $value ) { if ( ! in_array( $property, $this->valid_font_face_properties, true ) ) { unset( $font_face[ $property ] ); } } return $font_face; }