W3cubDocs

/WordPress

WP_REST_Font_Faces_Controller::prepare_item_for_database( WP_REST_Request $request ): stdClass

Prepares a single font face post for creation.

Parameters

$requestWP_REST_Requestrequired
Request object.

Return

stdClass Post object.

Source

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;
}

Changelog

Version Description
6.5.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_font_faces_controller/prepare_item_for_database