Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Automatic Sync not adding comment post ID #115

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions disqus/rest-api/class-disqus-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,25 +738,23 @@ private function comment_data_from_post( $post ) {
) );

if ( $post_query->have_posts() ) {
$wp_post_id = $post_query->post->ID;
wp_reset_postdata();
$wp_post_id = $post_query->posts[0]->ID;
}

// If that doesn't exist, get the and update the matching post metadata.
if ( null === $wp_post_id || false === $wp_post_id ) {
if ( empty($wp_post_id) ) {
$identifiers = $thread['identifiers'];
$first_identifier = count( $identifiers ) > 0 ? $identifiers[0] : null;

if ( null !== $first_identifier ) {
$ident_parts = explode( ' ', $first_identifier, 2 );
$wp_post_id = reset( $ident_parts );
if ( ! is_null( $first_identifier ) ) {
$wp_post_id = url_to_postid( $first_identifier );
}

// Keep the post's thread ID meta up to date.
update_post_meta( $wp_post_id, 'dsq_thread_id', $thread['id'] );
}

if ( null === $wp_post_id || false == $wp_post_id ) {
if ( empty( $wp_post_id ) ) {
throw new Exception( 'No post found associated with the thread.' );
}

Expand All @@ -779,7 +777,6 @@ private function comment_data_from_post( $post ) {

// Email is a special permission for Disqus API applications and won't be present
// if the user has not set the permission for their API application.
$author_email = null;
if ( isset( $author['email'] ) ) {
$author_email = $author['email'];
} elseif ( $author['isAnonymous'] ) {
Expand Down