-
Notifications
You must be signed in to change notification settings - Fork 12
Add namespaces and PSR-4 autoloader #304
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
Conversation
- Add Micropub namespace to all classes - Add PSR-4-like autoloader (class-autoloader.php) - Add singleton loader class (class-micropub.php) - Rename class files to match WordPress conventions: - class-micropub-base.php → class-base.php - class-micropub-endpoint.php → class-endpoint.php - class-micropub-media.php → class-media.php - class-micropub-render.php → class-render.php - class-micropub-error.php → class-error.php - Update all class references to use namespaced versions - Remove orphaned templates directory (settings page was never implemented) - Update phpcs.xml configuration - Fix PHPCS violations
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 modernizes the Micropub WordPress plugin by introducing PHP namespaces and a PSR-4-like autoloader, matching the architecture of the webmention plugin. The changes include namespacing all classes under \Micropub, implementing an autoloader, creating a singleton loader class, and renaming class files to follow WordPress conventions.
Key Changes
- Adds
Micropubnamespace to all plugin classes - Implements PSR-4-like autoloader for automatic class loading
- Introduces singleton pattern with
Micropub\Micropubmain class - Renames and reorganizes class files following WordPress conventions (e.g.,
class-micropub-base.php→class-base.php) - Updates all class references throughout codebase to use namespaced versions
- Removes orphaned templates directory
- Updates PHPCS configuration for broader code coverage
- Fixes various PHPCS violations (formatting, alignment, escaping)
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| micropub.php | Main plugin file with namespace declaration, autoloader integration, and plugin initialization |
| includes/class-autoloader.php | New PSR-4 autoloader implementation for WordPress-style file naming |
| includes/class-micropub.php | New singleton main class managing plugin initialization and hooks |
| includes/class-base.php | Renamed from class-micropub-base.php, now \Micropub\Base with namespace |
| includes/class-endpoint.php | Renamed from class-micropub-endpoint.php, now \Micropub\Endpoint with namespace |
| includes/class-media.php | Renamed from class-micropub-media.php, now \Micropub\Media with namespace |
| includes/class-render.php | Renamed from class-micropub-render.php, now \Micropub\Render with namespace |
| includes/class-error.php | Renamed from class-micropub-error.php, now \Micropub\Error with namespace |
| includes/functions.php | Updated global utility functions with proper namespacing and documentation |
| includes/compat-functions.php | Updated compatibility functions with documentation |
| tests/*.php | Updated all test files with namespaced class references |
| phpcs.xml | Modernized PHPCS configuration with broader exclusions and updated rulesets |
| templates/*.php | Removed orphaned template files that were never implemented |
Comments suppressed due to low confidence (1)
includes/class-endpoint.php:1078
- The function reference 'micropub_get_plugin_version' is being called, but this function no longer exists in the codebase. It was replaced with 'get_plugin_version()' in the namespace. This should be '\Micropub\get_plugin_version()' or use the Micropub class method directly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@dshanske do you directly call Micropub classes somewhere? do we need to bridge from the old classes to the new ones? |
|
Not that I recall outside of the plugin.... |
- Add rest/ directory with Endpoint_Controller and Media_Controller - Controllers extend WP_REST_Controller and use Micropub trait - Add separate Discovery class for endpoint discovery - Update Micropub singleton to properly hook into rest_api_init, init, admin_notices - Add MICROPUB_PLUGIN_VERSION constant - Remove old Base, Endpoint, and Media classes
dshanske
left a comment
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.
Very different, but can't see any issue here.
Resolve conflicts: - .distignore: Combined entries from both branches - includes/class-micropub-endpoint.php: Keep deleted (replaced by namespaced version) - includes/class-render.php: Keep namespace prefix, add PHPDoc documentation Also added PHPDoc documentation to micropub_syndicate-to filter in the new namespaced endpoint controller.
Summary
Modernizes the plugin architecture by adding PHP namespaces and a PSR-4-like autoloader, matching the structure used in the webmention plugin.
Changes
Micropubnamespace to all classesclass-autoloader.php)class-micropub.php)class-micropub-base.php→class-base.php(Micropub\Base)class-micropub-endpoint.php→class-endpoint.php(Micropub\Endpoint)class-micropub-media.php→class-media.php(Micropub\Media)class-micropub-render.php→class-render.php(Micropub\Render)class-micropub-error.php→class-error.php(Micropub\Error)templates/directory (settings page was never implemented)phpcs.xmlconfigurationBreaking Changes
External code referencing the old class names will need to update to the new namespaced versions:
Micropub_Base→\Micropub\BaseMicropub_Endpoint→\Micropub\EndpointMicropub_Media→\Micropub\MediaMicropub_Render→\Micropub\RenderWP_Micropub_Error→\Micropub\ErrorTest plan
./vendor/bin/phpcs --standard=phpcs.xml