organization = $organization; } /** * @param array $page_node The page's own node (CollectionPage). * * @return array */ public function build( array $page_node ): array { // An empty description says nothing — leave the property out rather // than print `"description": ""`. if ( isset( $page_node['description'] ) && '' === $page_node['description'] ) { unset( $page_node['description'] ); } $website = WebSiteSchemaType::node(); $nodes = array( $page_node, $website ); if ( $this->organization->applies_to_archive() ) { $nodes[] = $this->organization->node(); } else { unset( $nodes[1]['publisher'] ); } $language = MultilingualPluginDetector::current_language(); foreach ( $nodes as $index => $node ) { if ( ! isset( $node['inLanguage'] ) ) { $nodes[ $index ]['inLanguage'] = $language; } } return array( '@context' => 'https://schema.org', '@graph' => $nodes, ); } /** * Serializes a graph for wp_print_inline_script_tag(). JSON_HEX_TAG turns * every literal "<"/">" into , so no dynamic string (a term * name, a page title) can close the script element early — same flags as * SchemaOutput::cached_json(), kept in sync. * * @param array $graph */ public static function encode( array $graph ): ?string { $json = wp_json_encode( $graph, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ); return is_string( $json ) ? $json : null; } }