Skip to content

Commit

Permalink
Various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsherlock authored and davidsherlock committed Mar 18, 2024
1 parent 08d78a8 commit 50778fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"autoload": {
"psr-4": {
"ArrayPress\\WP\\CPT_Inline_List_Table": "src/"
"ArrayPress\\WP\\CPT_Inline_List_Table\\": "src/"
},
"files": [
"src/Functions.php",
Expand Down
5 changes: 3 additions & 2 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ function register_inline_table( string $post_type, array $column_callbacks, stri
* @param string $slug The slug for the post type, used in URLs and query vars.
* @param array $additional_supports An array of additional features that the post type supports. Default features include 'title' and 'page-attributes'.
* @param bool $show_in_rest Whether to expose this post type in the WordPress REST API. Enables use of the Gutenberg editor and REST API queries.
* @param array $args An associative array of custom arguments to override or extend the default post type registration settings.
*/
function register_inline_table_post_type( string $post_type, string $singular_name, string $plural_name, string $slug, array $additional_supports = [], bool $show_in_rest = true ) {
new Post_Type( $post_type, $singular_name, $plural_name, $slug, $additional_supports, $show_in_rest );
function register_inline_table_post_type( string $post_type, string $singular_name, string $plural_name, string $slug, array $additional_supports = [], bool $show_in_rest = true, array $args = [] ) {
new Post_Type( $post_type, $singular_name, $plural_name, $slug, $additional_supports, $show_in_rest, $args );
}
}
16 changes: 13 additions & 3 deletions src/Post_Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace ArrayPress\WP\CPT_Inline_List_Table;

/**
* Check if the class `Register_Post_Type` is defined, and if not, define it.
* Check if the class `\\Post_Type` is defined, and if not, define it.
*/
if ( ! class_exists( __NAMESPACE__ . '\\Post_Type' ) ) :

Expand Down Expand Up @@ -58,6 +58,11 @@ class Post_Type {
*/
protected bool $show_in_rest = false;

/**
* @var array Custom arguments to override the default post type arguments.
*/
protected array $args;

/**
* Constructor for the custom post type registration class.
* This constructor initializes the post type with provided settings and automatically registers it with WordPress during the 'init' action.
Expand All @@ -68,14 +73,16 @@ class Post_Type {
* @param string $slug The slug for the post type, used in URLs and query vars.
* @param array $additional_supports An array of additional features that the post type supports. Default features include 'title' and 'page-attributes'.
* @param bool $show_in_rest Whether to expose this post type in the WordPress REST API. Enables use of the Gutenberg editor and REST API queries.
* @param array $args An associative array of custom arguments to override or extend the default post type registration settings.
*/
public function __construct( string $post_type, string $singular_name, string $plural_name, string $slug, array $additional_supports = [], bool $show_in_rest = true ) {
public function __construct( string $post_type, string $singular_name, string $plural_name, string $slug, array $additional_supports = [], bool $show_in_rest = true, array $args = [] ) {
$this->post_type = $post_type;
$this->singular_name = $singular_name;
$this->plural_name = $plural_name;
$this->slug = $slug;
$this->additional_supports = $additional_supports;
$this->show_in_rest = $show_in_rest;
$this->args = $args; // Store the custom arguments

add_action( 'init', [ $this, 'register' ] );
}
Expand All @@ -87,7 +94,7 @@ public function register(): void {
$labels = $this->generate_labels();
$supports = array_merge( [ 'title', 'page-attributes' ], $this->additional_supports );

$args = [
$default_args = [
'labels' => $labels,
'public' => false,
'publicly_queryable' => false,
Expand All @@ -102,6 +109,9 @@ public function register(): void {

];

// Merge the default args with the custom args, allowing for overrides
$args = array_merge( $default_args, $this->args );

register_post_type( $this->post_type, $args );
}

Expand Down

0 comments on commit 50778fd

Please sign in to comment.