Skip to content

Commit d89cc0f

Browse files
committed
Merge branch 'hotfix/naming-conventions'
2 parents 54a88d0 + e38b061 commit d89cc0f

16 files changed

+221
-220
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ wp-content/plugins/hello.php
1818

1919
.DS_Store
2020
node_modules
21+
better-rest-endpoints.zip

better-wp-endpoints.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Better Rest Endpoints
44
Plugin URI: https://github.com/factor1/better-rest-endpoints/
55
Description: Serves up slimmer WordPress Rest API endpoints, with some great enhancements.
6-
Version: 0.2.0
6+
Version: 1.0.0
77
Author: Eric Stout, Factor1 Studios
88
Author URI: https://factor1studios.com/
99
License: GPL3
@@ -29,10 +29,10 @@
2929
exit; // Exit if accessed directly
3030
}
3131

32-
class F1_Better_WP_Endpoints {
32+
class F1_Better_Rest_Endpoints {
3333

3434
/**
35-
* @var $instance - The One true copy of F1_Better_WP_Endpoints that we'll ever need
35+
* @var $instance - The One true copy of F1_Better_Rest_Endpoints that we'll ever need
3636
*/
3737
private static $instance;
3838

@@ -42,7 +42,7 @@ class F1_Better_WP_Endpoints {
4242
private static $plugin_dir;
4343

4444
/**
45-
* F1_Better_WP_Endpoints constructor.
45+
* F1_Better_Rest_Endpoints constructor.
4646
*/
4747
private function __construct() {}
4848

@@ -52,11 +52,11 @@ private function __construct() {}
5252
*
5353
* This is the singleton method.
5454
*
55-
* @return F1_Better_WP_Endpoints
55+
* @return F1_Better_Rest_Endpoints
5656
*/
5757
public function instance() {
58-
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof F1_Better_WP_Endpoints ) ) {
59-
self::$instance = new F1_Better_WP_Endpoints;
58+
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof F1_Better_Rest_Endpoints ) ) {
59+
self::$instance = new F1_Better_Rest_Endpoints;
6060

6161
self::$plugin_dir = trailingslashit( dirname( __FILE__ ) );
6262

@@ -117,13 +117,13 @@ private function includes() {
117117
}
118118

119119
/**
120-
* Returns the one true F1_Better_WP_Endpoints.
120+
* Returns the one true F1_Better_Rest_Endpoints.
121121
*
122122
* Loads on plugins_loaded.
123123
*
124-
* @return F1_Better_WP_Endpoints
124+
* @return F1_Better_Rest_Endpoints
125125
*/
126-
function better_wp_endpoints() {
127-
return F1_Better_WP_Endpoints::instance();
126+
function better_rest_endpoints() {
127+
return F1_Better_Rest_Endpoints::instance();
128128
}
129-
add_action( 'plugins_loaded', 'better_wp_endpoints', 99 );
129+
add_action( 'plugins_loaded', 'better_rest_endpoints', 99 );

includes/create_cpt_endpoints.php

+18-18
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,23 @@ function bwe_build_cpt_endpoints() {
6060
$query->the_post();
6161

6262
// better wordpress endpoint post object
63-
$bwe_post = new stdClass();
63+
$bre_post = new stdClass();
6464

6565
// get post data
66-
$bwe_post->id = get_the_ID();
67-
$bwe_post->title = get_the_title();
68-
$bwe_post->slug = basename(get_permalink());
69-
$bwe_post->date = get_the_date('c');
70-
$bwe_post->excerpt = get_the_excerpt();
66+
$bre_post->id = get_the_ID();
67+
$bre_post->title = get_the_title();
68+
$bre_post->slug = basename(get_permalink());
69+
$bre_post->date = get_the_date('c');
70+
$bre_post->excerpt = get_the_excerpt();
7171

7272
// show post content unless parameter is false
7373
if( $content === null || $show_content === true ) {
74-
$bwe_post->content = apply_filters('the_content', get_the_content());
74+
$bre_post->content = apply_filters('the_content', get_the_content());
7575
}
7676

77-
$bwe_post->author = esc_html__(get_the_author(), 'text_domain');
78-
$bwe_post->author_id = get_the_author_meta('ID');
79-
$bwe_post->author_nicename = get_the_author_meta('user_nicename');
77+
$bre_post->author = esc_html__(get_the_author(), 'text_domain');
78+
$bre_post->author_id = get_the_author_meta('ID');
79+
$bre_post->author_nicename = get_the_author_meta('user_nicename');
8080

8181
/*
8282
*
@@ -86,39 +86,39 @@ function bwe_build_cpt_endpoints() {
8686
if( get_object_taxonomies($cpt) ){
8787
$cpt_taxonomies = get_object_taxonomies($cpt, 'names');
8888

89-
$bwe_post->terms = get_the_terms(get_the_ID(), $cpt_taxonomies);
89+
$bre_post->terms = get_the_terms(get_the_ID(), $cpt_taxonomies);
9090

9191
} else {
92-
$bwe_post->terms = array();
92+
$bre_post->terms = array();
9393
}
9494

9595
/*
9696
*
9797
* return acf fields if they exist
9898
*
9999
*/
100-
$bwe_post->acf = bwe_get_acf();
100+
$bre_post->acf = bwe_get_acf();
101101

102102
/*
103103
*
104104
* get possible thumbnail sizes and urls
105105
*
106106
*/
107107
$thumbnail_names = get_intermediate_image_sizes();
108-
$bwe_thumbnails = new stdClass();
108+
$bre_thumbnails = new stdClass();
109109

110110
if( has_post_thumbnail() ){
111111
foreach ($thumbnail_names as $key => $name) {
112-
$bwe_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
112+
$bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
113113
}
114114

115-
$bwe_post->media = $bwe_thumbnails;
115+
$bre_post->media = $bre_thumbnails;
116116
} else {
117-
$bwe_post->media = false;
117+
$bre_post->media = false;
118118
}
119119

120120
// Push the post to the main $post array
121-
array_push($posts, $bwe_post);
121+
array_push($posts, $bre_post);
122122
}
123123

124124
// return the post array

includes/get_cpt_by_id.php

+18-18
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ function bwe_build_single_cpt_endpoints() {
3939
if( $query->have_posts() ){
4040

4141
// setup post object
42-
$bwe_cpt_post = new stdClass();
42+
$bre_cpt_post = new stdClass();
4343

4444
while( $query->have_posts() ) {
4545
$query->the_post();
4646

4747

4848
// get post data
49-
$bwe_cpt_post->id = get_the_ID();
50-
$bwe_cpt_post->title = get_the_title();
51-
$bwe_cpt_post->slug = basename(get_permalink());
52-
$bwe_cpt_post->date = get_the_date('c');
53-
$bwe_cpt_post->excerpt = get_the_excerpt();
54-
$bwe_cpt_post->content = apply_filters('the_content', get_the_content());
55-
$bwe_cpt_post->author = esc_html__(get_the_author(), 'text_domain');
56-
$bwe_cpt_post->author_id = get_the_author_meta('ID');
57-
$bwe_cpt_post->author_nicename = get_the_author_meta('user_nicename');
49+
$bre_cpt_post->id = get_the_ID();
50+
$bre_cpt_post->title = get_the_title();
51+
$bre_cpt_post->slug = basename(get_permalink());
52+
$bre_cpt_post->date = get_the_date('c');
53+
$bre_cpt_post->excerpt = get_the_excerpt();
54+
$bre_cpt_post->content = apply_filters('the_content', get_the_content());
55+
$bre_cpt_post->author = esc_html__(get_the_author(), 'text_domain');
56+
$bre_cpt_post->author_id = get_the_author_meta('ID');
57+
$bre_cpt_post->author_nicename = get_the_author_meta('user_nicename');
5858

5959
/*
6060
*
@@ -64,10 +64,10 @@ function bwe_build_single_cpt_endpoints() {
6464
if( get_object_taxonomies($cpt) ){
6565
$cpt_taxonomies = get_object_taxonomies($cpt, 'names');
6666

67-
$bwe_cpt_post->terms = get_the_terms(get_the_ID(), $cpt_taxonomies);
67+
$bre_cpt_post->terms = get_the_terms(get_the_ID(), $cpt_taxonomies);
6868

6969
} else {
70-
$bwe_cpt_post->terms = array();
70+
$bre_cpt_post->terms = array();
7171
}
7272

7373

@@ -76,29 +76,29 @@ function bwe_build_single_cpt_endpoints() {
7676
* return acf fields if they exist
7777
*
7878
*/
79-
$bwe_cpt_post->acf = bwe_get_acf();
79+
$bre_cpt_post->acf = bwe_get_acf();
8080

8181
/*
8282
*
8383
* get possible thumbnail sizes and urls
8484
*
8585
*/
8686
$thumbnail_names = get_intermediate_image_sizes();
87-
$bwe_thumbnails = new stdClass();
87+
$bre_thumbnails = new stdClass();
8888

8989
if( has_post_thumbnail() ){
9090
foreach ($thumbnail_names as $key => $name) {
91-
$bwe_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
91+
$bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
9292
}
9393

94-
$bwe_cpt_post->media = $bwe_thumbnails;
94+
$bre_cpt_post->media = $bre_thumbnails;
9595
} else {
96-
$bwe_cpt_post->media = false;
96+
$bre_cpt_post->media = false;
9797
}
9898

9999
}
100100

101-
return $bwe_cpt_post;
101+
return $bre_cpt_post;
102102
} else {
103103
// if no post is found
104104
return array();

includes/get_cpt_by_slug.php

+18-18
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ function bwe_build_single_cpt_endpoints_slug() {
3939
if( $query->have_posts() ){
4040

4141
// setup post object
42-
$bwe_cpt_post = new stdClass();
42+
$bre_cpt_post = new stdClass();
4343

4444
while( $query->have_posts() ) {
4545
$query->the_post();
4646

4747

4848
// get post data
49-
$bwe_cpt_post->id = get_the_ID();
50-
$bwe_cpt_post->title = get_the_title();
51-
$bwe_cpt_post->slug = basename(get_permalink());
52-
$bwe_cpt_post->date = get_the_date('c');
53-
$bwe_cpt_post->excerpt = get_the_excerpt();
54-
$bwe_cpt_post->content = apply_filters('the_content', get_the_content());
55-
$bwe_cpt_post->author = esc_html__(get_the_author(), 'text_domain');
56-
$bwe_cpt_post->author_id = get_the_author_meta('ID');
57-
$bwe_cpt_post->author_nicename = get_the_author_meta('user_nicename');
49+
$bre_cpt_post->id = get_the_ID();
50+
$bre_cpt_post->title = get_the_title();
51+
$bre_cpt_post->slug = basename(get_permalink());
52+
$bre_cpt_post->date = get_the_date('c');
53+
$bre_cpt_post->excerpt = get_the_excerpt();
54+
$bre_cpt_post->content = apply_filters('the_content', get_the_content());
55+
$bre_cpt_post->author = esc_html__(get_the_author(), 'text_domain');
56+
$bre_cpt_post->author_id = get_the_author_meta('ID');
57+
$bre_cpt_post->author_nicename = get_the_author_meta('user_nicename');
5858

5959
/*
6060
*
@@ -64,10 +64,10 @@ function bwe_build_single_cpt_endpoints_slug() {
6464
if( get_object_taxonomies($cpt) ){
6565
$cpt_taxonomies = get_object_taxonomies($cpt, 'names');
6666

67-
$bwe_cpt_post->terms = get_the_terms(get_the_ID(), $cpt_taxonomies);
67+
$bre_cpt_post->terms = get_the_terms(get_the_ID(), $cpt_taxonomies);
6868

6969
} else {
70-
$bwe_cpt_post->terms = array();
70+
$bre_cpt_post->terms = array();
7171
}
7272

7373

@@ -76,29 +76,29 @@ function bwe_build_single_cpt_endpoints_slug() {
7676
* return acf fields if they exist
7777
*
7878
*/
79-
$bwe_cpt_post->acf = bwe_get_acf();
79+
$bre_cpt_post->acf = bwe_get_acf();
8080

8181
/*
8282
*
8383
* get possible thumbnail sizes and urls
8484
*
8585
*/
8686
$thumbnail_names = get_intermediate_image_sizes();
87-
$bwe_thumbnails = new stdClass();
87+
$bre_thumbnails = new stdClass();
8888

8989
if( has_post_thumbnail() ){
9090
foreach ($thumbnail_names as $key => $name) {
91-
$bwe_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
91+
$bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
9292
}
9393

94-
$bwe_cpt_post->media = $bwe_thumbnails;
94+
$bre_cpt_post->media = $bre_thumbnails;
9595
} else {
96-
$bwe_cpt_post->media = false;
96+
$bre_cpt_post->media = false;
9797
}
9898

9999
}
100100

101-
return $bwe_cpt_post;
101+
return $bre_cpt_post;
102102
} else {
103103
// if no post is found
104104
return array();

includes/get_cpts.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
function bwe_get_cpts() {
1414

15-
$bwe_cpts = array();
15+
$bre_cpts = array();
1616

1717
foreach ( get_post_types( '', 'names', 'and' ) as $post_type ) {
1818

@@ -25,13 +25,13 @@ function bwe_get_cpts() {
2525
&& $post_type !== 'customize_changeset'
2626
&& $post_type !== 'acf-field-group'
2727
&& $post_type !== 'acf-field'){
28-
array_push($bwe_cpts, $post_type);
28+
array_push($bre_cpts, $post_type);
2929
}
3030
}
3131

3232
// check if array is empty, returns array if data exists, return false if empty
33-
if( !empty($bwe_cpts) ){
34-
return $bwe_cpts;
33+
if( !empty($bre_cpts) ){
34+
return $bre_cpts;
3535
} else {
3636
return false;
3737
}

0 commit comments

Comments
 (0)