The problem was that when using get_comment_text
the usual comment_text
filter was not used at all and some filters where missing:
add_filter( 'comment_text', 'wptexturize' );
add_filter( 'comment_text', 'convert_chars' );
add_filter( 'comment_text', 'make_clickable', 9 );
add_filter( 'comment_text', 'force_balance_tags', 25 );
add_filter( 'comment_text', 'convert_smilies', 20 );
add_filter( 'comment_text', 'wpautop', 30 );
Reference: https://stackoverflow.com/a/2609197/1165121
also using comment_text()
did not work because its then filtered infinite.
removing the rating filter temporary did also not work in my themes funcion.
This is what now works for me:
i combined all values regarding to rating in an array an use it as parameter for the filter apply_filters('wpcr_comment_tut_add_title_to_text', $comment_text, $rating, $comment)
.
/wp-post-comment-rating/inc/function.php line 136
///// show rating stars with visitors comment /////
add_filter('comment_text','wpcr_comment_tut_add_title_to_text',99,2);
function wpcr_comment_tut_add_title_to_text($comment_text, $comment){
$wpcr_options = get_option('wpcr_settings'); // no need for $wpdb
$rating = array( // all rating values combined for better filtering afterwards
'enable' => apply_filters('wpcr_options_checkbox1', $wpcr_options['checkbox1'], $comment), // "Enable rating" possible overwrite on per post_type basis
'text' => '', // added to $comment_text
'star_pos' => 'above', // default stars position
'filtered_comment_content' => $comment_text, // Was allready filtered
);
if ( $rating['enable'] ) { // "Enable rating"
$rating['rating'] = get_comment_meta($comment->comment_ID, 'rating', true);
if ( $rating['rating'] ) {
$rating_inner_text = '(' . $rating['rating'] . '/5)';
$rating['text'] = '<div class="cmstr-out"><span class="wpcr_author_stars" data-rating="' . $rating['rating'] . '" ></span></div><span class="tval">' . $rating_inner_text . '</span>';
if ( isset($wpcr_options['cmstr_pos']) && $wpcr_options['cmstr_pos'] === 0 ) {
$rating['star_pos'] = 'below';
}
if ( $rating['star_pos'] === 'above' ) {
$comment_text = $rating['text'] . $rating['filtered_comment_content'];
} else {
$comment_text = $rating['filtered_comment_content'] . $rating['text'];
}
}
}
return apply_filters('wpcr_comment_tut_add_title_to_text', $comment_text, $rating, $comment);
}
This is now how my theme works (with getting all the rating values, its much smaller):
add_filter('wpcr_comment_tut_add_title_to_text', 'myTheme_comment_rating_comment_text', 10, 3);
function sandbox_comment_rating_comment_text($comment_text, $rating, $comment){
$profile_post_ID = 1234; // on profile page or descendants
$star_pos = isset($rating['star_pos']) ? $rating['star_pos'] : 'above'; // default stars position
$enable_rating = isset($rating['enable']) ? $rating['enable'] : false;
if ( $enable_rating ) { // "Enable rating"
if ( isset($rating['rating']) ) {
$post = get_post();
$parents = get_post_ancestors($post);
$parents[] = $post->ID;
if ( in_array($profile_post_ID, $parents) ) {
$star_pos = 'above';
}
if ( $star_pos === 'above' ) {
$comment_text = $rating['text'] . $rating['filtered_comment_content'];
} else {
$comment_text = $rating['filtered_comment_content'] . $rating['text'];
}
}
}
return $comment_text;
}