-
Notifications
You must be signed in to change notification settings - Fork 43
Feature/scaffold plugin structure issue 24 #38
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
Feature/scaffold plugin structure issue 24 #38
Conversation
|
@jeffpaul you're welcome. I'll assign it for review today after I finish my iteration on it. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @mohamed.khaled@9hdigital.com. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@jeffpaul it's ready now |
felixarntz
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.
@Ref34t Thank you for kick-starting this! I think a lot of it goes in the right direction, but a few pieces seem overly complicated or catering for theoretical problems that we don't know are relevant.
I encourage you to simplify the PR according to my feedback and break out all the documentation into separate PRs to streamline the review process and decouple documentation and marketing language from source code.
readme.txt
Outdated
| @@ -0,0 +1,89 @@ | |||
| === AI Experiments === | |||
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.
See above, adding the readme.txt should be its own PR, also as it requires a completely different expertise to review.
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.
Note that I added the readme.txt file as some changes were made to README.md that are more properly formatted for the WPORG txt version. Happy to strip that out and roll into a separate PR if helpful.
eee2a66 to
99fe2cb
Compare
felixarntz
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.
@Ref34t Getting close!
My last remaining concern is to make the feature abstraction a bit easier and also more error-proof to use.
- Add Invalid_Feature_Exception and Invalid_Feature_Metadata_Exception classes - Implement validate_feature method in Abstract_Feature with metadata checks - Refactor Feature_Loader to use new exceptions and validation - Update bootstrap to handle exceptions with user-friendly notices - Add comprehensive test coverage for validation scenarios
|
@felixarntz I've pushed a new commit covering the points you mentioned yesterday with some improvements over them. Here is what this last iteration does: Introducing a comprehensive validation system for the plugin's feature architecture, ensuring all features have valid metadata before they can be loaded. The changes centralize metadata management in the Summary of ChangesNew Exception Classes
Abstract_Feature
Feature_Loader
Example_Feature
bootstrap.php
|
dkotter
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.
Thanks for all the work here @Ref34t! Overall this looks good to me, noting I'd expect there to be some changes as we actually start building things out but I feel this is a good base to start with
Move the master enable/disable hook to the `Feature_Loader` to act as a global "master switch" and simplify the `Abstract_Feature` class. This improves separation of concerns and clarifies the roles of the classes.
felixarntz
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.
@Ref34t Thank you for the iterations, LGTM!
Just one minor thing that we can fix inline.
|
I'm seeing a PHP notice due to translations being loaded too early.
This happens when Maybe the feature initialization could be deferred to the |
| try { | ||
| $registry = new Feature_Registry(); | ||
| $loader = new Feature_Loader( $registry ); | ||
| $loader->register_default_features(); | ||
| $loader->initialize_features(); | ||
| } catch ( \Exception $e ) { | ||
| _doing_it_wrong( | ||
| __NAMESPACE__ . '\load', | ||
| sprintf( | ||
| /* translators: %s: Error message. */ | ||
| esc_html__( 'AI Plugin initialization failed: %s', 'ai' ), | ||
| esc_html( $e->getMessage() ) | ||
| ), | ||
| '0.1.0' | ||
| ); | ||
| } |
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.
+1 in regards to @mindctrl's comment, this should probably only happen on init:
- Only before
initthe user gets initialized by default, and that influences translation strings. It's a best practice to not run any translation functions before the user is normally initialized. - It's common in WordPress for things to be registered on
init, so this would tie in nicely with that practice. - It would enforce that no feature can break these patterns either.
initis sufficiently early in the WordPress bootstrap process for probably any kind of interaction a specific feature may need to support.
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.
@felixarntz I went with John's approach, is this satisfying for you? 65139be
better readibility Co-authored-by: Felix Arntz <flixos90@gmail.com>
| * @return bool True if PHP version is sufficient, false otherwise. | ||
| */ | ||
| function check_php_version(): bool { | ||
| if ( version_compare( phpversion(), AI_MIN_PHP_VERSION, '<' ) ) { |
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.
A small thing but when testing this PR against WP 6.9-beta1, using this constant set to 6.9 causes the plugin to show an admin notice and stops the bootstrap process.
AI plugin requires WordPress version 6.9 or higher. You are running WordPress version 6.9-beta1-61040-src.
I had to edit the value to make the plugin work during beta testing. Of course it's only a temporary inconvenience, but it made me wonder if we should use a different way, like checking if the wp_register_ability() function exists. Thoughts?
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.
@mindctrl I went with using a lower version for now until the release of 6.9, we can pump it up then
Move feature initialization from plugins_loaded to init hook by extracting the try/catch block into initialize_features() function. This allows the plugin to bootstrap dependencies on plugins_loaded for early access by integrations, while features initialize at the appropriate init timing.
Remove the $features parameter from register_default_features() method. This method should only register built-in default features. Custom features should use the ai_register_features action hook instead.
Change AI_MIN_WP_VERSION from 6.9 to 6.8 to allow the plugin to work with WordPress 6.9-beta1. Version comparison treats 6.9-beta1 as less than 6.9, preventing the plugin from loading during testing.
Add isset() check before accessing title['site'] to prevent PHP warning on front page where WordPress doesn't set the site key when is_front_page() returns true.
Scaffold Initial Plugin Structure
Implements #24 – Foundational plugin structure for the WordPress AI Experiments plugin.
Overview
This work delivers the core architecture for a modular, feature-based AI plugin. Features can be
registered, toggled, and tested in isolation, and the repository now follows the conventions we’ll
reuse as we add more experiments.
What’s Included
Core Architecture
initialization wiring.
disable logic and conditional feature support.
exposes the same surface.
Plugin Structure
ai/
├── ai.php
├── includes/
│ ├── Plugin.php
│ ├── Feature_Collection.php
│ ├── Feature_Registry.php
│ ├── Interfaces/
│ └── Abstracts/
├── features/
│ └── Example_Feature/
├── tests/
│ ├── bootstrap.php
│ ├── Integration/
│ │ ├── Features/
│ │ └── Includes/
│ └── Unit/
│ └── Includes/
├── docs/
│ ├── CONTRIBUTING.md
│ └── TESTING.md
├── phpcs.xml.dist
└── phpunit.xml.dist
Development Infrastructure
4 directories.
Documentation
contribution workflow.
Key Features
Encapsulation
Every experiment lives under its own directory in features/, making reviews, toggles, and
migrations painless.
Extensibility
Third-party developers can add custom features by hooking into the registry:
Feature Control
Features remain fully overridable: