Skip to content

Add city-only Provider Listings meta box with JSON-safe persistence#2

Open
sanruiz with Copilot wants to merge 2 commits into
mainfrom
copilot/feat-add-admin-ui-meta-box
Open

Add city-only Provider Listings meta box with JSON-safe persistence#2
sanruiz with Copilot wants to merge 2 commits into
mainfrom
copilot/feat-add-admin-ui-meta-box

Conversation

Copilot AI commented Jul 6, 2026

Copy link
Copy Markdown

community posts currently store provider_listings as a raw JSON string consumed by WPGraphQL, but editors had no admin UI to maintain it. This change adds an editor-facing meta box for city pages and preserves JSON escape integrity by writing via $wpdb instead of metadata APIs that unslash values.

  • Admin UI (city-level only)

    • Registers a Provider Listings meta box on community edit screens only when listing_type = city.
    • Places the box in normal context with high priority.
    • Renders a 20-row JSON textarea prefilled with pretty-printed JSON (JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) when parseable.
  • Editor feedback in-box

    • Displays live byte count and provider count.
    • Adds inline client-side JSON validation on blur/change/input:
      • invalid JSON → red border + inline error
      • valid JSON → clears error state
  • Save path and data integrity

    • Adds nonce generation/verification (wp_create_nonce / wp_verify_nonce) and edit_posts capability gating.
    • Validates submitted JSON with json_decode; invalid payloads are not persisted and surface an admin notice:
      • Provider Listings not saved: invalid JSON.
    • Persists valid JSON through direct SQL update to wp_postmeta using $wpdb->update() (with insert fallback when row is missing), avoiding update_post_meta() unslash corruption.
  • Plugin wiring

    • Introduces ProviderListingsMetaBox admin component and registers it in plugin bootstrap.
$updated = $wpdb->update(
    $wpdb->postmeta,
    [ 'meta_value' => $json_string ],
    [ 'post_id' => $post_id, 'meta_key' => 'provider_listings' ],
    [ '%s' ],
    [ '%d', '%s' ]
);

Copilot AI changed the title [WIP] Add admin UI meta box for editing provider listings in community plugin Add city-only Provider Listings meta box with JSON-safe persistence Jul 6, 2026
Copilot AI requested a review from sanruiz July 6, 2026 18:06
@sanruiz sanruiz marked this pull request as ready for review July 7, 2026 18:02
@sanruiz

sanruiz commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

LGTM

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5d8464a878

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +238 to +240
$updated = $wpdb->update(
$wpdb->postmeta,
array( 'meta_value' => $json_string ),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Invalidate post-meta cache after direct writes

When a persistent object cache is enabled, this direct $wpdb->update() leaves WordPress' post_meta cache stale. The method already calls get_post_meta() for listing_type, which primes the meta cache for the whole post before this write, so later get_post_meta( $post_id, 'provider_listings', true ) calls (including WPGraphQL consumers) can keep returning the old JSON even though the database row changed. Please clear or update the post meta cache after both the update and insert paths while preserving the direct SQL write.

Useful? React with 👍 / 👎.

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.

feat: Add admin UI meta box for editing provider_listings in community-listings plugin

2 participants