-
Notifications
You must be signed in to change notification settings - Fork 82
Consolidate custom post type and meta registrations into Post_Types class #2215
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
base: trunk
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR consolidates the registration of custom post types and post meta into a dedicated Post_Types
class to improve code organization and maintainability. The changes move scattered registration logic from multiple locations into semantic methods within a single class.
- Created new
Post_Types
class with dedicated methods for each post type and meta registration - Moved post type registrations from
Activitypub::register_post_types()
and post meta fromBlocks::register_postmeta()
- Updated test to use the new class method instead of the old
Activitypub
method
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
includes/class-post-types.php | New class containing all custom post type and meta registrations with dedicated methods |
includes/class-activitypub.php | Removed register_post_types() method and unused imports, minor grammar fixes to user meta descriptions |
includes/class-blocks.php | Removed register_postmeta() method and its hook registration |
tests/includes/collection/class-test-inbox.php | Updated test to use new Post_Types::register_inbox_post_type() method |
activitypub.php | Added initialization of new Post_Types class |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
array( | ||
'type' => 'string', | ||
'single' => false, | ||
'sanitize_callback' => 'esc_sql', |
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.
Using esc_sql
as a sanitize callback is incorrect. The esc_sql
function is meant for preparing data for SQL queries, not for sanitizing meta values. Use sanitize_text_field
instead for proper sanitization of string meta values.
'sanitize_callback' => 'esc_sql', | |
'sanitize_callback' => 'sanitize_text_field', |
Copilot uses AI. Check for mistakes.
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.
@pfefferle Should this be absint
?
…lass - Created new Post_Types class to manage all custom post type and meta registrations - Moved post type registrations from Activitypub::register_post_types() to dedicated methods - Consolidated post meta registration with each post type for better organization - Removed duplicate post meta registrations from Blocks class - Updated tests to use new Post_Types class methods - Maintained user meta registrations in original Activitypub class location - All 895 tests pass, ensuring backward compatibility
5b5c632
to
72167b4
Compare
@pfefferle Should |
Deleted an unnecessary blank line for improved code cleanliness in the Activitypub class.
The regex pattern was failing to match @Covers warnings with escaped backslashes in class names. Changed from .* to [^"]* to properly capture content within quotes.
- Changed from trying to match specific warning count format to just looking for WARNINGS! - Updated sed pattern to handle both singular and plural warning formats - This is more robust and handles any number of warnings
If we also move every meta registration I am not sure if Post_Type is still the right name!? |
I guess I defined it generously in my head, anything post types related, including built-in post types. |
- Updated @Covers annotation in test_activity_meta_sanitization to reference Post_Types::register_outbox_post_type - Updated @Covers annotation in test_register_post_meta to reference Post_Types::register_activitypub_post_meta - These methods were moved from Activitypub::register_post_types and Blocks::register_postmeta to the new Post_Types class
- Added tracking of processed file:line combinations to avoid duplicate annotations - Tests with dataProvider create multiple warnings for the same @Covers annotation - Now only creates one checkstyle annotation per unique file/line location - Reduces noise in PR annotations while still catching all unique issues
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.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
throw new \Exception( 'Error message is no valid string' ); | ||
} | ||
|
||
return \esc_sql( $value ); |
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.
Using esc_sql
for post meta sanitization is incorrect. esc_sql
is for preparing values for SQL queries, not for sanitizing stored data. Use sanitize_text_field
or appropriate sanitization function instead.
Copilot uses AI. Check for mistakes.
This has been on my mental list for a while. Mainly because we register post meta in two places. After that, because the Activitypub class is a junk drawer class and this is something that we can pull out and it makes sense on its own.
Proposed changes:
This PR consolidates all custom post type and post meta registrations into a single, well-organized
Post_Types
class to improve code maintainability and organization.Post_Types
class with dedicated methods for each post type registrationActivitypub::register_post_types()
andBlocks::register_postmeta()
) into semantic functionsOther information:
Testing instructions:
npm run env-test
to verify all 895 tests passap_actor
,ap_inbox
,ap_outbox
, extra fields) are properly registered