Skip to content

Commit 325db10

Browse files
committed
Merge branch 'develop'
2 parents 4c290b4 + 371210c commit 325db10

14 files changed

+1159
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ wp-content/plugins/hello.php
1616
/sitemap.xml
1717
/sitemap.xml.gz
1818

19+
.DS_Store
20+
node_modules

README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,130 @@
11
# better-wp-endpoints
22
A WordPress plugin that serves up slimmer WP Rest API endpoints - WIP
3+
4+
## Endpoints
5+
6+
### Posts
7+
**`better-wp-endpoints/v1/posts`**
8+
Gets a collection of posts. Accepts the following parameters:
9+
10+
- page (int)
11+
- per_page (int)
12+
- category id (int)
13+
- tag id (int)
14+
- content (boolean) set to false to omit content from showing in JSON response
15+
16+
It returns a JSON response with the following:
17+
- id
18+
- slug
19+
- title
20+
- date (ISO 8601)
21+
- excerpt
22+
- content
23+
- all possible thumbnail sizes & URL
24+
- Author & Author ID
25+
- Categories
26+
- Category IDs
27+
- Tags
28+
- Tag IDs
29+
- ACF fields, if applicable
30+
31+
### Post
32+
**`better-wp-endpoints/v1/post/{id}`**
33+
Get a post by ID.
34+
35+
Accepts the following parameters:
36+
37+
- ID (int)
38+
39+
Returns a JSON response with the following:
40+
41+
- id
42+
- slug
43+
- title
44+
- date (ISO 8601)
45+
- excerpt
46+
- content
47+
- all possible thumbnail sizes & URLs
48+
- Author & Author ID
49+
- Categories
50+
- Category IDs
51+
- Tags
52+
- Tag IDs
53+
- ACF fields, if applicable
54+
55+
### Pages
56+
**`better-wp-endpoints/v1/pages`**
57+
Gets a collection of pages. Accepts the following parameters:
58+
59+
- exclude (int)
60+
- orderby (string)
61+
- order (string - 'ASC' vs 'DESC')
62+
- per_page (int)
63+
- page (int)
64+
- content (boolean - setting to false hides the content from the response)
65+
66+
Returns the following JSON Response:
67+
68+
- ID
69+
- Slug
70+
- Title
71+
- Content
72+
- ACF Fields
73+
- all possible thumbnail sizes & URLs
74+
75+
### Page by ID
76+
**`better-wp-endpoints/v1/page/{id}`**
77+
Get a page by ID.
78+
79+
Accepts the following parameters:
80+
81+
- ID (int)
82+
83+
Returns a JSON response with the following:
84+
85+
- id
86+
- slug
87+
- title
88+
- content
89+
- all possible thumbnail sizes & URLs
90+
- ACF fields, if applicable
91+
92+
### Custom Post Type Collection
93+
**`better-wp-endpoints/v1/{custom_post_type}`**
94+
Gets a collection of posts from a custom post type. Accepts the following parameters:
95+
96+
- per_page (int)
97+
- page (int)
98+
- content (boolean - setting to false omits `the_content` from being returned)
99+
100+
Returns the following JSON response:
101+
102+
- ID
103+
- slug
104+
- title
105+
- date (ISO 8601)
106+
- post terms
107+
- excerpt
108+
- content
109+
- all possible thumbnail sizes & URLs
110+
- Author & Author ID
111+
- ACF fields if applicable
112+
113+
### Custom Post Type Post
114+
**`better-wp-endpoints/v1/{custom_post_type}/{id}`**
115+
Gets a single custom post type item. Accepts the following parameters:
116+
117+
- ID
118+
119+
Returns the following JSON Response:
120+
121+
- ID
122+
- slug
123+
- title
124+
- date (ISO 8601)
125+
- post terms
126+
- excerpt
127+
- content
128+
- all possible thumbnail sizes & URLs
129+
- Author & Author ID
130+
- ACF Fields, if applicable

better-wp-endpoints.php

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/*
3+
Plugin Name: Better WordPress Endpoints
4+
Plugin URI: https://github.com/factor1/better-wp-endpoints/
5+
Description: Serves up slimmer WordPress Rest API endpoints, with some great enhancements.
6+
Version: 0.1.0
7+
Author: Eric Stout, Factor1 Studios
8+
Author URI: https://factor1studios.com/
9+
License: GPL3
10+
License URI: https://www.gnu.org/licenses/gpl-3.0.html
11+
Text Domain: better-wp-endpoints
12+
Domain Path: /languages
13+
14+
Better WordPress Endpoints is free software: you can redistribute it and/or modify
15+
it under the terms of the GNU General Public License as published by
16+
the Free Software Foundation, either version 2 of the License, or
17+
any later version.
18+
19+
Better WordPress Endpoints is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
GNU General Public License for more details.
23+
24+
You should have received a copy of the GNU General Public License
25+
along with Better WordPress Endpoints. If not, see {URI to Plugin License}.
26+
*/
27+
28+
if ( ! defined( 'ABSPATH' ) ) {
29+
exit; // Exit if accessed directly
30+
}
31+
32+
class F1_Better_WP_Endpoints {
33+
34+
/**
35+
* @var $instance - The One true copy of F1_Better_WP_Endpoints that we'll ever need
36+
*/
37+
private static $instance;
38+
39+
/**
40+
* @var $plugin_dir - The plugin directory, for reuse in the includes.
41+
*/
42+
private static $plugin_dir;
43+
44+
/**
45+
* F1_Better_WP_Endpoints constructor.
46+
*/
47+
private function __construct() {}
48+
49+
/**
50+
* Determines if we've already loaded the plugin, and if so returns it.
51+
* Otherwise it kicks up a new instance of itself and stores it for later use.
52+
*
53+
* This is the singleton method.
54+
*
55+
* @return F1_Better_WP_Endpoints
56+
*/
57+
public function instance() {
58+
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof F1_Better_WP_Endpoints ) ) {
59+
self::$instance = new F1_Better_WP_Endpoints;
60+
61+
self::$plugin_dir = trailingslashit( dirname( __FILE__ ) );
62+
63+
// Load the includes
64+
self::$instance->includes();
65+
}
66+
67+
return self::$instance;
68+
}
69+
70+
/**
71+
* Include the necessary files.
72+
*/
73+
private function includes() {
74+
// include acf function
75+
include_once self::$plugin_dir . 'includes/get_acf.php';
76+
77+
// get a post by id
78+
include_once self::$plugin_dir . 'includes/get_post_by_id.php';
79+
80+
// get posts
81+
include_once self::$plugin_dir . 'includes/get_posts.php';
82+
83+
// get pages
84+
include_once self::$plugin_dir . 'includes/get_pages.php';
85+
86+
// get page by id
87+
include_once self::$plugin_dir . 'includes/get_page_by_id.php';
88+
89+
// get cpts
90+
include_once self::$plugin_dir . 'includes/get_cpts.php';
91+
92+
// create custom post type endpoints
93+
include_once self::$plugin_dir . 'includes/create_cpt_endpoints.php';
94+
95+
// get custom post type by id
96+
include_once self::$plugin_dir . 'includes/get_cpt_by_id.php';
97+
}
98+
99+
}
100+
101+
/**
102+
* Returns the one true F1_Better_WP_Endpoints.
103+
*
104+
* Loads on plugins_loaded.
105+
*
106+
* @return F1_Better_WP_Endpoints
107+
*/
108+
function better_wp_endpoints() {
109+
return F1_Better_WP_Endpoints::instance();
110+
}
111+
add_action( 'plugins_loaded', 'better_wp_endpoints', 99 );

copy.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const fs = require('fs-extra'),
2+
target = '/Users/ericstout/Local Sites/reacttestwp/app/public/wp-content/plugins/better-wp-endpoints',
3+
files = './';
4+
5+
fs.copy(files, target)
6+
.then(() => console.log('Files copied successfully!'))
7+
.catch(err => console.error(err))

0 commit comments

Comments
 (0)