| @@ -32,17 +32,34 @@ | ||
| 32 | 32 | else { |
| 33 | 33 | $logo = $this->helpers->schema->image->generate_from_attachment_id( $logo_schema_id, $this->context->company_logo_id, $this->context->company_name ); |
| 34 | 34 | } |
| 35 | 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_schema_id ], | |
| 36 | + $organization = [ | |
| 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 ), | |
| 44 | 40 | ]; |
| 41 | + | |
| 42 | + if ( ! empty( $this->context->company_alternate_name ) ) { | |
| 43 | + $organization['alternateName'] = $this->context->company_alternate_name; | |
| 44 | + } | |
| 45 | + | |
| 46 | + $organization['url'] = $this->context->site_url; | |
| 47 | + $organization['logo'] = $logo; | |
| 48 | + $organization['image'] = [ '@id' => $logo['@id'] ]; | |
| 49 | + | |
| 50 | + $same_as = \array_values( \array_unique( \array_filter( $this->fetch_social_profiles() ) ) ); | |
| 51 | + if ( ! empty( $same_as ) ) { | |
| 52 | + $organization['sameAs'] = $same_as; | |
| 53 | + } | |
| 54 | + | |
| 55 | + if ( \is_array( $this->context->schema_page_type ) && \in_array( 'ProfilePage', $this->context->schema_page_type, true ) ) { | |
| 56 | + $organization['mainEntityOfPage'] = [ | |
| 57 | + '@id' => $this->context->main_schema_id, | |
| 58 | + ]; | |
| 59 | + } | |
| 60 | + | |
| 61 | + return $organization; | |
| 45 | 62 | } |
| 46 | 63 | |
| 47 | 64 | /** |
| 48 | 65 | * Retrieve the social profiles to display in the organization schema. |
| @@ -49,28 +66,14 @@ | ||
| 49 | 66 | * |
| 50 | 67 | * @return array An array of social profiles. |
| 51 | 68 | */ |
| 52 | 69 | 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 | - } | |
| 70 | + $profiles = $this->helpers->social_profiles->get_organization_social_profiles(); | |
| 69 | 71 | |
| 70 | - $twitter = $this->helpers->options->get( 'twitter_site', '' ); | |
| 71 | - if ( $twitter !== '' ) { | |
| 72 | - $profiles[] = 'https://twitter.com/' . $twitter; | |
| 72 | + if ( isset( $profiles['other_social_urls'] ) ) { | |
| 73 | + $other_social_urls = $profiles['other_social_urls']; | |
| 74 | + unset( $profiles['other_social_urls'] ); | |
| 75 | + $profiles = \array_merge( $profiles, $other_social_urls ); | |
| 73 | 76 | } |
| 74 | 77 | |
| 75 | 78 | /** |
| 76 | 79 | * Filter: 'wpseo_schema_organization_social_profiles' - Allows filtering social profiles for the |
| @@ -75,9 +78,9 @@ | ||
| 75 | 78 | /** |
| 76 | 79 | * Filter: 'wpseo_schema_organization_social_profiles' - Allows filtering social profiles for the |
| 77 | 80 | * represented organization. |
| 78 | 81 | * |
| 79 | - * @api string[] $profiles | |
| 82 | + * @param string[] $profiles | |
| 80 | 83 | */ |
| 81 | 84 | $profiles = \apply_filters( 'wpseo_schema_organization_social_profiles', $profiles ); |
| 82 | 85 | |
| 83 | 86 | return $profiles; |