PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.7
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.7
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
wordpress-seo / src / generators / schema / third-party / coauthor.php

coauthor.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.7, at src/generators/schema/third-party/coauthor.php

74 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Generators\Schema\Third_Party;
4
5 use Yoast\WP\SEO\Generators\Schema\Author;
6
7 /**
8 * Returns schema Author data for the CoAuthor Plus assigned user on a post.
9 */
10 class CoAuthor extends Author {
11
12 /**
13 * The user ID of the author we're generating data for.
14 *
15 * @var int $user_id
16 */
17 private $user_id;
18
19 /**
20 * Determine whether we should return Person schema.
21 *
22 * @return bool
23 */
24 public function is_needed() {
25 return true;
26 }
27
28 /**
29 * Returns Person Schema data.
30 *
31 * @return bool|array Person data on success, false on failure.
32 */
33 public function generate() {
34 $user_id = $this->determine_user_id();
35 if ( ! $user_id ) {
36 return false;
37 }
38
39 $data = $this->build_person_data( $user_id, true );
40
41 $data['@type'] = 'Person';
42 unset( $data['logo'] );
43
44 // If this is a post and the author archives are enabled, set the author archive url as the author url.
45 if ( $this->helpers->options->get( 'disable-author' ) !== true ) {
46 $data['url'] = $this->helpers->user->get_the_author_posts_url( $user_id );
47 }
48
49 return $data;
50 }
51
52 /**
53 * Generate the Person data given a user ID.
54 *
55 * @param int $user_id User ID.
56 *
57 * @return array|bool
58 */
59 public function generate_from_user_id( $user_id ) {
60 $this->user_id = $user_id;
61
62 return $this->generate();
63 }
64
65 /**
66 * Determines a User ID for the Person data.
67 *
68 * @return bool|int User ID or false upon return.
69 */
70 protected function determine_user_id() {
71 return $this->user_id;
72 }
73 }
74