PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.8
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.8
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / generators / schema / organization.php

organization.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.8, at src/generators/schema/organization.php

86 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Generators\Schema;
4
5 use Yoast\WP\SEO\Config\Schema_IDs;
6
7 /**
8 * Returns schema Organization data.
9 */
10 class Organization extends Abstract_Schema_Piece {
11
12 /**
13 * Determines whether an Organization graph piece should be added.
14 *
15 * @return bool
16 */
17 public function is_needed() {
18 return $this->context->site_represents === 'company';
19 }
20
21 /**
22 * Returns the Organization Schema data.
23 *
24 * @return array The Organization schema.
25 */
26 public function generate() {
27 $logo_schema_id = $this->context->site_url . Schema_IDs::ORGANIZATION_LOGO_HASH;
28
29 if ( $this->context->company_logo_meta ) {
30 $logo = $this->helpers->schema->image->generate_from_attachment_meta( $logo_schema_id, $this->context->company_logo_meta, $this->context->company_name );
31 }
32 else {
33 $logo = $this->helpers->schema->image->generate_from_attachment_id( $logo_schema_id, $this->context->company_logo_id, $this->context->company_name );
34 }
35
36 return [
37 '@type' => 'Organization',
38 '@id' => $this->context->site_url . Schema_IDs::ORGANIZATION_HASH,
39 'name' => $this->helpers->schema->html->smart_strip_tags( $this->context->company_name ),
40 'url' => $this->context->site_url,
41 'sameAs' => \array_values( \array_unique( $this->fetch_social_profiles() ) ),
42 'logo' => $logo,
43 'image' => [ '@id' => $logo['@id'] ],
44 ];
45 }
46
47 /**
48 * Retrieve the social profiles to display in the organization schema.
49 *
50 * @return array An array of social profiles.
51 */
52 private function fetch_social_profiles() {
53 $profiles = [];
54 $social_profiles = [
55 'facebook_site',
56 'instagram_url',
57 'linkedin_url',
58 'myspace_url',
59 'youtube_url',
60 'pinterest_url',
61 'wikipedia_url',
62 ];
63 foreach ( $social_profiles as $profile ) {
64 $social_profile = $this->helpers->options->get( $profile, '' );
65 if ( $social_profile !== '' ) {
66 $profiles[] = \urldecode( $social_profile );
67 }
68 }
69
70 $twitter = $this->helpers->options->get( 'twitter_site', '' );
71 if ( $twitter !== '' ) {
72 $profiles[] = 'https://twitter.com/' . $twitter;
73 }
74
75 /**
76 * Filter: 'wpseo_schema_organization_social_profiles' - Allows filtering social profiles for the
77 * represented organization.
78 *
79 * @api string[] $profiles
80 */
81 $profiles = \apply_filters( 'wpseo_schema_organization_social_profiles', $profiles );
82
83 return $profiles;
84 }
85 }
86