KgOrganization.php
1.97 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
<?php
namespace AIOSEO\Plugin\Common\Schema\Graphs\KnowledgeGraph;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use \AIOSEO\Plugin\Common\Schema\Graphs;
/**
* Knowledge Graph Organization graph class.
*
* @since 4.0.0
*/
class KgOrganization extends Graphs\Graph {
/**
* Returns the graph data.
*
* @since 4.0.0
*
* @return array $data The graph data.
*/
public function get() {
$homeUrl = trailingslashit( home_url() );
$organizationName = aioseo()->options->searchAppearance->global->schema->organizationName;
$data = [
'@type' => 'Organization',
'@id' => $homeUrl . '#organization',
'name' => $organizationName ? $organizationName : aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'name' ) ),
'url' => $homeUrl,
];
$logo = $this->logo();
if ( ! empty( $logo ) ) {
$data['logo'] = $logo;
$data['image'] = [ '@id' => $homeUrl . '#organizationLogo' ];
}
$socialUrls = $this->getOrganizationProfiles();
if ( $socialUrls ) {
$data['sameAs'] = $socialUrls;
}
$phone = aioseo()->options->searchAppearance->global->schema->phone;
$contactType = aioseo()->options->searchAppearance->global->schema->contactType;
if ( $phone && $contactType ) {
if ( 'manual' === $contactType ) {
$contactType = aioseo()->options->searchAppearance->global->schema->contactTypeManual;
}
if ( $contactType ) {
$data['contactPoint'] = [
'@type' => 'ContactPoint',
'telephone' => $phone,
'contactType' => $contactType,
];
}
}
return $data;
}
/**
* Returns the logo data.
*
* @since 4.0.0
*
* @return array The logo data.
*/
public function logo() {
$logo = aioseo()->options->searchAppearance->global->schema->organizationLogo;
if ( $logo ) {
return $this->image( $logo, 'organizationLogo' );
}
$imageId = aioseo()->helpers->getSiteLogoId();
if ( $imageId ) {
return $this->image( $imageId, 'organizationLogo' );
}
return [];
}
}