Changeset 2932770
- Timestamp:
- 06/30/2023 08:19:55 PM (3 years ago)
- Location:
- add-wpgraphql-seo
- Files:
-
- 8 edited
- 1 copied
-
tags/4.22.5 (copied) (copied from add-wpgraphql-seo/trunk)
-
tags/4.22.5/CHANGELOG.md (modified) (1 diff)
-
tags/4.22.5/package.json (modified) (1 diff)
-
tags/4.22.5/readme.txt (modified) (1 diff)
-
tags/4.22.5/wp-graphql-yoast-seo.php (modified) (7 diffs)
-
trunk/CHANGELOG.md (modified) (1 diff)
-
trunk/package.json (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/wp-graphql-yoast-seo.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
add-wpgraphql-seo/tags/4.22.5/CHANGELOG.md
r2918717 r2932770 5 5 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 6 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 8 ## [4.22.5] - 2023-06-30 9 10 ### Fixed 11 12 - Cannot redeclare get_post_type_graphql_fields() previously declared (#161) (thanks @renatonascalves) 13 - fixes missing seo data on contentTypes 7 14 8 15 ## [4.22.4] - 2023-05-29 -
add-wpgraphql-seo/tags/4.22.5/package.json
r2918717 r2932770 1 1 { 2 2 "name": "wp-graphql-yoast-seo", 3 "version": "4.22. 4",3 "version": "4.22.5", 4 4 "description": "A WPGraphQL Extension that adds support for Yoast SEO", 5 5 "scripts": { -
add-wpgraphql-seo/tags/4.22.5/readme.txt
r2918717 r2932770 5 5 Tested up to: 6.1.1 6 6 Requires PHP: 7.1 7 Stable tag: 4.22. 47 Stable tag: 4.22.5 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html -
add-wpgraphql-seo/tags/4.22.5/wp-graphql-yoast-seo.php
r2918717 r2932770 9 9 * Text Domain: wp-graphql-yoast-seo 10 10 * Domain Path: /languages 11 * Version: 4.22. 411 * Version: 4.22.5 12 12 * 13 13 * @package WP_Graphql_YOAST_SEO … … 178 178 { 179 179 $carry = []; 180 181 // Validate input parameters 182 if (!is_array($types) || empty($types) || !is_array($all) || empty($all)) { 183 return $carry; 184 } 185 180 186 foreach ($types as $type) { 181 187 $post_type_object = get_post_type_object($type); 182 188 183 if ($post_type_object->graphql_single_name) { 184 $tag = wp_gql_seo_get_field_key($post_type_object->graphql_single_name); 185 186 $meta = YoastSEO()->meta->for_post_type_archive($type); 187 188 if (empty($meta)) { 189 continue; 189 // Validate post type object 190 if (!$post_type_object || !$post_type_object->graphql_single_name) { 191 continue; 192 } 193 194 $tag = wp_gql_seo_get_field_key($post_type_object->graphql_single_name); 195 196 $meta = YoastSEO()->meta->for_post_type_archive($type); 197 198 $carry[$tag] = [ 199 'title' => wp_gql_seo_format_string(wp_gql_seo_replace_vars($all['title-' . $type] ?? null)), 200 'metaDesc' => wp_gql_seo_format_string(wp_gql_seo_replace_vars($all['metadesc-' . $type] ?? null)), 201 'metaRobotsNoindex' => boolval($all['noindex-' . $type] ?? false), 202 'schemaType' => $all['schema-page-type-' . $type] ?? null, 203 'schema' => [ 204 'raw' => 205 !empty($meta) && !empty($meta->schema) 206 ? json_encode($meta->schema, JSON_UNESCAPED_SLASHES) 207 : null, 208 ], 209 'archive' => [ 210 'hasArchive' => boolval($post_type_object->has_archive), 211 'archiveLink' => apply_filters('wp_gql_seo_archive_link', get_post_type_archive_link($type), $type), 212 'title' => wp_gql_seo_format_string($meta->title ?? null), 213 'metaDesc' => wp_gql_seo_format_string($all['metadesc-ptarchive-' . $type] ?? null), 214 'metaRobotsNoindex' => 215 !empty($meta) && !empty($meta->robots['index']) && $meta->robots['index'] === 'index' 216 ? false 217 : true, 218 'metaRobotsNofollow' => 219 !empty($meta) && !empty($meta->robots['follow']) && $meta->robots['follow'] === 'follow' 220 ? false 221 : true, 222 'metaRobotsIndex' => $meta->robots['index'] ?? 'noindex', 223 'metaRobotsFollow' => $meta->robots['follow'] ?? 'nofollow', 224 'breadcrumbTitle' => wp_gql_seo_format_string($all['bctitle-ptarchive-' . $type] ?? null), 225 'fullHead' => wp_gql_seo_get_full_head($meta), 226 ], 227 ]; 228 } 229 230 return $carry; 231 } 232 233 function wp_gql_seo_get_post_type_graphql_fields($post, array $args, AppContext $context) 234 { 235 // Base array 236 $seo = []; 237 238 $map = [ 239 '@id' => 'id', 240 '@type' => 'type', 241 '@graph' => 'graph', 242 '@context' => 'context', 243 ]; 244 if ($post instanceof Term) { 245 $meta = YoastSEO()->meta->for_term($post->term_id); 246 } else { 247 $meta = YoastSEO()->meta->for_post($post->ID); 248 } 249 250 $schemaArray = $meta !== false ? $meta->schema : []; 251 252 // https://developer.yoast.com/blog/yoast-seo-14-0-using-yoast-seo-surfaces/ 253 $robots = $meta !== false ? $meta->robots : []; 254 255 // Get data 256 $seo = [ 257 'title' => wp_gql_seo_format_string($meta !== false ? $meta->title : ''), 258 'metaDesc' => wp_gql_seo_format_string($meta !== false ? $meta->description : ''), 259 'focuskw' => wp_gql_seo_format_string(get_post_meta($post->ID, '_yoast_wpseo_focuskw', true)), 260 'metaKeywords' => wp_gql_seo_format_string(get_post_meta($post->ID, '_yoast_wpseo_metakeywords', true)), 261 'metaRobotsNoindex' => $robots['index'] ?? '', 262 'metaRobotsNofollow' => $robots['follow'] ?? '', 263 'opengraphTitle' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_title : ''), 264 'opengraphUrl' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_url : ''), 265 'opengraphSiteName' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_site_name : ''), 266 'opengraphType' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_type : ''), 267 'opengraphAuthor' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_article_author : ''), 268 'opengraphPublisher' => wp_gql_seo_format_string( 269 $meta !== false ? $meta->open_graph_article_publisher : '' 270 ), 271 'opengraphPublishedTime' => wp_gql_seo_format_string( 272 $meta !== false ? $meta->open_graph_article_published_time : '' 273 ), 274 'opengraphModifiedTime' => wp_gql_seo_format_string( 275 $meta !== false ? $meta->open_graph_article_modified_time : '' 276 ), 277 'opengraphDescription' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_description : ''), 278 'opengraphImage' => function () use ($post, $context, $meta) { 279 $id = wp_gql_seo_get_og_image($meta !== false ? $meta->open_graph_images : []); 280 281 return $context->get_loader('post')->load_deferred(absint($id)); 282 }, 283 'twitterCardType' => wp_gql_seo_format_string($meta !== false ? $meta->twitter_card : ''), 284 'twitterTitle' => wp_gql_seo_format_string($meta !== false ? $meta->twitter_title : ''), 285 'twitterDescription' => wp_gql_seo_format_string($meta !== false ? $meta->twitter_description : ''), 286 'twitterImage' => function () use ($post, $context, $meta) { 287 $twitter_image = $meta->twitter_image; 288 289 if (empty($twitter_image)) { 290 return null; 190 291 } 191 292 192 $carry[$tag] = [ 193 'title' => !empty($all['title-' . $type]) 194 ? wp_gql_seo_format_string(wp_gql_seo_replace_vars($all['title-' . $type])) 195 : null, 196 'metaDesc' => !empty($all['metadesc-' . $type]) 197 ? wp_gql_seo_format_string(wp_gql_seo_replace_vars($all['metadesc-' . $type])) 198 : null, 199 'metaRobotsNoindex' => !empty($all['noindex-' . $type]) ? boolval($all['noindex-' . $type]) : false, 200 'schemaType' => !empty($all['schema-page-type-' . $type]) 201 ? $all['schema-page-type-' . $type] 202 : null, 203 204 'schema' => [ 205 'raw' => !empty($meta->schema) ? json_encode($meta->schema, JSON_UNESCAPED_SLASHES) : null, 206 ], 207 'archive' => [ 208 'hasArchive' => boolval($post_type_object->has_archive), 209 'archiveLink' => apply_filters( 210 'wp_gql_seo_archive_link', 211 get_post_type_archive_link($type), 212 $type 213 ), 214 'title' => !empty($meta->title) ? wp_gql_seo_format_string($meta->title) : null, 215 'metaDesc' => !empty($all['metadesc-ptarchive-' . $type]) 216 ? wp_gql_seo_format_string($all['metadesc-ptarchive-' . $type]) 217 : null, 218 'metaRobotsNoindex' => 219 !empty($meta->robots['index']) && $meta->robots['index'] === 'index' ? false : true, 220 'metaRobotsNofollow' => 221 !empty($meta->robots['follow']) && $meta->robots['follow'] === 'follow' ? false : true, 222 'metaRobotsIndex' => !empty($meta->robots['index']) ? $meta->robots['index'] : 'noindex', 223 'metaRobotsFollow' => !empty($meta->robots['follow']) ? $meta->robots['follow'] : 'nofollow', 224 'breadcrumbTitle' => !empty($all['bctitle-ptarchive-' . $type]) 225 ? wp_gql_seo_format_string($all['bctitle-ptarchive-' . $type]) 226 : null, 227 'fullHead' => is_string($meta->get_head()) ? $meta->get_head() : $meta->get_head()->html, 228 ], 229 ]; 230 } 231 } 232 return $carry; 293 $id = wpcom_vip_attachment_url_to_postid($twitter_image); 294 295 return $context->get_loader('post')->load_deferred(absint($id)); 296 }, 297 'canonical' => wp_gql_seo_format_string($meta !== false ? $meta->canonical : ''), 298 'readingTime' => floatval($meta !== false ? $meta->estimated_reading_time_minutes : ''), 299 'breadcrumbs' => $meta !== false ? $meta->breadcrumbs : [], 300 // TODO: Default should be true or false? 301 'cornerstone' => boolval($meta !== false ? $meta->indexable->is_cornerstone : false), 302 'fullHead' => wp_gql_seo_get_full_head($meta), 303 'schema' => [ 304 'pageType' => $meta !== false && is_array($meta->schema_page_type) ? $meta->schema_page_type : [], 305 'articleType' => 306 $meta !== false && is_array($meta->schema_article_type) ? $meta->schema_article_type : [], 307 'raw' => json_encode($schemaArray, JSON_UNESCAPED_SLASHES), 308 ], 309 ]; 310 311 return !empty($seo) ? $seo : null; 233 312 } 234 313 … … 746 825 ]); 747 826 748 function get_post_type_graphql_fields($post, array $args, AppContext $context)749 {750 // Base array751 $seo = [];752 753 $map = [754 '@id' => 'id',755 '@type' => 'type',756 '@graph' => 'graph',757 '@context' => 'context',758 ];759 if ($post instanceof Term) {760 $meta = YoastSEO()->meta->for_term($post->term_id);761 } else {762 $meta = YoastSEO()->meta->for_post($post->ID);763 }764 765 $schemaArray = $meta !== false ? $meta->schema : [];766 767 // https://developer.yoast.com/blog/yoast-seo-14-0-using-yoast-seo-surfaces/768 $robots = $meta !== false ? $meta->robots : [];769 770 // Get data771 $seo = [772 'title' => wp_gql_seo_format_string($meta !== false ? $meta->title : ''),773 'metaDesc' => wp_gql_seo_format_string($meta !== false ? $meta->description : ''),774 'focuskw' => wp_gql_seo_format_string(get_post_meta($post->ID, '_yoast_wpseo_focuskw', true)),775 'metaKeywords' => wp_gql_seo_format_string(get_post_meta($post->ID, '_yoast_wpseo_metakeywords', true)),776 'metaRobotsNoindex' => $robots['index'] ?? '',777 'metaRobotsNofollow' => $robots['follow'] ?? '',778 'opengraphTitle' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_title : ''),779 'opengraphUrl' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_url : ''),780 'opengraphSiteName' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_site_name : ''),781 'opengraphType' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_type : ''),782 'opengraphAuthor' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_article_author : ''),783 'opengraphPublisher' => wp_gql_seo_format_string(784 $meta !== false ? $meta->open_graph_article_publisher : ''785 ),786 'opengraphPublishedTime' => wp_gql_seo_format_string(787 $meta !== false ? $meta->open_graph_article_published_time : ''788 ),789 'opengraphModifiedTime' => wp_gql_seo_format_string(790 $meta !== false ? $meta->open_graph_article_modified_time : ''791 ),792 'opengraphDescription' => wp_gql_seo_format_string(793 $meta !== false ? $meta->open_graph_description : ''794 ),795 'opengraphImage' => function () use ($post, $context, $meta) {796 $id = wp_gql_seo_get_og_image($meta !== false ? $meta->open_graph_images : []);797 798 return $context->get_loader('post')->load_deferred(absint($id));799 },800 'twitterCardType' => wp_gql_seo_format_string($meta !== false ? $meta->twitter_card : ''),801 'twitterTitle' => wp_gql_seo_format_string($meta !== false ? $meta->twitter_title : ''),802 'twitterDescription' => wp_gql_seo_format_string($meta !== false ? $meta->twitter_description : ''),803 'twitterImage' => function () use ($post, $context, $meta) {804 $twitter_image = $meta->twitter_image;805 806 if (empty($twitter_image)) {807 return null;808 }809 810 $id = wpcom_vip_attachment_url_to_postid($twitter_image);811 812 return $context->get_loader('post')->load_deferred(absint($id));813 },814 'canonical' => wp_gql_seo_format_string($meta !== false ? $meta->canonical : ''),815 'readingTime' => floatval($meta !== false ? $meta->estimated_reading_time_minutes : ''),816 'breadcrumbs' => $meta !== false ? $meta->breadcrumbs : [],817 // TODO: Default should be true or false?818 'cornerstone' => boolval($meta !== false ? $meta->indexable->is_cornerstone : false),819 'fullHead' => wp_gql_seo_get_full_head($meta),820 'schema' => [821 'pageType' => $meta !== false && is_array($meta->schema_page_type) ? $meta->schema_page_type : [],822 'articleType' =>823 $meta !== false && is_array($meta->schema_article_type) ? $meta->schema_article_type : [],824 'raw' => json_encode($schemaArray, JSON_UNESCAPED_SLASHES),825 ],826 ];827 828 return !empty($seo) ? $seo : null;829 }830 831 827 register_graphql_field('ContentNode', 'seo', [ 832 828 'type' => 'PostTypeSEO', 833 829 'description' => __('The Yoast SEO data of the ContentNode', 'wp-graphql-yoast-seo'), 834 830 'resolve' => function ($post, array $args, AppContext $context) { 835 return get_post_type_graphql_fields($post, $args, $context);831 return wp_gql_seo_get_post_type_graphql_fields($post, $args, $context); 836 832 }, 837 833 ]); … … 840 836 'description' => __('The Yoast SEO data of the ContentNode', 'wp-graphql-yoast-seo'), 841 837 'resolve' => function ($post, array $args, AppContext $context) { 842 return get_post_type_graphql_fields($post, $args, $context);838 return wp_gql_seo_get_post_type_graphql_fields($post, $args, $context); 843 839 }, 844 840 ]); … … 850 846 'description' => __('The Yoast SEO data of the ContentNode', 'wp-graphql-yoast-seo'), 851 847 'resolve' => function ($post, array $args, AppContext $context) { 852 return get_post_type_graphql_fields($post, $args, $context);848 return wp_gql_seo_get_post_type_graphql_fields($post, $args, $context); 853 849 }, 854 850 ]); … … 945 941 'region' => YoastSEO()->meta->for_author($user->userId)->region, 946 942 'breadcrumbTitle' => YoastSEO()->meta->for_author($user->userId)->breadcrumb_title, 947 'fullHead' => is_string( 948 YoastSEO() 949 ->meta->for_author($user->userId) 950 ->get_head() 951 ) 952 ? YoastSEO() 953 ->meta->for_author($user->userId) 954 ->get_head() 955 : YoastSEO() 956 ->meta->for_author($user->userId) 957 ->get_head()->html, 943 'fullHead' => wp_gql_seo_get_full_head(YoastSEO()->meta->for_author($user->userId)), 958 944 'social' => [ 959 945 'facebook' => wp_gql_seo_format_string(get_the_author_meta('facebook', $user->userId)), … … 1069 1055 'breadcrumbs' => YoastSEO()->meta->for_term($term->term_id)->breadcrumbs, 1070 1056 'cornerstone' => boolval(YoastSEO()->meta->for_term($term->term_id)->is_cornerstone), 1071 'fullHead' => is_string( 1072 YoastSEO() 1073 ->meta->for_term($term->term_id) 1074 ->get_head() 1075 ) 1076 ? YoastSEO() 1077 ->meta->for_term($term->term_id) 1078 ->get_head() 1079 : YoastSEO() 1080 ->meta->for_term($term->term_id) 1081 ->get_head()->html, 1057 'fullHead' => wp_gql_seo_get_full_head(YoastSEO()->meta->for_term($term->term_id)), 1082 1058 'schema' => [ 1083 1059 'raw' => json_encode($schemaArray, JSON_UNESCAPED_SLASHES), -
add-wpgraphql-seo/trunk/CHANGELOG.md
r2918717 r2932770 5 5 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 6 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 8 ## [4.22.5] - 2023-06-30 9 10 ### Fixed 11 12 - Cannot redeclare get_post_type_graphql_fields() previously declared (#161) (thanks @renatonascalves) 13 - fixes missing seo data on contentTypes 7 14 8 15 ## [4.22.4] - 2023-05-29 -
add-wpgraphql-seo/trunk/package.json
r2918717 r2932770 1 1 { 2 2 "name": "wp-graphql-yoast-seo", 3 "version": "4.22. 4",3 "version": "4.22.5", 4 4 "description": "A WPGraphQL Extension that adds support for Yoast SEO", 5 5 "scripts": { -
add-wpgraphql-seo/trunk/readme.txt
r2918717 r2932770 5 5 Tested up to: 6.1.1 6 6 Requires PHP: 7.1 7 Stable tag: 4.22. 47 Stable tag: 4.22.5 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html -
add-wpgraphql-seo/trunk/wp-graphql-yoast-seo.php
r2918717 r2932770 9 9 * Text Domain: wp-graphql-yoast-seo 10 10 * Domain Path: /languages 11 * Version: 4.22. 411 * Version: 4.22.5 12 12 * 13 13 * @package WP_Graphql_YOAST_SEO … … 178 178 { 179 179 $carry = []; 180 181 // Validate input parameters 182 if (!is_array($types) || empty($types) || !is_array($all) || empty($all)) { 183 return $carry; 184 } 185 180 186 foreach ($types as $type) { 181 187 $post_type_object = get_post_type_object($type); 182 188 183 if ($post_type_object->graphql_single_name) { 184 $tag = wp_gql_seo_get_field_key($post_type_object->graphql_single_name); 185 186 $meta = YoastSEO()->meta->for_post_type_archive($type); 187 188 if (empty($meta)) { 189 continue; 189 // Validate post type object 190 if (!$post_type_object || !$post_type_object->graphql_single_name) { 191 continue; 192 } 193 194 $tag = wp_gql_seo_get_field_key($post_type_object->graphql_single_name); 195 196 $meta = YoastSEO()->meta->for_post_type_archive($type); 197 198 $carry[$tag] = [ 199 'title' => wp_gql_seo_format_string(wp_gql_seo_replace_vars($all['title-' . $type] ?? null)), 200 'metaDesc' => wp_gql_seo_format_string(wp_gql_seo_replace_vars($all['metadesc-' . $type] ?? null)), 201 'metaRobotsNoindex' => boolval($all['noindex-' . $type] ?? false), 202 'schemaType' => $all['schema-page-type-' . $type] ?? null, 203 'schema' => [ 204 'raw' => 205 !empty($meta) && !empty($meta->schema) 206 ? json_encode($meta->schema, JSON_UNESCAPED_SLASHES) 207 : null, 208 ], 209 'archive' => [ 210 'hasArchive' => boolval($post_type_object->has_archive), 211 'archiveLink' => apply_filters('wp_gql_seo_archive_link', get_post_type_archive_link($type), $type), 212 'title' => wp_gql_seo_format_string($meta->title ?? null), 213 'metaDesc' => wp_gql_seo_format_string($all['metadesc-ptarchive-' . $type] ?? null), 214 'metaRobotsNoindex' => 215 !empty($meta) && !empty($meta->robots['index']) && $meta->robots['index'] === 'index' 216 ? false 217 : true, 218 'metaRobotsNofollow' => 219 !empty($meta) && !empty($meta->robots['follow']) && $meta->robots['follow'] === 'follow' 220 ? false 221 : true, 222 'metaRobotsIndex' => $meta->robots['index'] ?? 'noindex', 223 'metaRobotsFollow' => $meta->robots['follow'] ?? 'nofollow', 224 'breadcrumbTitle' => wp_gql_seo_format_string($all['bctitle-ptarchive-' . $type] ?? null), 225 'fullHead' => wp_gql_seo_get_full_head($meta), 226 ], 227 ]; 228 } 229 230 return $carry; 231 } 232 233 function wp_gql_seo_get_post_type_graphql_fields($post, array $args, AppContext $context) 234 { 235 // Base array 236 $seo = []; 237 238 $map = [ 239 '@id' => 'id', 240 '@type' => 'type', 241 '@graph' => 'graph', 242 '@context' => 'context', 243 ]; 244 if ($post instanceof Term) { 245 $meta = YoastSEO()->meta->for_term($post->term_id); 246 } else { 247 $meta = YoastSEO()->meta->for_post($post->ID); 248 } 249 250 $schemaArray = $meta !== false ? $meta->schema : []; 251 252 // https://developer.yoast.com/blog/yoast-seo-14-0-using-yoast-seo-surfaces/ 253 $robots = $meta !== false ? $meta->robots : []; 254 255 // Get data 256 $seo = [ 257 'title' => wp_gql_seo_format_string($meta !== false ? $meta->title : ''), 258 'metaDesc' => wp_gql_seo_format_string($meta !== false ? $meta->description : ''), 259 'focuskw' => wp_gql_seo_format_string(get_post_meta($post->ID, '_yoast_wpseo_focuskw', true)), 260 'metaKeywords' => wp_gql_seo_format_string(get_post_meta($post->ID, '_yoast_wpseo_metakeywords', true)), 261 'metaRobotsNoindex' => $robots['index'] ?? '', 262 'metaRobotsNofollow' => $robots['follow'] ?? '', 263 'opengraphTitle' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_title : ''), 264 'opengraphUrl' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_url : ''), 265 'opengraphSiteName' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_site_name : ''), 266 'opengraphType' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_type : ''), 267 'opengraphAuthor' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_article_author : ''), 268 'opengraphPublisher' => wp_gql_seo_format_string( 269 $meta !== false ? $meta->open_graph_article_publisher : '' 270 ), 271 'opengraphPublishedTime' => wp_gql_seo_format_string( 272 $meta !== false ? $meta->open_graph_article_published_time : '' 273 ), 274 'opengraphModifiedTime' => wp_gql_seo_format_string( 275 $meta !== false ? $meta->open_graph_article_modified_time : '' 276 ), 277 'opengraphDescription' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_description : ''), 278 'opengraphImage' => function () use ($post, $context, $meta) { 279 $id = wp_gql_seo_get_og_image($meta !== false ? $meta->open_graph_images : []); 280 281 return $context->get_loader('post')->load_deferred(absint($id)); 282 }, 283 'twitterCardType' => wp_gql_seo_format_string($meta !== false ? $meta->twitter_card : ''), 284 'twitterTitle' => wp_gql_seo_format_string($meta !== false ? $meta->twitter_title : ''), 285 'twitterDescription' => wp_gql_seo_format_string($meta !== false ? $meta->twitter_description : ''), 286 'twitterImage' => function () use ($post, $context, $meta) { 287 $twitter_image = $meta->twitter_image; 288 289 if (empty($twitter_image)) { 290 return null; 190 291 } 191 292 192 $carry[$tag] = [ 193 'title' => !empty($all['title-' . $type]) 194 ? wp_gql_seo_format_string(wp_gql_seo_replace_vars($all['title-' . $type])) 195 : null, 196 'metaDesc' => !empty($all['metadesc-' . $type]) 197 ? wp_gql_seo_format_string(wp_gql_seo_replace_vars($all['metadesc-' . $type])) 198 : null, 199 'metaRobotsNoindex' => !empty($all['noindex-' . $type]) ? boolval($all['noindex-' . $type]) : false, 200 'schemaType' => !empty($all['schema-page-type-' . $type]) 201 ? $all['schema-page-type-' . $type] 202 : null, 203 204 'schema' => [ 205 'raw' => !empty($meta->schema) ? json_encode($meta->schema, JSON_UNESCAPED_SLASHES) : null, 206 ], 207 'archive' => [ 208 'hasArchive' => boolval($post_type_object->has_archive), 209 'archiveLink' => apply_filters( 210 'wp_gql_seo_archive_link', 211 get_post_type_archive_link($type), 212 $type 213 ), 214 'title' => !empty($meta->title) ? wp_gql_seo_format_string($meta->title) : null, 215 'metaDesc' => !empty($all['metadesc-ptarchive-' . $type]) 216 ? wp_gql_seo_format_string($all['metadesc-ptarchive-' . $type]) 217 : null, 218 'metaRobotsNoindex' => 219 !empty($meta->robots['index']) && $meta->robots['index'] === 'index' ? false : true, 220 'metaRobotsNofollow' => 221 !empty($meta->robots['follow']) && $meta->robots['follow'] === 'follow' ? false : true, 222 'metaRobotsIndex' => !empty($meta->robots['index']) ? $meta->robots['index'] : 'noindex', 223 'metaRobotsFollow' => !empty($meta->robots['follow']) ? $meta->robots['follow'] : 'nofollow', 224 'breadcrumbTitle' => !empty($all['bctitle-ptarchive-' . $type]) 225 ? wp_gql_seo_format_string($all['bctitle-ptarchive-' . $type]) 226 : null, 227 'fullHead' => is_string($meta->get_head()) ? $meta->get_head() : $meta->get_head()->html, 228 ], 229 ]; 230 } 231 } 232 return $carry; 293 $id = wpcom_vip_attachment_url_to_postid($twitter_image); 294 295 return $context->get_loader('post')->load_deferred(absint($id)); 296 }, 297 'canonical' => wp_gql_seo_format_string($meta !== false ? $meta->canonical : ''), 298 'readingTime' => floatval($meta !== false ? $meta->estimated_reading_time_minutes : ''), 299 'breadcrumbs' => $meta !== false ? $meta->breadcrumbs : [], 300 // TODO: Default should be true or false? 301 'cornerstone' => boolval($meta !== false ? $meta->indexable->is_cornerstone : false), 302 'fullHead' => wp_gql_seo_get_full_head($meta), 303 'schema' => [ 304 'pageType' => $meta !== false && is_array($meta->schema_page_type) ? $meta->schema_page_type : [], 305 'articleType' => 306 $meta !== false && is_array($meta->schema_article_type) ? $meta->schema_article_type : [], 307 'raw' => json_encode($schemaArray, JSON_UNESCAPED_SLASHES), 308 ], 309 ]; 310 311 return !empty($seo) ? $seo : null; 233 312 } 234 313 … … 746 825 ]); 747 826 748 function get_post_type_graphql_fields($post, array $args, AppContext $context)749 {750 // Base array751 $seo = [];752 753 $map = [754 '@id' => 'id',755 '@type' => 'type',756 '@graph' => 'graph',757 '@context' => 'context',758 ];759 if ($post instanceof Term) {760 $meta = YoastSEO()->meta->for_term($post->term_id);761 } else {762 $meta = YoastSEO()->meta->for_post($post->ID);763 }764 765 $schemaArray = $meta !== false ? $meta->schema : [];766 767 // https://developer.yoast.com/blog/yoast-seo-14-0-using-yoast-seo-surfaces/768 $robots = $meta !== false ? $meta->robots : [];769 770 // Get data771 $seo = [772 'title' => wp_gql_seo_format_string($meta !== false ? $meta->title : ''),773 'metaDesc' => wp_gql_seo_format_string($meta !== false ? $meta->description : ''),774 'focuskw' => wp_gql_seo_format_string(get_post_meta($post->ID, '_yoast_wpseo_focuskw', true)),775 'metaKeywords' => wp_gql_seo_format_string(get_post_meta($post->ID, '_yoast_wpseo_metakeywords', true)),776 'metaRobotsNoindex' => $robots['index'] ?? '',777 'metaRobotsNofollow' => $robots['follow'] ?? '',778 'opengraphTitle' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_title : ''),779 'opengraphUrl' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_url : ''),780 'opengraphSiteName' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_site_name : ''),781 'opengraphType' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_type : ''),782 'opengraphAuthor' => wp_gql_seo_format_string($meta !== false ? $meta->open_graph_article_author : ''),783 'opengraphPublisher' => wp_gql_seo_format_string(784 $meta !== false ? $meta->open_graph_article_publisher : ''785 ),786 'opengraphPublishedTime' => wp_gql_seo_format_string(787 $meta !== false ? $meta->open_graph_article_published_time : ''788 ),789 'opengraphModifiedTime' => wp_gql_seo_format_string(790 $meta !== false ? $meta->open_graph_article_modified_time : ''791 ),792 'opengraphDescription' => wp_gql_seo_format_string(793 $meta !== false ? $meta->open_graph_description : ''794 ),795 'opengraphImage' => function () use ($post, $context, $meta) {796 $id = wp_gql_seo_get_og_image($meta !== false ? $meta->open_graph_images : []);797 798 return $context->get_loader('post')->load_deferred(absint($id));799 },800 'twitterCardType' => wp_gql_seo_format_string($meta !== false ? $meta->twitter_card : ''),801 'twitterTitle' => wp_gql_seo_format_string($meta !== false ? $meta->twitter_title : ''),802 'twitterDescription' => wp_gql_seo_format_string($meta !== false ? $meta->twitter_description : ''),803 'twitterImage' => function () use ($post, $context, $meta) {804 $twitter_image = $meta->twitter_image;805 806 if (empty($twitter_image)) {807 return null;808 }809 810 $id = wpcom_vip_attachment_url_to_postid($twitter_image);811 812 return $context->get_loader('post')->load_deferred(absint($id));813 },814 'canonical' => wp_gql_seo_format_string($meta !== false ? $meta->canonical : ''),815 'readingTime' => floatval($meta !== false ? $meta->estimated_reading_time_minutes : ''),816 'breadcrumbs' => $meta !== false ? $meta->breadcrumbs : [],817 // TODO: Default should be true or false?818 'cornerstone' => boolval($meta !== false ? $meta->indexable->is_cornerstone : false),819 'fullHead' => wp_gql_seo_get_full_head($meta),820 'schema' => [821 'pageType' => $meta !== false && is_array($meta->schema_page_type) ? $meta->schema_page_type : [],822 'articleType' =>823 $meta !== false && is_array($meta->schema_article_type) ? $meta->schema_article_type : [],824 'raw' => json_encode($schemaArray, JSON_UNESCAPED_SLASHES),825 ],826 ];827 828 return !empty($seo) ? $seo : null;829 }830 831 827 register_graphql_field('ContentNode', 'seo', [ 832 828 'type' => 'PostTypeSEO', 833 829 'description' => __('The Yoast SEO data of the ContentNode', 'wp-graphql-yoast-seo'), 834 830 'resolve' => function ($post, array $args, AppContext $context) { 835 return get_post_type_graphql_fields($post, $args, $context);831 return wp_gql_seo_get_post_type_graphql_fields($post, $args, $context); 836 832 }, 837 833 ]); … … 840 836 'description' => __('The Yoast SEO data of the ContentNode', 'wp-graphql-yoast-seo'), 841 837 'resolve' => function ($post, array $args, AppContext $context) { 842 return get_post_type_graphql_fields($post, $args, $context);838 return wp_gql_seo_get_post_type_graphql_fields($post, $args, $context); 843 839 }, 844 840 ]); … … 850 846 'description' => __('The Yoast SEO data of the ContentNode', 'wp-graphql-yoast-seo'), 851 847 'resolve' => function ($post, array $args, AppContext $context) { 852 return get_post_type_graphql_fields($post, $args, $context);848 return wp_gql_seo_get_post_type_graphql_fields($post, $args, $context); 853 849 }, 854 850 ]); … … 945 941 'region' => YoastSEO()->meta->for_author($user->userId)->region, 946 942 'breadcrumbTitle' => YoastSEO()->meta->for_author($user->userId)->breadcrumb_title, 947 'fullHead' => is_string( 948 YoastSEO() 949 ->meta->for_author($user->userId) 950 ->get_head() 951 ) 952 ? YoastSEO() 953 ->meta->for_author($user->userId) 954 ->get_head() 955 : YoastSEO() 956 ->meta->for_author($user->userId) 957 ->get_head()->html, 943 'fullHead' => wp_gql_seo_get_full_head(YoastSEO()->meta->for_author($user->userId)), 958 944 'social' => [ 959 945 'facebook' => wp_gql_seo_format_string(get_the_author_meta('facebook', $user->userId)), … … 1069 1055 'breadcrumbs' => YoastSEO()->meta->for_term($term->term_id)->breadcrumbs, 1070 1056 'cornerstone' => boolval(YoastSEO()->meta->for_term($term->term_id)->is_cornerstone), 1071 'fullHead' => is_string( 1072 YoastSEO() 1073 ->meta->for_term($term->term_id) 1074 ->get_head() 1075 ) 1076 ? YoastSEO() 1077 ->meta->for_term($term->term_id) 1078 ->get_head() 1079 : YoastSEO() 1080 ->meta->for_term($term->term_id) 1081 ->get_head()->html, 1057 'fullHead' => wp_gql_seo_get_full_head(YoastSEO()->meta->for_term($term->term_id)), 1082 1058 'schema' => [ 1083 1059 'raw' => json_encode($schemaArray, JSON_UNESCAPED_SLASHES),
Note: See TracChangeset
for help on using the changeset viewer.