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.

…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.

@pfefferle
Copy link
Member

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

When we talk about these, we would also have to move:

  • prevent_empty_post_meta
  • register_user_meta

But then, the class would be very bloated again.

Should we only have the Post_Types defined there and introduce two other classes for user_meta and post_meta?

@pfefferle
Copy link
Member

I think I would move all the post_metas to the Post_Types class and we should think about having a User_Metas class.

@obenland
Copy link
Member Author

When we talk about these, we would also have to move:

  • prevent_empty_post_meta
  • register_user_meta

What's the connection between prevent_empty_post_meta and register_user_meta?

@pfefferle
Copy link
Member

What's the connection between prevent_empty_post_meta and register_user_meta?

There is none, except what I wrote above: We might want to also have a dedicated space for user metas. That said, I had a look at the code and the metas and options are all over the place, because it is not always the best solution to have them in one place (options for example). So I think we are fine with your PR for now.

Refactored prevent_empty_post_meta and default_post_metadata methods from Activitypub to Post_Types for better separation of concerns. Updated hooks in Activitypub to use the new Post_Types methods. Added unit tests for these methods in a new Test_Post_Types class, and removed related tests from Test_Activitypub.
Extract duplicate post meta args into reusable private helper methods:
- get_object_id_meta_args() for _activitypub_object_id
- get_activity_actor_meta_args() for _activitypub_activity_actor
- get_activity_type_meta_args() for _activitypub_activity_type
- get_content_visibility_meta_args() for activitypub_content_visibility

This eliminates code duplication between inbox/outbox registrations and ensures consistency across all post meta configurations.
Replaces custom and esc_sql sanitize_callback functions with WordPress's built-in sanitize_text_field for better input sanitization and consistency.
Remove duplicate annotation tracking logic that was added in this branch.
Will be fixed in a separate PR focused on CI improvements.
@obenland obenland requested a review from pfefferle September 22, 2025 16:11
Relocates the registration of post meta-related filters from Activitypub to the Post_Types class for better organization and separation of concerns.

Props @pfefferle.
The register_ap_actor_rest_field method and its related rest_api_init hook have been moved from the Activitypub class to the Post_Types class. This change centralizes REST field registration logic related to post types, improving code organization.
Relocates the registration of ActivityPub support for custom post types and the actor extra fields filter from class-activitypub.php to class-post-types.php. This change improves code organization by grouping post type related logic within the Post_Types class.
@obenland obenland requested a review from pfefferle September 22, 2025 16:32
@obenland obenland merged commit 764d53f into trunk Sep 24, 2025
13 checks passed
@obenland obenland deleted the consolidate-post-type-registrations branch September 24, 2025 11:21
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