PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
← All changes | src/bulk-editor/application/updates/bulk-updater.php +60 -3 28.1 → trunk View file →
@@ -35,16 +35,29 @@
35 35 */
36 36 private $meta_writer;
37 37
38 38 /**
39 + * The field renderer.
40 + *
41 + * @var Field_Renderer_Interface
42 + */
43 + private $field_renderer;
44 +
45 + /**
39 46 * The constructor.
40 47 *
41 48 * @param Post_Access_Checker_Interface $post_access_checker The post access checker.
42 49 * @param Meta_Writer_Interface $meta_writer The meta writer.
50 + * @param Field_Renderer_Interface $field_renderer The field renderer.
43 51 */
44 - public function __construct( Post_Access_Checker_Interface $post_access_checker, Meta_Writer_Interface $meta_writer ) {
52 + public function __construct(
53 + Post_Access_Checker_Interface $post_access_checker,
54 + Meta_Writer_Interface $meta_writer,
55 + Field_Renderer_Interface $field_renderer
56 + ) {
45 57 $this->post_access_checker = $post_access_checker;
46 58 $this->meta_writer = $meta_writer;
59 + $this->field_renderer = $field_renderer;
47 60 $this->logger = new NullLogger();
48 61 }
49 62
50 63 /**
@@ -88,8 +101,9 @@
88 101 if ( ! $this->post_access_checker->can_edit( $post_id ) ) {
89 102 return Update_Result::for_failure( $post_id, Update_Error::FORBIDDEN );
90 103 }
91 104
105 + $saved_focus_keyphrase = null;
92 106 try {
93 107 if ( $update->has_title() ) {
94 108 $this->meta_writer->write_title( $type, $post_id, $update->get_title() );
95 109 }
@@ -98,9 +112,9 @@
98 112 $this->meta_writer->write_description( $type, $post_id, $update->get_description() );
99 113 }
100 114
101 115 if ( $update->has_focus_keyphrase() ) {
102 - $this->meta_writer->write_focus_keyphrase( $post_id, $update->get_focus_keyphrase() );
116 + $saved_focus_keyphrase = $this->meta_writer->write_focus_keyphrase( $post_id, $update->get_focus_keyphrase() );
103 117 }
104 118 } catch ( Exception $exception ) {
105 119 $this->logger->warning(
106 120 'Bulk update failed to save post {post_id}: {error}',
@@ -112,7 +126,50 @@
112 126
113 127 return Update_Result::for_failure( $post_id, Update_Error::SAVE_FAILED );
114 128 }
115 129
116 - return Update_Result::for_success( $post_id );
130 + return Update_Result::for_success(
131 + $post_id,
132 + $this->render_fields( $type, $post_id ),
133 + $this->sanitized_fields( $saved_focus_keyphrase ),
134 + );
135 + }
136 +
137 + /**
138 + * Renders the search fields with replacement variables resolved, for re-scoring after a save.
139 + *
140 + * Only called for search updates; social updates carry no scored fields.
141 + *
142 + * @param Update_Type $type The appearance the update targets.
143 + * @param int $post_id The ID of the post.
144 + *
145 + * @return array<string, string> The rendered fields, keyed by field.
146 + */
147 + private function render_fields( Update_Type $type, int $post_id ): array {
148 + if ( ! $type->is_search() ) {
149 + return [];
150 + }
151 +
152 + return [
153 + 'seo_title' => $this->field_renderer->render( $post_id, 'title' ),
154 + 'meta_description' => $this->field_renderer->render( $post_id, 'metadesc' ),
155 + ];
156 + }
157 +
158 + /**
159 + * Builds the sanitized-literals payload for the response.
160 + *
161 + * The focus keyphrase is echoed back when it was part of the update, so the frontend can detect
162 + * when sanitization silently altered the submitted value (e.g. HTML stripped).
163 + *
164 + * @param string|null $saved_focus_keyphrase The sanitized focus keyphrase that was stored, or null if not updated.
165 + *
166 + * @return array<string, string> The sanitized literals, keyed by field.
167 + */
168 + private function sanitized_fields( ?string $saved_focus_keyphrase ): array {
169 + if ( $saved_focus_keyphrase === null ) {
170 + return [];
171 + }
172 +
173 + return [ 'focus_keyphrase' => $saved_focus_keyphrase ];
117 174 }
118 175 }