WP_REST_Font_Families_Controller::create_item
Creates a single font family.
Method of the class: WP_REST_Font_Families_Controller{}
No Hooks.
Returns
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() WP REST Font Families Controller::create item code WP 6.9
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 );
}