https://github.com/ogulcan/filter-wp-api
A plugin that clears some WordPress Rest API fields
https://github.com/ogulcan/filter-wp-api
wordpress-plugin wp-rest-api
Last synced: about 1 year ago
JSON representation
A plugin that clears some WordPress Rest API fields
- Host: GitHub
- URL: https://github.com/ogulcan/filter-wp-api
- Owner: ogulcan
- License: gpl-3.0
- Created: 2017-09-18T08:59:43.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-21T13:16:25.000Z (over 8 years ago)
- Last Synced: 2025-03-31T04:51:20.115Z (about 1 year ago)
- Topics: wordpress-plugin, wp-rest-api
- Language: PHP
- Size: 85.9 KB
- Stars: 8
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Filter Wordpress REST API
A wordpress plugin that clears huge fields of WP Rest API.
## Overview
If you ever used WP Rest API, you should have noticed that there are lots of fields that even your client does not need. It makes no sense to load all fields for simple list or even single post view.
This plugin aims to remove redundant fields on Rest API. For now, it's only available for posts and users.
## Features
There are two endpoints: `compact` and `detailed`.
Compact is useful for listing posts/users/ and Detailed is better for single post/user view.
Here is what `compact` endpoint looks like for example posts:
```json
[
{
"id": 1178,
"title": "Markup: HTML Tags and Formatting",
"link": "http://localhost/wordpress/2013/01/11/markup-html-tags-and-formatting/",
"date": "2013-01-11T20:22:19",
"image": null
},
{
"id": 1177,
"title": "Markup: Image Alignment",
"link": "http://localhost/wordpress/2013/01/10/markup-image-alignment/",
"date": "2013-01-11T20:22:19",
"image": "http://localhost/wordpress/wp-content/uploads/2013/03/soworthloving-wallpaper.jpg"
},
{
"id": 1176,
"title": "Markup: Text Alignment",
"link": "http://localhost/wordpress/2013/01/09/markup-text-alignment/",
"date": "2013-01-11T20:22:19",
"image": null
}
]
```
Here is `detailed` endpoint:
```json
[
{
"id": 1178,
"title": "Markup: HTML Tags and Formatting",
"link": "http://localhost/wordpress/2013/01/11/markup-html-tags-and-formatting/",
"author": 2,
"image": null,
"content": "
Headings
\nHeader one
\nHeader two
\nHeader three
\nHeader four
\nHeader five
\nHeader six
\nBlockquotes
\nSingle line blockquote:
\nStay hungry. Stay foolish.
\nMulti line blockquote with a cite reference:
\nPeople think focus means saying yes to the thing you’ve got to focus on. But that’s not what it means at all. It means saying no to the hundred other good ideas that there are. You have to pick carefully. I’m actually as proud of the things we haven’t done as the things I have done. Innovation is saying no to 1,000 things.
\nSteve Jobs – Apple Worldwide Developers’ Conference, 1997
\nTables
\n\n\n\nEmployee\nSalary\n\n\n\n\n\nJohn Doe\n$1\nBecause that’s all Steve Jobs needed for a salary.\n\n\nJane Doe\n$100K\nFor all the blogging she does.\n\n\nFred Bloggs\n$100M\nPictures are worth a thousand words, right? So Jane x 1,000.\n\n\nJane Bloggs\n$100B\nWith hair like that?!",
"date": "2013-01-11T20:22:19",
"categories": [
29
]
},
{
"id": 1177,
"title": "Markup: Image Alignment",
"link": "http://localhost/wordpress/2013/01/10/markup-image-alignment/",
"author": 2,
"image": "http://localhost/wordpress/wp-content/uploads/2013/03/soworthloving-wallpaper.jpg",
"content": "Welcome to image alignment! The best way to demonstrate the ebb and flow of the various image positioning options is to nestle them snuggly among an ocean of words. Grab a paddle and let’s get started.
\nOn the topic of alignment, it should be noted that users can choose from the options of None, Left, Right, and Center. In addition, they also get the options of Thumbnail, Medium, Large & Fullsize.
\n
\nThe image above happens to be centered.
\n
The rest of this paragraph is filler for the sake of seeing the text wrap around the 150×150 image, which is left aligned.",
"date": "2013-01-10T20:15:40",
"categories": [
29
]
}
]
```
So here is `compact` endpoint looks like for example users:
```json
[
{
"id": 1,
"name": "Example User",
"image": "http://0.gravatar.com/avatar/ce98d9ae462f57b6427e3c8abad827?s=96&d=mm&r=g"
},
{
"id": 2,
"name": "Another Example User",
"image": "http://0.gravatar.com/avatar/6f673b94785fd6f49c62202aff96b5?s=96&d=mm&r=g"
}
]
```
And here is `detailed` endpoint looks like for example users:
```json
[
{
"id": 2,
"name": "Murat Karayalçın",
"desc": "",
"image": "http://0.gravatar.com/avatar/ce98d9ae4bc62f57b6427e3c8abad827?s=96&d=mm&r=g",
"link": "http://localhost/politikyol/author/mkarayalcin/"
},
{
"id": 1,
"name": "Oğulcan Orhan",
"desc": "",
"image": "http://0.gravatar.com/avatar/6f673b9475f85fd6f49c62202aff96b5?s=96&d=mm&r=g",
"link": "http://localhost/politikyol/author/root/"
}
]
```
## Installition
Plugin is ready on wordpress [plugins][https://wordpress.org/plugins/filter-wp-api/]. You can find via search on plugins. Or just download this project and upload `filter-wp-api/` directory into your `wp-content/plugins`.
After installition, just add `?_compact` or `?_detailed` as GET parameter at the end of the URL.
## Notes
* First image of featured media will be added as 'image' on detailed.
* Modified was used as default date.
* Wordpress version should be higher than 4.7
### Links
* [WP Rest API](https://developer.wordpress.org/rest-api/)
* [WordPress Plugin Boilerplate](https://github.com/DevinVinson/WordPress-Plugin-Boilerplate)
* [Awesome Readme](https://github.com/matiassingers/awesome-readme)
* [Issues](https://github.com/ogulcan/filter-wp-api/issues)
* [Changelog](https://github.com/ogulcan/filter-wp-api/blob/master/CHANGELOG.md)
#### License
All code found in this repository is licensed under GPL v3
[source]
----
Copyright (C) 2017 Ogulcan Orhan
Filter WP Api is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Filter WP Api is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
----