Skip to content

Commit

Permalink
Various fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
arraypress committed Mar 30, 2024
1 parent 3179c00 commit a599161
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ composer require arraypress/cpt-inline-list-table

### Example Usage

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

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

// Registers an inline list table for a specified custom post type, configuring it with
// custom columns, administrative URLs, and settings for menu highlighting.
register_inline_list_table(
register_inline_table(
'conditional_fee', // The custom post type identifier.
$columns, // Associative array of columns with render callbacks and formatters.
'edd_conditional_fees_table', // Hook name to attach the list table initialization.
Expand Down
4 changes: 2 additions & 2 deletions src/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public static function get_instance(): ?AJAX {
/**
* Prevent cloning.
*/
private function __clone() {
public function __clone() {
}

/**
* Prevent unserialization.
*/
private function __wakeup() {
public function __wakeup() {
}

/** AJAX **********************************************************************/
Expand Down
4 changes: 2 additions & 2 deletions src/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public static function get_instance(): ?Actions {
/**
* Prevent cloning.
*/
private function __clone() {
public function __clone() {
}

/**
* Prevent unserialization.
*/
private function __wakeup() {
public function __wakeup() {
}

/** Actions *******************************************************************/
Expand Down
36 changes: 31 additions & 5 deletions src/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ function get_duplicate_post_link( $post = 0 ): ?string {
'_wpnonce' => wp_create_nonce( 'duplicate_post_' . $post->ID ),
), admin_url( 'post.php' ) );

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

/**
* Filters the capability check result for editing posts created by other users. This can be used to dynamically
* alter permission checks, allowing or restricting user capabilities based on custom logic (e.g., user roles,
* specific conditions, or post types).
*
* @param bool $can_edit_others True if the current user has the capability to edit others' posts, false otherwise.
* @param string $post_type The post type being checked for the 'edit others' capability.
*/

return apply_filters( 'cpt_inline_list_table_edit_others_capability', current_user_can( $edit_others_cap ), $post_type );
}
}
Expand All @@ -99,6 +114,14 @@ function check_delete_others_caps( string $post_type ): bool {
$post_type_object = get_post_type_object( $post_type );
$delete_others_cap = empty( $post_type_object ) ? 'delete_others_' . $post_type . 's' : $post_type_object->cap->delete_others_posts;

/**
* Filters the capability check result for deleting posts created by other users. Similar to the edit capability filter,
* this allows for custom control over who can delete others' posts within specific contexts or conditions.
*
* @param bool $can_delete_others True if the current user has the capability to delete others' posts, false otherwise.
* @param string $post_type The post type being checked for the 'delete others' capability.
*/

return apply_filters( 'cpt_inline_list_table_delete_others_capability', current_user_can( $delete_others_cap ), $post_type );
}
}
Expand All @@ -120,11 +143,14 @@ function is_post_type_sortable( string $post_type = 'post' ): bool {
$sortable = ( post_type_supports( $post_type, 'page-attributes' ) && ! is_post_type_hierarchical( $post_type ) );

/**
* Filters the determination of whether a post type is considered sortable.
* Filters the determination of whether a post type is considered sortable. Sortability can be defined by themes
* or plugins based on whether a post type supports 'page-attributes' and is not hierarchical. This filter allows
* overriding the default sortability condition to accommodate custom logic or requirements for sorting posts.
*
* @param bool $sortable Whether the post type is sortable.
* @param string $post_type The post type being checked.
* @param bool $sortable Whether the post type is sortable, determined by support for 'page-attributes' and non-hierarchical structure.
* @param string $post_type The post type being evaluated for sortability.
*/
return apply_filters( 'is_post_type_sortable', $sortable, $post_type );

return apply_filters( 'cpt_inline_list_table_post_type_sortable', $sortable, $post_type );
}
}
4 changes: 2 additions & 2 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function register_inline_table( string $post_type, array $column_callbacks, stri
}
}

if ( ! function_exists( 'register_inline_table_post_type' ) ) {
if ( ! function_exists( 'register_inline_post_type' ) ) {
/**
* Helper function to simplify the registration of custom post types for inline table display.
*
Expand All @@ -81,7 +81,7 @@ function register_inline_table( string $post_type, array $column_callbacks, stri
* @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, array $args = [] ) {
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 = [] ) {
new Post_Type( $post_type, $singular_name, $plural_name, $slug, $additional_supports, $show_in_rest, $args );
}
}
2 changes: 1 addition & 1 deletion src/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,4 @@ public function menu_highlight() {

}

endif;
endif;

0 comments on commit a599161

Please sign in to comment.