Skip to content

refactor: simplify plugin activation and remove duplicate rewrite registration#12

Closed
jdevalk wants to merge 1 commit intomainfrom
optimize/plugin-core
Closed

refactor: simplify plugin activation and remove duplicate rewrite registration#12
jdevalk wants to merge 1 commit intomainfrom
optimize/plugin-core

Conversation

@jdevalk
Copy link
Member

@jdevalk jdevalk commented Feb 16, 2026

Summary

Simplifies the plugin activation flow and removes code duplication between Plugin::activate() and RewriteHandler::register_rules().

Changes

  • Removed RewriteHandler::register_rules() static method (single-use abstraction)
  • Updated Plugin::activate() to instantiate RewriteHandler directly instead of calling static method
  • Eliminates DRY violation where rewrite registration logic existed in two places
  • Maintains identical functionality - rules still registered on activation and on every init hook

Testing

  • Plugin activates without errors
  • .md URLs work after activation
  • Plugin deactivates cleanly
  • Rewrite rules flush properly
  • No changes to runtime behavior

Why This Improves the Code

  1. Removes unnecessary abstraction - The static register_rules() method existed solely for the activation hook and created an awkward instantiation pattern
  2. Improves consistency - Activation now follows the same pattern as the constructor (instantiate → call instance method)
  3. Reduces maintenance burden - One less method to maintain, clearer flow from activation → rewrite registration

🤖 Generated with Claude Code

…istration

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy link

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 simplifies the plugin activation flow by removing an unnecessary static method wrapper and making the activation pattern consistent with the rest of the codebase. The RewriteHandler::register_rules() static method was a single-use abstraction that instantiated the class and called an instance method - this is now done directly in Plugin::activate().

Changes:

  • Removed RewriteHandler::register_rules() static method that served as a thin wrapper
  • Updated Plugin::activate() to directly instantiate RewriteHandler and call add_rewrite_rules()
  • Aligned activation pattern with the constructor pattern used elsewhere in the codebase

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Router/RewriteHandler.php Removes the static register_rules() wrapper method
src/Plugin.php Updates activation to directly instantiate and call instance method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jdevalk
Copy link
Member Author

jdevalk commented Feb 17, 2026

Consolidation note: overlaps with #10 and #13 in RewriteHandler/plugin-core area. Suggest consolidation into one integration PR after #8/#9 land.

@jdevalk
Copy link
Member Author

jdevalk commented Feb 17, 2026

Superseded by consolidated PR #15 to reduce overlap/conflicts. Closing this one in favor of the combined integration path.

@jdevalk jdevalk closed this Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments