Plugin Directory

Changeset 1335458


Ignore:
Timestamp:
01/25/2016 11:49:28 AM (10 years ago)
Author:
Braad
Message:

Version 1.1.0, now with a better_rest_api_featured_image filter

Location:
better-rest-api-featured-images
Files:
8 added
4 edited

Legend:

Unmodified
Added
Removed
  • better-rest-api-featured-images/trunk/better-rest-api-featured-images.php

    r1321789 r1335458  
    1111 * Plugin URI:          https://wordpress.org/plugins/better-rest-api-featured-images/
    1212 * Description:         Enhances the featured image data returned on the post object by the REST API to include urls for all available sizes and other useful image data.
    13  * Version:             1.0.2
     13 * Version:             1.1.0
    1414 * Author:              Braad Martin
    1515 * Author URI:          http://braadmartin.com
     
    110110    }
    111111
    112     return $featured_image;
     112    return apply_filters( 'better_rest_api_featured_image', $featured_image, $image_id );
    113113}
  • better-rest-api-featured-images/trunk/languages/better-rest-api-featured-images.pot

    r1274063 r1335458  
    1 # Copyright (C) 2015 Braad Martin
     1# Copyright (C) 2016 Braad Martin
    22# This file is distributed under the GPL-2.0+.
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Better REST API Featured Images 1.0.1\n"
     5"Project-Id-Version: Better REST API Featured Images 1.1.0\n"
    66"Report-Msgid-Bugs-To: "
    77"https://wordpress.org/support/plugin/better-rest-api-featured-images\n"
    8 "POT-Creation-Date: 2015-10-27 15:40:55+00:00\n"
     8"POT-Creation-Date: 2016-01-25 11:33:53+00:00\n"
    99"MIME-Version: 1.0\n"
    1010"Content-Type: text/plain; charset=utf-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n"
     12"PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
    1313"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    1414"Language-Team: LANGUAGE <[email protected]>\n"
  • better-rest-api-featured-images/trunk/readme.md

    r1321789 r1335458  
    55**Requires at least:** 4.0 
    66**Tested up to:** 4.4 
    7 **Stable tag:** 1.0.2 
     7**Stable tag:** 1.1.0 
    88**License:** GPLv2 or later 
    99**License URI:** http://www.gnu.org/licenses/gpl-2.0.html 
     
    9090I'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.
    9191
     92As 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:
     93
     94
     95    add_filter( 'better_rest_api_featured_image', 'xxx_modify_rest_api_featured_image', 10, 2 );
     96    /**
     97     * Modify the Better REST API Featured Image response.
     98     *
     99     * @param   array  $featured_image  The array of image data.
     100     * @param   int    $image_id        The image ID.
     101     *
     102     * @return  array                   The modified image data.
     103     */
     104    function xxx_modify_rest_api_featured_image( $featured_image, $image_id ) {
     105   
     106      // Add an extra_data_string field with a string value.
     107      $featured_image['extra_data_string'] = 'A custom value.';
     108   
     109      // Add an extra_data_array field with an array value.
     110      $featured_image['extra_data_array'] = array(
     111        'custom_key' => 'A custom value.',
     112      );
     113   
     114      return $featured_image;
     115    }
     116
     117
    92118This 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. :)
    93119
     
    120146## Changelog ##
    121147
     148### 1.1.0 ###
     149* Add a better_rest_api_featured_image filter for adding custom data to the response. Props: avishayil
     150
    122151### 1.0.2 ###
    123152* Change register_api_field to register_rest_field for compatibility with the REST API v2 beta 9. Props: Soean
     
    131160## Upgrade Notice ##
    132161
     162### 1.1.0 ###
     163* Add a better_rest_api_featured_image filter for adding custom data to the response. Props: avishayil
     164
    133165### 1.0.2 ###
    134166* Change register_api_field to register_rest_field for compatibility with the REST API v2 beta 9. Props: Soean
  • better-rest-api-featured-images/trunk/readme.txt

    r1321789 r1335458  
    55Requires at least: 4.0
    66Tested up to: 4.4
    7 Stable tag: 1.0.2
     7Stable tag: 1.1.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    9090I'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.
    9191
     92As 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:
     93
     94`
     95add_filter( 'better_rest_api_featured_image', 'xxx_modify_rest_api_featured_image', 10, 2 );
     96/**
     97 * Modify the Better REST API Featured Image response.
     98 *
     99 * @param   array  $featured_image  The array of image data.
     100 * @param   int    $image_id        The image ID.
     101 *
     102 * @return  array                   The modified image data.
     103 */
     104function xxx_modify_rest_api_featured_image( $featured_image, $image_id ) {
     105
     106  // Add an extra_data_string field with a string value.
     107  $featured_image['extra_data_string'] = 'A custom value.';
     108
     109  // Add an extra_data_array field with an array value.
     110  $featured_image['extra_data_array'] = array(
     111    'custom_key' => 'A custom value.',
     112  );
     113
     114  return $featured_image;
     115}
     116`
     117
    92118This 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. :)
    93119
     
    120146== Changelog ==
    121147
     148= 1.1.0 =
     149* Add a better_rest_api_featured_image filter for adding custom data to the response. Props: avishayil
     150
    122151= 1.0.2 =
    123152* Change register_api_field to register_rest_field for compatibility with the REST API v2 beta 9. Props: Soean
     
    131160== Upgrade Notice ==
    132161
     162= 1.1.0 =
     163* Add a better_rest_api_featured_image filter for adding custom data to the response. Props: avishayil
     164
    133165= 1.0.2 =
    134166* Change register_api_field to register_rest_field for compatibility with the REST API v2 beta 9. Props: Soean
Note: See TracChangeset for help on using the changeset viewer.