Prepares a single font family post for create or update.
Parameters
$request
WP_REST_Requestrequired- Request object.
Source
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;
}
Changelog
Version | Description |
---|---|
6.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.