Last active
December 29, 2015 16:39
-
-
Save Zodiac1978/7698876 to your computer and use it in GitHub Desktop.
Threaded Comment Feed Enhancer - Adds an info text in comment body from comment feed if it is a threaded comment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Threaded Comment Feed Enhancer | |
* Plugin URI: http://torstenlandsiedel.de | |
* Text Domain: threaded-comment-feed-enhancer | |
* Domain Path: /languages | |
* Description: Enhances the threaded comments feed | |
* Version: 1.2.0 | |
* Author: Torstenlandsiedel | |
* Author URI: http://torstenlandsiedel.de | |
* License: GPLv3 | |
*/ | |
/* Thanks to Dominik Schilling (@ocean90) and Thomas Scholz (@toscho) for many hints */ | |
// Exit if accessed directly | |
if ( ! defined( 'ABSPATH' ) ) exit; | |
// Load Translation | |
function threaded_comment_feed_enhancer_init() { | |
load_plugin_textdomain( 'threaded-comment-feed-enhancer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); | |
} | |
add_action('plugins_loaded', 'threaded_comment_feed_enhancer_init'); | |
// Add info text in comment body if there is a threaded comment | |
function threaded_comment_feed_body_enhancer( $comment_text ) { | |
if ( ! is_comment_feed() ) | |
return $comment_text; | |
//$comment_object = get_comment( get_comment_ID() ); | |
$comment_id = get_comment_ID(); | |
$comment_object = get_comment( $comment_id ); | |
if ( ! $comment_object->comment_parent ) | |
return $comment_text; | |
$parent_comment_object = get_comment( $comment_object->comment_parent ); | |
$parent_comment_link = get_comment_link ( $parent_comment_object->comment_ID ); | |
$parent_comment_author = $parent_comment_object->comment_author; | |
$parent_comment_content = $comment_object->comment_content; | |
$message = sprintf( __( '(This is a reply to the <a href=\'%s\'>comment</a> from %s.)', 'threaded-comment-feed-enhancer' ), esc_url( $parent_comment_link ), esc_html( $parent_comment_author ) ); | |
$message .= '<br><br>'; | |
$message .= '<blockquote>' . $parent_comment_object->comment_content . '</blockquote>'; | |
$message .= '<br><br>'; | |
$message .= $comment_text; | |
return $message; | |
} | |
if ( get_option( 'thread_comments' ) ) { | |
add_filter ('comment_text', 'threaded_comment_feed_body_enhancer'); | |
add_filter ('comment_text_rss', 'threaded_comment_feed_body_enhancer'); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment