Automattic\WooCommerce\Internal\Font
FontFace::insert_font_face()
Inserts a font face.
Метод класса: FontFace{}
Хуков нет.
Возвращает
\WP_Error|\WP_Post
. The inserted font face post or an error if the font face already exists.
Использование
$result = FontFace::insert_font_face( $font_face, $parent_font_family_id );
- $font_face(массив) (обязательный)
- The font face settings.
- $parent_font_family_id(int) (обязательный)
- The parent font family ID.
Код FontFace::insert_font_face() FontFace::insert font face WC 9.6.1
public static function insert_font_face( array $font_face, int $parent_font_family_id ) { $slug = \WP_Font_Utils::get_font_face_slug( $font_face ); // Check that the font face slug is unique. $query = new \WP_Query( array( 'post_type' => self::POST_TYPE, 'posts_per_page' => 1, 'name' => $slug, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ) ); if ( ! empty( $query->get_posts() ) ) { return new \WP_Error( 'duplicate_font_face', /* translators: %s: Font face slug. */ sprintf( __( 'A font face with slug "%s" already exists.', 'woocommerce' ), $slug ), ); } // Validate the font face settings. $validation_error = self::validate_font_face( $font_face ); if ( is_wp_error( $validation_error ) ) { return $validation_error; } $parsed_font_face['fontFamily'] = addslashes( \WP_Font_Utils::sanitize_font_family( $font_face['fontFamily'] ) ); $parsed_font_face['fontStyle'] = sanitize_text_field( $font_face['fontStyle'] ); $parsed_font_face['fontWeight'] = sanitize_text_field( $font_face['fontWeight'] ); $file = self::download_file( $font_face['src'] ); $uploaded_file = self::handle_font_file_upload( $file ); $parsed_font_face['src'] = self::sanitize_src( $uploaded_file['url'] ); $parsed_font_face['preview'] = esc_url_raw( $font_face['preview'] ); // Insert the font face. wp_insert_post( array( 'post_type' => self::POST_TYPE, 'post_parent' => $parent_font_family_id, 'post_title' => $slug, 'post_name' => sanitize_title( $slug ), 'post_content' => wp_json_encode( $parsed_font_face ), 'post_status' => 'publish', ) ); }