WP_REST_Font_Faces_Controller::get_parent_font_family_post()protectedWP 6.5.0

Get the parent font family, if the ID is valid.

Method of the class: WP_REST_Font_Faces_Controller{}

No Hooks.

Return

WP_Post|WP_Error. Post object if ID is valid, WP_Error otherwise.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_parent_font_family_post( $font_family_id );
$font_family_id(int) (required)
Supplied ID.

Changelog

Since 6.5.0 Introduced.

WP_REST_Font_Faces_Controller::get_parent_font_family_post() code WP 6.6.2

protected function get_parent_font_family_post( $font_family_id ) {
	$error = new WP_Error(
		'rest_post_invalid_parent',
		__( 'Invalid post parent ID.', 'default' ),
		array( 'status' => 404 )
	);

	if ( (int) $font_family_id <= 0 ) {
		return $error;
	}

	$font_family_post = get_post( (int) $font_family_id );

	if ( empty( $font_family_post ) || empty( $font_family_post->ID )
	|| 'wp_font_family' !== $font_family_post->post_type
	) {
		return $error;
	}

	return $font_family_post;
}