PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
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 +48 -39 18.728.5 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.
@@ -128,9 +127,9 @@
128 127 *
129 128 * @param int $user_id The user ID to use.
130 129 * @param bool $add_hash Wether or not the person's image url hash should be added to the image id.
131 130 *
132 - * @return array An array of Schema Person data.
131 + * @return array<string|string[]> An array of Schema Person data.
133 132 */
134 133 protected function build_person_data( $user_id, $add_hash = false ) {
135 134 $user_data = \get_userdata( $user_id );
136 135 $data = [
@@ -143,14 +142,25 @@
143 142 return $data;
144 143 }
145 144
146 145 $data['name'] = $this->helpers->schema->html->smart_strip_tags( $user_data->display_name );
147 - $data = $this->add_image( $data, $user_data, $add_hash );
148 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 +
149 154 if ( ! empty( $user_data->description ) ) {
150 155 $data['description'] = $this->helpers->schema->html->smart_strip_tags( $user_data->description );
151 156 }
152 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 + }
153 163 $data = $this->add_same_as_urls( $data, $user_data, $user_id );
154 164
155 165 /**
156 166 * Filter: 'wpseo_schema_person_data' - Allows filtering of schema data per user.
@@ -165,13 +175,13 @@
165 175
166 176 /**
167 177 * Returns an ImageObject for the persons avatar.
168 178 *
169 - * @param array $data The Person schema.
170 - * @param WP_User $user_data User data.
171 - * @param bool $add_hash Wether or not the person's image url hash should be added to the image id.
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.
172 182 *
173 - * @return array The Person schema.
183 + * @return array<string|string[]> The Person schema.
174 184 */
175 185 protected function add_image( $data, $user_data, $add_hash = false ) {
176 186 $schema_id = $this->context->site_url . Schema_IDs::PERSON_LOGO_HASH;
177 187
@@ -176,13 +186,13 @@
176 186 $schema_id = $this->context->site_url . Schema_IDs::PERSON_LOGO_HASH;
177 187
178 188 $data = $this->set_image_from_options( $data, $schema_id, $add_hash, $user_data );
179 189 if ( ! isset( $data['image'] ) ) {
180 - $data = $this->set_image_from_avatar( $data, $user_data, $schema_id, $add_hash );
190 + $data = $this->set_image_from_avatar( $data, $user_data, $add_hash );
181 191 }
182 192
183 193 if ( \is_array( $this->type ) && \in_array( 'Organization', $this->type, true ) ) {
184 - $data_logo = isset( $data['image']['@id'] ) ? $data['image']['@id'] : $schema_id;
194 + $data_logo = ( $data['image']['@id'] ?? $schema_id );
185 195 $data['logo'] = [ '@id' => $data_logo ];
186 196 }
187 197
188 198 return $data;
@@ -190,14 +200,14 @@
190 200
191 201 /**
192 202 * Generate the person image from our settings.
193 203 *
194 - * @param array $data The Person schema.
195 - * @param string $schema_id The string used in the `@id` for the schema.
196 - * @param bool $add_hash Whether or not the person's image url hash should be added to the image id.
197 - * @param WP_User $user_data User data.
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.
198 208 *
199 - * @return array The Person schema.
209 + * @return array<string|string[]> The Person schema.
200 210 */
201 211 protected function set_image_from_options( $data, $schema_id, $add_hash = false, $user_data = null ) {
202 212 if ( $this->context->site_represents !== 'person' ) {
203 213 return $data;
@@ -202,9 +212,9 @@
202 212 if ( $this->context->site_represents !== 'person' ) {
203 213 return $data;
204 214 }
205 215 if ( \is_array( $this->context->person_logo_meta ) ) {
206 - $data['image'] = $this->helpers->schema->image->generate_from_attachment_meta( $schema_id, $this->context->person_logo_meta, $data['name'], $add_hash );
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 );
207 217 }
208 218
209 219 return $data;
210 220 }
@@ -211,16 +221,15 @@
211 221
212 222 /**
213 223 * Generate the person logo from gravatar.
214 224 *
215 - * @param array $data The Person schema.
216 - * @param WP_User $user_data User data.
217 - * @param string $schema_id The string used in the `@id` for the schema.
218 - * @param bool $add_hash Wether or not the person's image url hash should be added to the image id.
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.
219 228 *
220 - * @return array The Person schema.
229 + * @return array<string|string[]> The Person schema.
221 230 */
222 - protected function set_image_from_avatar( $data, $user_data, $schema_id, $add_hash = false ) {
231 + protected function set_image_from_avatar( $data, $user_data, $add_hash = false ) {
223 232 // If we don't have an image in our settings, fall back to an avatar, if we're allowed to.
224 233 $show_avatars = \get_option( 'show_avatars' );
225 234 if ( ! $show_avatars ) {
226 235 return $data;
@@ -230,9 +239,9 @@
230 239 if ( empty( $url ) ) {
231 240 return $data;
232 241 }
233 242
234 - $data['image'] = $this->helpers->schema->image->simple_image_object( $schema_id, $url, $user_data->display_name, $add_hash );
243 + $data['image'] = $this->helpers->schema->image->simple_image_object( $url, $url, $user_data->display_name, $add_hash );
235 244
236 245 return $data;
237 246 }
238 247
@@ -238,10 +247,10 @@
238 247
239 248 /**
240 249 * Returns an author's social site URL.
241 250 *
242 - * @param string $social_site The social site to retrieve the URL for.
243 - * @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.
244 253 *
245 254 * @return string
246 255 */
247 256 protected function url_social_site( $social_site, $user_id = false ) {
@@ -247,9 +256,9 @@
247 256 protected function url_social_site( $social_site, $user_id = false ) {
248 257 $url = \get_the_author_meta( $social_site, $user_id );
249 258
250 259 if ( ! empty( $url ) && $social_site === 'twitter' ) {
251 - $url = 'https://twitter.com/' . $url;
260 + $url = 'https://x.com/' . $url;
252 261 }
253 262
254 263 return $url;
255 264 }
@@ -256,9 +265,9 @@
256 265
257 266 /**
258 267 * Checks the site is represented by the same person as this indexable.
259 268 *
260 - * @param WP_User $user_data User data.
269 + * @param WP_User|null $user_data User data.
261 270 *
262 271 * @return bool True when the site is represented by the same person as this indexable.
263 272 */
264 273 protected function site_represents_current_author( $user_data = null ) {
@@ -272,9 +281,9 @@
272 281 $this->context->indexable->object_type === 'post'
273 282 && $this->helpers->schema->article->is_author_supported( $this->context->indexable->object_sub_type )
274 283 && $this->context->schema_article_type !== 'None'
275 284 ) {
276 - $user_id = ( ( ! \is_null( $user_data ) ) && ( isset( $user_data->ID ) ) ) ? $user_data->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;
277 286
278 287 return $this->context->site_user_id === $user_id;
279 288 }
280 289
@@ -284,13 +293,13 @@
284 293
285 294 /**
286 295 * Builds our SameAs array.
287 296 *
288 - * @param array $data The Person schema data.
289 - * @param WP_User $user_data The user data object.
290 - * @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.
291 300 *
292 - * @return array The Person schema data.
301 + * @return array<string|string[]> The Person schema data.
293 302 */
294 303 protected function add_same_as_urls( $data, $user_data, $user_id ) {
295 304 $same_as_urls = [];
296 305