/**
  * Start things up by plugging us into all of filter and actions hooks we'll need to support custom comment type registration
  */
 public function __construct()
 {
     // 9 so that we run before most plugin code that way other plugins can add actions without interference
     add_filter('comment_row_actions', array($this, 'comment_row_actions'), 9, 2);
     add_filter('bulk_actions-edit-comments', array($this, 'bulk_actions'), 9, 2);
     add_filter('comment_status_links', array($this, 'comment_status_links_remove'), 9, 2);
     add_filter('comment_status_links', array($this, 'comment_status_links_add'), 11, 2);
     add_filter('wp_count_comments', array($this, 'wp_count_comments'), 10, 2);
     add_filter('comments_per_page', array($this, 'comments_per_page'));
     add_filter('comments_clauses', array($this, 'comments_clauses'));
     add_filter('admin_comment_types_dropdown', array($this, 'admin_comment_types_dropdown'));
     add_filter('get_avatar_comment_types', array($this, 'get_avatar_comment_types'));
     add_action('transition_comment_status', array($this, 'transition_comment_status'), 10, 3);
     add_action('wp_insert_comment', array($this, 'wp_insert_comment'));
     add_action('untrash_comment', array($this, 'untrash_unspam_comment'));
     add_action('unspam_comment', array($this, 'untrash_unspam_comment'));
     add_action('wp_set_comment_status', array($this, 'wp_set_comment_status'));
     // Doing this involves a performance hit, so it'll be off by default until a better method for this comes along
     if (bsocial_comments()->options()->register->filter_text) {
         // 11 so that we run after any translation code has done so
         add_filter('gettext', array($this, 'gettext'), 11, 3);
         add_filter('gettext_with_context', array($this, 'gettext_with_context'), 11, 4);
     }
     // END if
 }
 /**
  * Hook to admin_enqueue_scripts
  */
 public function admin_enqueue_scripts($current_page)
 {
     $script_config = apply_filters('go_config', array('version' => bsocial_comments()->version), 'go-script-version');
     wp_enqueue_style($this->id_base . '-admin', plugins_url('/css/bsocial-comments-feedback-admin.css', __FILE__), array(), $script_config['version']);
     wp_register_script($this->id_base . '-admin', plugins_url('/js/bsocial-comments-feedback-admin.js', __FILE__), array('jquery'), $script_config['version'], TRUE);
     // Only enqueue script when on a comment edit page where it's needed
     if ('comment.php' == $current_page || 'edit-comments.php' == $current_page) {
         wp_enqueue_script($this->id_base . '-admin');
     }
     // END if
 }
 /**
  * Enqueue admin JS
  */
 public function admin_enqueue_scripts($hook)
 {
     $script_config = apply_filters('go_config', array('version' => bsocial_comments()->version), 'go-script-version');
     wp_register_script($this->id_base . '-admin', plugins_url('/js/bsocial-comments-featured-admin.js', __FILE__), array('jquery'), $script_config['version'], TRUE);
     wp_enqueue_style($this->id_base . '-admin', plugins_url('/css/bsocial-comments-featured-admin.css', __FILE__), array(), $script_config['version']);
     //pass the hook to the javascript for comparison
     wp_localize_script($this->id_base . '-admin', 'bsocial_comments_featured_admin', array('hook' => $hook));
     $valid_bases = array('comment', 'edit-comments');
     if (!in_array(get_current_screen()->base, $valid_bases) && (!isset(get_current_screen()->post_type) && !post_type_supports(get_current_screen()->post_type, 'comments'))) {
         return;
     }
     // END if
     wp_enqueue_script($this->id_base . '-admin');
 }
 /**
  * Creates the post for a featured comment when given a valid comment_id
  */
 public function create_post($comment_id)
 {
     $comment = get_comment($comment_id);
     $parent = get_post($comment->comment_post_ID);
     $featured = $this->_get_featured_comment_text($comment->comment_content);
     // @TODO = wrap the content in a blockquote tag with the cite URL set to the comment permalink
     $post = array('post_title' => $featured, 'post_content' => $featured, 'post_name' => sanitize_title($featured), 'post_date' => bsocial_comments()->options()->featured_comments->use_commentdate ? $comment->comment_date : FALSE, 'post_date_gmt' => bsocial_comments()->options()->featured_comments->use_commentdate ? $comment->comment_date_gmt : FALSE, 'post_author' => $parent->post_author, 'post_parent' => $parent->ID, 'post_status' => $parent->post_status, 'post_password' => $parent->post_password, 'post_type' => $this->post_type_name);
     $post_id = wp_insert_post($post);
     // simple sanity check
     if (!is_numeric($post_id)) {
         return $post_id;
     }
     // save the meta
     update_post_meta($post_id, $this->meta_key . '-comment_id', $comment->comment_ID);
     update_comment_meta($comment->comment_ID, $this->meta_key . '-post_id', $post_id);
     // get all the terms on the parent post
     foreach ((array) wp_get_object_terms($parent->ID, get_object_taxonomies($parent->post_type)) as $term) {
         $parent_terms[$term->taxonomy][] = $term->name;
     }
     //END foreach
     // set those terms on the comment
     foreach ((array) $parent_terms as $tax => $terms) {
         wp_set_object_terms($post_id, $terms, $tax, FALSE);
     }
     //END foreach
     return $post_id;
 }
<?php

/*
Plugin Name: bSocial Blogging Comment Tools
Plugin URI: https://github.com/misterbisson/bsocial-comments
Description: Tools to extend WordPress comment functionality.
Version: 1.0
Author: Casey Bisson, Jamie Poitra
Author URI: http://maisonbisson.com/blog/
*/
require_once __DIR__ . '/components/class-bsocial-comments.php';
bsocial_comments();
    /**
     * hooked to bsocial_comments_feedback_info outputs feedback UI for a comment
     */
    public function feedback_info($comment, $args)
    {
        $message_logged_out = '<p>Sign in to %1$s this comment</p>';
        $message_logged_in = '<h2>Reason for flagging this comment:</h2>';
        $reasons = bsocial_comments()->options()->reasons;
        $message_fave_logged_out = apply_filters('bsocial_comments_feedback_fave_logged_out_message', sprintf($message_logged_out, 'fave', wp_login_url(get_permalink())), $comment);
        $message_flag_logged_out = apply_filters('bsocial_comments_feedback_flag_logged_out_message', sprintf($message_logged_out, 'flag', wp_login_url(get_permalink())), $comment);
        $message_flag_logged_in = apply_filters('bsocial_comments_feedback_flag_logged_in_message', sprintf($message_logged_in, 'flag'), $comment);
        // Make sure IDs are always unique
        $id_slug = $comment->comment_ID;
        if (isset($args['featured-comments']) && $args['featured-comments']) {
            $id_slug .= '-featured';
        }
        //end if
        ?>
		<div class="feedback-box">
			<section class="fave fave-logged-out">
				<?php 
        // this will need to be sanitized up stream as we must be able to support HTML in here
        echo wp_kses_post($message_fave_logged_out);
        ?>
			</section>
			<section class="flag flag-logged-out">
				<?php 
        // this will need to be sanitized up stream as we must be able to support HTML in here
        echo wp_kses_post($message_flag_logged_out);
        ?>
			</section>
			<section class="flag flag-logged-in">
				<form class="<?php 
        echo esc_attr(implode(' ', apply_filters('bsocial_comments_feedback_form_classes', array())));
        ?>
" action="<?php 
        echo esc_url($this->get_comment_feedback_url($comment->comment_ID, 'flag', FALSE, array('direction' => 'flag')));
        ?>
">
					<?php 
        // this will need to be sanitized up stream as we must be able to support HTML in here
        echo wp_kses_post($message_flag_logged_in);
        ?>
					<p>
						<?php 
        foreach ($reasons as $reason_id => $reason) {
            $id = "comment-{$id_slug}-reason-" . sanitize_key($reason_id);
            $name = preg_replace('/_reason_.+$/', '_reason', str_replace('-', '_', $id));
            ?>
							<label for="<?php 
            echo esc_attr($id);
            ?>
">
							<input
								type="radio"
								class="go-radio reason"
								name="<?php 
            echo esc_attr($name);
            ?>
"
								id="<?php 
            echo esc_attr($id);
            ?>
"
								value="<?php 
            echo esc_attr($reason['reason']);
            ?>
"
								data-reason-type="<?php 
            echo esc_attr($reason_id);
            ?>
"
							>
								<span><?php 
            /* using wp_kses_post because we wish to support HTML here */
            echo wp_kses_post($reason['display-text']);
            ?>
</span>
							</label>
							<?php 
        }
        //end foreach
        $id = "comment-{$id_slug}-reason-other";
        $name = preg_replace('/_reason_.+$/', '_reason', str_replace('-', '_', $id));
        $description_id = "comment-{$id_slug}-reason-description";
        $description_name = str_replace('-', '_', $description_id);
        ?>
						<label for="<?php 
        echo esc_attr($id);
        ?>
">
							<input type="radio" class="go-radio reason" name="<?php 
        echo esc_attr($name);
        ?>
" id="<?php 
        echo esc_attr($id);
        ?>
" value="Other" data-reason-type="other">
							<span>Other</span>
						</label>
					</p>
					<p class="other-describe">
						<textarea placeholder="Please describe" class="reason-description" name="<?php 
        echo esc_attr($description_name);
        ?>
" id="<?php 
        echo esc_attr($description_id);
        ?>
"></textarea>
						<span class="required">Describe your reason for flagging this comment.</span>
					</p>
					<p>
						<button class="button primary comment-flag-confirm" disabled="true">Flag</button>
						<button class="button link cancel">Cancel</button>
					</p>
				</form>
			</section>
		</div>
		<?php 
    }