graphql_single_name) { $carry[wp_gql_seo_get_field_key($post_type_object->graphql_single_name)] = ['type' => 'SEOContentType']; } } return $carry; } /** * Build taxonomy types data array for GraphQL schema. * * @param array $taxonomies Taxonomies. * @return array */ function wp_gql_seo_build_taxonomy_types($taxonomies) { $carry = []; foreach ($taxonomies as $taxonomy) { $taxonomy_object = get_taxonomy($taxonomy); if ($taxonomy_object->graphql_single_name) { $carry[wp_gql_seo_get_field_key($taxonomy_object->graphql_single_name)] = ['type' => 'SEOTaxonomyType']; } } return $carry; } /** * Get full head content from Yoast SEO. * * @param \Yoast\WP\SEO\Surfaces\Values\Meta|bool $metaForPost Meta object. * @return string */ function wp_gql_seo_get_full_head($metaForPost) { if ($metaForPost !== false) { $head = $metaForPost->get_head(); return is_string($head) ? $head : $head->html; } return ''; } /** * Build content type data for GraphQL schema. * * @param array $types Post types. * @param array $all All Yoast SEO options. * @return array */ function wp_gql_seo_build_content_type_data($types, $all) { $carry = []; // Validate input parameters if (!is_array($types) || empty($types) || !is_array($all) || empty($all)) { return $carry; } foreach ($types as $type) { $post_type_object = get_post_type_object($type); // Validate post type object if (!$post_type_object || !$post_type_object->graphql_single_name) { continue; } $tag = wp_gql_seo_get_field_key($post_type_object->graphql_single_name); $meta = YoastSEO()->meta->for_post_type_archive($type); $carry[$tag] = [ 'title' => wp_gql_seo_format_string(wp_gql_seo_replace_vars($all['title-' . $type] ?? null)), 'metaDesc' => wp_gql_seo_format_string(wp_gql_seo_replace_vars($all['metadesc-' . $type] ?? null)), 'metaRobotsNoindex' => boolval($all['noindex-' . $type] ?? false), 'schemaType' => $all['schema-page-type-' . $type] ?? null, 'schema' => [ 'raw' => !empty($meta) && !empty($meta->schema) ? wp_json_encode($meta->schema, JSON_UNESCAPED_SLASHES) : null, ], 'archive' => [ 'hasArchive' => boolval($post_type_object->has_archive), 'archiveLink' => apply_filters('wp_gql_seo_archive_link', get_post_type_archive_link($type), $type), 'title' => wp_gql_seo_format_string($meta->title ?? null), 'metaDesc' => wp_gql_seo_format_string($all['metadesc-ptarchive-' . $type] ?? null), 'metaRobotsNoindex' => !empty($meta) && !empty($meta->robots['index']) && $meta->robots['index'] === 'index' ? false : true, 'metaRobotsNofollow' => !empty($meta) && !empty($meta->robots['follow']) && $meta->robots['follow'] === 'follow' ? false : true, 'metaRobotsIndex' => $meta->robots['index'] ?? 'noindex', 'metaRobotsFollow' => $meta->robots['follow'] ?? 'nofollow', 'breadcrumbTitle' => wp_gql_seo_format_string($all['bctitle-ptarchive-' . $type] ?? null), 'fullHead' => wp_gql_seo_get_full_head($meta), ], ]; } return $carry; } /** * Build taxonomy data for GraphQL schema. * * @param array $taxonomies Taxonomies. * @param array $all All Yoast SEO options. * @return array */ function wp_gql_seo_build_taxonomy_data($taxonomies, $all) { $carry = []; // Validate input parameters if (!is_array($taxonomies) || empty($taxonomies) || !is_array($all) || empty($all)) { return $carry; } foreach ($taxonomies as $taxonomy) { $taxonomy_object = get_taxonomy($taxonomy); // Validate taxonomy object if (!$taxonomy_object || !$taxonomy_object->graphql_single_name) { continue; } $tag = wp_gql_seo_get_field_key($taxonomy_object->graphql_single_name); $carry[$tag] = [ 'archive' => [ 'title' => wp_gql_seo_format_string(wp_gql_seo_replace_vars($all['title-tax-' . $taxonomy] ?? null)), 'metaDesc' => wp_gql_seo_format_string( wp_gql_seo_replace_vars($all['metadesc-tax-' . $taxonomy] ?? null) ), 'metaRobotsNoindex' => boolval($all['noindex-tax-' . $taxonomy] ?? false), ], ]; } return $carry; }