WordPress.org

Ready to get started?Download WordPress

Forums

WPML comment merging
Amends to make WPML Comment Merging work again (4 posts)

  1. Simon Wheatley
    Code for the People
    Posted 2 years ago #

    We've got the comment merging working with the latest WordPress and WPML for all post types. Caveat: I have a very strong feeling that this patch won't help if you want to use translated comments, but I may be wrong about that (so test if you want to use this feature and don't just trust me).

    Replace the merge_comments function in the latest version of the plugin with this:

    function merge_comments($comments, $post_ID) {
    	global $sitepress;
    	remove_filter( 'comments_clauses', array( $sitepress, 'comments_clauses' ) );
    	// get all the languages for which this post exists
    	$languages = icl_get_languages('skip_missing=1');
    	$post = get_post( $post_ID );
    	$type = $post->post_type;
    	foreach($languages as $code => $l) {
    		// in $comments are already the comments from the current language
    		if(!$l['active']) {
    			$otherID = icl_object_id($post_ID, $type, false, $l['language_code']);
    			$othercomments = get_comments( array('post_id' => $otherID, 'status' => 'approve', 'order' => 'ASC') );
    			$comments = array_merge($comments, $othercomments);
    		}
    	}
    	if ($languages) {
    		// if we merged some comments in we need to reestablish an order
    		usort($comments, 'sort_merged_comments');
    	}
    	//
    	add_filter( 'comments_clauses', array( $sitepress, 'comments_clauses' ) );
    
    	return $comments;
    }

    If you want a diff, you can find one here: http://pastebin.com/f1VFG4t2

  2. Simon Wheatley
    Code for the People
    Posted 2 years ago #

    Just noticed that you need the following amend to the beginning of merge_comment_count to make that work correctly with custom post types:

    function merge_comment_count($count, $post_ID) {
    	// get all the languages for which this post exists
    	$languages = icl_get_languages('skip_missing=1');
    	$post = get_post( $post_ID );
    	$type = $post->post_type;
    
    	foreach($languages as $l) {

    (then the rest unchanged)

    Here's the diff.

  3. Elan42.com
    Member
    Posted 2 years ago #

    Hi guys,
    why are you not updating the plugin ?

    I opened that discussion months ago:
    http://wordpress.org/support/topic/dont-works?replies=2#post-2187531

    And now I discovered that you resolved the problem here,
    but the plugin in wordpress plugin repository is still not working.

    Thanks for the good fix.

  4. bchoward
    Member
    Posted 2 years ago #

    Thank you Simon for this fix. Saved my bacon!!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic