How can I allow editors to leave comments on posts that have not yet been published?

On my NFL football blog all users are allowed to make blog posts. New registrants are given contributor status. When users make a post it is reviewed by an editor, then the editor schedules the post to publish at a time fitting our blog schedule.

Multiple editors have asked me if they could make a comment on the article right after they edit the post and schedule it to be published, but before it is actually published.

Read More

By comments, I mean comments on the article content, not comments to the contributor about their writing style, grammar, spelling, etc. or comments that other editors can see in the backend. I use Peter’s Post Notes and Peter’s Collaboration E-mails to handle communication with contributors about these issues/situations.

What I need, example: A contributor writes an article about Peyton Manning signing with the Denver Broncos. The editor is notified at 10pm that the post has been submitted for review. He/she goes in to check the post for grammar, spelling, tags, proper category, etc. The editor makes all the necessary corrections and schedules the post to publish at 9am tomorrow. Now, the editor wants to leave his thoughts about Peyton Manning’s contract with the Broncos for the world to see. The problem, the post publishes at 9am tomorrow, but he is reading the post at 10pm today… and does not want to come back 11 hours later to leave a comment on a post he is reading right now.

This makes sense to allow the editor to comment before the post publishes, since the editor has already read the post, so I would like to make it easier for editors if possible, rather than the editor needing to come back once the post has published to make their comments.

I really have no preference as to whether the timestamp on the comment is the same as the post publish time or the time the comment was actually made, even if it was before the post was scheduled to publish.

I found a forum post that is two years old ( http://core.trac.wordpress.org/ticket/11810 ) discussing a vulnerability in WordPress that used to allow comments on unpublished posts, but I simply cannot find a way to allow Editors to leave comments on unpublished posts in WordPress 3.

Related posts

Leave a Reply

2 comments

  1. It depends on who the comments are for, are they for the administrators and editors or are they also for the contributors?

    I’ve setup a system, somewhat elaborate, which handles some of what you’re asking, however the easiest way to achieve something like this is by using custom fields.

    In particular, a custom metabox with repeating fields which allows you to add multiple fields (for example textareas) for which editors can leave their comments.

    Depending on how you have your blog structured, contributors may or may not be able to see those comments. Usually they will see them if they have access to the dashboard. If on the other hand they are contributing via the front end of your site then they wont see those comments unless you query your custom fields into your template.

    Either way, you can also restrict the view of those fields to a certain user class.

    I highly recommend using the WP Alchemy Metabox Class found HERE

    It’s powerful, well documented and relatively easy to use with plenty of example metabox files that you can use right out the gate and to help you wrap your head around their usage.

    UPDATE

    Ok I’m just thinking aloud here but my thoughts on this are that you will still need to use a custom field from within the post-edit screen for which your editor can leave his/her comment however on post publish, you then hook into wp_comments and take the value of the custom field and have it inserted into comments.

    However it might be just as easy to call the custom field value from within your theme file but within the section where you display your actual comments. Then in fact you could quite easily style the comments to make them standout in a unique fashion (being editorial comments).

    But if you desperately don’t want to do that then you need to be thinking along the lines of… (conceptual code below)

    add_action('pending_to_publish_CUSTOM_POST_TYPE_NAME', 'insert_editor_comment');
    
    function insert_editor_comment( $data){
    
    $time = current_time('mysql');
    
    $data = array(
        'comment_post_ID' => 1,
        'comment_author' => 'admin',
        'comment_author_email' => 'admin@admin.com',
        'comment_author_url' => 'http://',
        'comment_content' => 'content here',
        'comment_type' => '',
        'comment_parent' => 0,
        'user_id' => 1,
        '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,
    );
    
    wp_insert_comment($data);
    }
    

    Again this is just conceptual, I’ve never done something like this but it should get you thinking along the right path. If I get a moment I might even test it out! Although I am sure many others could chime in and seal this deal for you quite easily.

  2. Through the thought process initiated by userabuser, more research and trial and error, I have come up with a solution.

    I have added a custom meta field using Easy Content Types (simply because I have used this plugin for a while) and added the following code to my functions.php

    if (current_user_can('editor')){
    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, 'ecpt_comment', 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);
    }
    }
    

    References

    Additional

    The meta box for comments is only visible for editor status and above.

    Being that an editor can choose whether to publish a post immediately, or schedule it to be published later, I added actions to save the comment on both instances.

    I also automatically subscribed editors to new comments made on the post.

    If you have suggestions to improve this method, please let me know!