Automattic\WooCommerce\Internal\Font

FontFamily::insert_font_family()public staticWC 1.0

Registers the font family post type.

Method of the class: FontFamily{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = FontFamily::insert_font_family( $font_family_settings );
$font_family_settings(array) (required)
The font family settings.

FontFamily::insert_font_family() code WC 9.6.1

public static function insert_font_family( array $font_family_settings ) {
	$font_family = $font_family_settings;
	// Check that the font family slug is unique.
	$query = new \WP_Query(
		array(
			'post_type'              => self::POST_TYPE,
			'posts_per_page'         => 1,
			'name'                   => $font_family['slug'],
			'update_post_meta_cache' => false,
			'update_post_term_cache' => false,
		)
	);

	if ( ! empty( $query->get_posts() ) ) {
		return new \WP_Error(
			'duplicate_font_family',
			/* translators: %s: Font family slug. */
			sprintf( __( 'A font family with slug "%s" already exists.', 'woocommerce' ), $font_family['slug'] )
		);
	}

	// Validate the font family settings.
	$validation_error = self::validate_font_family( $font_family );
	if ( is_wp_error( $validation_error ) ) {
		return $validation_error;
	}

	$post['fontFamily'] = addslashes( \WP_Font_Utils::sanitize_font_family( $font_family['fontFamily'] ) );
	$post['preview']    = $font_family['preview'];

	// Insert the font family.
	return wp_insert_post(
		array(
			'post_type'    => self::POST_TYPE,
			'post_title'   => $font_family['name'],
			'name'         => $font_family['slug'],
			'post_content' => wp_json_encode( $post ),
			'post_status'  => 'publish',
		)
	);

}