Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Thumbnails for post types that does'nt support and docs update #43

Merged
merged 2 commits into from

2 participants

@phh
phh commented

The hook "plugins_loaded" does'nt work with the "json_endpoints". It would be good to update the docs:
https://github.com/phh/WP-API/blob/b2471aa355a84eb180ca7ab423bd59eecf236a88/docs/guides/extending.md#registering-your-endpoints

The json file always contains "featured_image: null" even for my post types that does'nt even support thumbnails. Checking for "post_type_supports( $post['post_type'], 'thumbnail' )" before appending that data to the json file would be a good idea.

@rmccue
Owner

Thanks! :cake:

@rmccue rmccue merged commit 5b0a670 into WP-API:master
@rmccue rmccue was assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 2 deletions.
  1. +2 −2 docs/guides/extending.md
  2. +4 −0 lib/class-wp-json-media.php
View
4 docs/guides/extending.md
@@ -235,7 +235,7 @@ built-in types, your registration code should look something like this:
$myplugin_api_mytype = new MyPlugin_API_MyType();
add_filter( 'json_endpoints', array( $myplugin_api_mytype, 'registerRoutes' ) );
}
- add_action( 'plugins_loaded', 'myplugin_api_init' );
+ add_action( 'wp_json_server_before_serve', 'myplugin_api_init' );
class MyPlugin_API_MyType {
public function registerRoutes( $routes ) {
@@ -267,7 +267,7 @@ hooking and more for you:
require_once dirname( __FILE__ ) . '/class-myplugin-api-mytype.php';
$myplugin_api_mytype = new MyPlugin_API_MyType();
}
- add_action( 'plugins_loaded', 'myplugin_api_init' );
+ add_action( 'wp_json_server_before_serve', 'myplugin_api_init' );
// class-myplugin-api-mytype.php
class MyPlugin_API_MyType extends WP_JSON_CustomPostType {
View
4 lib/class-wp-json-media.php
@@ -402,6 +402,10 @@ public function attachThumbnail( $post, $data, $update ) {
* @return array Filtered post data
*/
public function addThumbnailData( $data, $post, $context ) {
+ if( !post_type_supports( $post['post_type'], 'thumbnail' ) ) {
+ return $data;
+ }
+
// Thumbnail
$data['featured_image'] = null;
$thumbnail_id = get_post_thumbnail_id( $post['ID'] );
Something went wrong with that request. Please try again.