WP_REST_Font_Faces_Controller::prepare_item_for_database()protectedWP 6.5.0

Prepares a single font face post for creation.

Method of the class: WP_REST_Font_Faces_Controller{}

No Hooks.

Return

stdClass. Post object.

Usage

// protected - for code of main (parent) or child class
$result = $this->prepare_item_for_database( $request );
$request(WP_REST_Request) (required)
Request object.

Changelog

Since 6.5.0 Introduced.

WP_REST_Font_Faces_Controller::prepare_item_for_database() code WP 6.6.2

protected function prepare_item_for_database( $request ) {
	$prepared_post = new stdClass();

	// Settings have already been decoded by ::sanitize_font_face_settings().
	$settings = $request->get_param( 'font_face_settings' );

	// Store this "slug" as the post_title rather than post_name, since it uses the fontFamily setting,
	// which may contain multibyte characters.
	$title = WP_Font_Utils::get_font_face_slug( $settings );

	$prepared_post->post_type    = $this->post_type;
	$prepared_post->post_parent  = $request['font_family_id'];
	$prepared_post->post_status  = 'publish';
	$prepared_post->post_title   = $title;
	$prepared_post->post_name    = sanitize_title( $title );
	$prepared_post->post_content = wp_json_encode( $settings );

	return $prepared_post;
}