Skip to content

Commit

Permalink
Fix exportable post types.
Browse files Browse the repository at this point in the history
  • Loading branch information
torounit committed Nov 27, 2024
1 parent d787fce commit 1fad919
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/Admin_UI.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Admin_UI {
/**
* Admin_UI constructor.
*
* @param string $slug Slug for admin page.
* @param string $slug Slug for admin page.
* @param string $post_type_var_name `name` attribute for post type select control.
* @param Nonce $nonce
*/
Expand All @@ -43,6 +43,9 @@ function () {
$this->post_type_var_name = $post_type_var_name;
}

/**
* Register admin page.
*/
private function register() {
add_management_page(
esc_html__( 'CSV Export', 'simple-csv-exporter' ),
Expand All @@ -56,6 +59,26 @@ private function register() {
);
}

/**
* @return WP_Post_Type[]
*/
private function get_post_types() {
return array_merge(
array(
get_post_type_object( 'post' ),
get_post_type_object( 'page' ),
get_post_type_object( 'attachment' ),
),
get_post_types(
array(
'_builtin' => false,
'can_export' => true,
),
'objects'
)
);
}

/**
* Admin UI.
*/
Expand All @@ -79,8 +102,7 @@ public function render() {
name="<?php echo esc_attr( $this->post_type_var_name ); ?>"
>
<?php
/** @var WP_Post_Type $post_type */
foreach ( get_post_types( array( 'can_export' => true ), 'objects' ) as $post_type ) :
foreach ( $this->get_post_types() as $post_type ) :
?>
<option value="<?php echo esc_attr( $post_type->name ); ?>"><?php echo esc_html( $post_type->label ); ?></option>
<?php
Expand Down

0 comments on commit 1fad919

Please sign in to comment.