From 652a4d816deb9243675543e8cfe8de947c000c91 Mon Sep 17 00:00:00 2001 From: Ashley Hitchcock Date: Mon, 7 Dec 2020 17:52:18 +0000 Subject: [PATCH] Feature/full schema v2 (#74) - Raw Schema returned as a string to be decoded in the client --- CHANGELOG.md | 6 +++++ package.json | 2 +- readme.txt | 2 +- wp-graphql-yoast-seo.php | 52 ++++++++++++++++++++++++++++++++++++++-- 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4f17029ae9..b11fa9f43bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [4.10.0] - 2020-12-07 + +### Added + +- Raw Schema data for post types, taxonomies, and users + ## [4.9.0] - 2020-11-25 ### Added diff --git a/package.json b/package.json index 4b15139937b..b1904d3f1b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wp-graphql-yoast-seo", - "version": "4.2.0", + "version": "4.10.0", "description": "A WPGraphQL Extension that adds support for Yoast SEO", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", diff --git a/readme.txt b/readme.txt index 7c811b9a791..700fb42fa58 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: SEO, Yoast, WPGraphQL, GraphQL, Headless WordPress, Decoupled WordPress, J Requires at least: 5.0 Tested up to: 5.4 Requires PHP: 7.1 -Stable tag: 4.9.0 +Stable tag: 4.10.0 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html diff --git a/wp-graphql-yoast-seo.php b/wp-graphql-yoast-seo.php index 8b72adf5522..c65691315ef 100755 --- a/wp-graphql-yoast-seo.php +++ b/wp-graphql-yoast-seo.php @@ -8,7 +8,7 @@ * Author URI: https://www.ashleyhitchcock.com * Text Domain: wp-graphql-yoast-seo * Domain Path: /languages - * Version: 4.9.0 + * Version: 4.10.0 * * @package WP_Graphql_YOAST_SEO */ @@ -196,6 +196,16 @@ function wp_gql_seo_build_content_type_data($types, $all) 'fields' => [ 'pageType' => ['type' => ['list_of' => 'String']], 'articleType' => ['type' => ['list_of' => 'String']], + 'raw' => ['type' => 'String'], + ], + ]); + register_graphql_object_type('SEOTaxonomySchema', [ + 'description' => __( + 'The Schema types for Taxonomy', + 'wp-graphql-yoast-seo' + ), + 'fields' => [ + 'raw' => ['type' => 'String'], ], ]); @@ -225,7 +235,9 @@ function wp_gql_seo_build_content_type_data($types, $all) ]; register_graphql_object_type('TaxonomySEO', [ - 'fields' => $baseSEOFields, + 'fields' => array_merge($baseSEOFields, [ + 'schema' => ['type' => 'SEOTaxonomySchema'], + ]), ]); register_graphql_object_type('PostTypeSEO', [ @@ -443,6 +455,13 @@ function wp_gql_seo_build_content_type_data($types, $all) ], ]); + register_graphql_object_type('SEOUserSchema', [ + 'description' => __('The Schema types for User', 'wp-graphql-yoast-seo'), + 'fields' => [ + 'raw' => ['type' => 'String'], + ], + ]); + register_graphql_object_type('SEOUser', [ 'fields' => [ 'title' => ['type' => 'String'], @@ -450,6 +469,7 @@ function wp_gql_seo_build_content_type_data($types, $all) 'metaRobotsNoindex' => ['type' => 'String'], 'metaRobotsNofollow' => ['type' => 'String'], 'social' => ['type' => 'SEOUserSocial'], + 'schema' => ['type' => 'SEOUserSchema'], ], ]); @@ -645,6 +665,16 @@ function wp_gql_seo_build_content_type_data($types, $all) // Base array $seo = []; + $map = [ + '@id' => 'id', + '@type' => 'type', + '@graph' => 'graph', + '@context' => 'context', + ]; + + $schemaArray = YoastSEO()->meta->for_post($post->ID) + ->schema; + // https://developer.yoast.com/blog/yoast-seo-14-0-using-yoast-seo-surfaces/ $robots = YoastSEO()->meta->for_post($post->ID) ->robots; @@ -762,6 +792,10 @@ function wp_gql_seo_build_content_type_data($types, $all) ? YoastSEO()->meta->for_post($post->ID) ->schema_article_type : [], + 'raw' => json_encode( + $schemaArray, + JSON_UNESCAPED_SLASHES + ), ], ]; @@ -826,6 +860,8 @@ function wp_gql_seo_build_content_type_data($types, $all) 'resolve' => function ($user, array $args, AppContext $context) { $robots = YoastSEO()->meta->for_author($user->userId)->robots; + $schemaArray = YoastSEO()->meta->for_author($user->userId)->schema; + $userSeo = [ 'title' => wp_gql_seo_format_string( YoastSEO()->meta->for_author($user->userId)->title @@ -865,6 +901,9 @@ function wp_gql_seo_build_content_type_data($types, $all) get_the_author_meta('wikipedia', $user->userId) ), ], + 'schema' => [ + 'raw' => json_encode($schemaArray, JSON_UNESCAPED_SLASHES), + ], ]; return !empty($userSeo) ? $userSeo : []; @@ -896,6 +935,9 @@ function wp_gql_seo_build_content_type_data($types, $all) ); $robots = YoastSEO()->meta->for_term($term->term_id)->robots; + $schemaArray = YoastSEO()->meta->for_term($term->term_id) + ->schema; + // Get data $seo = [ 'title' => wp_gql_seo_format_string( @@ -984,6 +1026,12 @@ function wp_gql_seo_build_content_type_data($types, $all) YoastSEO()->meta->for_term($term->term_id) ->is_cornerstone ), + 'schema' => [ + 'raw' => json_encode( + $schemaArray, + JSON_UNESCAPED_SLASHES + ), + ], ]; wp_reset_query();