WebPage.php
2.6 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
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
<?php
namespace AIOSEO\Plugin\Common\Schema\Graphs\WebPage;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Schema\Graphs;
/**
* WebPage graph class.
*
* @since 4.0.0
*/
class WebPage extends Graphs\Graph {
/**
* The graph type.
*
* This value can be overridden by WebPage child graphs that are more specific.
*
* @since 4.0.0
*
* @var string
*/
protected $type = 'WebPage';
/**
* Returns the graph data.
*
* @since 4.0.0
*
* @return array $data The graph data.
*/
public function get() {
$homeUrl = trailingslashit( home_url() );
$data = [
'@type' => $this->type,
'@id' => aioseo()->schema->context['url'] . '#' . strtolower( $this->type ),
'url' => aioseo()->schema->context['url'],
'name' => aioseo()->meta->title->getTitle(),
'description' => aioseo()->schema->context['description'],
'inLanguage' => aioseo()->helpers->currentLanguageCodeBCP47(),
'isPartOf' => [ '@id' => $homeUrl . '#website' ],
'breadcrumb' => [ '@id' => aioseo()->schema->context['url'] . '#breadcrumblist' ]
];
if ( is_singular() && ! is_page() ) {
$post = aioseo()->helpers->getPost();
if ( is_a( $post, 'WP_Post' ) ) {
$author = get_author_posts_url( $post->post_author );
if ( ! empty( $author ) ) {
if ( ! in_array( 'PersonAuthor', aioseo()->schema->graphs, true ) ) {
aioseo()->schema->graphs[] = 'PersonAuthor';
}
$data['author'] = [ '@id' => $author . '#author' ];
$data['creator'] = [ '@id' => $author . '#author' ];
}
}
}
if ( isset( aioseo()->schema->context['description'] ) && aioseo()->schema->context['description'] ) {
$data['description'] = aioseo()->schema->context['description'];
}
if ( is_singular() ) {
if ( ! isset( aioseo()->schema->context['object'] ) || ! aioseo()->schema->context['object'] ) {
return $data;
}
$post = aioseo()->schema->context['object'];
if ( has_post_thumbnail( $post ) ) {
$image = $this->image( get_post_thumbnail_id(), 'mainImage' );
if ( $image ) {
$data['image'] = $image;
$data['primaryImageOfPage'] = [
'@id' => aioseo()->schema->context['url'] . '#mainImage'
];
}
}
$data['datePublished'] = mysql2date( DATE_W3C, $post->post_date_gmt, false );
$data['dateModified'] = mysql2date( DATE_W3C, $post->post_modified_gmt, false );
return $data;
}
if ( is_front_page() ) {
$data['about'] = [ '@id' => trailingslashit( home_url() ) . '#' . aioseo()->options->searchAppearance->global->schema->siteRepresents ];
}
return $data;
}
}