WP_REST_Font_Families_Controller::create_item()publicWP 6.5.0

Creates a single font family.

Method of the class: WP_REST_Font_Families_Controller{}

No Hooks.

Return

WP_REST_Response|WP_Error. Response object on success, or WP_Error object on failure.

Usage

$WP_REST_Font_Families_Controller = new WP_REST_Font_Families_Controller();
$WP_REST_Font_Families_Controller->create_item( $request );
$request(WP_REST_Request) (required)
Full details about the request.

Changelog

Since 6.5.0 Introduced.

WP_REST_Font_Families_Controller::create_item() code WP 6.7.1

public function create_item( $request ) {
	$settings = $request->get_param( 'font_family_settings' );

	// Check that the font family slug is unique.
	$query = new WP_Query(
		array(
			'post_type'              => $this->post_type,
			'posts_per_page'         => 1,
			'name'                   => $settings['slug'],
			'update_post_meta_cache' => false,
			'update_post_term_cache' => false,
		)
	);
	if ( ! empty( $query->posts ) ) {
		return new WP_Error(
			'rest_duplicate_font_family',
			/* translators: %s: Font family slug. */
			sprintf( __( 'A font family with slug "%s" already exists.' ), $settings['slug'] ),
			array( 'status' => 400 )
		);
	}

	return parent::create_item( $request );
}