Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress - Show comment-numbers in a comment-thread
<?php
/**
* Plugin Name: Show Comment Number
* Plugin URI: http://neun12.de
* Text Domain:
* Domain Path:
* Description: Dieses Plugin zeigt die laufende Kommentar-Nummer in einem Kommentar-Thread an.
* Author: Ralf Albert
* Version: 0.1
* Author URI: http://neun12.de/
* Donate URI: http://neun12.de/
* License: GPL
* Last change: 05.12.11 04:00:00
*/
/**
License:
==============================================================================
Copyright 2010 Ralf Albert (email : neun12@googlemail.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Requirements:
==============================================================================
This plugin requires WordPress >= 2.8 and tested with PHP Interpreter >= 5.2.9.
*/
// do not use this script without WordPress
if( ! defined( 'ABSPATH' ) )
die( "Cheetin' uh!?" );
else
add_action( 'plugins_loaded', array( 'ShowCommentNumbers', 'start_plugin' ) );
if( ! class_exists( 'ShowCommentNumbers' ) ){
class ShowCommentNumbers
{
private static $instance = NULL;
private static $comment_count = 1;
public function __construct(){
add_action( 'init', array( &$this, 'cpt_hook' ) );
}
public static function start_plugin(){
if( NULL == self::$instance )
self::$instance = new self;
return self::$instance;
}
public function cpt_hook(){
add_action( 'comment_text', array( &$this, 'show_comment_number' ) );
}
public static function show_comment_number( $content ){
global $current_user;
if( ! isset( $current_user->data->wp_capabilities['administrator'] ) || 1 != $current_user->data->wp_capabilities['administrator'] )
return $content;
$content .= '<hr />#' . self::$comment_count;
self::$comment_count++;
return $content;
}
} // .end class ShowCommentNumbers
} // .end if-class-exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.