Skip to content

Commit 50778fd

Browse files
davidsherlockdavidsherlock
authored andcommitted
Various improvements
1 parent 08d78a8 commit 50778fd

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"autoload": {
1818
"psr-4": {
19-
"ArrayPress\\WP\\CPT_Inline_List_Table": "src/"
19+
"ArrayPress\\WP\\CPT_Inline_List_Table\\": "src/"
2020
},
2121
"files": [
2222
"src/Functions.php",

src/Helper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ function register_inline_table( string $post_type, array $column_callbacks, stri
7979
* @param string $slug The slug for the post type, used in URLs and query vars.
8080
* @param array $additional_supports An array of additional features that the post type supports. Default features include 'title' and 'page-attributes'.
8181
* @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.
82+
* @param array $args An associative array of custom arguments to override or extend the default post type registration settings.
8283
*/
83-
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 ) {
84-
new Post_Type( $post_type, $singular_name, $plural_name, $slug, $additional_supports, $show_in_rest );
84+
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 = [] ) {
85+
new Post_Type( $post_type, $singular_name, $plural_name, $slug, $additional_supports, $show_in_rest, $args );
8586
}
8687
}

src/Post_Type.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace ArrayPress\WP\CPT_Inline_List_Table;
2323

2424
/**
25-
* Check if the class `Register_Post_Type` is defined, and if not, define it.
25+
* Check if the class `\\Post_Type` is defined, and if not, define it.
2626
*/
2727
if ( ! class_exists( __NAMESPACE__ . '\\Post_Type' ) ) :
2828

@@ -58,6 +58,11 @@ class Post_Type {
5858
*/
5959
protected bool $show_in_rest = false;
6060

61+
/**
62+
* @var array Custom arguments to override the default post type arguments.
63+
*/
64+
protected array $args;
65+
6166
/**
6267
* Constructor for the custom post type registration class.
6368
* This constructor initializes the post type with provided settings and automatically registers it with WordPress during the 'init' action.
@@ -68,14 +73,16 @@ class Post_Type {
6873
* @param string $slug The slug for the post type, used in URLs and query vars.
6974
* @param array $additional_supports An array of additional features that the post type supports. Default features include 'title' and 'page-attributes'.
7075
* @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.
76+
* @param array $args An associative array of custom arguments to override or extend the default post type registration settings.
7177
*/
72-
public function __construct( string $post_type, string $singular_name, string $plural_name, string $slug, array $additional_supports = [], bool $show_in_rest = true ) {
78+
public function __construct( string $post_type, string $singular_name, string $plural_name, string $slug, array $additional_supports = [], bool $show_in_rest = true, array $args = [] ) {
7379
$this->post_type = $post_type;
7480
$this->singular_name = $singular_name;
7581
$this->plural_name = $plural_name;
7682
$this->slug = $slug;
7783
$this->additional_supports = $additional_supports;
7884
$this->show_in_rest = $show_in_rest;
85+
$this->args = $args; // Store the custom arguments
7986

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

90-
$args = [
97+
$default_args = [
9198
'labels' => $labels,
9299
'public' => false,
93100
'publicly_queryable' => false,
@@ -102,6 +109,9 @@ public function register(): void {
102109

103110
];
104111

112+
// Merge the default args with the custom args, allowing for overrides
113+
$args = array_merge( $default_args, $this->args );
114+
105115
register_post_type( $this->post_type, $args );
106116
}
107117

0 commit comments

Comments
 (0)