Skip to content

Instantly share code, notes, and snippets.

@markjaquith
Created January 17, 2012 10:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markjaquith/1626078 to your computer and use it in GitHub Desktop.
Save markjaquith/1626078 to your computer and use it in GitHub Desktop.
Moderation Buddy
<?php
/*
Plugin Name: Moderation Buddy
Description: A friendly assistent to make sure you don't get behind on your comment moderation tasks.
Version: 0.1
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
class CWS_Moderation_Buddy_Plugin {
static $instance;
private $bar;
function __construct() {
self::$instance = $this;
add_action( 'init', array( $this, 'init' ), 15 );
}
function init() {
if ( isset( $GLOBALS['wp_admin_bar'] ) && is_object( $GLOBALS['wp_admin_bar'] ) ) {
add_action( 'wp_before_admin_bar_render', array( $this, 'add_css' ) );
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ) );
}
}
function comments_pending() {
return wp_count_comments()->moderated;
}
function admin_bar_menu( $bar ) {
$this->bar = $bar;
}
function render_css( $level = 1 ) {
switch( $level ) {
case 3 :
echo $this->animate( '#FF3333', '0.5' );
break;
case 2 :
echo $this->animate( '#FF3333', '1' );
break;
case 1 :
default :
echo $this->animate( '#B94A00', '2' );
break;
}
}
function css_vendors() {
return array( '', '-moz-', '-webkit-' );
}
function css3( $prop, $value ) {
$return = '';
foreach ( $this->css_vendors() as $vendor ) {
$return .= $vendor . $prop . ':' . $value . ';';
}
return $return;
}
function css3_keyframes( $name, $frames ) {
$return = '';
foreach ( $this->css_vendors() as $vendor ) {
$return .= '@' . $vendor . 'keyframes ' . $name . ' {' . $frames . '}';
}
return $return;
}
function animate( $color, $duration ) {
return $this->style( $this->css3_keyframes('cwsmoderationbuddy', '
80% { background-color: ' . $color . ' }
100% { background-color: #464646 }'
) .
'#wp-admin-bar-comments { background-color: ' . $color . ' !important;'
. $this->css3( 'animation-name', 'cwsmoderationbuddy' )
. $this->css3( 'animation-duration', $duration . 's' )
. $this->css3( 'animation-iteration-count', 'infinite' )
. $this->css3( 'animation-direction', 'alternate' )
. $this->css3( 'animation-timing-function', 'ease-in-out' ) );
}
function style( $css ) {
return '<style>' . $css . '</style>';
}
function add_css() {
if ( $this->bar->get_node( 'comments' ) ) {
$pending = $this->comments_pending();
if ( $pending < 5 ) {
return;
} elseif ( $pending < 10 ) {
$this->render_css( 1 );
} elseif ( $pending < 25 ) {
$this->render_css( 2 );
} else {
$this->render_css( 3 );
}
}
}
}
new CWS_Moderation_Buddy_Plugin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment