Skip to content

Instantly share code, notes, and snippets.

@trepmal
Created June 21, 2012 03:03
Show Gist options
  • Select an option

  • Save trepmal/2963556 to your computer and use it in GitHub Desktop.

Select an option

Save trepmal/2963556 to your computer and use it in GitHub Desktop.
Images for Comments
<?php
/*
Plugin Name: Images for Comments
Plugin URI: http://trepmal.com/
Description: Replaces plain textarea with one that has media uploader and formatting buttons
Version: 1
Author: Kailey Lampert
Author URI: http://kaileylampert.com
*/
new Images_For_Comments();
class Images_For_Comments {
function __construct() {
add_filter( 'comment_form_field_comment', array( &$this, 'field_replacement' ) );
//add_action( 'wp_head', array( &$this, 'scripts' ) ); //quick fix for Twenty Eleven
}
function field_replacement( $field ) {
if (!is_single()) return $field;
global $post;
ob_start();
wp_editor( '', 'comment', array(
'tinymce' => false,
'textarea_rows' => 5,
'quicktags' => array(
'buttons' => 'em,strong,link,img,code',
)
) );
$editor = ob_get_contents();
ob_end_clean();
//hack to make sure comment media is attached to correct post
$editor = str_replace( 'post_id=0', 'post_id='.get_the_ID(), $editor );
return $editor;
}
function scripts() {
?>
<style>
#respond textarea {
width:100%;
}
</style>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment