PersonAuthor.php
1.25 KB
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
<?php
namespace AIOSEO\Plugin\Common\Schema\Graphs;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Person Author graph class.
*
* This a secondary Person graph for post authors and BuddyPress profile pages.
*
* @since 4.0.0
*/
class PersonAuthor extends Person {
/**
* Returns the graph data.
*
* @since 4.0.0
*
* @return array $data The graph data.
*/
public function get() {
$post = aioseo()->helpers->getPost();
if ( ! $post ) {
return [];
}
$userId = $post->post_author;
if ( function_exists( 'bp_is_user' ) && bp_is_user() ) {
$userId = intval( wp_get_current_user()->ID );
}
if ( ! $userId ) {
return [];
}
$authorUrl = get_author_posts_url( $post->post_author );
$data = [
'@type' => 'Person',
'@id' => $authorUrl . '#author',
'url' => $authorUrl,
'name' => get_the_author_meta( 'display_name', $userId )
];
$avatar = $this->avatar( $userId, 'authorImage' );
if ( $avatar ) {
$data['image'] = $avatar;
}
$socialUrls = $this->socialUrls( $userId );
if ( $socialUrls ) {
$data['sameAs'] = $socialUrls;
}
if ( is_author() ) {
$data['mainEntityOfPage'] = [
'#id' => aioseo()->schema->context['url'] . '#profilepage'
];
}
return $data;
}
}