Created
August 26, 2010 03:43
-
-
Save mjangda/550752 to your computer and use it in GitHub Desktop.
Patched version of the "Recent Comments" widget for WordPress to hide editorial comments
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 | |
/** | |
* Recent_Comments_EF widget class | |
* | |
* Patched for Edit Flow | |
* | |
* @since 2.8.0 | |
*/ | |
class WP_Widget_Recent_Comments_EF extends WP_Widget { | |
function WP_Widget_Recent_Comments_EF() { | |
$widget_ops = array('classname' => 'widget_recent_comments_ef', 'description' => __( 'The most recent comments (Edit Flow fix)' ) ); | |
$this->WP_Widget('recent-comments-ef', __('Recent Comments (Edit Flow Fix)'), $widget_ops); | |
$this->alt_option_name = 'widget_recent_comments_ef'; | |
if ( is_active_widget(false, false, $this->id_base) ) | |
add_action( 'wp_head', array(&$this, 'recent_comments_style') ); | |
add_action( 'comment_post', array(&$this, 'flush_widget_cache') ); | |
add_action( 'transition_comment_status', array(&$this, 'flush_widget_cache') ); | |
} | |
function recent_comments_style() { ?> | |
<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style> | |
<?php | |
} | |
function flush_widget_cache() { | |
wp_cache_delete('widget_recent_comments_ef', 'widget'); | |
} | |
function widget( $args, $instance ) { | |
global $comments, $comment; | |
$cache = wp_cache_get('widget_recent_comments_ef', 'widget'); | |
if ( ! is_array( $cache ) ) | |
$cache = array(); | |
if ( isset( $cache[$args['widget_id']] ) ) { | |
echo $cache[$args['widget_id']]; | |
return; | |
} | |
extract($args, EXTR_SKIP); | |
$output = ''; | |
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title']); | |
if ( ! $number = (int) $instance['number'] ) | |
$number = 5; | |
else if ( $number < 1 ) | |
$number = 1; | |
$comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'type' => 'comment' ) ); | |
$output .= $before_widget; | |
if ( $title ) | |
$output .= $before_title . $title . $after_title; | |
$output .= '<ul id="recentcomments">'; | |
if ( $comments ) { | |
foreach ( (array) $comments as $comment) { | |
$output .= '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; | |
} | |
} | |
$output .= '</ul>'; | |
$output .= $after_widget; | |
echo $output; | |
$cache[$args['widget_id']] = $output; | |
wp_cache_set('widget_recent_comments_ef', $cache, 'widget'); | |
} | |
function update( $new_instance, $old_instance ) { | |
$instance = $old_instance; | |
$instance['title'] = strip_tags($new_instance['title']); | |
$instance['number'] = (int) $new_instance['number']; | |
$this->flush_widget_cache(); | |
$alloptions = wp_cache_get( 'alloptions', 'options' ); | |
if ( isset($alloptions['widget_recent_comments_ef']) ) | |
delete_option('widget_recent_comments_ef'); | |
return $instance; | |
} | |
function form( $instance ) { | |
$title = isset($instance['title']) ? esc_attr($instance['title']) : ''; | |
$number = isset($instance['number']) ? absint($instance['number']) : 5; | |
?> | |
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p> | |
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of comments to show:'); ?></label> | |
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p> | |
<?php | |
} | |
} | |
add_action('widgets_init', 'init_ef_recent_comments_widget'); | |
function init_ef_recent_comments_widget() { | |
register_widget('WP_Widget_Recent_Comments_EF'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment