This repository was archived by the owner on Sep 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacweekly_rest_api_extensions.php
More file actions
54 lines (52 loc) · 1.74 KB
/
macweekly_rest_api_extensions.php
File metadata and controls
54 lines (52 loc) · 1.74 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/*
Plugin Name: The Mac Weekly REST API Extensions
Description: Extend the REST API for The Mac Weekly's needs.
Version: 0.0.1
Author: The Mac Weekly
Author URI: https://themacweekly.com
License: MIT
*/
use Molongui\Authorship\Includes\Author;
add_action( 'rest_api_init', function() {
register_rest_field('post', 'guest_author', array(
'get_callback' => function( $post_arr ) {
$author = new Author();
$author_id = $author->get_main_author( $post_arr['id']);
$author_data = $author->get_data($author_id->id, $author_id->type);
$author_data['img_url'] = get_the_post_thumbnail_url($author_id->id, "thumbnail");
return $author_data;
},
));
register_rest_field('post', 'excerpt_plaintext', array(
'get_callback' => function( $post_arr ) {
return get_the_excerpt($post_arr['id']);
},
));
register_rest_field('post', 'normal_thumbnail_url', array(
'get_callback' => function( $post_arr ) {
$url = get_the_post_thumbnail_url($post_arr['id'], 'thumbnail');
if ($url == false) {
return null;
} else {
return $url;
}
},
));
register_rest_field('post', 'full_thumbnail_url', array(
'get_callback' => function( $post_arr ) {
$url = get_the_post_thumbnail_url($post_arr['id'], 'large');
if ($url == false) {
return null;
} else {
return $url;
}
},
));
register_rest_field('post', 'post_meta', array(
'get_callback' => function( $post_arr ) {
return get_post_meta( $post_arr['id']);
},
));
})
?>