Plugin Directory

Changeset 1817679


Ignore:
Timestamp:
02/07/2018 09:55:53 PM (8 years ago)
Author:
factor1
Message:

Add ACF and Media endpoint queries

Location:
better-rest-endpoints/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • better-rest-endpoints/trunk/CHANGELOG.md

    r1809677 r1817679  
    88n/a
    99
     10## [1.2.0] - 2018-02-07
     11### Added
     12- ACF query in endpoint url to hide acf values from the response where applicable (all collections)
     13- Media query in endpoint url to hide featured media from the response where applicable (all collections)
     14
    1015## [1.1.2] - 2018-01-25
    1116### Update
    1217- Fix issue where get post by slug was returning just the first post
    13 - Fix instance of lefover $bwe variable naming 
     18- Fix instance of lefover $bwe variable naming
    1419
    1520## [1.1.1] - 2018-01-25
  • better-rest-endpoints/trunk/README.md

    r1809642 r1817679  
    1818- exclude (int) a post ID to exclude from the response
    1919- author (string) limit posts by author nice name (user_nicename)
     20- acf (boolean - setting to false omits `acf` from being returned)
     21- media (boolean - setting to false omits `media` (featured media) from being returned)
    2022
    2123It returns a JSON response with the following:
     
    9395- content (boolean - setting to false hides the content from the response)
    9496- exclude (int) a post ID to exclude from the response
     97- acf (boolean - setting to false omits `acf` from being returned)
     98- media (boolean - setting to false omits `media` (featured media) from being returned)
    9599
    96100Returns the following JSON Response:
     
    131135- orderby (string) - see the [codex](https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters) for options, currently does not support multiple values
    132136- exclude (int) a post ID to exclude from the response
     137- acf (boolean - setting to false omits `acf` from being returned)
     138- media (boolean - setting to false omits `media` (featured media) from being returned)
    133139
    134140Returns the following JSON response:
     
    192198- orderby (string) - see the [codex](https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters) for options, currently does not support multiple values
    193199- exclude (int) a post ID to exclude from the response
     200- acf (boolean - setting to false omits `acf` from being returned)
     201- media (boolean - setting to false omits `media` (featured media) from being returned)
    194202
    195203Returns the following JSON Response:
     
    243251- content (boolean) set to false to omit content from showing in JSON response
    244252- search (string | required)
     253- acf (boolean - setting to false omits `acf` from being returned)
     254- media (boolean - setting to false omits `media` (featured media) from being returned)
    245255
    246256It returns a JSON response with the following (returns an empty array if no posts found):
  • better-rest-endpoints/trunk/better-wp-endpoints.php

    r1809677 r1817679  
    44Plugin URI:   https://github.com/factor1/better-rest-endpoints/
    55Description:  Serves up slimmer WordPress Rest API endpoints, with some great enhancements.
    6 Version:      1.1.2
     6Version:      1.2.0
    77Author:       Eric Stout, Factor1 Studios
    88Author URI:   https://factor1studios.com/
  • better-rest-endpoints/trunk/includes/create_cpt_endpoints.php

    r1806011 r1817679  
    2929            $content = $request['content'];
    3030            $show_content = filter_var($content, FILTER_VALIDATE_BOOLEAN);
     31            $acf = $request['acf'];
     32            $show_acf = filter_var($acf, FILTER_VALIDATE_BOOLEAN);
     33            $media = $request['media'];
     34            $show_media = filter_var($media, FILTER_VALIDATE_BOOLEAN);
    3135            $orderby = $request['orderby']?: null;
    3236            $order = $request['order']?: null;
     
    9599                /*
    96100                 *
    97                  * return acf fields if they exist
     101                 * return acf fields if they exist and depending on query string
    98102                 *
    99103                 */
    100                 $bre_post->acf = bre_get_acf();
     104                if( $acf === null || $show_acf === true ) {
     105                  $bre_post->acf = bre_get_acf();
     106                }
    101107
    102108                /*
    103109                 *
    104                  * get possible thumbnail sizes and urls
     110                 * get possible thumbnail sizes and urls if query set to true or by default
    105111                 *
    106112                 */
    107                 $thumbnail_names = get_intermediate_image_sizes();
    108                 $bre_thumbnails = new stdClass();
    109 
    110                 if( has_post_thumbnail() ){
    111                   foreach ($thumbnail_names as $key => $name) {
    112                     $bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
     113
     114                if( $media === null || $show_media === true ) {
     115                  $thumbnail_names = get_intermediate_image_sizes();
     116                  $bre_thumbnails = new stdClass();
     117
     118                  if( has_post_thumbnail() ){
     119                    foreach ($thumbnail_names as $key => $name) {
     120                      $bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
     121                    }
     122
     123                    $bre_post->media = $bre_thumbnails;
     124                  } else {
     125                    $bre_post->media = false;
    113126                  }
    114 
    115                   $bre_post->media = $bre_thumbnails;
    116                 } else {
    117                   $bre_post->media = false;
    118127                }
    119128
     
    168177               }
    169178            ),
     179            'acf' =>  array(
     180              'description'       => 'Hide or show acf fields from the collection.',
     181              'type'              => 'boolean',
     182              'validate_callback' => function( $param, $request, $key ) {
     183
     184                if ( $param == 'true' || $param == 'TRUE' ) {
     185                  $param = true;
     186                } else if( $param == 'false' || $param == 'FALSE') {
     187                  $param = false;
     188                }
     189
     190                return is_bool( $param );
     191               }
     192            ),
    170193            'order' =>  array(
    171194              'description'       => 'Change order of the collection.',
  • better-rest-endpoints/trunk/includes/get_pages.php

    r1806011 r1817679  
    1717  $content = $request['content'];
    1818  $show_content = filter_var($content, FILTER_VALIDATE_BOOLEAN);
     19  $acf = $request['acf'];
     20  $show_acf = filter_var($acf, FILTER_VALIDATE_BOOLEAN);
     21  $media = $request['media'];
     22  $show_media = filter_var($media, FILTER_VALIDATE_BOOLEAN);
    1923  $orderby = $request['orderby']?: null;
    2024  $order = $request['order']?: null;
     
    99103       *
    100104       */
    101       $bre_page->acf = bre_get_acf();
    102 
    103       /*
    104        *
    105        * get possible thumbnail sizes and urls
    106        *
    107        */
    108       $thumbnail_names = get_intermediate_image_sizes();
    109       $bre_thumbnails = new stdClass();
    110 
    111       if( has_post_thumbnail() ){
    112         foreach ($thumbnail_names as $key => $name) {
    113           $bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
    114         }
    115 
    116         $bre_page->media = $bre_thumbnails;
    117       } else {
    118         $bre_page->media = false;
    119       }
     105       if( $acf === null || $show_acf === true ) {
     106         $bre_page->acf = bre_get_acf();
     107       }
     108
     109       /*
     110        *
     111        * get possible thumbnail sizes and urls if query set to true or by default
     112        *
     113        */
     114
     115       if( $media === null || $show_media === true ) {
     116         $thumbnail_names = get_intermediate_image_sizes();
     117         $bre_thumbnails = new stdClass();
     118
     119         if( has_post_thumbnail() ){
     120           foreach ($thumbnail_names as $key => $name) {
     121             $bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
     122           }
     123
     124           $bre_page->media = $bre_thumbnails;
     125         } else {
     126           $bre_page->media = false;
     127         }
     128       }
    120129
    121130      // Push the post to the main $post array
     
    206215          }
    207216       ),
     217       'acf' =>  array(
     218         'description'       => 'Hide or show acf fields from the collection.',
     219         'type'              => 'boolean',
     220         'validate_callback' => function( $param, $request, $key ) {
     221
     222           if ( $param == 'true' || $param == 'TRUE' ) {
     223             $param = true;
     224           } else if( $param == 'false' || $param == 'FALSE') {
     225             $param = false;
     226           }
     227
     228           return is_bool( $param );
     229          }
     230       ),
     231       'media' =>  array(
     232         'description'       => 'Hide or show featured media from the collection.',
     233         'type'              => 'boolean',
     234         'validate_callback' => function( $param, $request, $key ) {
     235
     236           if ( $param == 'true' || $param == 'TRUE' ) {
     237             $param = true;
     238           } else if( $param == 'false' || $param == 'FALSE') {
     239             $param = false;
     240           }
     241
     242           return is_bool( $param );
     243          }
     244       ),
    208245     ),
    209246   ) );
  • better-rest-endpoints/trunk/includes/get_posts.php

    r1806011 r1817679  
    1919  $content = $request['content'];
    2020  $show_content = filter_var($content, FILTER_VALIDATE_BOOLEAN);
     21  $acf = $request['acf'];
     22  $show_acf = filter_var($acf, FILTER_VALIDATE_BOOLEAN);
     23  $media = $request['media'];
     24  $show_media = filter_var($media, FILTER_VALIDATE_BOOLEAN);
    2125  $orderby = $request['orderby']?: null;
    2226  $order = $request['order']?: null;
     
    115119      /*
    116120       *
    117        * return acf fields if they exist
    118        *
    119        */
    120       $bre_post->acf = bre_get_acf();
    121 
    122       /*
    123        *
    124        * get possible thumbnail sizes and urls
    125        *
    126        */
    127       $thumbnail_names = get_intermediate_image_sizes();
    128       $bre_thumbnails = new stdClass();
    129 
    130       if( has_post_thumbnail() ){
    131         foreach ($thumbnail_names as $key => $name) {
    132           $bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
     121       * return acf fields if they exist and depending on query string
     122       *
     123       */
     124      if( $acf === null || $show_acf === true ) {
     125        $bre_post->acf = bre_get_acf();
     126      }
     127
     128      /*
     129       *
     130       * get possible thumbnail sizes and urls if query set to true or by default
     131       *
     132       */
     133
     134      if( $media === null || $show_media === true ) {
     135        $thumbnail_names = get_intermediate_image_sizes();
     136        $bre_thumbnails = new stdClass();
     137
     138        if( has_post_thumbnail() ){
     139          foreach ($thumbnail_names as $key => $name) {
     140            $bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
     141          }
     142
     143          $bre_post->media = $bre_thumbnails;
     144        } else {
     145          $bre_post->media = false;
    133146        }
    134 
    135         $bre_post->media = $bre_thumbnails;
    136       } else {
    137         $bre_post->media = false;
    138147      }
    139148
     
    223232         }
    224233      ),
     234      'acf' =>  array(
     235        'description'       => 'Hide or show acf fields from the collection.',
     236        'type'              => 'boolean',
     237        'validate_callback' => function( $param, $request, $key ) {
     238
     239          if ( $param == 'true' || $param == 'TRUE' ) {
     240            $param = true;
     241          } else if( $param == 'false' || $param == 'FALSE') {
     242            $param = false;
     243          }
     244
     245          return is_bool( $param );
     246         }
     247      ),
     248      'media' =>  array(
     249        'description'       => 'Hide or show featured media from the collection.',
     250        'type'              => 'boolean',
     251        'validate_callback' => function( $param, $request, $key ) {
     252
     253          if ( $param == 'true' || $param == 'TRUE' ) {
     254            $param = true;
     255          } else if( $param == 'false' || $param == 'FALSE') {
     256            $param = false;
     257          }
     258
     259          return is_bool( $param );
     260         }
     261      ),
    225262      'order' =>  array(
    226263        'description'       => 'Change order of the collection.',
  • better-rest-endpoints/trunk/includes/get_posts_tax.php

    r1806011 r1817679  
    3636            $content = $request['content'];
    3737            $show_content = filter_var($content, FILTER_VALIDATE_BOOLEAN);
     38            $acf = $request['acf'];
     39            $show_acf = filter_var($acf, FILTER_VALIDATE_BOOLEAN);
     40            $media = $request['media'];
     41            $show_media = filter_var($media, FILTER_VALIDATE_BOOLEAN);
    3842            $orderby = $request['orderby']?: null;
    3943            $order = $request['order']?: null;
     
    108112                   *
    109113                   */
    110                   $bre_tax_post->acf = bre_get_acf();
    111 
    112                   /*
    113                    *
    114                    * get possible thumbnail sizes and urls
    115                    *
    116                    */
    117                   $thumbnail_names = get_intermediate_image_sizes();
    118                   $bre_thumbnails = new stdClass();
    119 
    120                   if( has_post_thumbnail() ){
    121                     foreach ($thumbnail_names as $key => $name) {
    122                       $bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
    123                     }
    124 
    125                     $bre_tax_post->media = $bre_thumbnails;
    126                   } else {
    127                     $bre_tax_post->media = false;
    128                   }
     114                   if( $acf === null || $show_acf === true ) {
     115                     $bre_tax_post->acf = bre_get_acf();
     116                   }
     117
     118                   /*
     119                    *
     120                    * get possible thumbnail sizes and urls if query set to true or by default
     121                    *
     122                    */
     123
     124                   if( $media === null || $show_media === true ) {
     125                     $thumbnail_names = get_intermediate_image_sizes();
     126                     $bre_thumbnails = new stdClass();
     127
     128                     if( has_post_thumbnail() ){
     129                       foreach ($thumbnail_names as $key => $name) {
     130                         $bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
     131                       }
     132
     133                       $bre_tax_post->media = $bre_thumbnails;
     134                     } else {
     135                       $bre_tax_post->media = false;
     136                     }
     137                   }
    129138
    130139                  // push the post to the main array
     
    167176              'content' =>  array(
    168177                'description'       => 'Hide or show the_content from the collection.',
     178                'type'              => 'boolean',
     179                'validate_callback' => function( $param, $request, $key ) {
     180
     181                  if ( $param == 'true' || $param == 'TRUE' ) {
     182                    $param = true;
     183                  } else if( $param == 'false' || $param == 'FALSE') {
     184                    $param = false;
     185                  }
     186
     187                  return is_bool( $param );
     188                 }
     189              ),
     190              'acf' =>  array(
     191                'description'       => 'Hide or show acf fields from the collection.',
     192                'type'              => 'boolean',
     193                'validate_callback' => function( $param, $request, $key ) {
     194
     195                  if ( $param == 'true' || $param == 'TRUE' ) {
     196                    $param = true;
     197                  } else if( $param == 'false' || $param == 'FALSE') {
     198                    $param = false;
     199                  }
     200
     201                  return is_bool( $param );
     202                 }
     203              ),
     204              'media' =>  array(
     205                'description'       => 'Hide or show featured media from the collection.',
    169206                'type'              => 'boolean',
    170207                'validate_callback' => function( $param, $request, $key ) {
  • better-rest-endpoints/trunk/includes/get_search.php

    r1806011 r1817679  
    1818  $content = $request['content'];
    1919  $show_content = filter_var($content, FILTER_VALIDATE_BOOLEAN);
     20  $acf = $request['acf'];
     21  $show_acf = filter_var($acf, FILTER_VALIDATE_BOOLEAN);
     22  $media = $request['media'];
     23  $show_media = filter_var($media, FILTER_VALIDATE_BOOLEAN);
    2024  $search = $request['search']?: null;
    2125
     
    107111      /*
    108112       *
    109        * return acf fields if they exist
    110        *
    111        */
    112       $bre_post->acf = bre_get_acf();
    113 
    114       /*
    115        *
    116        * get possible thumbnail sizes and urls
    117        *
    118        */
    119       $thumbnail_names = get_intermediate_image_sizes();
    120       $bre_thumbnails = new stdClass();
    121 
    122       if( has_post_thumbnail() ){
    123         foreach ($thumbnail_names as $key => $name) {
    124           $bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
     113       * return acf fields if they exist and depending on query string
     114       *
     115       */
     116      if( $acf === null || $show_acf === true ) {
     117        $bre_post->acf = bre_get_acf();
     118      }
     119
     120      /*
     121       *
     122       * get possible thumbnail sizes and urls if query set to true or by default
     123       *
     124       */
     125
     126      if( $media === null || $show_media === true ) {
     127        $thumbnail_names = get_intermediate_image_sizes();
     128        $bre_thumbnails = new stdClass();
     129
     130        if( has_post_thumbnail() ){
     131          foreach ($thumbnail_names as $key => $name) {
     132            $bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
     133          }
     134
     135          $bre_post->media = $bre_thumbnails;
     136        } else {
     137          $bre_post->media = false;
    125138        }
    126 
    127         $bre_post->media = $bre_thumbnails;
    128       } else {
    129         $bre_post->media = false;
    130139      }
    131140
     
    205214         }
    206215      ),
     216      'acf' =>  array(
     217        'description'       => 'Hide or show acf fields from the collection.',
     218        'type'              => 'boolean',
     219        'validate_callback' => function( $param, $request, $key ) {
     220
     221          if ( $param == 'true' || $param == 'TRUE' ) {
     222            $param = true;
     223          } else if( $param == 'false' || $param == 'FALSE') {
     224            $param = false;
     225          }
     226
     227          return is_bool( $param );
     228         }
     229      ),
     230      'media' =>  array(
     231        'description'       => 'Hide or show featured media from the collection.',
     232        'type'              => 'boolean',
     233        'validate_callback' => function( $param, $request, $key ) {
     234
     235          if ( $param == 'true' || $param == 'TRUE' ) {
     236            $param = true;
     237          } else if( $param == 'false' || $param == 'FALSE') {
     238            $param = false;
     239          }
     240
     241          return is_bool( $param );
     242         }
     243      ),
    207244      'search' =>  array(
    208245        'description'       => 'The search term used to fetch the collection.',
  • better-rest-endpoints/trunk/package-lock.json

    r1809677 r1817679  
    11{
    22  "name": "better-rest-endpoints",
    3   "version": "1.1.2",
     3  "version": "1.2.0",
    44  "lockfileVersion": 1,
    55  "requires": true,
  • better-rest-endpoints/trunk/package.json

    r1809677 r1817679  
    11{
    22  "name": "better-rest-endpoints",
    3   "version": "1.1.2",
     3  "version": "1.2.0",
    44  "description": "Serves up slimmer WordPress Rest API endpoints.",
    55  "main": "index.js",
  • better-rest-endpoints/trunk/readme.txt

    r1809677 r1817679  
    66Tags: rest, api, endpoints, acf, json
    77Requires at least: 4.7.1
    8 Tested up to: 4.9.2
    9 Stable Tag: 1.1.2
     8Tested up to: 4.9.4
     9Stable Tag: 1.2.0
    1010License: GNU Version 3 or Any Later Version
    1111
     
    4343== Changelog ==
    4444
     45= 1.2.0, Febuary 7, 2018 =
     46* Add: ACF query in endpoint url to hide acf values from the response where applicable (all collections)
     47* Add: Media query in endpoint url to hide featured media from the response where applicable (all collections)
     48
    4549= 1.1.2, January 25, 2018 =
    4650* Fix: issue where get post by slug was returning just the first post
    47 * Fix: instance of lefover $bwe variable naming 
     51* Fix: instance of lefover $bwe variable naming
    4852
    4953= 1.1.1, January 25, 2018 =
Note: See TracChangeset for help on using the changeset viewer.