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
|
<?php
namespace Yoast\WP\SEO\Generators\Schema;
use Yoast\WP\SEO\Config\Schema_IDs;
/** * Returns schema Organization data. */ class Organization extends Abstract_Schema_Piece {
/** * Determines whether an Organization graph piece should be added. * * @return bool */ public function is_needed() { return $this->context->site_represents === 'company'; }
/** * Returns the Organization Schema data. * * @return array $data The Organization schema. */ public function generate() { $logo_schema_id = $this->context->site_url . Schema_IDs::ORGANIZATION_LOGO_HASH;
return [ '@type' => 'Organization', '@id' => $this->context->site_url . Schema_IDs::ORGANIZATION_HASH, 'name' => $this->helpers->schema->html->smart_strip_tags( $this->context->company_name ), 'url' => $this->context->site_url, 'sameAs' => $this->fetch_social_profiles(), 'logo' => $this->helpers->schema->image->generate_from_attachment_id( $logo_schema_id, $this->context->company_logo_id, $this->context->company_name ), 'image' => [ '@id' => $logo_schema_id ], ]; }
/** * Retrieve the social profiles to display in the organization schema. * * @return array $profiles An array of social profiles. */ private function fetch_social_profiles() { $profiles = []; $social_profiles = [ 'facebook_site', 'instagram_url', 'linkedin_url', 'myspace_url', 'youtube_url', 'pinterest_url', 'wikipedia_url', ]; foreach ( $social_profiles as $profile ) { $social_profile = $this->helpers->options->get( $profile, '' ); if ( $social_profile !== '' ) { $profiles[] = \urldecode( $social_profile ); } }
$twitter = $this->helpers->options->get( 'twitter_site', '' ); if ( $twitter !== '' ) { $profiles[] = 'https://twitter.com/' . $twitter; }
/** * Filter: 'wpseo_schema_organization_social_profiles' - Allows filtering social profiles for the * represented organization. * * @api string[] $profiles */ $profiles = \apply_filters( 'wpseo_schema_organization_social_profiles', $profiles );
return $profiles; } }
|