From 9c7b63325d6fe3f96a7c2407ca6b7f729ae90b03 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Jul 2026 18:02:07 +0000 Subject: [PATCH 1/3] Initial plan From 45969f207bdada538e6a46a7e9da0bcdbfc9308d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Jul 2026 18:05:46 +0000 Subject: [PATCH 2/3] feat(community-listings): add provider listings admin meta box for city posts --- .../Admin/ProviderListingsMetaBox.php | 303 ++++++++++++++++++ community-listings/includes/Core/Plugin.php | 2 + 2 files changed, 305 insertions(+) create mode 100644 community-listings/includes/Admin/ProviderListingsMetaBox.php diff --git a/community-listings/includes/Admin/ProviderListingsMetaBox.php b/community-listings/includes/Admin/ProviderListingsMetaBox.php new file mode 100644 index 0000000..9936979 --- /dev/null +++ b/community-listings/includes/Admin/ProviderListingsMetaBox.php @@ -0,0 +1,303 @@ +ID, 'listing_type', true ); + + if ( 'city' !== $listing_type ) { + return; + } + + \add_meta_box( + 'provider-listings-meta-box', + \__( 'Provider Listings', 'community-listings' ), + array( $this, 'render_meta_box' ), + 'community', + 'normal', + 'high' + ); + } + + /** + * Render the Provider Listings meta box. + * + * @since 2.2.5 + * + * @param \WP_Post $post Post object. + * @return void + */ + public function render_meta_box( \WP_Post $post ): void { + $raw_json = \get_post_meta( $post->ID, 'provider_listings', true ); + $raw_json = \is_string( $raw_json ) ? $raw_json : ''; + + $formatted_json = $raw_json; + $decoded_json = null; + + if ( '' !== $raw_json ) { + $decoded_json = \json_decode( $raw_json, true ); + + if ( \JSON_ERROR_NONE === \json_last_error() ) { + $pretty_json = \json_encode( $decoded_json, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE ); + + if ( false !== $pretty_json ) { + $formatted_json = $pretty_json; + } + } + } + + $provider_count = \is_array( $decoded_json ) && \array_is_list( $decoded_json ) ? \count( $decoded_json ) : 0; + $byte_count = \strlen( $formatted_json ); + $nonce = \wp_create_nonce( self::NONCE_ACTION ); + ?> + + +

+ bytes + · + +

+ + + update( + $wpdb->postmeta, + array( 'meta_value' => $json_string ), + array( + 'post_id' => $post_id, + 'meta_key' => 'provider_listings', + ), + array( '%s' ), + array( '%d', '%s' ) + ); + + if ( false === $updated ) { + return; + } + + if ( 0 === $updated && ! \metadata_exists( 'post', $post_id, 'provider_listings' ) ) { + $wpdb->insert( + $wpdb->postmeta, + array( + 'post_id' => $post_id, + 'meta_key' => 'provider_listings', + 'meta_value' => $json_string, + ), + array( '%d', '%s', '%s' ) + ); + } + } + + /** + * Add invalid JSON flag to redirect URL. + * + * @since 2.2.5 + * + * @param string $location Redirect URL. + * @return string + */ + public function append_invalid_json_query_arg( string $location ): string { + \remove_filter( 'redirect_post_location', array( $this, __FUNCTION__ ) ); + return \add_query_arg( self::INVALID_JSON_QUERY_ARG, '1', $location ); + } + + /** + * Render invalid JSON admin notice. + * + * @since 2.2.5 + * + * @return void + */ + public function render_invalid_json_notice(): void { + $screen = \function_exists( 'get_current_screen' ) ? \get_current_screen() : null; + if ( ! $screen || 'community' !== $screen->post_type ) { + return; + } + + $invalid_flag = $_GET[ self::INVALID_JSON_QUERY_ARG ] ?? ''; + $invalid_flag = \is_string( $invalid_flag ) ? \sanitize_text_field( \wp_unslash( $invalid_flag ) ) : ''; + if ( '1' !== $invalid_flag ) { + return; + } + ?> +
+

+
+ Date: Mon, 17 Aug 2026 02:28:15 -0500 Subject: [PATCH 3/3] fix(community-listings): invalidate post-meta cache after direct writes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $wpdb->update()/insert() bypass update_post_meta() on purpose (it calls wp_unslash() and would corrupt the JSON's \" escapes), but that also skips WordPress' own cache invalidation. With a persistent object cache active, get_post_meta( $post_id, 'provider_listings' ) — including the WPGraphQL resolver — could keep serving the pre-edit JSON after a save. Addresses review feedback from Codex on PR #2. --- .../includes/Admin/ProviderListingsMetaBox.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/community-listings/includes/Admin/ProviderListingsMetaBox.php b/community-listings/includes/Admin/ProviderListingsMetaBox.php index 9936979..12778c3 100644 --- a/community-listings/includes/Admin/ProviderListingsMetaBox.php +++ b/community-listings/includes/Admin/ProviderListingsMetaBox.php @@ -261,6 +261,13 @@ public function save_provider_listings( int $post_id, \WP_Post $post, bool $upda array( '%d', '%s', '%s' ) ); } + + // The write above bypasses update_post_meta()/add_metadata() on purpose (they + // call wp_unslash() and would corrupt the JSON's \" escapes), but that also + // means WordPress' own cache invalidation never runs. Without this, a + // persistent object cache keeps serving the stale value to get_post_meta() + // callers — including the WPGraphQL resolver — until the cache group expires. + \wp_cache_delete( $post_id, 'post_meta' ); } /**