Yoast\WP\SEO\Bulk_Editor\Application\Updates
Bulk_Updater::apply
Applies a single post update.
Метод класса: Bulk_Updater{}
Хуков нет.
Возвращает
Update_Result. The result of the update.
Использование
// private - только в коде основоного (родительского) класса $result = $this->apply( $type, $update ): Update_Result;
- $type(Update_Type) (обязательный)
- The appearance the update targets.
- $update(Post_Update) (обязательный)
- The post update to apply.
Код Bulk_Updater::apply() Bulk Updater::apply Yoast 28.9
private function apply( Update_Type $type, Post_Update $update ): Update_Result {
$post_id = $update->get_post_id();
if ( ! $this->post_access_checker->exists( $post_id ) ) {
return Update_Result::for_failure( $post_id, Update_Error::NOT_FOUND );
}
if ( ! $this->post_access_checker->is_supported_type( $post_id ) ) {
return Update_Result::for_failure( $post_id, Update_Error::INVALID_POST_TYPE );
}
if ( ! $this->post_access_checker->can_edit( $post_id ) ) {
return Update_Result::for_failure( $post_id, Update_Error::FORBIDDEN );
}
$saved_focus_keyphrase = null;
try {
if ( $update->has_title() ) {
$this->meta_writer->write_title( $type, $post_id, $update->get_title() );
}
if ( $update->has_description() ) {
$this->meta_writer->write_description( $type, $post_id, $update->get_description() );
}
if ( $update->has_focus_keyphrase() ) {
$saved_focus_keyphrase = $this->meta_writer->write_focus_keyphrase( $post_id, $update->get_focus_keyphrase() );
}
} catch ( Exception $exception ) {
$this->logger->warning(
'Bulk update failed to save post {post_id}: {error}',
[
'post_id' => $post_id,
'error' => $exception->getMessage(),
],
);
return Update_Result::for_failure( $post_id, Update_Error::SAVE_FAILED );
}
return Update_Result::for_success(
$post_id,
$this->render_fields( $type, $post_id ),
$this->sanitized_fields( $saved_focus_keyphrase ),
);
}