forked from jmfurlott/wp-api-yoast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
36 lines (33 loc) · 2.15 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
* Plugin Name: JSON REST API Yoast routes
* Description: Adds Yoast fields to page and post metadata
* Author: jmfurlott<[email protected]>
* Author URI: https://jmfurlott.com
* Version: 0.1.1
* Plugin URI: https://github.com/jmfurlott/wp-api-yoast
*/
function wp_api_encode_yoast($data, $post, $context) {
$yoastMeta = array(
'yoast_wpseo_focuskw' => get_post_meta($post['ID'], '_yoast_wpseo_focuskw', true),
'yoast_wpseo_title' => get_post_meta($post['ID'], '_yoast_wpseo_title', true),
'yoast_wpseo_metadesc' => get_post_meta($post['ID'], '_yoast_wpseo_metadesc', true),
'yoast_wpseo_linkdex' => get_post_meta($post['ID'], '_yoast_wpseo_linkdex', true),
'yoast_wpseo_metakeywords' => get_post_meta($post['ID'], '_yoast_wpseo_metakeywords', true),
'yoast_wpseo_meta-robots-noindex' => get_post_meta($post['ID'], '_yoast_wpseo_meta-robots-noindex', true),
'yoast_wpseo_meta-robots-nofollow' => get_post_meta($post['ID'], '_yoast_wpseo_meta-robots-nofollow', true),
'yoast_wpseo_meta-robots-adv' => get_post_meta($post['ID'], '_yoast_wpseo_meta-robots-adv', true),
'yoast_wpseo_canonical' => get_post_meta($post['ID'], '_yoast_wpseo_canonical', true),
'yoast_wpseo_redirect' => get_post_meta($post['ID'], '_yoast_wpseo_redirect', true),
'yoast_wpseo_opengraph-title' => get_post_meta($post['ID'], '_yoast_wpseo_opengraph-title', true),
'yoast_wpseo_opengraph-description' => get_post_meta($post['ID'], '_yoast_wpseo_opengraph-description', true),
'yoast_wpseo_opengraph-image' => get_post_meta($post['ID'], '_yoast_wpseo_opengraph-image', true),
'yoast_wpseo_twitter-title' => get_post_meta($post['ID'], '_yoast_wpseo_twitter-title', true),
'yoast_wpseo_twitter-description' => get_post_meta($post['ID'], '_yoast_wpseo_twitter-description', true),
'yoast_wpseo_twitter-image' => get_post_meta($post['ID'], '_yoast_wpseo_twitter-image', true)
);
$data['yoast_meta'] = (array) $yoastMeta;
return $data;
}
add_filter('json_prepare_post', 'wp_api_encode_yoast', 10, 3);
add_filter('json_prepare_page', 'wp_api_encode_yoast', 10, 3);