Skip to content

Commit

Permalink
fixed undefined variable (props @funkolector), added No Custom Post T…
Browse files Browse the repository at this point in the history
…ypes header
  • Loading branch information
petenelson committed Jan 16, 2017
1 parent 5d73ff3 commit f056d65
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,29 @@ static public function register_cpt_settings() {
$section_remove = 'cpt-remove';
$section_auth = 'cpt-authentication';

add_settings_section( $section_remove, '', array( __CLASS__, 'section_header_remove' ), $key );
add_settings_section( $section_auth, '', array( __CLASS__, 'section_header_require_authentication' ), $key );

$namespace = REST_API_Toolbox_Common::core_namespace();

// Get the list of custom post types.
$post_types = REST_API_Toolbox_Common::get_custom_post_types();

// Build the list of endpoints based on each post type's rest_base.
$endpoints = array();
foreach( $post_types as $post_type_object ) {
$endpoints[] = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
}

// Are there custom post types available?
if ( empty( $endpoints ) ) {

// Create an empty section for No Custom Post Types
add_settings_section( $section_remove, '', array( __CLASS__, 'section_header_no_cpts' ), $key );
} else {

// Create sections for remove and require authentication.
add_settings_section( $section_remove, '', array( __CLASS__, 'section_header_remove' ), $key );
add_settings_section( $section_auth, '', array( __CLASS__, 'section_header_require_authentication' ), $key );
}

foreach( $endpoints as $endpoint ) {

// Add yes/no options to remove the endpoint.
Expand Down Expand Up @@ -75,5 +85,14 @@ static public function register_cpt_settings() {
static public function sanitize_cpt_settings( $settings ) {
return $settings;
}

/**
* Outputs the No Custom Post Types header.
*
* @return void
*/
static public function section_header_no_cpts() {
self::header( __( 'No Custom Post Types', 'rest-api-toolbox' ) );
}
}
}

0 comments on commit f056d65

Please sign in to comment.