Skip to content

Bug Inconsistency: Standardize post meta key naming with the wpai_ prefix #866

Description

@hbhalodia

Description

The plugin's options are almost universally namespaced with the wpai_ prefix (wpai_features_enabled, wpai_feature_*, wpai_version, etc.), but the post meta keys are inconsistent:

Current meta key Prefix Where registered
wpai_meta_description wpai_ SEO_Integration::FALLBACK_META_KEY
ai_generated ai_ Image Generation feature
ai_generated_summary ai_ Summarization experiment
ai_note ai_ Comment Generation experiment

wpai_meta_description already follows the convention, so it can serve as the reference. The two ai_-prefixed keys (ai_generated, ai_generated_summary) should be renamed so all plugin-owned meta consistently uses the wpai_ prefix.

This makes plugin data easier to identify, query, and clean up (e.g. the uninstall routine can then rely on a single wpai_ prefix sweep).

Proposed rename

Old key New key
ai_generated wpai_generated
ai_generated_summary wpai_generated_summary
ai_note wpai_note

(Exact new names are open for discussion — the goal is simply a consistent wpai_ prefix.)

Important: this is a breaking change and needs a data migration

Renaming a meta key changes:

  1. The row stored in wp_postmeta (existing content keeps the old key).
  2. The row stored in wp_commentmeta (existing content keeps the old key).
  3. The REST API field name (since these are registered with show_in_rest), which the editor JS reads/writes.

So the rename must ship with a migration that copies existing values from the old key to the new key (and removes the old one) for all affected posts, comments meta, plus a lockstep update of every PHP and JS reference. Without a migration, existing AI-generated flags and saved summaries would be orphaned.

Files to change

1. Meta registration

2. PHP read/write of the meta

3. Editor JavaScript / TypeScript (must change in lockstep with REST field)

4. New migration

  • includes/Admin/Upgrades/V_x_x_x.php (new) — extend Abstract_Upgrade, copy ai_generatedwpai_generated and ai_generated_summarywpai_generated_summary for existing posts, then delete the old keys.
  • includes/Admin/Upgrades.php (line ~51, UPGRADE_CLASSES) — register the new upgrade class (follows the existing V0_5_0 / V0_6_0 / V1_0_0 pattern).

5. Uninstall cleanup

  • includes/Admin/Uninstall.php (delete_meta()) — update the meta key patterns; after the rename, both keys fall under the wpai_ prefix so the cleanup can be simplified accordingly.

6. Tests

  • tests/Integration/Includes/Features/Image_Generation/Image_GenerationTest.php -
    $this->assertEquals( 'integer', $meta['ai_generated']['type'], 'ai_generated meta type should be integer' );
    $this->assertTrue( $meta['ai_generated']['show_in_rest'], 'ai_generated meta should be available in REST API' );
  • tests/Integration/Includes/Abilities/Image_ImportTest.php -
    $this->assertSame( '1', get_post_meta( $result['image']['id'], 'ai_generated', true ), 'AI-generated flag should be saved' );
  • tests/Integration/Includes/Experiments/Editorial_Notes/Editorial_NotesTest.php and wp-content/plugins/ai/tests/e2e/specs/experiments/editorial-updates.spec.js
  • Add a test for the new migration (old key → new key, old key removed).

Acceptance criteria

  • ai_generated, ai_generated_summary and ai_note renamed to wpai_-prefixed keys across PHP and JS.
  • A migration moves existing meta from old keys to new keys and removes the old keys, for all affected posts/attachments.
  • REST + editor behavior (AI image label, generated summaries, bulk summarize) works unchanged after the rename.
  • Uninstall cleanup and tests updated.

Step-by-step reproduction instructions

  1. Enable AI Plugin.
  2. Generate AI summary on any post/page with content.
  3. Check the DB, and notice the meta stored for that post ID has key ai_generated_summary.
  4. Generate the meta description.
  5. Check for the same post ID and would have key wpai_meta_description.

Screenshots, screen recording, code snippet

  • None

Environment info

  • WordPress 7.0.1.
  • AI plugin develop branch.
  • No extra plugin/theme activated.

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except the AI plugin.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Usage of AI tool

  • Claude Opus 4.8 to generate the description and PR title.
  • Used to make it more polished and detailed.

Metadata

Metadata

Assignees

Labels

[Type] BugSomething isn't working

Type

Projects

Status
Needs review

Relationships

None yet

Development

No branches or pull requests

Issue actions