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/infrastructure/updates/meta-writer.php +29 -5 28.2 → trunk View file →
@@ -64,28 +64,52 @@
64 64 /**
65 65 * Writes the focus keyphrase for a post. The focus keyphrase is channel-agnostic,
66 66 * so it does not depend on the update type.
67 67 *
68 + * Returns the sanitized value that was actually stored, so callers can detect
69 + * when the input was silently altered (e.g. HTML stripped by sanitize_text_field).
70 + *
68 71 * @param int $post_id The ID of the post.
69 72 * @param string $focus_keyphrase The focus keyphrase to write.
70 73 *
74 + * @return string The sanitized focus keyphrase that was persisted.
75 + */
76 + public function write_focus_keyphrase( int $post_id, string $focus_keyphrase ): string {
77 + return $this->write( 'focuskw', $post_id, $focus_keyphrase );
78 + }
79 +
80 + /**
81 + * Writes a per-field score for a post.
82 + *
83 + * The score is routed through the same sanitization as a normal post save, which clamps it to a
84 + * 0-100 integer.
85 + *
86 + * @param int $post_id The ID of the post.
87 + * @param string $key The score meta key (without prefix) to write.
88 + * @param int $score The 0-100 score to write.
89 + *
71 90 * @return void
72 91 */
73 - public function write_focus_keyphrase( int $post_id, string $focus_keyphrase ): void {
74 - $this->write( 'focuskw', $post_id, $focus_keyphrase );
92 + public function write_score( int $post_id, string $key, int $score ): void {
93 + $this->write( $key, $post_id, (string) $score );
75 94 }
76 95
77 96 /**
78 97 * Sanitizes and persists a value under the given meta key.
79 98 *
99 + * Returns the sanitized value so callers that need the stored value (e.g. to echo
100 + * it back in the REST response) do not have to re-read from the database.
101 + *
80 102 * @param string $key The meta key (without prefix) to store the value under.
81 103 * @param int $post_id The ID of the post.
82 104 * @param string $value The value to write.
83 105 *
84 - * @return void
106 + * @return string The sanitized value that was persisted.
85 107 */
86 - private function write( string $key, int $post_id, string $value ): void {
87 - $this->meta_helper->set_value( $key, $this->sanitize( $key, $value ), $post_id );
108 + private function write( string $key, int $post_id, string $value ): string {
109 + $sanitized = $this->sanitize( $key, $value );
110 + $this->meta_helper->set_value( $key, $sanitized, $post_id );
111 + return $sanitized;
88 112 }
89 113
90 114 /**
91 115 * Sanitizes a value the same way the post editor sanitizes meta values.