Skip to content

Commit

Permalink
Merge branch 'hotfix/naming-conventions'
Browse files Browse the repository at this point in the history
  • Loading branch information
erwstout committed Jan 18, 2018
2 parents 54a88d0 + e38b061 commit d89cc0f
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 220 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ wp-content/plugins/hello.php

.DS_Store
node_modules
better-rest-endpoints.zip
24 changes: 12 additions & 12 deletions better-wp-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Better Rest Endpoints
Plugin URI: https://github.com/factor1/better-rest-endpoints/
Description: Serves up slimmer WordPress Rest API endpoints, with some great enhancements.
Version: 0.2.0
Version: 1.0.0
Author: Eric Stout, Factor1 Studios
Author URI: https://factor1studios.com/
License: GPL3
Expand All @@ -29,10 +29,10 @@
exit; // Exit if accessed directly
}

class F1_Better_WP_Endpoints {
class F1_Better_Rest_Endpoints {

/**
* @var $instance - The One true copy of F1_Better_WP_Endpoints that we'll ever need
* @var $instance - The One true copy of F1_Better_Rest_Endpoints that we'll ever need
*/
private static $instance;

Expand All @@ -42,7 +42,7 @@ class F1_Better_WP_Endpoints {
private static $plugin_dir;

/**
* F1_Better_WP_Endpoints constructor.
* F1_Better_Rest_Endpoints constructor.
*/
private function __construct() {}

Expand All @@ -52,11 +52,11 @@ private function __construct() {}
*
* This is the singleton method.
*
* @return F1_Better_WP_Endpoints
* @return F1_Better_Rest_Endpoints
*/
public function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof F1_Better_WP_Endpoints ) ) {
self::$instance = new F1_Better_WP_Endpoints;
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof F1_Better_Rest_Endpoints ) ) {
self::$instance = new F1_Better_Rest_Endpoints;

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

Expand Down Expand Up @@ -117,13 +117,13 @@ private function includes() {
}

/**
* Returns the one true F1_Better_WP_Endpoints.
* Returns the one true F1_Better_Rest_Endpoints.
*
* Loads on plugins_loaded.
*
* @return F1_Better_WP_Endpoints
* @return F1_Better_Rest_Endpoints
*/
function better_wp_endpoints() {
return F1_Better_WP_Endpoints::instance();
function better_rest_endpoints() {
return F1_Better_Rest_Endpoints::instance();
}
add_action( 'plugins_loaded', 'better_wp_endpoints', 99 );
add_action( 'plugins_loaded', 'better_rest_endpoints', 99 );
36 changes: 18 additions & 18 deletions includes/create_cpt_endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ function bwe_build_cpt_endpoints() {
$query->the_post();

// better wordpress endpoint post object
$bwe_post = new stdClass();
$bre_post = new stdClass();

// get post data
$bwe_post->id = get_the_ID();
$bwe_post->title = get_the_title();
$bwe_post->slug = basename(get_permalink());
$bwe_post->date = get_the_date('c');
$bwe_post->excerpt = get_the_excerpt();
$bre_post->id = get_the_ID();
$bre_post->title = get_the_title();
$bre_post->slug = basename(get_permalink());
$bre_post->date = get_the_date('c');
$bre_post->excerpt = get_the_excerpt();

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

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

/*
*
Expand All @@ -86,39 +86,39 @@ function bwe_build_cpt_endpoints() {
if( get_object_taxonomies($cpt) ){
$cpt_taxonomies = get_object_taxonomies($cpt, 'names');

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

} else {
$bwe_post->terms = array();
$bre_post->terms = array();
}

/*
*
* return acf fields if they exist
*
*/
$bwe_post->acf = bwe_get_acf();
$bre_post->acf = bwe_get_acf();

/*
*
* get possible thumbnail sizes and urls
*
*/
$thumbnail_names = get_intermediate_image_sizes();
$bwe_thumbnails = new stdClass();
$bre_thumbnails = new stdClass();

if( has_post_thumbnail() ){
foreach ($thumbnail_names as $key => $name) {
$bwe_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
$bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
}

$bwe_post->media = $bwe_thumbnails;
$bre_post->media = $bre_thumbnails;
} else {
$bwe_post->media = false;
$bre_post->media = false;
}

// Push the post to the main $post array
array_push($posts, $bwe_post);
array_push($posts, $bre_post);
}

// return the post array
Expand Down
36 changes: 18 additions & 18 deletions includes/get_cpt_by_id.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ function bwe_build_single_cpt_endpoints() {
if( $query->have_posts() ){

// setup post object
$bwe_cpt_post = new stdClass();
$bre_cpt_post = new stdClass();

while( $query->have_posts() ) {
$query->the_post();


// get post data
$bwe_cpt_post->id = get_the_ID();
$bwe_cpt_post->title = get_the_title();
$bwe_cpt_post->slug = basename(get_permalink());
$bwe_cpt_post->date = get_the_date('c');
$bwe_cpt_post->excerpt = get_the_excerpt();
$bwe_cpt_post->content = apply_filters('the_content', get_the_content());
$bwe_cpt_post->author = esc_html__(get_the_author(), 'text_domain');
$bwe_cpt_post->author_id = get_the_author_meta('ID');
$bwe_cpt_post->author_nicename = get_the_author_meta('user_nicename');
$bre_cpt_post->id = get_the_ID();
$bre_cpt_post->title = get_the_title();
$bre_cpt_post->slug = basename(get_permalink());
$bre_cpt_post->date = get_the_date('c');
$bre_cpt_post->excerpt = get_the_excerpt();
$bre_cpt_post->content = apply_filters('the_content', get_the_content());
$bre_cpt_post->author = esc_html__(get_the_author(), 'text_domain');
$bre_cpt_post->author_id = get_the_author_meta('ID');
$bre_cpt_post->author_nicename = get_the_author_meta('user_nicename');

/*
*
Expand All @@ -64,10 +64,10 @@ function bwe_build_single_cpt_endpoints() {
if( get_object_taxonomies($cpt) ){
$cpt_taxonomies = get_object_taxonomies($cpt, 'names');

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

} else {
$bwe_cpt_post->terms = array();
$bre_cpt_post->terms = array();
}


Expand All @@ -76,29 +76,29 @@ function bwe_build_single_cpt_endpoints() {
* return acf fields if they exist
*
*/
$bwe_cpt_post->acf = bwe_get_acf();
$bre_cpt_post->acf = bwe_get_acf();

/*
*
* get possible thumbnail sizes and urls
*
*/
$thumbnail_names = get_intermediate_image_sizes();
$bwe_thumbnails = new stdClass();
$bre_thumbnails = new stdClass();

if( has_post_thumbnail() ){
foreach ($thumbnail_names as $key => $name) {
$bwe_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
$bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
}

$bwe_cpt_post->media = $bwe_thumbnails;
$bre_cpt_post->media = $bre_thumbnails;
} else {
$bwe_cpt_post->media = false;
$bre_cpt_post->media = false;
}

}

return $bwe_cpt_post;
return $bre_cpt_post;
} else {
// if no post is found
return array();
Expand Down
36 changes: 18 additions & 18 deletions includes/get_cpt_by_slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ function bwe_build_single_cpt_endpoints_slug() {
if( $query->have_posts() ){

// setup post object
$bwe_cpt_post = new stdClass();
$bre_cpt_post = new stdClass();

while( $query->have_posts() ) {
$query->the_post();


// get post data
$bwe_cpt_post->id = get_the_ID();
$bwe_cpt_post->title = get_the_title();
$bwe_cpt_post->slug = basename(get_permalink());
$bwe_cpt_post->date = get_the_date('c');
$bwe_cpt_post->excerpt = get_the_excerpt();
$bwe_cpt_post->content = apply_filters('the_content', get_the_content());
$bwe_cpt_post->author = esc_html__(get_the_author(), 'text_domain');
$bwe_cpt_post->author_id = get_the_author_meta('ID');
$bwe_cpt_post->author_nicename = get_the_author_meta('user_nicename');
$bre_cpt_post->id = get_the_ID();
$bre_cpt_post->title = get_the_title();
$bre_cpt_post->slug = basename(get_permalink());
$bre_cpt_post->date = get_the_date('c');
$bre_cpt_post->excerpt = get_the_excerpt();
$bre_cpt_post->content = apply_filters('the_content', get_the_content());
$bre_cpt_post->author = esc_html__(get_the_author(), 'text_domain');
$bre_cpt_post->author_id = get_the_author_meta('ID');
$bre_cpt_post->author_nicename = get_the_author_meta('user_nicename');

/*
*
Expand All @@ -64,10 +64,10 @@ function bwe_build_single_cpt_endpoints_slug() {
if( get_object_taxonomies($cpt) ){
$cpt_taxonomies = get_object_taxonomies($cpt, 'names');

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

} else {
$bwe_cpt_post->terms = array();
$bre_cpt_post->terms = array();
}


Expand All @@ -76,29 +76,29 @@ function bwe_build_single_cpt_endpoints_slug() {
* return acf fields if they exist
*
*/
$bwe_cpt_post->acf = bwe_get_acf();
$bre_cpt_post->acf = bwe_get_acf();

/*
*
* get possible thumbnail sizes and urls
*
*/
$thumbnail_names = get_intermediate_image_sizes();
$bwe_thumbnails = new stdClass();
$bre_thumbnails = new stdClass();

if( has_post_thumbnail() ){
foreach ($thumbnail_names as $key => $name) {
$bwe_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
$bre_thumbnails->$name = esc_url(get_the_post_thumbnail_url($post->ID, $name));
}

$bwe_cpt_post->media = $bwe_thumbnails;
$bre_cpt_post->media = $bre_thumbnails;
} else {
$bwe_cpt_post->media = false;
$bre_cpt_post->media = false;
}

}

return $bwe_cpt_post;
return $bre_cpt_post;
} else {
// if no post is found
return array();
Expand Down
8 changes: 4 additions & 4 deletions includes/get_cpts.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

function bwe_get_cpts() {

$bwe_cpts = array();
$bre_cpts = array();

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

Expand All @@ -25,13 +25,13 @@ function bwe_get_cpts() {
&& $post_type !== 'customize_changeset'
&& $post_type !== 'acf-field-group'
&& $post_type !== 'acf-field'){
array_push($bwe_cpts, $post_type);
array_push($bre_cpts, $post_type);
}
}

// check if array is empty, returns array if data exists, return false if empty
if( !empty($bwe_cpts) ){
return $bwe_cpts;
if( !empty($bre_cpts) ){
return $bre_cpts;
} else {
return false;
}
Expand Down
Loading

0 comments on commit d89cc0f

Please sign in to comment.