Skip to content

Commit

Permalink
Merge pull request #2 from CentralTimes/cappy-#1
Browse files Browse the repository at this point in the history
rename, add sno-gallery
  • Loading branch information
GreenCappuccino authored Oct 10, 2021
2 parents c66371a + fcda4db commit 327655d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ This plugin currently performs the following changes to the REST API:
- Registers a field, `ct_raw`, containing raw un-rendered post data, with shortcodes, to each post on `/wp/v2/posts`
- Registers a new endpoint `/centraltimes/v1/shortcodes`, which returns an array of shortcode names.
- Registers a new endpoint `/wp/v2/staff_profile` for the SNO `staff_profile` custom post type.
- Registers a new endpoint `/centraltimes/v1/ngg-gallery/(?P<id>\d+)`, to return gallery image data.
- Registers a new endpoint `/centraltimes/v1/ngg-gallery/(?P<id>\d+)`, to return NextGEN gallery image data.
- Registers a new endpoint `/centraltimes/v1/sno-gallery/(?P<ids>(\d+,*)+)`, to return SNO gallery image data
- Registers metas of `post` (endpoint `posts` in namespace `wp/v2`): `writer`, `sno_deck`, `jobtitle`, `video`,
& `videographer` to REST fields `ct_writer`, `ct_subtitle`, `ct_jobtitle`, `ct_video`, & `ct_videographer`,
respectively.
Expand All @@ -14,6 +15,10 @@ This plugin currently performs the following changes to the REST API:

# Changelog

## v0.7.0
- Project has been renamed from `wp_ct_rest_api` to `wp_centraltimes`
- Registered a new endpoint `/centraltimes/v1/sno-gallery/(?P<ids>(\d+,*)+)`, to return SNO gallery image data

## v0.6.0
- Registered a new endpoint `/centraltimes/v1/ngg-gallery/(?P<id>\d+)`, to return gallery image data
- Modified `/centraltimes/v1/shortcodes` to return an array of shortcode names instead of shortcode keys
Expand Down
37 changes: 27 additions & 10 deletions wp-ct-rest-api.php → wp-centraltimes.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
/*
Plugin Name: Central Times REST API
Plugin URI: https://github.com/CentralTimes/wp_ct_rest_api
Description: A WordPress plugin designed to modify the REST API to include data present in the Central Times SNO FLEX installation. Used by Central Times for its mobile app.
Version: 0.7.0
Author: Central Times
Author URI: https://github.com/CentralTimes
License: MIT
*/
/**
* Plugin Name: Central Times
* Plugin URI: https://github.com/CentralTimes/wp_centraltimes
* Description: A WordPress plugin designed to modify the REST API to include data present in the Central Times SNO FLEX installation. Used by Central Times for its mobile app.
* Version: 0.7.0
* Author: Central Times App Development Team
* Author URI: https://github.com/CentralTimes
* License: MIT
*/
defined('ABSPATH') or die;

add_action('rest_api_init', function () {
Expand Down Expand Up @@ -36,7 +36,7 @@
},
));

// Register list of NextGEN images for gallery
// Register list of NextGEN images for ngg gallery
register_rest_route('centraltimes/v1', '/ngg-gallery/(?P<id>\d+)', array(
'methods' => 'GET',
'callback' => function ($data) {
Expand All @@ -56,6 +56,23 @@
},
));

// Register list of media for sno gallery
register_rest_route('centraltimes/v1', '/sno-gallery/(?P<ids>(\d+,*)+)', array(
'methods' => 'GET',
'callback' => function ($data) {
$images = array();
// ids are in format id,id,id,
$ids = preg_split("/,/", $data["ids"]);

foreach ($ids as $id) {
if (is_numeric($id))
$images[] = get_post($id, ARRAY_A, "display");
}

return $images;
},
));

// Register raw data field for post
register_rest_field(
'post',
Expand Down
Binary file added wp-centraltimes.zip
Binary file not shown.

0 comments on commit 327655d

Please sign in to comment.