From 4181491e5149f5858002f52d768f41da2e551425 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 29 Sep 2025 17:22:07 +0100 Subject: [PATCH] Remove legacy setting (#554) 'Match Posts by Title' has not be of utility for some years now. It's use of deprecated wp functions is the precipitating cause of its removal --- admin/network-options.php | 17 ----------------- admin/webhook-settings.php | 29 ---------------------------- lib/discourse.php | 1 - lib/sync-discourse-topic.php | 37 ------------------------------------ 4 files changed, 84 deletions(-) diff --git a/admin/network-options.php b/admin/network-options.php index ca991af..877ace2 100644 --- a/admin/network-options.php +++ b/admin/network-options.php @@ -391,23 +391,6 @@ class NetworkOptions { ); } - /** - * Outputs markup for webhook-match-old-topics input. - */ - public function webhook_match_old_topics_checkbox() { - $this->checkbox_input( - 'webhook-match-old-topics', - __( - 'Match WordPress posts with Discourse topics by title.', - 'wp-discourse' - ), - __( - 'Sync Comment Data will attempt to match posts to topics by title if other methods of matching have not worked.', - 'wp-discourse' - ) - ); - } - /** * Outputs markup for use-discourse-user-webhook checkbox. */ diff --git a/admin/webhook-settings.php b/admin/webhook-settings.php index bede2d5..c225363 100644 --- a/admin/webhook-settings.php +++ b/admin/webhook-settings.php @@ -79,17 +79,6 @@ class WebhookSettings { 'discourse_webhook_settings_section' ); - add_settings_field( - 'discourse_webhook_match_old_topics', - __( 'Match Posts by Title', 'wp-discourse' ), - array( - $this, - 'webhook_match_old_topics_checkbox', - ), - 'discourse_webhook', - 'discourse_webhook_settings_section' - ); - add_settings_field( 'discourse_use_discourse_user_webhook', __( 'Update Userdata', 'wp-discourse' ), @@ -182,24 +171,6 @@ class WebhookSettings { ); } - /** - * Outputs markup for webhook-match-old-topics input. - */ - public function webhook_match_old_topics_checkbox() { - $this->form_helper->checkbox_input( - 'webhook-match-old-topics', - 'discourse_webhook', - __( - 'Match WordPress posts with Discourse topics by title.', - 'wp-discourse' - ), - __( - 'Sync Comment Data will attempt to match posts to topics by title if other methods of matching have not worked.', - 'wp-discourse' - ) - ); - } - /** * Outputs markup for use-discourse-user-webhook checkbox. */ diff --git a/lib/discourse.php b/lib/discourse.php index c41b6e4..daa91d8 100644 --- a/lib/discourse.php +++ b/lib/discourse.php @@ -124,7 +124,6 @@ class Discourse { protected $discourse_webhook = array( 'use-discourse-webhook' => 0, 'webhook-secret' => '', - 'webhook-match-old-topics' => 0, 'use-discourse-user-webhook' => 0, 'webhook-match-user-email' => 0, ); diff --git a/lib/sync-discourse-topic.php b/lib/sync-discourse-topic.php index fbc4eac..14b2cc9 100644 --- a/lib/sync-discourse-topic.php +++ b/lib/sync-discourse-topic.php @@ -174,14 +174,6 @@ class SyncDiscourseTopic extends DiscourseBase { $post_ids = $this->get_post_ids_from_topic_id( $topic_id ); - // For matching posts that were published before the plugin was saving the discourse_topic_id as post_metadata. - if ( ! $post_ids && ! empty( $this->options['webhook-match-old-topics'] ) ) { - $post_id = $this->get_post_id_by_title( $post_title, $topic_id ); - if ( $post_id ) { - $post_ids[] = $post_id; - } - } - if ( $post_ids ) { foreach ( $post_ids as $post_id ) { update_post_meta( $post_id, 'wpdc_sync_post_comments', 1 ); @@ -244,35 +236,6 @@ class SyncDiscourseTopic extends DiscourseBase { return null; } - /** - * Tries to match a WordPress post with a Discourse topic by the topic title. - * - * This function is used to match posts that have been published through the WP Discourse plugin prior to version 1.4.0 - * with their associated Discourse topics. It assumes that the posts are using the 'post' type. There is a filter - * available to change the post type. There's also an action that can be hooked into if you'd like to try to match - * more than one post type. - * - * @param string $title The topic_title returned from Discourse. - * @param int $topic_id The topic_id returned from Discourse. - * - * @return int|null - */ - protected function get_post_id_by_title( $title, $topic_id ) { - $id = null; - $title = strtolower( $title ); - $post_type = apply_filters( 'wpdc_webhook_get_page_by_title_post_type', 'post' ); - $post = get_page_by_title( $title, 'OBJECT', $post_type ); - if ( $post && ! is_wp_error( $post ) ) { - $id = $post->ID; - // Update the 'discourse_topic_id' metadata so that it can be used on the next webhook request. - update_post_meta( $id, 'discourse_topic_id', $topic_id ); - } - - do_action( 'wpdc_webhook_after_get_page_by_title', $title ); - - return $id; - } - /** * Tries to find a WordPress posts that are associated with a Discourse topic_id. *