diff --git a/.gitignore b/.gitignore index b892bfc..8afb51a 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ wp-content/plugins/hello.php .DS_Store node_modules +better-rest-endpoints.zip diff --git a/better-wp-endpoints.php b/better-wp-endpoints.php index 90613b6..2cb1ee1 100644 --- a/better-wp-endpoints.php +++ b/better-wp-endpoints.php @@ -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 @@ -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; @@ -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() {} @@ -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__ ) ); @@ -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 ); diff --git a/includes/create_cpt_endpoints.php b/includes/create_cpt_endpoints.php index 19d807f..109754f 100644 --- a/includes/create_cpt_endpoints.php +++ b/includes/create_cpt_endpoints.php @@ -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'); /* * @@ -86,10 +86,10 @@ 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(); } /* @@ -97,7 +97,7 @@ function bwe_build_cpt_endpoints() { * return acf fields if they exist * */ - $bwe_post->acf = bwe_get_acf(); + $bre_post->acf = bwe_get_acf(); /* * @@ -105,20 +105,20 @@ function bwe_build_cpt_endpoints() { * */ $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 diff --git a/includes/get_cpt_by_id.php b/includes/get_cpt_by_id.php index 37bf1ec..cecda90 100644 --- a/includes/get_cpt_by_id.php +++ b/includes/get_cpt_by_id.php @@ -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'); /* * @@ -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(); } @@ -76,7 +76,7 @@ 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(); /* * @@ -84,21 +84,21 @@ function bwe_build_single_cpt_endpoints() { * */ $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(); diff --git a/includes/get_cpt_by_slug.php b/includes/get_cpt_by_slug.php index 5f1ec43..992cc8d 100644 --- a/includes/get_cpt_by_slug.php +++ b/includes/get_cpt_by_slug.php @@ -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'); /* * @@ -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(); } @@ -76,7 +76,7 @@ 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(); /* * @@ -84,21 +84,21 @@ function bwe_build_single_cpt_endpoints_slug() { * */ $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(); diff --git a/includes/get_cpts.php b/includes/get_cpts.php index 8c28817..25ca2c4 100644 --- a/includes/get_cpts.php +++ b/includes/get_cpts.php @@ -12,7 +12,7 @@ function bwe_get_cpts() { - $bwe_cpts = array(); + $bre_cpts = array(); foreach ( get_post_types( '', 'names', 'and' ) as $post_type ) { @@ -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; } diff --git a/includes/get_page_by_id.php b/includes/get_page_by_id.php index a9095e4..86b8775 100644 --- a/includes/get_page_by_id.php +++ b/includes/get_page_by_id.php @@ -24,11 +24,11 @@ function get_page_by_id( WP_REST_Request $request ){ global $post; // better wordpress endpoint post object - $bwe_page = new stdClass(); + $bre_page = new stdClass(); - $bwe_page->id = get_the_ID(); - $bwe_page->title = get_the_title(); - $bwe_page->slug = basename(get_permalink()); + $bre_page->id = get_the_ID(); + $bre_page->title = get_the_title(); + $bre_page->slug = basename(get_permalink()); /* * @@ -39,13 +39,13 @@ function get_page_by_id( WP_REST_Request $request ){ // strip file extension to return just the name of the template $template_name = preg_replace('/\\.[^.\\s]{3,4}$/', '', basename(get_page_template())); - $bwe_page->template = $template_name; + $bre_page->template = $template_name; } else { - $bwe_page->template = 'default'; + $bre_page->template = 'default'; } - $bwe_page->content = apply_filters('the_content', get_the_content()); + $bre_page->content = apply_filters('the_content', get_the_content()); /* * @@ -57,14 +57,14 @@ function get_page_by_id( WP_REST_Request $request ){ $id = ($parents) ? $parents[count($parents)-1]: $post->ID; /* Get the parent and set the $class with the page slug (post_name) */ $parent = get_post( $id ); - $bwe_page->parent = $parent->post_name != $post->post_name ? $parent->post_name : false; + $bre_page->parent = $parent->post_name != $post->post_name ? $parent->post_name : false; /* * * return acf fields if they exist * */ - $bwe_page->acf = bwe_get_acf(); + $bre_page->acf = bwe_get_acf(); /* * @@ -72,26 +72,26 @@ function get_page_by_id( WP_REST_Request $request ){ * */ $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_page->media = $bwe_thumbnails; + $bre_page->media = $bre_thumbnails; } else { - $bwe_page->media = false; + $bre_page->media = false; } // Push the post to the main $post array - return $bwe_page; + return $bre_page; } } else { // return empty page array if no page - return $bwe_page; + return $bre_page; } diff --git a/includes/get_pages.php b/includes/get_pages.php index 9eff0a5..e979ab3 100644 --- a/includes/get_pages.php +++ b/includes/get_pages.php @@ -48,16 +48,16 @@ function bwe_get_pages( WP_REST_Request $request ) { global $post; // better wordpress endpoint page object - $bwe_page = new stdClass(); + $bre_page = new stdClass(); /* * * get page data * */ - $bwe_page->id = get_the_ID(); - $bwe_page->title = get_the_title(); - $bwe_page->slug = basename(get_permalink()); + $bre_page->id = get_the_ID(); + $bre_page->title = get_the_title(); + $bre_page->slug = basename(get_permalink()); /* * @@ -68,10 +68,10 @@ function bwe_get_pages( WP_REST_Request $request ) { // strip file extension to return just the name of the template $template_name = preg_replace('/\\.[^.\\s]{3,4}$/', '', basename(get_page_template())); - $bwe_page->template = $template_name; + $bre_page->template = $template_name; } else { - $bwe_page->template = 'default'; + $bre_page->template = 'default'; } /* @@ -84,12 +84,12 @@ function bwe_get_pages( WP_REST_Request $request ) { $id = ($parents) ? $parents[count($parents)-1]: $post->ID; /* Get the parent and set the $class with the page slug (post_name) */ $parent = get_post( $id ); - $bwe_page->parent = $parent->post_name != $post->post_name ? $parent->post_name : false; + $bre_page->parent = $parent->post_name != $post->post_name ? $parent->post_name : false; // show post content unless parameter is false if( $content === null || $show_content === true ) { - $bwe_page->content = apply_filters('the_content', get_the_content()); + $bre_page->content = apply_filters('the_content', get_the_content()); } /* @@ -97,7 +97,7 @@ function bwe_get_pages( WP_REST_Request $request ) { * return acf fields if they exist * */ - $bwe_page->acf = bwe_get_acf(); + $bre_page->acf = bwe_get_acf(); /* * @@ -105,20 +105,20 @@ function bwe_get_pages( WP_REST_Request $request ) { * */ $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_page->media = $bwe_thumbnails; + $bre_page->media = $bre_thumbnails; } else { - $bwe_page->media = false; + $bre_page->media = false; } // Push the post to the main $post array - array_push($pages, $bwe_page); + array_push($pages, $bre_page); } // return the pages array diff --git a/includes/get_post_by_id.php b/includes/get_post_by_id.php index f456d77..486d206 100644 --- a/includes/get_post_by_id.php +++ b/includes/get_post_by_id.php @@ -22,17 +22,17 @@ function get_post_by_id( $data ) { $query->the_post(); // better wordpress endpoint post object - $bwe_post = new stdClass(); - - $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(); - $bwe_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 = new stdClass(); + + $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(); + $bre_post->content = apply_filters('the_content', get_the_content()); + $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'); /* * @@ -41,18 +41,18 @@ function get_post_by_id( $data ) { */ $categories = get_the_category(); - $bwe_categories = []; - $bwe_category_ids = []; + $bre_categories = []; + $bre_category_ids = []; if( !empty($categories) ){ foreach ($categories as $key => $category) { - array_push($bwe_category_ids, $category->term_id); - array_push($bwe_categories, $category->cat_name); + array_push($bre_category_ids, $category->term_id); + array_push($bre_categories, $category->cat_name); } } - $bwe_post->category_ids = $bwe_category_ids; - $bwe_post->category_names = $bwe_categories; + $bre_post->category_ids = $bre_category_ids; + $bre_post->category_names = $bre_categories; /* * @@ -61,25 +61,25 @@ function get_post_by_id( $data ) { */ $tags = get_the_tags(); - $bwe_tags = []; - $bwe_tag_ids = []; + $bre_tags = []; + $bre_tag_ids = []; if( !empty($tags) ){ foreach ($tags as $key => $tag) { - array_push($bwe_tag_ids, $tag->term_id); - array_push($bwe_tags, $tag->name); + array_push($bre_tag_ids, $tag->term_id); + array_push($bre_tags, $tag->name); } } - $bwe_post->tag_ids = $bwe_tag_ids; - $bwe_post->tag_names = $bwe_tags; + $bre_post->tag_ids = $bre_tag_ids; + $bre_post->tag_names = $bre_tags; /* * * return acf fields if they exist * */ - $bwe_post->acf = bwe_get_acf(); + $bre_post->acf = bwe_get_acf(); /* * @@ -87,27 +87,27 @@ function get_post_by_id( $data ) { * */ $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 - return $bwe_post; + return $bre_post; } } else { // no posts found $bwepost = []; - return $bwe_post; + return $bre_post; } // Restore original Post Data diff --git a/includes/get_posts.php b/includes/get_posts.php index 0087dff..29c2580 100644 --- a/includes/get_posts.php +++ b/includes/get_posts.php @@ -52,23 +52,23 @@ function bwe_get_posts( WP_REST_Request $request ) { $pages = $query->max_num_pages; // 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'); /* * @@ -77,18 +77,18 @@ function bwe_get_posts( WP_REST_Request $request ) { */ $categories = get_the_category(); - $bwe_categories = []; - $bwe_category_ids = []; + $bre_categories = []; + $bre_category_ids = []; if( !empty($categories) ){ foreach ($categories as $key => $category) { - array_push($bwe_category_ids, $category->term_id); - array_push($bwe_categories, $category->cat_name); + array_push($bre_category_ids, $category->term_id); + array_push($bre_categories, $category->cat_name); } } - $bwe_post->category_ids = $bwe_category_ids; - $bwe_post->category_names = $bwe_categories; + $bre_post->category_ids = $bre_category_ids; + $bre_post->category_names = $bre_categories; /* * @@ -97,26 +97,26 @@ function bwe_get_posts( WP_REST_Request $request ) { */ $tags = get_the_tags(); - $bwe_tags = []; - $bwe_tag_ids = []; + $bre_tags = []; + $bre_tag_ids = []; if( !empty($tags) ){ foreach ($tags as $key => $tag) { - array_push($bwe_tag_ids, $tag->term_id); - array_push($bwe_tags, $tag->name); + array_push($bre_tag_ids, $tag->term_id); + array_push($bre_tags, $tag->name); } } - $bwe_post->tag_ids = $bwe_tag_ids; - $bwe_post->tag_names = $bwe_tags; + $bre_post->tag_ids = $bre_tag_ids; + $bre_post->tag_names = $bre_tags; /* * * return acf fields if they exist * */ - $bwe_post->acf = bwe_get_acf(); + $bre_post->acf = bwe_get_acf(); /* * @@ -124,20 +124,20 @@ function bwe_get_posts( WP_REST_Request $request ) { * */ $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 diff --git a/includes/get_posts_tax.php b/includes/get_posts_tax.php index 5358002..5947a1c 100644 --- a/includes/get_posts_tax.php +++ b/includes/get_posts_tax.php @@ -66,27 +66,27 @@ function bwe_build_custom_tax_endpoint() { $pages = $query->max_num_pages; // setup post object - $bwe_tax_posts = array(); + $bre_tax_posts = array(); while( $query->have_posts() ) { $query->the_post(); - $bwe_tax_post = new stdClass(); + $bre_tax_post = new stdClass(); // get post data - $bwe_tax_post->id = get_the_ID(); - $bwe_tax_post->title = get_the_title(); - $bwe_tax_post->slug = basename(get_permalink()); - $bwe_tax_post->date = get_the_date('c'); - $bwe_tax_post->excerpt = get_the_excerpt(); + $bre_tax_post->id = get_the_ID(); + $bre_tax_post->title = get_the_title(); + $bre_tax_post->slug = basename(get_permalink()); + $bre_tax_post->date = get_the_date('c'); + $bre_tax_post->excerpt = get_the_excerpt(); if( $content === null || $show_content === true ){ - $bwe_tax_post->content = apply_filters('the_content', get_the_content()); + $bre_tax_post->content = apply_filters('the_content', get_the_content()); } - $bwe_tax_post->author = esc_html__(get_the_author(), 'text_domain'); - $bwe_tax_post->author_id = get_the_author_meta('ID'); - $bwe_tax_post->author_nicename = get_the_author_meta('user_nicename'); + $bre_tax_post->author = esc_html__(get_the_author(), 'text_domain'); + $bre_tax_post->author_id = get_the_author_meta('ID'); + $bre_tax_post->author_nicename = get_the_author_meta('user_nicename'); /* * @@ -95,10 +95,10 @@ function bwe_build_custom_tax_endpoint() { */ if( get_the_terms(get_the_ID(), $tax) ){ - $bwe_tax_post->terms = get_the_terms(get_the_ID(), $tax); + $bre_tax_post->terms = get_the_terms(get_the_ID(), $tax); } else { - $bwe_tax_post->terms = array(); + $bre_tax_post->terms = array(); } @@ -107,7 +107,7 @@ function bwe_build_custom_tax_endpoint() { * return acf fields if they exist * */ - $bwe_tax_post->acf = bwe_get_acf(); + $bre_tax_post->acf = bwe_get_acf(); /* * @@ -115,24 +115,24 @@ function bwe_build_custom_tax_endpoint() { * */ $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_tax_post->media = $bwe_thumbnails; + $bre_tax_post->media = $bre_thumbnails; } else { - $bwe_tax_post->media = false; + $bre_tax_post->media = false; } // push the post to the main array - array_push($bwe_tax_posts, $bwe_tax_post); + array_push($bre_tax_posts, $bre_tax_post); } // return the post array - $response = rest_ensure_response( $bwe_tax_posts ); + $response = rest_ensure_response( $bre_tax_posts ); $response->header( 'X-WP-Total', (int) $total ); $response->header( 'X-WP-TotalPages', (int) $pages ); diff --git a/includes/get_search.php b/includes/get_search.php index 1b2fc91..5deadf5 100644 --- a/includes/get_search.php +++ b/includes/get_search.php @@ -44,23 +44,23 @@ function bwe_get_search( WP_REST_Request $request ) { $pages = $query->max_num_pages; // 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'); /* * @@ -69,18 +69,18 @@ function bwe_get_search( WP_REST_Request $request ) { */ $categories = get_the_category(); - $bwe_categories = []; - $bwe_category_ids = []; + $bre_categories = []; + $bre_category_ids = []; if( !empty($categories) ){ foreach ($categories as $key => $category) { - array_push($bwe_category_ids, $category->term_id); - array_push($bwe_categories, $category->cat_name); + array_push($bre_category_ids, $category->term_id); + array_push($bre_categories, $category->cat_name); } } - $bwe_post->category_ids = $bwe_category_ids; - $bwe_post->category_names = $bwe_categories; + $bre_post->category_ids = $bre_category_ids; + $bre_post->category_names = $bre_categories; /* * @@ -89,26 +89,26 @@ function bwe_get_search( WP_REST_Request $request ) { */ $tags = get_the_tags(); - $bwe_tags = []; - $bwe_tag_ids = []; + $bre_tags = []; + $bre_tag_ids = []; if( !empty($tags) ){ foreach ($tags as $key => $tag) { - array_push($bwe_tag_ids, $tag->term_id); - array_push($bwe_tags, $tag->name); + array_push($bre_tag_ids, $tag->term_id); + array_push($bre_tags, $tag->name); } } - $bwe_post->tag_ids = $bwe_tag_ids; - $bwe_post->tag_names = $bwe_tags; + $bre_post->tag_ids = $bre_tag_ids; + $bre_post->tag_names = $bre_tags; /* * * return acf fields if they exist * */ - $bwe_post->acf = bwe_get_acf(); + $bre_post->acf = bwe_get_acf(); /* * @@ -116,20 +116,20 @@ function bwe_get_search( WP_REST_Request $request ) { * */ $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 diff --git a/includes/get_tax.php b/includes/get_tax.php index 404a003..d49dcd5 100644 --- a/includes/get_tax.php +++ b/includes/get_tax.php @@ -8,14 +8,14 @@ */ function bwe_get_custom_tax() { - $bwe_custom_tax = array(); + $bre_custom_tax = array(); foreach ( get_taxonomies() as $custom_tax ){ - array_push($bwe_custom_tax, $custom_tax); + array_push($bre_custom_tax, $custom_tax); } - if( !empty($bwe_custom_tax) ){ - return $bwe_custom_tax; + if( !empty($bre_custom_tax) ){ + return $bre_custom_tax; } else { return false; } diff --git a/includes/get_taxonomies.php b/includes/get_taxonomies.php index 6993059..b44240b 100644 --- a/includes/get_taxonomies.php +++ b/includes/get_taxonomies.php @@ -10,22 +10,22 @@ function bwe_get_taxonomies() { // set an empty array - $bwe_taxonomies = array(); + $bre_taxonomies = array(); // get all taxonomies as objects $taxonomies = get_taxonomies(array(),'objects'); // Loop through each taxonomy and get its data foreach($taxonomies as $tax){ - $bwe_tax_obj = new stdClass(); + $bre_tax_obj = new stdClass(); - $bwe_tax_obj->name = $tax->label; - $bwe_tax_obj->slug = $tax->name; - $bwe_tax_obj->description = $tax->description; - $bwe_tax_obj->hierarchical = $tax->hierarchical; + $bre_tax_obj->name = $tax->label; + $bre_tax_obj->slug = $tax->name; + $bre_tax_obj->description = $tax->description; + $bre_tax_obj->hierarchical = $tax->hierarchical; // push the data to the array - array_push($bwe_taxonomies, $bwe_tax_obj); + array_push($bre_taxonomies, $bre_tax_obj); } /* @@ -36,8 +36,8 @@ function bwe_get_taxonomies() { register_rest_route( 'better-rest-endpoints/v1', '/taxonomies/', array( 'methods' => 'GET', - 'callback' => function ( WP_REST_Request $request ) use($bwe_taxonomies) { - return $bwe_taxonomies; + 'callback' => function ( WP_REST_Request $request ) use($bre_taxonomies) { + return $bre_taxonomies; }, )); } diff --git a/package-lock.json b/package-lock.json index 990b9ff..ee4d168 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "better-rest-endpoints", - "version": "0.2.0", + "version": "1.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e27276d..23d81cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "better-rest-endpoints", - "version": "0.2.0", + "version": "1.0.0", "description": "Serves up slimmer WordPress Rest API endpoints.", "main": "index.js", "scripts": {