settings = $settings; } public function get_id(): string { return 'Organization'; } public function applies_to( \WP_Post $post ): bool { // Scope (like LocalBusiness): 'site' (default) keeps the node on every // page as the brand identity. When narrowed, SchemaGraphBuilder also // strips the now-dangling publisher @id references from other nodes. $settings = $this->settings->get(); $scope = $this->scope(); if ( 'site' === $scope ) { return true; } $is_front = $post->ID === (int) get_option( 'page_on_front' ) || is_front_page(); if ( 'front_page' === $scope ) { return $is_front; } return $is_front || in_array( $post->ID, array_map( 'intval', (array) ( $settings['organization_page_ids'] ?? array() ) ), true ); } /** * Scope check for pages that have no WP_Post (taxonomy archives, the * blog index): the node belongs there when it is site-wide, or when the * archive IS the front page (a "latest posts" home page) — the selected * page IDs of the 'pages' scope can never match an archive. */ public function applies_to_archive(): bool { return 'site' === $this->scope() || is_front_page(); } public function build( \WP_Post $post ): array { return $this->node(); } /** * @return array */ public function node(): array { $settings = $this->settings->get(); $name = '' !== $settings['organization_name'] ? (string) $settings['organization_name'] : get_bloginfo( 'name' ); $data = array( '@type' => 'Organization', '@id' => SchemaIds::organization(), 'name' => $name, 'url' => home_url( '/' ), ); $logo_id = (int) $settings['organization_logo_id']; $logo_id = $logo_id > 0 ? $logo_id : (int) get_option( 'site_icon' ); if ( $logo_id > 0 ) { $logo_url = wp_get_attachment_image_url( $logo_id, 'full' ); if ( is_string( $logo_url ) ) { $data['logo'] = array( '@type' => 'ImageObject', 'url' => $logo_url, ); } } if ( ! empty( $settings['social_profiles'] ) ) { $data['sameAs'] = array_values( (array) $settings['social_profiles'] ); } /** * Filters the Organization schema node. * * @param array $data */ return (array) apply_filters( 'acez_seo_organization', $data ); } private function scope(): string { return (string) ( $this->settings->get()['organization_scope'] ?? 'site' ); } }