Discourse WordPress plugin version 0.7.0

The wp-discourse plugin got updated to version 0.7.0 just now. Thanks to @simon, @pjv, @Grex315, @tnorthcutt, and @AdamCapriola for these updates!

:warning: Have you made changes to the HTML templates at all? The templates are no longer handled from the plugin admin, they must be customized with filters. See Template Customization from the GH wiki.

0.7.0: May 18th, 2016

  • Move templates out of options (#194)
  • Validate settings (#189)
  • Add notices to indicate connection status (#193)
  • Sanitize admin options page (#196)
  • Sanitize comment template output (#195)
  • Add type argument to text input method (#192)
  • Use cached categories when there is a configuration error (#191)
  • Fix name property not available in participants array (#187)
  • Use wp_get_current_user (#185)
  • Fix add_query_arg undefined offset notice (#184)
  • Update Discourse post on WP post update (#176)
  • Better method for including comments script and other small tweaks (#181)
  • Allow choosing Discourse category per post (#177)
  • Replace avatar URL function (#172)
  • Fix timezone for custom timestamp (#162)

You can download the new version from Releases · discourse/wp-discourse · GitHub or via Composer

10 Likes

Hei @benword, its possible see the example in action of this plugin?

Any chance it’ll get submitted through wordpress.org so that we can get automated updates that don’t lose settings? I assume this is a pain in the butt to do.

1 Like

Sure. Check out any post in http://blog.discourse.org/ for instance. We’re using this plugin.

Yep, we’re actively working towards this together with @simon plus @benword kindly offering his guidance.

3 Likes

Very cool!

Thank you :slight_smile:

It seems that the plugin was submitted to the Plugin Directory a few days ago:

Looks like it’s the official plugin, but i find it quite strange that nobody mentioned this here or on Github. Can anyone confirm that this is the real deal and we won’t lose our settings after each update with this?

Yes that’s the official wp-discourse plugin. We want to finish writing the plugin’s documentation and update its version number before giving it much publicity on here. If you already have the plugin installed, wait until the version number goes past 0.7.0 before updating it. For a new installation of the plugin, using the version in the plugin directory will be fine.

4 Likes

I’ve got a test version of Discourse installed (last week) and a test blog created (today) and I’m seeing quirks. Before these tests, I went through all of the Wordpress updates. Wordpress 4.5.3, and wp-discourse Version 0.9.1 (which I do not see a topic for).

Note settings for historical comments and changed minimum score:

Yet:

And that’s even though two users have commented on the Discourse side:

Suggestions for what I might be doing wrong?

(I rarely do anything with Wordpress, so I’m not very sure I’ve done everything right.)

Check your setting for ‘debug mode’. By default the plugin only syncs the Discourse comments once every 10 minutes. By enabling ‘debug mode’ it will sync the comments on every page request.

It looks like the problem might be your ‘Min number of replies’ setting. I think the default value of that is now ‘1’.

4 Likes

I updated to 0.9.1, but sadly it didn’t fix the few quirks I’ve had with 0.7.0 and earlier versions of the plugin. Which are:

  • The {comment_url} tag seems to only output the current page URL with /%7Bcomment_url%7D added to the end. For example: http://blog.discourse.org/2016/07/reply-by-email-enabled-for-all-discourse-customers/{comment_url}.

  • As mentioned on GitHub, the Emoji images sometimes have the wrong URL. The weird thing is that this only happens with some Emojis and comments, while others are fine.

  • I was able to edit discourse-comment.php to change the Leave a reply/Replies/Reply-Strings, but I would have to do that with every update. Is there any way to do this via the functions.php? I’ve tried the method from the wiki, but that didn’t work.

Is there any way to fix these problems? And thanks to everyone for the great new features added in 0.7.0 and above, which are awesome! :tada:

3 Likes

Yeah, I tried that. The main index page shows “2 comments”, but the actual post page (where the comments would appear) still shows “Start the discussion” AND the supposedly disabled Wordpress-native comment. And that’s this morning, well after a ten minute update window.

But did you try this?

2 Likes

No, I missed that. Adding more replies did work, so that’s it.

2 Likes

I’ll look at that.

Yes this is because we’re trying to fix the Discourse urls with a regular expression :stuck_out_tongue:

It falls apart if there is an absolute image path followed by a relative one. I think the emoji image paths have been fixed in the latest version of Discourse, so the best solution is to update the version of Discourse you are using.

Does this work for you?

function discourse_no_replies( $input ) {
	ob_start();
	?>

	<div id="comments" class="comments-area">
		<div class="respond comment-respond">
			<h3 id="reply-title" class="comment-reply-title"><a href="{topic_url}">Join the discussion on our forum</a></h3>
		</div>
	</div>

  <?php
	$output = ob_get_clean();
	return $output;
}
add_filter( 'discourse_no_replies_html', 'discourse_no_replies' );

Edit: If all you are trying to do is change the text content, there is an easier way to do it. I’ll add some documentation for overriding the plugin’s text content soon. But here is a quick example that could be added to your theme’s functions.php file.

add_filter( 'gettext', 'change_continue_discussion_text', 20, 3 );
function change_continue_discussion_text( $translated_text, $text, $domain ) {
	switch ( $translated_text ) {
		case 'Continue the discussion' :
			$translated_text = __( 'Join the discussion', 'wp-discourse' );
			break;
	}

	return $translated_text;
}
1 Like

Thanks for noticing that! It’s not included in any of the default templates, but it wasn’t doing anything at all. I’ve sent a PR that makes the {comment_url} equal the post_permalink + the comment number.

Yes, I’ve tried the add_filter( 'gettext', 'change_continue_discussion_text', 20, 3 ); method, but that erased several text blocks from the panel, while doing nothing on the site, so I just edited the plugin. I’m not even shure if I can translate that part, since it hooks into the comments_number and overwrites it? Or do I just need to use discourse_comments_count?

/**
 * Returns the comments number.
 *
 * If Discourse comments are enabled, returns the 'discourse_comments_count', otherwise
 * returns the $count value. Hooks into 'comments_number'.
 *
 * @param int $count The comment count supplied by WordPress.
 *
 * @return mixed|string
 */
function comments_number( $count ) {
	global $post;
	if ( $this->use_discourse_comments( $post->ID ) ) {
		$this->sync_comments( $post->ID );
		$count = get_post_meta( $post->ID, 'discourse_comments_count', true );
		if ( ! $count ) {
			$count = 'Leave a reply';
		} else {
			$count = ( 1 === intval( $count ) ) ? '1 Reply' : $count . ' Replies';
		}
	}

	return $count;
}

Also, thank you so much for your help and the quick fixes regarding the Emojis and {comment_url}!

Edit:

I’ve just noticed another problem with comments.js and links to YouTube. It seems unable to get the correct ID and replaces it with “undefined”:

<a href="https://www.youtube.com/watch?v=undefined" class="fancybox-youtube">https://www.youtube.com/watch?v=undefined</a>

This worked fine on 0.6.6…strange.

1 Like

Right, that bit of text has not been internationalized. I’ll do that right away and then hooking into gettext will work.

Thanks, I’ll fix that.

1 Like

I can’t reproduce this. If you get a chance could you try again?

Edit: OK, now I can reproduce it. It’s being escaped by WordPress.

1 Like

Just pushed version 0.9.3 to the WordPress plugin repository. It includes fixes for:

  • substituting the comment url for the comment_url tag
  • not escaping the data-youtube-id attribute
  • internationalizing the comments_number function

Here’s a sample function for changing the comments number text:

add_filter( 'gettext', 'change_comments_number_text', 20, 3 );
function change_comments_number_text( $translated_text, $text, $domain ) {
	switch ( $translated_text ) {
		case 'Leave a reply' :
			$translated_text = __( 'Please leave a reply', 'wp-discourse' );
			break;

		case 'Reply' :
			$translated_text = __( 'Response', 'wp-discourse' );
			break;

		case 'Replies' :
			$translated_text = __( 'Responses', 'wp-discourse' );
			break;
	}

	return $translated_text;
}
3 Likes