WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Pulling comment image into comment RSS Feed (2 posts)

  1. teso
    Member
    Posted 6 months ago #

    Hello - I am using the Comment Images plugin ( http://wordpress.org/plugins/comment-images/ ) which allows my users to upload an image to their comments within posts. However, the comment RSS feed doesn't grab the image to include along with comment text. I tried to create the below filter (I'm amateur) to include the image in the feed, but I can't get it working. FYI, "comment_image" within the below filter is used as the comment image meta in the Comment Images plugin's code, and "$comment_image" is used to render the image in a paragraph element appended to the actual comment (not RSS). Any help with the filter or a suggested new approach will be much appreciated.

    function image_in_comment_feed($image) {
                if(is_comment_feed()) {
                    $comment_id = get_comment_ID();
            		$comment_image = get_comment_meta($comment_id, 'comment_image', true);
                    $output .= '
                    <img src="' . $comment_image['url'] . '" alt="" />
                    ';
                    $output .= '</div>
                    ';
                    $image = $image.$output;
                }
                return $image;
            }
            add_filter('comment_content','image_in_comment_feed');
  2. teso
    Member
    Posted 5 months ago #

    This pulls in comment images and resizes Oembed Vimeo and Youtube in the comments RSS feed (sorry for the poor variables convention):

    function change_vimeo_width($contentwv) {
    if (is_comment_feed()) {
    $post_id = get_the_ID();
    		 	$comments = get_comments( $post_id );
    	   foreach ($comments as $comment) {
     $comment_id = get_comment_ID($comment);
     $contentwv = get_comment_text($comment_id);
     $retstringwv= 'width="269"';
     $retstringhv= 'height="auto"';
    	$patternwv = '(width=[\'\"](\d+)[\'\"])'; //pattern to look for
    	$patternhv = '(height=[\'\"](\d+)[\'\"])';
        if (false !== strpos($contentwv,"youtube")) {
           $replacedwidthv = preg_replace($patternwv, $retstringwv, $contentwv );
           return preg_replace($patternhv, $retstringhv, $replacedwidthv );
        } elseif (false !== strpos($contentwv,"vimeo")) {
           $replacedwidthv = preg_replace($patternwv, $retstringwv, $contentwv );
           return preg_replace($patternhv, $retstringhv, $replacedwidthv );
        } elseif (get_comment_meta($comment_id, 'comment_image', true)) {
            		$comment_image = get_comment_meta($comment_id, 'comment_image', true);
                    $output .= '
                    <img src="' . $comment_image['url'] . '" alt="" />
                    ';
                    $output .= '</div>
                    ';
                    $contentwv = $contentwv.$output;
        	return $contentwv;}
        }
        }
        return $contentwv;
    }
    add_filter('comment_text','change_vimeo_width');

Reply

You must log in to post.

About this Topic