Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Makes the textarea the first field of the comment form.
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: T5 Comment Textarea On Top
* Plugin URI: http://toscho.de/?p=2239
* Description: Makes the textarea the first field of the comment form.
* Version: 2012.09.04
* Author: Thomas Scholz <info@toscho.de>
* Author URI: http://toscho.de
* License: MIT
* License URI: http://www.opensource.org/licenses/mit-license.php
*/
/* We use just one function for both jobs.
* The first filter hooks in very late to let other plugins
* (anti spam and such) do their job first.
*/
add_filter( 'comment_form_defaults', 't5_move_textarea', 100 );
add_action( 'comment_form_top', 't5_move_textarea' );
/**
* Take the textarea code out of the default fields and print it on top.
*
* @wp-hook comment_form_defaults 100
* @wp-hook comment_form_top
* @param array $input Default fields if called as filter
* @return string|void
*/
function t5_move_textarea( $input = array () )
{
static $textarea = '';
if ( 'comment_form_defaults' === current_filter() )
{
// Copy the field to our internal variable …
$textarea = $input['comment_field'];
// … and remove it from the defaults array.
$input['comment_field'] = '';
return $input;
}
// Now called on comment_form_top, $textarea is filled.
print apply_filters( 'comment_form_field_comment', $textarea );
}

tevyaw commented Oct 29, 2014

You should put this on the WP.org repository. If you update it, it'd be nice to get auto-updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment