Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Unpublished Post: Editor Comments
- Plugin URI: http://travis.pflanz.me/2012/unpublished-post-editor-comments-wordpress-plugin
- Description: Plugin for allowing Editors and Administrators to leave comments on an unpublished post. The comments will be published to the frontend when the post is published.
- Author: Travis Pflanz
- Version: 1.0
- Author URI: http://Travis.Pflanz.ME
- */
- /* Add a new meta box to the admin menu. */
- add_action( 'admin_menu', 'editor_comment_create_meta_box' );
- /* Saves the meta box data. */
- add_action( 'save_post', 'editor_comment_save_meta_data' );
- function editor_comment_create_meta_box() {
- global $theme_name;
- add_meta_box( 'post-meta-boxes', __('Editor Comment on the Post'), 'post_meta_boxes', 'post', 'normal', 'high' );
- }
- function editor_comment_post_meta_boxes() {
- /* Array of the meta box options. */
- $meta_boxes = array(
- 'editor_commets' => array( 'name' => 'Comments', 'title' => __('Comments', 'upec'), 'type' => 'textarea' ),
- );
- return apply_filters( 'editor_comment_post_meta_boxes', $meta_boxes );
- }
- function post_meta_boxes() {
- global $post;
- $meta_boxes = editor_comment_post_meta_boxes(); ?>
- <table class="form-table">
- <?php foreach ( $meta_boxes as $meta ) :
- $value = get_post_meta( $post->ID, $meta['name'], true );
- if ( $meta['type'] == 'text' )
- get_meta_text_input( $meta, $value );
- elseif ( $meta['type'] == 'textarea' )
- get_meta_textarea( $meta, $value );
- elseif ( $meta['type'] == 'select' )
- get_meta_select( $meta, $value );
- endforeach; ?>
- </table>
- <?php
- }
- function get_meta_text_input( $args = array(), $value = false ) {
- extract( $args ); ?>
- <tr>
- <th style="width:10%;">
- <label for="<?php echo $name; ?>"><?php echo $title; ?></label>
- </th>
- <td>
- <input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo wp_specialchars( $value, 1 ); ?>" size="30" tabindex="30" style="width: 97%;" />
- <input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
- </td>
- </tr>
- <?php
- }
- function get_meta_select( $args = array(), $value = false ) {
- extract( $args ); ?>
- <tr>
- <th style="width:10%;">
- <label for="<?php echo $name; ?>"><?php echo $title; ?></label>
- </th>
- <td>
- <select name="<?php echo $name; ?>" id="<?php echo $name; ?>">
- <?php foreach ( $options as $option ) : ?>
- <option <?php if ( htmlentities( $value, ENT_QUOTES ) == $option ) echo ' selected="selected"'; ?>>
- <?php echo $option; ?>
- </option>
- <?php endforeach; ?>
- </select>
- <input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
- </td>
- </tr>
- <?php
- }
- function get_meta_textarea( $args = array(), $value = false ) {
- extract( $args ); ?>
- <tr>
- <th style="width:10%;">
- <label for="<?php echo $name; ?>"><?php echo $title; ?></label>
- </th>
- <td>
- <textarea name="<?php echo $name; ?>" id="<?php echo $name; ?>" cols="60" rows="4" tabindex="30" style="width: 97%;"><?php echo wp_specialchars( $value, 1 ); ?></textarea>
- <input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
- </td>
- </tr>
- <?php
- }
- function editor_comment_save_meta_data( $post_id ) {
- global $post;
- $meta_boxes = array_merge( editor_comment_post_meta_boxes() );
- foreach ( $meta_boxes as $meta_box ) :
- if ( !wp_verify_nonce( $_POST[$meta_box['name'] . '_noncename'], plugin_basename( __FILE__ ) ) )
- return $post_id;
- elseif ( 'post' == $_POST['post_type'] && !current_user_can( 'edit_post', $post_id ) )
- return $post_id;
- $data = stripslashes( $_POST[$meta_box['name']] );
- if ( get_post_meta( $post_id, $meta_box['name'] ) == '' )
- add_post_meta( $post_id, $meta_box['name'], $data, true );
- elseif ( $data != get_post_meta( $post_id, $meta_box['name'], true ) )
- update_post_meta( $post_id, $meta_box['name'], $data );
- elseif ( $data == '' )
- delete_post_meta( $post_id, $meta_box['name'], get_post_meta( $post_id, $meta_box['name'], true ) );
- endforeach;
- }
- add_action('pending_to_future', 'insert_editor_comment');
- add_action('pending_to_publish', 'insert_editor_comment');
- function insert_editor_comment( $data){
- global $current_user;
- get_currentuserinfo();
- global $post;
- $time = current_time('mysql');
- $editor_comment = get_post_meta($post->ID, 'Comments', TRUE);
- $data = array(
- 'comment_post_ID' => $post->ID,
- 'comment_author' => $current_user->display_name,
- 'comment_author_email' => $current_user->user_email,
- 'comment_author_url' => $current_user->user_url,
- 'comment_content' => $editor_comment,
- 'comment_type' => 'comment',
- 'comment_parent' => 0,
- 'user_id' => $current_user->ID ,
- 'comment_author_IP' => '127.0.0.1',
- 'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
- 'comment_date' => $time,
- 'comment_approved' => 1,
- 'comment_subscribe' => 'Y',
- );
- wp_insert_comment($data);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement