Comment Overload Original Zip: Comment Overload 1.0includes/wp-ajax.php<?php if (!class_exists('WP_Ajax')) { class WP_Ajax { function __construct( $ajax_prefix = 'a', $nopriv_prefix = 'n' ) { $regex = "/^($ajax_prefix)?($nopriv_prefix)?_|^($nopriv_prefix)?($ajax_prefix)?_/"; $methods = get_class_methods( $this ); foreach ( $methods as $method ) { if ( preg_match( $regex, $method, $matches ) ) { if ( count( $matches ) > 1 ) { $action = preg_replace( $regex, '', $method ); if ( count( $matches ) == 3 ) { add_action( "wp_ajax_$action", array( $this, $method ) ); add_action( "wp_ajax_nopriv_$action", array( $this, $method ) ); } else { if ( $matches[1] == $ajax_prefix ) { add_action( "wp_ajax_$action", array( $this, $method ) ); } else { add_action( "wp_ajax_nopriv_$action", array( $this, $method ) ); } } } } } } } } js/comment-overload.jsjQuery(document).ready( function($) { var co_max_nl = null, co_alert_msg = null, co_content = null co_total = null; //get the recommended maximum allowed $.post(comment_overload.ajaxurl, { 'action' : 'max_num_newlines' }, function(response) { co_max_nl = response; }, 'text' ); //get the the message we'll show if the max is breached $.post(comment_overload.ajaxurl, { 'action' : 'alert_when_max_reached' }, function(response) { co_alert_msg = response; }, 'text' ); //do magic if 'enter' key is pressed $('#comment').keyup( function( event ) { if (event.keyCode == '13') { co_content = $(this).val(), co_content = co_content.replace("/nn/g", "n"); co_content = co_content.split("n"); co_total = co_content.length -1; // alert( // 'co_total: ' + co_total + "n" + // 'co_max_nl: ' + co_max_nl + "n" + // 'co_alert_msg: ' + co_alert_msg + "n" + // '' // ); if ( co_total >= co_max_nl ) { co_alert_msg = co_alert_msg.replace(/%total%/g, co_total); co_alert_msg = co_alert_msg.replace(/%max%/g, co_max_nl); alert( co_alert_msg ); } } }); });readme.txt=== Comment Overload === Contributors: trepmal Tags: comments Donate link: http://kaileylampert.com/donate/ Requires at least: 3.2.1 (untested with other versions) Tested up to: 3.2.1 Stable tag: 1.0 Alert commenters when they begin writing too many paragraphs. == Description == Some posts make readers want to leave *really* long comments that would really be better suited as their own blog posts. This itty bitty plugin will give your rambling commenters a hint. Inspired by <a href="http://profiles.wordpress.org/users/jane/">Jane Wells</a> <a href="https://twitter.com/#!/janeforshort/status/111586232231931905">tweet</a> == Installation == 1. Unzip 'comment-overload.zip' and upload to your plugin directory (default: wp-content/plugins/). 2. Activate the plugin through the 'plugins' page in WP. 3. Customize in Settings > Discussion == Frequently Asked Questions == = none yet = == Changelog == = Version 1. = * Now with customizable options! = Version 0.1 = * Initial releasecomment-overload.php<?php /* Plugin Name: Comment Overload Plugin URI: http://trepmal.com/plugins/comment-overload Description: Alert commenters when they start writing too many paragraphs Version: 1.0 Author: Kailey Lampert Author URI: http://kaileylampert.com Copyright (C) 2011 Kailey Lampert 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 3 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, see <http://www.gnu.org/licenses/>. */ require_once( plugin_dir_path( __FILE__ ) . 'includes/wp-ajax.php' ); class Comment_Overload extends WP_Ajax { function __construct() { parent::__construct(); wp_enqueue_script( 'comment-overload', plugins_url( 'js/comment-overload.js', __FILE__ ), array( 'jquery' ) ); wp_localize_script( 'comment-overload', 'comment_overload', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); add_filter( 'admin_init' , array( &$this , 'register_fields' ) ); } function an_max_num_newlines() { $options = $this->_options(); die( strval( $options['max'] ) ); } function an_alert_when_max_reached() { $options = $this->_options(); die( $options['alert'] ); } function register_fields() { register_setting( 'discussion', 'comment_overload_options', array( &$this, '_validate') ); add_settings_field('comment_overload', __( 'Comment Overload' , 'comment-overload' ) , array(&$this, 'fields') , 'discussion', 'default', array() ); } function fields() { $options = $this->_options(); _e( 'Maximum number of new lines' , 'comment-overload' ); echo ' <input class="small-text" type="text" name="comment_overload_options[max]" value="'. $options['max'] .'" /><br />'; _e( 'If maximum is reached, tell the commenter' , 'comment-overload' ); echo '<br /> <textarea class="large-text code" name="comment_overload_options[alert]">'. $options['alert'] .'</textarea>'; echo '<code>%total%</code> = '; _e( 'number of paragraphs being written by user' , 'comment-overload' ); echo '<br /><code>%max%</code> = '; _e( 'maximum number recommended' , 'comment-overload' ); } function _validate( $input ) { $input[ 'max' ] = intval( $input[ 'max' ] ); $input[ 'alert' ] = esc_js( $input[ 'alert' ] ); return $input; } function _options() { return get_option( 'comment_overload_options', array( 'max' => 3, 'alert' => '%total% paragraphs? How about you write a blog post and link it here?' ) ); } } new Comment_Overload(); Pages: 1 2