├── .gitignore ├── Gruntfile.js ├── package.json ├── languages └── better-rest-api-featured-images.pot ├── better-rest-api-featured-images.php ├── readme.txt └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function(grunt) { 2 | 3 | grunt.initConfig({ 4 | pkg: grunt.file.readJSON('package.json'), 5 | wp_readme_to_markdown: { 6 | your_target: { 7 | files: { 8 | 'readme.md': 'readme.txt' 9 | } 10 | } 11 | }, 12 | makepot: { 13 | target: { 14 | options: { 15 | type: 'wp-plugin' 16 | } 17 | } 18 | } 19 | }); 20 | 21 | grunt.loadNpmTasks( 'grunt-wp-readme-to-markdown' ); 22 | grunt.loadNpmTasks( 'grunt-wp-i18n' ); 23 | 24 | grunt.registerTask( 'build', [ 25 | 'wp_readme_to_markdown', 26 | 'makepot' 27 | ] ); 28 | 29 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "better-rest-api-featured-images", 3 | "version": "1.2.1", 4 | "description": "Adds a top-level field with featured image data including available sizes and URLs to the post object returned by the REST API.", 5 | "main": "Gruntfile.js", 6 | "scripts": { 7 | "test": "echo 'working'" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/BraadMartin/better-rest-api-featured-images.git" 12 | }, 13 | "author": "BraadMartin", 14 | "license": "GPL", 15 | "devDependencies": { 16 | "grunt": "~0.4.5", 17 | "grunt-wp-i18n": "^0.5.3", 18 | "grunt-wp-readme-to-markdown": "^1.0.0" 19 | } 20 | } -------------------------------------------------------------------------------- /languages/better-rest-api-featured-images.pot: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2016 Braad Martin 2 | # This file is distributed under the GPL-2.0+. 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: Better REST API Featured Images 1.2.1\n" 6 | "Report-Msgid-Bugs-To: " 7 | "https://wordpress.org/support/plugin/better-rest-api-featured-images\n" 8 | "POT-Creation-Date: 2016-07-30 16:43:34+00:00\n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=utf-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "X-Generator: grunt-wp-i18n 0.5.3\n" 16 | 17 | #. Plugin Name of the plugin/theme 18 | msgid "Better REST API Featured Images" 19 | msgstr "" 20 | 21 | #. Plugin URI of the plugin/theme 22 | msgid "https://wordpress.org/plugins/better-rest-api-featured-images/" 23 | msgstr "" 24 | 25 | #. Description of the plugin/theme 26 | msgid "" 27 | "Adds a top-level field with featured image data including available sizes " 28 | "and URLs to the post object returned by the REST API." 29 | msgstr "" 30 | 31 | #. Author of the plugin/theme 32 | msgid "Braad Martin" 33 | msgstr "" 34 | 35 | #. Author URI of the plugin/theme 36 | msgid "http://braadmartin.com" 37 | msgstr "" -------------------------------------------------------------------------------- /better-rest-api-featured-images.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * 9 | * @wordpress-plugin 10 | * Plugin Name: Better REST API Featured Images 11 | * Plugin URI: https://wordpress.org/plugins/better-rest-api-featured-images/ 12 | * Description: Adds a top-level field with featured image data including available sizes and URLs to the post object returned by the REST API. 13 | * Version: 1.2.1 14 | * Author: Braad Martin 15 | * Author URI: http://braadmartin.com 16 | * License: GPL-2.0+ 17 | * License URI: http://www.gnu.org/licenses/gpl-2.0.txt 18 | * Text Domain: better-rest-api-featured-images 19 | * Domain Path: /languages 20 | */ 21 | 22 | add_action( 'plugins_loaded', 'better_rest_api_featured_images_load_translations' ); 23 | /** 24 | * Load translation files. 25 | * 26 | * @since 1.2.0 27 | */ 28 | function better_rest_api_featured_images_load_translations() { 29 | load_plugin_textdomain( 'better-rest-api-featured-images', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' ); 30 | } 31 | 32 | add_action( 'init', 'better_rest_api_featured_images_init', 12 ); 33 | /** 34 | * Register our enhanced better_featured_image field to all public post types 35 | * that support post thumbnails. 36 | * 37 | * @since 1.0.0 38 | */ 39 | function better_rest_api_featured_images_init() { 40 | 41 | $post_types = get_post_types( array( 'public' => true ), 'objects' ); 42 | 43 | foreach ( $post_types as $post_type ) { 44 | 45 | $post_type_name = $post_type->name; 46 | $show_in_rest = ( isset( $post_type->show_in_rest ) && $post_type->show_in_rest ) ? true : false; 47 | $supports_thumbnail = post_type_supports( $post_type_name, 'thumbnail' ); 48 | 49 | // Only proceed if the post type is set to be accessible over the REST API 50 | // and supports featured images. 51 | if ( $show_in_rest && $supports_thumbnail ) { 52 | 53 | // Compatibility with the REST API v2 beta 9+ 54 | if ( function_exists( 'register_rest_field' ) ) { 55 | register_rest_field( $post_type_name, 56 | 'better_featured_image', 57 | array( 58 | 'get_callback' => 'better_rest_api_featured_images_get_field', 59 | 'schema' => null, 60 | ) 61 | ); 62 | } elseif ( function_exists( 'register_api_field' ) ) { 63 | register_api_field( $post_type_name, 64 | 'better_featured_image', 65 | array( 66 | 'get_callback' => 'better_rest_api_featured_images_get_field', 67 | 'schema' => null, 68 | ) 69 | ); 70 | } 71 | } 72 | } 73 | } 74 | 75 | /** 76 | * Return the better_featured_image field. 77 | * 78 | * @since 1.0.0 79 | * 80 | * @param object $object The response object. 81 | * @param string $field_name The name of the field to add. 82 | * @param object $request The WP_REST_Request object. 83 | * 84 | * @return object|null 85 | */ 86 | function better_rest_api_featured_images_get_field( $object, $field_name, $request ) { 87 | 88 | // Only proceed if the post has a featured image. 89 | if ( ! empty( $object['featured_media'] ) ) { 90 | $image_id = (int)$object['featured_media']; 91 | } elseif ( ! empty( $object['featured_image'] ) ) { 92 | // This was added for backwards compatibility with < WP REST API v2 Beta 11. 93 | $image_id = (int)$object['featured_image']; 94 | } else { 95 | return null; 96 | } 97 | 98 | $image = get_post( $image_id ); 99 | 100 | if ( ! $image ) { 101 | return null; 102 | } 103 | 104 | // This is taken from WP_REST_Attachments_Controller::prepare_item_for_response(). 105 | $featured_image['id'] = $image_id; 106 | $featured_image['alt_text'] = get_post_meta( $image_id, '_wp_attachment_image_alt', true ); 107 | $featured_image['caption'] = $image->post_excerpt; 108 | $featured_image['description'] = $image->post_content; 109 | $featured_image['media_type'] = wp_attachment_is_image( $image_id ) ? 'image' : 'file'; 110 | $featured_image['media_details'] = wp_get_attachment_metadata( $image_id ); 111 | $featured_image['post'] = ! empty( $image->post_parent ) ? (int) $image->post_parent : null; 112 | $featured_image['source_url'] = wp_get_attachment_url( $image_id ); 113 | 114 | if ( empty( $featured_image['media_details'] ) ) { 115 | $featured_image['media_details'] = new stdClass; 116 | } elseif ( ! empty( $featured_image['media_details']['sizes'] ) ) { 117 | $img_url_basename = wp_basename( $featured_image['source_url'] ); 118 | foreach ( $featured_image['media_details']['sizes'] as $size => &$size_data ) { 119 | $image_src = wp_get_attachment_image_src( $image_id, $size ); 120 | if ( ! $image_src ) { 121 | continue; 122 | } 123 | $size_data['source_url'] = $image_src[0]; 124 | } 125 | } elseif ( is_string( $featured_image['media_details'] ) ) { 126 | // This was added to work around conflicts with plugins that cause 127 | // wp_get_attachment_metadata() to return a string. 128 | $featured_image['media_details'] = new stdClass(); 129 | $featured_image['media_details']->sizes = new stdClass(); 130 | } else { 131 | $featured_image['media_details']['sizes'] = new stdClass; 132 | } 133 | 134 | return apply_filters( 'better_rest_api_featured_image', $featured_image, $image_id ); 135 | } 136 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Better REST API Featured Images === 2 | Contributors: Braad 3 | Donate link: http://braadmartin.com/ 4 | Tags: featured, images, post, thumbnail, rest, api, better 5 | Requires at least: 4.0 6 | Tested up to: 4.6 7 | Stable tag: 1.2.1 8 | License: GPLv2 or later 9 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 | 11 | Adds a top-level field with featured image data including available sizes and URLs to the post object returned by the REST API. 12 | 13 | == Description == 14 | 15 | **Note:** You probably do not need this plugin. The REST API already supports adding the query param `?_embed` to your URL and the response will then include all "embedded media", including the featured image, and the data you get there is exactly what this plugin gives you. The only reasons to use this plugin at this point are if you prefer to have the featured image data in a top level field in the response rather than among other embedded media in the `_embedded` field, and if you _always_ want the featured image data in the response rather than having to ask for it with `?_embed`. I still use this plugin because I do usually want both these things, but definitely give `?_embed` a try before using this plugin. :) 16 | 17 | Version 2 of the WordPress REST API returns a `featured_media` field (formerly featured_image) on the post object by default, but this field is simply the image ID. 18 | 19 | This plugin adds a `better_featured_image` field to the post object that contains the available image sizes and urls, allowing you to get this information without making a second request. 20 | 21 | It takes this: 22 | 23 | ` 24 | "featured_media": 13, 25 | ` 26 | 27 | And turns it into this: 28 | 29 | ` 30 | "featured_media": 13, 31 | "better_featured_image": { 32 | "id": 13, 33 | "alt_text": "Hot Air Balloons", 34 | "caption": "The event featured hot air balloon rides", 35 | "description": "The hot air balloons from the big event", 36 | "media_type": "image", 37 | "media_details": { 38 | "width": 5760, 39 | "height": 3840, 40 | "file": "2015/09/balloons.jpg", 41 | "sizes": { 42 | "thumbnail": { 43 | "file": "balloons-150x150.jpg", 44 | "width": 150, 45 | "height": 150, 46 | "mime-type": "image/jpeg", 47 | "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons-150x150.jpg" 48 | }, 49 | "medium": { 50 | "file": "balloons-300x200.jpg", 51 | "width": 300, 52 | "height": 200, 53 | "mime-type": "image/jpeg", 54 | "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons-300x200.jpg" 55 | }, 56 | "large": { 57 | "file": "balloons-1024x683.jpg", 58 | "width": 1024, 59 | "height": 683, 60 | "mime-type": "image/jpeg", 61 | "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons-1024x683.jpg" 62 | }, 63 | "post-thumbnail": { 64 | "file": "balloons-825x510.jpg", 65 | "width": 825, 66 | "height": 510, 67 | "mime-type": "image/jpeg", 68 | "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons-825x510.jpg" 69 | } 70 | }, 71 | "image_meta": { 72 | "aperture": 6.3, 73 | "credit": "", 74 | "camera": "Canon EOS 5D Mark III", 75 | "caption": "", 76 | "created_timestamp": 1433110262, 77 | "copyright": "", 78 | "focal_length": "50", 79 | "iso": "100", 80 | "shutter_speed": "0.004", 81 | "title": "", 82 | "orientation": 1 83 | } 84 | }, 85 | "post": null, 86 | "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons.jpg" 87 | }, 88 | ` 89 | 90 | The format of the response is nearly identical to what you would get sending a request to `/wp-json/wp/v2/media/13` or using `?_embed`. When no featured image has been set on the post the `better_featured_image` field will have a value of `null`. 91 | 92 | I've done some basic performance tests that indicate the difference in response times with and without this plugin to be about 10-15ms for a collection of 10 posts and 0-5ms for a single post. For me this is much faster than making a second request to `/media/`, especially for multiple posts. 93 | 94 | As of version 1.1.0, there is a filter `better_rest_api_featured_image` that allows you to add custom data to the better_featured_image field. The filter is directly on the return value of the function that returns the better_featured_image field. This can be used to do things like add custom image meta or an SVG version of the image to the response. Here's an example of how you might use it: 95 | 96 | ` 97 | add_filter( 'better_rest_api_featured_image', 'xxx_modify_rest_api_featured_image', 10, 2 ); 98 | /** 99 | * Modify the Better REST API Featured Image response. 100 | * 101 | * @param array $featured_image The array of image data. 102 | * @param int $image_id The image ID. 103 | * 104 | * @return array The modified image data. 105 | */ 106 | function xxx_modify_rest_api_featured_image( $featured_image, $image_id ) { 107 | 108 | // Add an extra_data_string field with a string value. 109 | $featured_image['extra_data_string'] = 'A custom value.'; 110 | 111 | // Add an extra_data_array field with an array value. 112 | $featured_image['extra_data_array'] = array( 113 | 'custom_key' => 'A custom value.', 114 | ); 115 | 116 | return $featured_image; 117 | } 118 | ` 119 | 120 | This plugin is on [on Github](https://github.com/BraadMartin/better-rest-api-featured-images "Better REST API Featured Images") and pull requests are always welcome. :) 121 | 122 | == Installation == 123 | 124 | = Manual Installation = 125 | 126 | 1. Upload the entire `/better-rest-api-featured-images` directory to the `/wp-content/plugins/` directory. 127 | 1. Activate 'Better REST API Featured Images' through the 'Plugins' menu in WordPress. 128 | 129 | = Better Installation = 130 | 131 | 1. Go to Plugins > Add New in your WordPress admin and search for 'Better REST API Featured Images'. 132 | 1. Click Install. 133 | 134 | == Frequently Asked Questions == 135 | 136 | = How does it work? = 137 | 138 | The WP REST API includes a filter on the response data it returns, and this plugin uses that filter to add a new field `better_featured_image` with the extra data for the featured image. 139 | 140 | = When does the plugin load? = 141 | 142 | The plugin loads on `init` at priority 12, in order to come after any custom post types have been registered. 143 | 144 | = Why doesn't the plugin replace the default `featured_media` field? = 145 | 146 | The `featured_media` field is a core field, and other applications might expect it to always be an integer value. To avoid any issues, this plugin includes the extra data under the `better_featured_image` field name. 147 | 148 | = Why is the core field called `featured_media` but the plugin field is `better_featured_image`? = 149 | 150 | Prior to V2 Beta 11 of the REST API the core field was called `featured_image`. As of Beta 11 this field was changed to `featured_media`, with the idea that at some point in the future there may be additional media items included on this field beyond the featured image. Version 1.1.1 of this plugin is compatible with both Beta 11 and all previous versions of V2. 151 | 152 | == Changelog == 153 | 154 | = 1.2.1 = 155 | * Add fix for bug caused by conflicts with plugins that manipulate image metadata 156 | 157 | = 1.2.0 = 158 | * Fix translation files present but not loading 159 | * Add note to the readme explaining that `?_embed` should be tried before using this plugin 160 | * Fix compat with older betas 161 | * Add missing PHPDoc statements 162 | * Tested with v2 beta 12 163 | 164 | = 1.1.1 = 165 | * Compatibility with v2 beta 11 of the REST API (now the core field is called featured_media; this plugin's field is still better_featured_image). Props: filose 166 | 167 | = 1.1.0 = 168 | * Add a better_rest_api_featured_image filter for adding custom data to the response. Props: avishayil 169 | 170 | = 1.0.2 = 171 | * Change register_api_field to register_rest_field for compatibility with the REST API v2 beta 9. Props: Soean 172 | 173 | = 1.0.1 = 174 | * Switch to returning null instead of 0 when no featured image is present 175 | 176 | = 1.0.0 = 177 | * First Release 178 | 179 | == Upgrade Notice == 180 | 181 | = 1.2.1 = 182 | * Add fix for bug caused by conflicts with plugins that manipulate image metadata 183 | 184 | = 1.2.0 = 185 | * Fix translation files present but not loading 186 | * Add note to the readme explaining that `?_embed` should be tried before using this plugin 187 | * Fix compat with older betas 188 | * Add missing PHPDoc statements 189 | * Tested with v2 beta 12 190 | 191 | = 1.1.1 = 192 | * Compatibility with v2 beta 11 of the REST API (now the core field is called featured_media; this plugin's field is still better_featured_image). Props: filose 193 | 194 | = 1.1.0 = 195 | * Add a better_rest_api_featured_image filter for adding custom data to the response. Props: avishayil 196 | 197 | = 1.0.2 = 198 | * Change register_api_field to register_rest_field for compatibility with the REST API v2 beta 9. Props: Soean 199 | 200 | = 1.0.1 = 201 | * Switch to returning null instead of 0 when no featured image is present 202 | 203 | = 1.0.0 = 204 | * First Release 205 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Better REST API Featured Images # 2 | **Contributors:** Braad 3 | **Donate link:** http://braadmartin.com/ 4 | **Tags:** featured, images, post, thumbnail, rest, api, better 5 | **Requires at least:** 4.0 6 | **Tested up to:** 4.6 7 | **Stable tag:** 1.2.1 8 | **License:** GPLv2 or later 9 | **License URI:** http://www.gnu.org/licenses/gpl-2.0.html 10 | 11 | Adds a top-level field with featured image data including available sizes and URLs to the post object returned by the REST API. 12 | 13 | ## Description ## 14 | 15 | **Note:** You probably do not need this plugin. The REST API already supports adding the query param `?_embed` to your URL and the response will then include all "embedded media", including the featured image, and the data you get there is exactly what this plugin gives you. The only reasons to use this plugin at this point are if you prefer to have the featured image data in a top level field in the response rather than among other embedded media in the `_embedded` field, and if you _always_ want the featured image data in the response rather than having to ask for it with `?_embed`. I still use this plugin because I do usually want both these things, but definitely give `?_embed` a try before using this plugin. :) 16 | 17 | Version 2 of the WordPress REST API returns a `featured_media` field (formerly featured_image) on the post object by default, but this field is simply the image ID. 18 | 19 | This plugin adds a `better_featured_image` field to the post object that contains the available image sizes and urls, allowing you to get this information without making a second request. 20 | 21 | It takes this: 22 | 23 | 24 | "featured_media": 13, 25 | 26 | 27 | And turns it into this: 28 | 29 | 30 | "featured_media": 13, 31 | "better_featured_image": { 32 | "id": 13, 33 | "alt_text": "Hot Air Balloons", 34 | "caption": "The event featured hot air balloon rides", 35 | "description": "The hot air balloons from the big event", 36 | "media_type": "image", 37 | "media_details": { 38 | "width": 5760, 39 | "height": 3840, 40 | "file": "2015/09/balloons.jpg", 41 | "sizes": { 42 | "thumbnail": { 43 | "file": "balloons-150x150.jpg", 44 | "width": 150, 45 | "height": 150, 46 | "mime-type": "image/jpeg", 47 | "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons-150x150.jpg" 48 | }, 49 | "medium": { 50 | "file": "balloons-300x200.jpg", 51 | "width": 300, 52 | "height": 200, 53 | "mime-type": "image/jpeg", 54 | "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons-300x200.jpg" 55 | }, 56 | "large": { 57 | "file": "balloons-1024x683.jpg", 58 | "width": 1024, 59 | "height": 683, 60 | "mime-type": "image/jpeg", 61 | "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons-1024x683.jpg" 62 | }, 63 | "post-thumbnail": { 64 | "file": "balloons-825x510.jpg", 65 | "width": 825, 66 | "height": 510, 67 | "mime-type": "image/jpeg", 68 | "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons-825x510.jpg" 69 | } 70 | }, 71 | "image_meta": { 72 | "aperture": 6.3, 73 | "credit": "", 74 | "camera": "Canon EOS 5D Mark III", 75 | "caption": "", 76 | "created_timestamp": 1433110262, 77 | "copyright": "", 78 | "focal_length": "50", 79 | "iso": "100", 80 | "shutter_speed": "0.004", 81 | "title": "", 82 | "orientation": 1 83 | } 84 | }, 85 | "post": null, 86 | "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons.jpg" 87 | }, 88 | 89 | 90 | The format of the response is nearly identical to what you would get sending a request to `/wp-json/wp/v2/media/13` or using `?_embed`. When no featured image has been set on the post the `better_featured_image` field will have a value of `null`. 91 | 92 | I've done some basic performance tests that indicate the difference in response times with and without this plugin to be about 10-15ms for a collection of 10 posts and 0-5ms for a single post. For me this is much faster than making a second request to `/media/`, especially for multiple posts. 93 | 94 | As of version 1.1.0, there is a filter `better_rest_api_featured_image` that allows you to add custom data to the better_featured_image field. The filter is directly on the return value of the function that returns the better_featured_image field. This can be used to do things like add custom image meta or an SVG version of the image to the response. Here's an example of how you might use it: 95 | 96 | 97 | add_filter( 'better_rest_api_featured_image', 'xxx_modify_rest_api_featured_image', 10, 2 ); 98 | /** 99 | * Modify the Better REST API Featured Image response. 100 | * 101 | * @param array $featured_image The array of image data. 102 | * @param int $image_id The image ID. 103 | * 104 | * @return array The modified image data. 105 | */ 106 | function xxx_modify_rest_api_featured_image( $featured_image, $image_id ) { 107 | 108 | // Add an extra_data_string field with a string value. 109 | $featured_image['extra_data_string'] = 'A custom value.'; 110 | 111 | // Add an extra_data_array field with an array value. 112 | $featured_image['extra_data_array'] = array( 113 | 'custom_key' => 'A custom value.', 114 | ); 115 | 116 | return $featured_image; 117 | } 118 | 119 | 120 | This plugin is on [on Github](https://github.com/BraadMartin/better-rest-api-featured-images "Better REST API Featured Images") and pull requests are always welcome. :) 121 | 122 | ## Installation ## 123 | 124 | ### Manual Installation ### 125 | 126 | 1. Upload the entire `/better-rest-api-featured-images` directory to the `/wp-content/plugins/` directory. 127 | 1. Activate 'Better REST API Featured Images' through the 'Plugins' menu in WordPress. 128 | 129 | ### Better Installation ### 130 | 131 | 1. Go to Plugins > Add New in your WordPress admin and search for 'Better REST API Featured Images'. 132 | 1. Click Install. 133 | 134 | ## Frequently Asked Questions ## 135 | 136 | ### How does it work? ### 137 | 138 | The WP REST API includes a filter on the response data it returns, and this plugin uses that filter to add a new field `better_featured_image` with the extra data for the featured image. 139 | 140 | ### When does the plugin load? ### 141 | 142 | The plugin loads on `init` at priority 12, in order to come after any custom post types have been registered. 143 | 144 | ### Why doesn't the plugin replace the default `featured_media` field? ### 145 | 146 | The `featured_media` field is a core field, and other applications might expect it to always be an integer value. To avoid any issues, this plugin includes the extra data under the `better_featured_image` field name. 147 | 148 | ### Why is the core field called `featured_media` but the plugin field is `better_featured_image`? ### 149 | 150 | Prior to V2 Beta 11 of the REST API the core field was called `featured_image`. As of Beta 11 this field was changed to `featured_media`, with the idea that at some point in the future there may be additional media items included on this field beyond the featured image. Version 1.1.1 of this plugin is compatible with both Beta 11 and all previous versions of V2. 151 | 152 | ## Changelog ## 153 | 154 | ### 1.2.1 ### 155 | * Add fix for bug caused by conflicts with plugins that manipulate image metadata 156 | 157 | ### 1.2.0 ### 158 | * Fix translation files present but not loading 159 | * Add note to the readme explaining that `?_embed` should be tried before using this plugin 160 | * Fix compat with older betas 161 | * Add missing PHPDoc statements 162 | * Tested with v2 beta 12 163 | 164 | ### 1.1.1 ### 165 | * Compatibility with v2 beta 11 of the REST API (now the core field is called featured_media; this plugin's field is still better_featured_image). Props: filose 166 | 167 | ### 1.1.0 ### 168 | * Add a better_rest_api_featured_image filter for adding custom data to the response. Props: avishayil 169 | 170 | ### 1.0.2 ### 171 | * Change register_api_field to register_rest_field for compatibility with the REST API v2 beta 9. Props: Soean 172 | 173 | ### 1.0.1 ### 174 | * Switch to returning null instead of 0 when no featured image is present 175 | 176 | ### 1.0.0 ### 177 | * First Release 178 | 179 | ## Upgrade Notice ## 180 | 181 | ### 1.2.1 ### 182 | * Add fix for bug caused by conflicts with plugins that manipulate image metadata 183 | 184 | ### 1.2.0 ### 185 | * Fix translation files present but not loading 186 | * Add note to the readme explaining that `?_embed` should be tried before using this plugin 187 | * Fix compat with older betas 188 | * Add missing PHPDoc statements 189 | * Tested with v2 beta 12 190 | 191 | ### 1.1.1 ### 192 | * Compatibility with v2 beta 11 of the REST API (now the core field is called featured_media; this plugin's field is still better_featured_image). Props: filose 193 | 194 | ### 1.1.0 ### 195 | * Add a better_rest_api_featured_image filter for adding custom data to the response. Props: avishayil 196 | 197 | ### 1.0.2 ### 198 | * Change register_api_field to register_rest_field for compatibility with the REST API v2 beta 9. Props: Soean 199 | 200 | ### 1.0.1 ### 201 | * Switch to returning null instead of 0 when no featured image is present 202 | 203 | ### 1.0.0 ### 204 | * First Release 205 | --------------------------------------------------------------------------------