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/generators/schema/person.php +59 -40 18.3 → trunk View file →
@@ -45,15 +45,15 @@
45 45 if ( $this->site_represents_current_author() ) {
46 46 return false;
47 47 }
48 48
49 - return $this->context->site_represents === 'person' || $this->context->indexable->object_type === 'user';
49 + return $this->context->site_represents === 'person';
50 50 }
51 51
52 52 /**
53 53 * Returns Person Schema data.
54 54 *
55 - * @return bool|array Person data on success, false on failure.
55 + * @return bool|array<string|string[]> Person data on success, false on failure.
56 56 */
57 57 public function generate() {
58 58 $user_id = $this->determine_user_id();
59 59 if ( ! $user_id ) {
@@ -71,9 +71,9 @@
71 71 protected function determine_user_id() {
72 72 /**
73 73 * Filter: 'wpseo_schema_person_user_id' - Allows filtering of user ID used for person output.
74 74 *
75 - * @api int|bool $user_id The user ID currently determined.
75 + * @param int|bool $user_id The user ID currently determined.
76 76 */
77 77 $user_id = \apply_filters( 'wpseo_schema_person_user_id', $this->context->site_user_id );
78 78
79 79 // It should to be an integer higher than 0.
@@ -86,10 +86,10 @@
86 86
87 87 /**
88 88 * Retrieve a list of social profile URLs for Person.
89 89 *
90 - * @param array $same_as_urls Array of SameAs URLs.
91 - * @param int $user_id User ID.
90 + * @param string[] $same_as_urls Array of SameAs URLs.
91 + * @param int $user_id User ID.
92 92 *
93 93 * @return string[] A list of SameAs URLs.
94 94 */
95 95 protected function get_social_profiles( $same_as_urls, $user_id ) {
@@ -95,12 +95,11 @@
95 95 protected function get_social_profiles( $same_as_urls, $user_id ) {
96 96 /**
97 97 * Filter: 'wpseo_schema_person_social_profiles' - Allows filtering of social profiles per user.
98 98 *
99 - * @param int $user_id The current user we're grabbing social profiles for.
100 - *
101 - * @api string[] $social_profiles The array of social profiles to retrieve. Each should be a user meta field
102 - * key. As they are retrieved using the WordPress function `get_the_author_meta`.
99 + * @param string[] $social_profiles The array of social profiles to retrieve. Each should be a user meta field
100 + * key. As they are retrieved using the WordPress function `get_the_author_meta`.
101 + * @param int $user_id The current user we're grabbing social profiles for.
103 102 */
104 103 $social_profiles = \apply_filters( 'wpseo_schema_person_social_profiles', $this->social_profiles, $user_id );
105 104
106 105 // We can only handle an array.
@@ -125,13 +124,14 @@
125 124
126 125 /**
127 126 * Builds our array of Schema Person data for a given user ID.
128 127 *
129 - * @param int $user_id The user ID to use.
128 + * @param int $user_id The user ID to use.
129 + * @param bool $add_hash Wether or not the person's image url hash should be added to the image id.
130 130 *
131 - * @return array An array of Schema Person data.
131 + * @return array<string|string[]> An array of Schema Person data.
132 132 */
133 - protected function build_person_data( $user_id ) {
133 + protected function build_person_data( $user_id, $add_hash = false ) {
134 134 $user_data = \get_userdata( $user_id );
135 135 $data = [
136 136 '@type' => $this->type,
137 137 '@id' => $this->helpers->schema->id->get_user_schema_id( $user_id, $this->context ),
@@ -142,14 +142,25 @@
142 142 return $data;
143 143 }
144 144
145 145 $data['name'] = $this->helpers->schema->html->smart_strip_tags( $user_data->display_name );
146 - $data = $this->add_image( $data, $user_data );
147 146
147 + $pronouns = $this->helpers->schema->html->smart_strip_tags( \get_the_author_meta( 'wpseo_pronouns', $user_id ) );
148 + if ( ! empty( $pronouns ) ) {
149 + $data['pronouns'] = $pronouns;
150 + }
151 +
152 + $data = $this->add_image( $data, $user_data, $add_hash );
153 +
148 154 if ( ! empty( $user_data->description ) ) {
149 155 $data['description'] = $this->helpers->schema->html->smart_strip_tags( $user_data->description );
150 156 }
151 157
158 + if ( \is_array( $this->context->schema_page_type ) && \in_array( 'ProfilePage', $this->context->schema_page_type, true ) ) {
159 + $data['mainEntityOfPage'] = [
160 + '@id' => $this->context->main_schema_id,
161 + ];
162 + }
152 163 $data = $this->add_same_as_urls( $data, $user_data, $user_id );
153 164
154 165 /**
155 166 * Filter: 'wpseo_schema_person_data' - Allows filtering of schema data per user.
@@ -164,23 +175,25 @@
164 175
165 176 /**
166 177 * Returns an ImageObject for the persons avatar.
167 178 *
168 - * @param array $data The Person schema.
169 - * @param WP_User $user_data User data.
179 + * @param array<string|string[]> $data The Person schema.
180 + * @param WP_User $user_data User data.
181 + * @param bool $add_hash Wether or not the person's image url hash should be added to the image id.
170 182 *
171 - * @return array The Person schema.
183 + * @return array<string|string[]> The Person schema.
172 184 */
173 - protected function add_image( $data, $user_data ) {
185 + protected function add_image( $data, $user_data, $add_hash = false ) {
174 186 $schema_id = $this->context->site_url . Schema_IDs::PERSON_LOGO_HASH;
175 187
176 - $data = $this->set_image_from_options( $data, $schema_id );
188 + $data = $this->set_image_from_options( $data, $schema_id, $add_hash, $user_data );
177 189 if ( ! isset( $data['image'] ) ) {
178 - $data = $this->set_image_from_avatar( $data, $user_data, $schema_id );
190 + $data = $this->set_image_from_avatar( $data, $user_data, $add_hash );
179 191 }
180 192
181 193 if ( \is_array( $this->type ) && \in_array( 'Organization', $this->type, true ) ) {
182 - $data['logo'] = [ '@id' => $schema_id ];
194 + $data_logo = ( $data['image']['@id'] ?? $schema_id );
195 + $data['logo'] = [ '@id' => $data_logo ];
183 196 }
184 197
185 198 return $data;
186 199 }
@@ -187,19 +200,21 @@
187 200
188 201 /**
189 202 * Generate the person image from our settings.
190 203 *
191 - * @param array $data The Person schema.
192 - * @param string $schema_id The string used in the `@id` for the schema.
204 + * @param array<string|string[]> $data The Person schema.
205 + * @param string $schema_id The string used in the `@id` for the schema.
206 + * @param bool $add_hash Whether or not the person's image url hash should be added to the image id.
207 + * @param WP_User|null $user_data User data.
193 208 *
194 - * @return array The Person schema.
209 + * @return array<string|string[]> The Person schema.
195 210 */
196 - protected function set_image_from_options( $data, $schema_id ) {
211 + protected function set_image_from_options( $data, $schema_id, $add_hash = false, $user_data = null ) {
197 212 if ( $this->context->site_represents !== 'person' ) {
198 213 return $data;
199 214 }
200 215 if ( \is_array( $this->context->person_logo_meta ) ) {
201 - $data['image'] = $this->helpers->schema->image->generate_from_attachment_meta( $schema_id, $this->context->person_logo_meta, $data['name'] );
216 + $data['image'] = $this->helpers->schema->image->generate_from_attachment_meta( $this->context->person_logo_meta['url'], $this->context->person_logo_meta, $data['name'], $add_hash );
202 217 }
203 218
204 219 return $data;
205 220 }
@@ -206,15 +221,15 @@
206 221
207 222 /**
208 223 * Generate the person logo from gravatar.
209 224 *
210 - * @param array $data The Person schema.
211 - * @param WP_User $user_data User data.
212 - * @param string $schema_id The string used in the `@id` for the schema.
225 + * @param array<string|string[]> $data The Person schema.
226 + * @param WP_User $user_data User data.
227 + * @param bool $add_hash Wether or not the person's image url hash should be added to the image id.
213 228 *
214 - * @return array The Person schema.
229 + * @return array<string|string[]> The Person schema.
215 230 */
216 - protected function set_image_from_avatar( $data, $user_data, $schema_id ) {
231 + protected function set_image_from_avatar( $data, $user_data, $add_hash = false ) {
217 232 // If we don't have an image in our settings, fall back to an avatar, if we're allowed to.
218 233 $show_avatars = \get_option( 'show_avatars' );
219 234 if ( ! $show_avatars ) {
220 235 return $data;
@@ -224,9 +239,9 @@
224 239 if ( empty( $url ) ) {
225 240 return $data;
226 241 }
227 242
228 - $data['image'] = $this->helpers->schema->image->simple_image_object( $schema_id, $url, $user_data->display_name );
243 + $data['image'] = $this->helpers->schema->image->simple_image_object( $url, $url, $user_data->display_name, $add_hash );
229 244
230 245 return $data;
231 246 }
232 247
@@ -232,10 +247,10 @@
232 247
233 248 /**
234 249 * Returns an author's social site URL.
235 250 *
236 - * @param string $social_site The social site to retrieve the URL for.
237 - * @param mixed $user_id The user ID to use function outside of the loop.
251 + * @param string $social_site The social site to retrieve the URL for.
252 + * @param int|false $user_id The user ID to use function outside of the loop.
238 253 *
239 254 * @return string
240 255 */
241 256 protected function url_social_site( $social_site, $user_id = false ) {
@@ -241,9 +256,9 @@
241 256 protected function url_social_site( $social_site, $user_id = false ) {
242 257 $url = \get_the_author_meta( $social_site, $user_id );
243 258
244 259 if ( ! empty( $url ) && $social_site === 'twitter' ) {
245 - $url = 'https://twitter.com/' . $url;
260 + $url = 'https://x.com/' . $url;
246 261 }
247 262
248 263 return $url;
249 264 }
@@ -250,11 +265,13 @@
250 265
251 266 /**
252 267 * Checks the site is represented by the same person as this indexable.
253 268 *
269 + * @param WP_User|null $user_data User data.
270 + *
254 271 * @return bool True when the site is represented by the same person as this indexable.
255 272 */
256 - protected function site_represents_current_author() {
273 + protected function site_represents_current_author( $user_data = null ) {
257 274 // Can only be the case when the site represents a user.
258 275 if ( $this->context->site_represents !== 'person' ) {
259 276 return false;
260 277 }
@@ -264,9 +281,11 @@
264 281 $this->context->indexable->object_type === 'post'
265 282 && $this->helpers->schema->article->is_author_supported( $this->context->indexable->object_sub_type )
266 283 && $this->context->schema_article_type !== 'None'
267 284 ) {
268 - return $this->context->site_user_id === $this->context->indexable->author_id;
285 + $user_id = ( $user_data instanceof WP_User && isset( $user_data->ID ) ) ? $user_data->ID : $this->context->indexable->author_id;
286 +
287 + return $this->context->site_user_id === $user_id;
269 288 }
270 289
271 290 // Author archive from the same user as the site represents.
272 291 return $this->context->indexable->object_type === 'user' && $this->context->site_user_id === $this->context->indexable->object_id;
@@ -274,13 +293,13 @@
274 293
275 294 /**
276 295 * Builds our SameAs array.
277 296 *
278 - * @param array $data The Person schema data.
279 - * @param WP_User $user_data The user data object.
280 - * @param int $user_id The user ID to use.
297 + * @param array<string|string[]> $data The Person schema data.
298 + * @param WP_User $user_data The user data object.
299 + * @param int $user_id The user ID to use.
281 300 *
282 - * @return array The Person schema data.
301 + * @return array<string|string[]> The Person schema data.
283 302 */
284 303 protected function add_same_as_urls( $data, $user_data, $user_id ) {
285 304 $same_as_urls = [];
286 305