Skip to content

Conversation

obenland
Copy link
Member

@obenland obenland commented Sep 19, 2025

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.

  • Created new Post_Types class with dedicated methods for each post type registration
  • Each method handles both post type registration and its related meta fields together
  • Moved registrations from scattered locations (Activitypub::register_post_types() and Blocks::register_postmeta()) into semantic functions
  • Maintained user meta registrations in original location as requested
  • Updated test to use new class methods
  • Removed unused imports after consolidation
  • Updated code coverage annotation job to account for multiple warnings

Other information:

  • Have you written new tests for your changes, if applicable? (Updated existing test)

Testing instructions:

  1. Ensure all existing functionality works as expected
  2. Run npm run env-test to verify all 895 tests pass
  3. Check that custom post types (ap_actor, ap_inbox, ap_outbox, extra fields) are properly registered
  4. Verify post meta fields are correctly associated with their respective post types
  5. Test ActivityPub functionality to ensure no regressions

@Copilot Copilot AI review requested due to automatic review settings September 19, 2025 15:07
@obenland obenland self-assigned this Sep 19, 2025
@obenland obenland requested a review from pfefferle September 19, 2025 15:07
@github-actions github-actions bot added the [Focus] Editor Changes to the ActivityPub experience in the block editor label Sep 19, 2025
@obenland obenland added the Skip Changelog Disables the "Changelog Updated" action for PRs where changelog entries are not necessary. label Sep 19, 2025
Copy link

@Copilot Copilot AI left a 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 from Blocks::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',
Copy link
Preview

Copilot AI Sep 19, 2025

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.

Suggested change
'sanitize_callback' => 'esc_sql',
'sanitize_callback' => 'sanitize_text_field',

Copilot uses AI. Check for mistakes.

Copy link
Member Author

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
@obenland obenland force-pushed the consolidate-post-type-registrations branch from 5b5c632 to 72167b4 Compare September 19, 2025 15:18
@obenland
Copy link
Member Author

@pfefferle Should prevent_empty_post_meta() and default_post_metadata() also be moved into Post_Types?

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
@pfefferle
Copy link
Member

If we also move every meta registration I am not sure if Post_Type is still the right name!?

@obenland
Copy link
Member Author

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
Copy link

@Copilot Copilot AI left a 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 );
Copy link
Preview

Copilot AI Sep 19, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Actions [Focus] Editor Changes to the ActivityPub experience in the block editor Skip Changelog Disables the "Changelog Updated" action for PRs where changelog entries are not necessary.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants