Skip to content

Commit

Permalink
Add post type extractor.
Browse files Browse the repository at this point in the history
  • Loading branch information
fumikito committed May 27, 2020
1 parent b3413f7 commit fd473cf
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Kunoichi/ThemeCustomizer/CustomizerSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,25 @@ protected function get_section() {
return $this->camelize( get_called_class() );
}
}

/**
* Get post type for multiple choices.
*
* @param array $query
* @param string[] $exclude
* @return array
*/
protected function get_post_types( $query = [], $exclude = [] ) {
if ( ! $query ) {
$query = [ 'public' => true ];
}
$post_types = [];
foreach ( get_post_types( $query, OBJECT ) as $post_type ) {
if ( in_array( $post_type->name, $exclude ) ) {
continue;
}
$post_types[ $post_type->name ] = $post_type->label;
}
return $post_types;
}
}

0 comments on commit fd473cf

Please sign in to comment.