-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better support for the default post
behavior
#85
Conversation
WalkthroughThe changes primarily focus on enhancing the handling of supported post types in the WordPress block editor. A new class Changes
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (3)
- blocks/query/index.php (1 hunks)
- entries/slotfills/index.php (2 hunks)
- src/class-supported-post-types.php (2 hunks)
Additional comments: 4
src/class-supported-post-types.php (2)
45-49: The addition of the comment block provides a clear explanation of the filter 'wp_curate_supported_post_types'. This is a good practice as it improves the readability and maintainability of the code.
71-77: The changes in this hunk handle the case when 'post_type' is not provided in the 'post-new.php' page. It defaults to 'post' if 'post_type' is not specified in the GET parameters. This is a good practice as it provides a default behavior and prevents potential errors due to undefined 'post_type'.
- } elseif ( 'post-new.php' === $pagenow && ! empty( $_GET['post_type'] ) ) { - // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended - $post_type = sanitize_text_field( $_GET['post_type'] ); + } elseif ( 'post-new.php' === $pagenow ) { + if ( ! empty( $_GET['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $post_type = sanitize_text_field( $_GET['post_type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended + } else { + // Default to post. + $post_type = 'post'; + } }entries/slotfills/index.php (2)
16-40: The
register_slotfills_scripts
function has been refactored to use theSupported_Post_Types
class for determining the current post type. This is a good improvement as it encapsulates the logic for determining the current post type within a dedicated class. However, ensure that theSupported_Post_Types
class is thoroughly tested, especially theget_current_post_type
method, as it is now a critical part of the script registration process.50-53: The
action_enqueue_slotfills_assets
function is now hooked to theenqueue_block_editor_assets
action. This is a good change as it ensures that the slotfill assets are enqueued only when the block editor assets are enqueued, improving the efficiency of asset management.
$supported_post_types = new Supported_Post_Types(); | ||
if ( ! in_array( $supported_post_types->get_current_post_type(), $allowed_post_types, true ) ) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Supported_Post_Types
class is being instantiated inside the register_slotfills_scripts
function. This could lead to unnecessary object creation if this function is called multiple times. Consider making Supported_Post_Types
a singleton or moving the instantiation to a higher scope to avoid unnecessary object creation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- src/class-supported-post-types.php (2 hunks)
Additional comments: 2
src/class-supported-post-types.php (2)
42-51: The
get_supported_post_types()
function now includes a filterwp_curate_supported_post_types
which allows customization of supported post types. This is a good practice as it provides flexibility for other developers to modify the behavior of your function without changing the source code. However, ensure that the filter is well-documented and its usage is clear to other developers.68-80: The
get_current_post_type()
function has been updated to handle thepost-new.php
page differently. If thepost_type
parameter is not provided in the URL, the default post type is set to 'post'. This is a sensible default, but it might be worth documenting this behavior in the function's docblock for clarity. Also, consider sanitizing thepost_type
parameter even when it's not empty to prevent potential security issues.Here's a suggested change to sanitize the
post_type
parameter:- if ( ! empty( $_GET['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended - $post_type = $_GET['post_type']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( ! empty( $_GET['post_type'] ) ) { + $post_type = sanitize_text_field( $_GET['post_type'] );
Summary
Changes to better support the default
post
behavior.How to Test
post
post: https://wp.test/wp-admin/post-new.phpSummary by CodeRabbit
New Features:
initialize_supported_post_types
function, allowing users to customize the supported post types. This provides more flexibility and control to the users.Refactor:
get_editor_post_type
function and moving certain function calls inside a conditional statement. This makes the code cleaner and easier to maintain.