WP_REST_Font_Families_Controller::prepare_item_for_database
Prepares a single font family post for create or update.
Method of the class: WP_REST_Font_Families_Controller{}
No Hooks.
Returns
stdClass|WP_Error. Post object or WP_Error.
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_Families_Controller::prepare_item_for_database() WP REST Font Families Controller::prepare item for database code WP 7.0
protected function prepare_item_for_database( $request ) {
$prepared_post = new stdClass();
// Settings have already been decoded by ::sanitize_font_family_settings().
$settings = $request->get_param( 'font_family_settings' );
// This is an update and we merge with the existing font family.
if ( isset( $request['id'] ) ) {
$existing_post = $this->get_post( $request['id'] );
if ( is_wp_error( $existing_post ) ) {
return $existing_post;
}
$prepared_post->ID = $existing_post->ID;
$existing_settings = $this->get_settings_from_post( $existing_post );
$settings = array_merge( $existing_settings, $settings );
}
$prepared_post->post_type = $this->post_type;
$prepared_post->post_status = 'publish';
$prepared_post->post_title = $settings['name'];
$prepared_post->post_name = sanitize_title( $settings['slug'] );
// Remove duplicate information from settings.
unset( $settings['name'] );
unset( $settings['slug'] );
$prepared_post->post_content = wp_json_encode( $settings );
return $prepared_post;
}