Skip to content

Commit a599161

Browse files
committed
Various fixes and improvements
1 parent 3179c00 commit a599161

File tree

6 files changed

+41
-15
lines changed

6 files changed

+41
-15
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ composer require arraypress/cpt-inline-list-table
3131

3232
### Example Usage
3333

34-
The `register_inline_list_table` function allows for easy setup and configuration of your custom post type's inline list
34+
The `register_inline_table` function allows for easy setup and configuration of your custom post type's inline list
3535
table. Here's how to use it:
3636

3737
```php
3838
// Example usage of register_inline_table_post_type to create a 'Conditional Fee' custom post type.
39-
register_inline_table_post_type(
39+
register_inline_post_type(
4040
'conditional_fee', // The key for the custom post type.
4141
__( 'Conditional Fee', 'edd-conditional-fees' ), // The singular name of the custom post type for labels.
4242
__( 'Conditional Fees', 'edd-conditional-fees' ), // The plural name of the custom post type for labels.
@@ -82,7 +82,7 @@ $columns = [
8282

8383
// Registers an inline list table for a specified custom post type, configuring it with
8484
// custom columns, administrative URLs, and settings for menu highlighting.
85-
register_inline_list_table(
85+
register_inline_table(
8686
'conditional_fee', // The custom post type identifier.
8787
$columns, // Associative array of columns with render callbacks and formatters.
8888
'edd_conditional_fees_table', // Hook name to attach the list table initialization.

src/AJAX.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ public static function get_instance(): ?AJAX {
6767
/**
6868
* Prevent cloning.
6969
*/
70-
private function __clone() {
70+
public function __clone() {
7171
}
7272

7373
/**
7474
* Prevent unserialization.
7575
*/
76-
private function __wakeup() {
76+
public function __wakeup() {
7777
}
7878

7979
/** AJAX **********************************************************************/

src/Actions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ public static function get_instance(): ?Actions {
7373
/**
7474
* Prevent cloning.
7575
*/
76-
private function __clone() {
76+
public function __clone() {
7777
}
7878

7979
/**
8080
* Prevent unserialization.
8181
*/
82-
private function __wakeup() {
82+
public function __wakeup() {
8383
}
8484

8585
/** Actions *******************************************************************/

src/Functions.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ function get_duplicate_post_link( $post = 0 ): ?string {
6666
'_wpnonce' => wp_create_nonce( 'duplicate_post_' . $post->ID ),
6767
), admin_url( 'post.php' ) );
6868

69-
// The nonce_url part is integrated directly into the duplicate link
69+
/**
70+
* Filters the URL used for duplicating a post. This allows plugins and themes to modify the duplicate post link.
71+
* Useful for adding or removing query args, or changing the base URL, based on specific conditions or requirements.
72+
*
73+
* @param string $duplicate_link The URL to duplicate the post, including nonce for security.
74+
* @param int $post_id The ID of the post being duplicated.
75+
*/
7076
return apply_filters( 'cpt_inline_list_table_duplicate_post_link', $duplicate_link, $post->ID );
7177
}
7278
}
@@ -83,6 +89,15 @@ function check_edit_others_caps( string $post_type ): bool {
8389
$post_type_object = get_post_type_object( $post_type );
8490
$edit_others_cap = empty( $post_type_object ) ? 'edit_others_' . $post_type . 's' : $post_type_object->cap->edit_others_posts;
8591

92+
/**
93+
* Filters the capability check result for editing posts created by other users. This can be used to dynamically
94+
* alter permission checks, allowing or restricting user capabilities based on custom logic (e.g., user roles,
95+
* specific conditions, or post types).
96+
*
97+
* @param bool $can_edit_others True if the current user has the capability to edit others' posts, false otherwise.
98+
* @param string $post_type The post type being checked for the 'edit others' capability.
99+
*/
100+
86101
return apply_filters( 'cpt_inline_list_table_edit_others_capability', current_user_can( $edit_others_cap ), $post_type );
87102
}
88103
}
@@ -99,6 +114,14 @@ function check_delete_others_caps( string $post_type ): bool {
99114
$post_type_object = get_post_type_object( $post_type );
100115
$delete_others_cap = empty( $post_type_object ) ? 'delete_others_' . $post_type . 's' : $post_type_object->cap->delete_others_posts;
101116

117+
/**
118+
* Filters the capability check result for deleting posts created by other users. Similar to the edit capability filter,
119+
* this allows for custom control over who can delete others' posts within specific contexts or conditions.
120+
*
121+
* @param bool $can_delete_others True if the current user has the capability to delete others' posts, false otherwise.
122+
* @param string $post_type The post type being checked for the 'delete others' capability.
123+
*/
124+
102125
return apply_filters( 'cpt_inline_list_table_delete_others_capability', current_user_can( $delete_others_cap ), $post_type );
103126
}
104127
}
@@ -120,11 +143,14 @@ function is_post_type_sortable( string $post_type = 'post' ): bool {
120143
$sortable = ( post_type_supports( $post_type, 'page-attributes' ) && ! is_post_type_hierarchical( $post_type ) );
121144

122145
/**
123-
* Filters the determination of whether a post type is considered sortable.
146+
* Filters the determination of whether a post type is considered sortable. Sortability can be defined by themes
147+
* or plugins based on whether a post type supports 'page-attributes' and is not hierarchical. This filter allows
148+
* overriding the default sortability condition to accommodate custom logic or requirements for sorting posts.
124149
*
125-
* @param bool $sortable Whether the post type is sortable.
126-
* @param string $post_type The post type being checked.
150+
* @param bool $sortable Whether the post type is sortable, determined by support for 'page-attributes' and non-hierarchical structure.
151+
* @param string $post_type The post type being evaluated for sortability.
127152
*/
128-
return apply_filters( 'is_post_type_sortable', $sortable, $post_type );
153+
154+
return apply_filters( 'cpt_inline_list_table_post_type_sortable', $sortable, $post_type );
129155
}
130156
}

src/Helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function register_inline_table( string $post_type, array $column_callbacks, stri
6969
}
7070
}
7171

72-
if ( ! function_exists( 'register_inline_table_post_type' ) ) {
72+
if ( ! function_exists( 'register_inline_post_type' ) ) {
7373
/**
7474
* Helper function to simplify the registration of custom post types for inline table display.
7575
*
@@ -81,7 +81,7 @@ function register_inline_table( string $post_type, array $column_callbacks, stri
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.
8282
* @param array $args An associative array of custom arguments to override or extend the default post type registration settings.
8383
*/
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 = [] ) {
84+
function register_inline_post_type( string $post_type, string $singular_name, string $plural_name, string $slug, array $additional_supports = [], bool $show_in_rest = true, array $args = [] ) {
8585
new Post_Type( $post_type, $singular_name, $plural_name, $slug, $additional_supports, $show_in_rest, $args );
8686
}
8787
}

src/Register.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,4 +535,4 @@ public function menu_highlight() {
535535

536536
}
537537

538-
endif;
538+
endif;

0 commit comments

Comments
 (0)