1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
<?php /** * WPSEO plugin file. * * @package WPSEO\Frontend\Schema */
/** * Returns schema Person data. * * @since 10.2 * * @property WPSEO_Schema_Context $context A value object with context variables. */ class WPSEO_Schema_Author extends WPSEO_Schema_Person implements WPSEO_Graph_Piece { /** * A value object with context variables. * * @var WPSEO_Schema_Context */ private $context;
/** * The Schema type we use for this class. * * @var string[] */ protected $type = array( 'Person' );
/** * WPSEO_Schema_Author constructor. * * @param WPSEO_Schema_Context $context A value object with context variables. */ public function __construct( WPSEO_Schema_Context $context ) { parent::__construct( $context ); $this->context = $context; $this->image_hash = WPSEO_Schema_IDs::AUTHOR_LOGO_HASH; }
/** * Determine whether we should return Person schema. * * @return bool */ public function is_needed() { if ( is_author() ) { return true; }
if ( $this->is_post_author() ) { $post = get_post( $this->context->id ); // If the author is the user the site represents, no need for an extra author block. if ( (int) $post->post_author === $this->context->site_user_id ) { return false; }
return true; }
return false; }
/** * Returns Person Schema data. * * @return bool|array Person data on success, false on failure. */ public function generate() { $user_id = $this->determine_user_id(); if ( ! $user_id ) { return false; }
$data = $this->build_person_data( $user_id );
// If this is an author page, the Person object is the main object, so we set it as such here. if ( is_author() ) { $data['mainEntityOfPage'] = array( '@id' => $this->context->canonical . WPSEO_Schema_IDs::WEBPAGE_HASH, ); }
return $data; }
/** * Determine whether the current URL is worthy of Article schema. * * @return bool */ protected function is_post_author() { /** * Filter: 'wpseo_schema_article_post_type' - Allow changing for which post types we output Article schema. * * @api array $post_types The post types for which we output Article. */ $post_types = apply_filters( 'wpseo_schema_article_post_type', array( 'post' ) ); if ( is_singular( $post_types ) ) { return true; }
return false; }
/** * Determines a User ID for the Person data. * * @return bool|int User ID or false upon return. */ protected function determine_user_id() { switch ( true ) { case is_author(): $user_id = get_queried_object_id(); break; default: $post = get_post( $this->context->id ); $user_id = (int) $post->post_author; break; }
/** * Filter: 'wpseo_schema_person_user_id' - Allows filtering of user ID used for person output. * * @api int|bool $user_id The user ID currently determined. */ return apply_filters( 'wpseo_schema_person_user_id', $user_id ); }
/** * Gets the Schema type we use for this class. * * @return string[] The schema type. */ public static function get_type() { return self::$type; } }
|