Skip to content

Conversation

@juanmaguitar
Copy link

@juanmaguitar juanmaguitar commented Dec 22, 2025

What?

Refactors the experiment lifecycle method from register() to init() across the entire codebase to better reflect its purpose of initializing experiments.

Closes #145

Why?

The term "register" was misleading as it suggested the experiments were being registered into a system, when in reality this method is called after registration to initialize the experiment's hooks and functionality. The method init() more accurately describes what the method does - it initializes the experiment by setting up WordPress hooks, filters, and actions when the experiment is enabled and loaded.

This improves code clarity and aligns the method naming with its actual behavior in the experiment lifecycle:

  1. Experiments are registered to the registry via Experiment_Registry::register()
  2. Experiments are initialized via Experiment::init() when they're loaded

How?

  • Updated the Experiment interface to declare init() instead of register()
  • Updated the Abstract_Experiment abstract class to declare abstract public function init()
  • Updated all concrete experiment implementations:
    • Example_Experiment
    • Excerpt_Generation
    • Image_Generation
    • Title_Generation
  • Updated Experiment_Loader::initialize_experiments() to call init()
  • Updated all test mock classes and test assertions
  • Updated developer documentation and inline comments

Testing Instructions

  1. Enable the AI Experiments plugin
  2. Go to Settings → AI Experiments
  3. Enable one or more experiments
  4. Verify the experiments load correctly and their functionality works as expected
  5. Check that no PHP errors or warnings appear in the debug log
  6. Run the full test suite: npm run test:php
  7. Verify all tests pass

Testing Instructions for Keyboard

Not applicable - this is an internal refactoring with no UI changes.

Open WordPress Playground Preview

Updated method names from `register()` to `init()` across various classes and interfaces to better reflect their purpose. This change enhances clarity in the codebase regarding the initialization of experiments and their hooks.
@github-actions
Copy link

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: juanmaguitar <juanmaguitar@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>
Co-authored-by: JasonTheAdams <jason_the_adams@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.89%. Comparing base (6478545) to head (50d96f7).
⚠️ Report is 7 commits behind head on develop.

Files with missing lines Patch % Lines
...eriments/Excerpt_Generation/Excerpt_Generation.php 0.00% 1 Missing ⚠️
.../Experiments/Title_Generation/Title_Generation.php 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop     #159   +/-   ##
==========================================
  Coverage      46.89%   46.89%           
  Complexity       208      208           
==========================================
  Files             19       19           
  Lines           1271     1271           
==========================================
  Hits             596      596           
  Misses           675      675           
Flag Coverage Δ
unit 46.89% <60.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@juanmaguitar
Copy link
Author

"Plugin Check" workflow is failing due to an issue reported at #160

@jeffpaul jeffpaul added this to the 0.2.0 milestone Dec 23, 2025
@jeffpaul
Copy link
Member

#160 has been merged in, so hopefully an update from develop will get the plugin check passing @juanmaguitar

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.

Rename experiment register() method to better reflect initialization

2 participants