Issues with setting up ajax comments

Scrteenshots:






Here’s except of the repeated errors in the logs:

[2022-04-16 00:08:52] comment_formatter.ERROR: format.missing_post_data {"keys":"discourse_permalink,discourse_comments_raw"} 
[2022-04-16 00:09:06] comment_formatter.ERROR: format.missing_post_data {"keys":"discourse_permalink,discourse_comments_raw"} 
[2022-04-16 00:09:08] comment_formatter.ERROR: format.missing_post_data {"keys":"discourse_permalink,discourse_comments_raw"} 
[2022-04-16 00:09:50] comment_formatter.ERROR: format.missing_post_data {"keys":"discourse_permalink,discourse_comments_raw"}

When I make a new post it works and the topic is created. However, when a comment is made in Discourse it’s not synced to WordPress.

I didn’t change much you can see the setting above. Any ideas about what I’m doing wrong or just missing?

I followed the guides here:

edit:
I have this same error, but in the forums, this was the only search result for:
comment_formatter.ERROR: format.missing_post_data

Is this a known issue? Or can be solved?

1 Like

Hey there,

  1. If possible, could you link me to a post on your Wordpress site where you’re seeing the issue?
  2. Is there a reason you’re using ajax comments? (you have “Load Comments With Ajax” checked).
1 Like

Hi Angus,

  1. Yes, sure: 60 Linux Networking commands and scripts (that’s the only synced post for now)
  2. I checked Ajax only as a last resort after hours of things not working fully. I’ve now unchecked ajax. I’m guessing without webhooks, the interval for syncing took a while.

It seems to work now, but the format is a bit inelegant. I’m guessing I have to figure out CSS?

Also, is there a way to show the “join the discussion” type links to our Discourse forum homepage for older WP blog posts? - In other words, if there are no comments on a post, or if the post has not been previously synced to Discourse, then the plugin will add a general link to my Discourse forum homepage instead of leaving it blank.

Thanks much for helping.

1 Like

Yes, how it displays will depend on your theme. There is minimal styling in the plugin itself.

The join the discussion link will not appear on topics that are not linked. You can add something like this yourself, separately from the plugin though by using the comments_template filter in your theme’s functions.php file. I haven’t tested this code, but something like this will work:


use WPDiscourse\Utilities\Utilities as DiscourseUtilities;

function non_discourse_comments_template( $comment_template ) {
   global $post;
   $post_id = $post->ID;
   $discourse_post_id = get_post_meta( $post_id, 'discourse_post_id', true );

   if ($discourse_post_id) {
     return;
   } else {
     $options = DiscourseUtilities::get_options();
     $discourse_permalink = $options['url'];
     $link_text = "Join the Discussion";
     return '<div class="wpdc-join-discussion"><a class="wpdc-join-discussion-link" href="' . esc_url_raw( $discourse_permalink ) . '" target="_blank" rel="noreferrer noopener">' . esc_html( $link_text ) . '</a></div>';
   }
}
add_filter( "comments_template", "non_discourse_comments_template" );
2 Likes

4 posts were split to a new topic: Comment formatter errors in logs

Thanks again for the additional help and guidance!

I’ve been reading and searching for CSS to paste that would improve the layout even just a little.

However, as I’m not familiar with CSS/styling (other than pasting existing CSS), I would like to make very basic modifications to the styling of the imported comments. Namely, to use smaller avatar images beside the discourse usernames in the comments and add a horizontal line between posts:

Is that something simple enough that I can paste some code into /admin/customize/themes/1/common/scss/edit ?

Edit:
For anyone else, I was able to solve gravatar resize using the code here:

2 Likes

I was able to style comments. Very basic was my styling lol… but an improvement.

The only thing left to do is to remove the list of participants at the bottom of WP- Discourse imported comment section.

I can’t use this code because it throws an error due to using “self”. Is they are a workaround?

ob_start();
?>
<div id="comments" class="comments-area discourse-comments-area">
<div class="comments-title-wrap">
<h2 class="comments-title discourse-comments-title"><?php echo esc_html( self::get_text_options( 'notable-replies-text' ) ); ?></h2>
</div>
<ol class="comment-list">{comments}</ol>
<div class="respond comment-respond">
<h3 id="reply-title" class="comment-reply-title">
<?php echo esc_html( self::get_text_options( 'continue-discussion-text' ) . ' ' ); ?>
<?php self::discourse_topic_link( self::new_tab() ); ?>
</h3>
<p class="more-replies">{more_replies}</p>
</div>
</div>
<?php
$output = ob_get_clean();

I removed these lines:

<div class="comment-reply-title">
<h4 class="discourse-participants"><?php echo esc_html( self::get_text_options( 'participants-text' ) ); ?></h4>
<p>{participants}</p>
</div>

However, the “self” syntax error I’m not sure how to solve. Especially these lines:

<?php echo esc_html( self::get_text_options( 'continue-discussion-text' ) . ' ' ); ?>
<?php self::discourse_topic_link( self::new_tab() ); ?>

I didn’t remove the participants’ section. If you are thinking about doing so, give it a chance, as with other Discourse features; the Devs have put some thought into it. It shows all participants even after only 5 of 15 posts are imported. (changeable setting) Also, the imported responses exclude posts by level 0 forum members. Which I find helpful.

In short, over time, I’ve noticed that it’s not all the time the participants’ list and the imported comments will be identical. In many cases, it helps to provide the blog reader a more accurate view of the level of comment activity without having to import every single post or risk importing posts from the first sign-up members. (which I believe can be changed in settings as well)

2 Likes

I think the comment_formatter.ERROR: format.missing_post_data is being over eager in its reporting. I’ll tweak that for the next release. Thanks for following up about it. I wouldn’t worry about it for now, unless you’re experiencing a visible issue.

There isn’t a formal guide on comment styling. There are a few other topics, e.g. this one. Wordpress themes come in so many shapes and sizes that it was initially thought to leave this up to the site admin. That said, I think some additional guides may be useful.

I’ve put it on my list to add to the WP Discourse guides. I won’t publish that for a few weeks, but if you get stuck with styling in the meantime let me know and I’ll give you some pointers.

2 Likes