WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I reply to a comment in the WP backend in the "Comments" section (edit-comments.php) I can only post the reply as the logged in user. Is it possible to select a certain user like in the "Add new post" section (post-new.php) where I have a dropdown with all users that are allowed to write posts?

share|improve this question
up vote 1 down vote accepted

Yes, add an user-select field in the comment form:

add_action('comment_form_after_fields', function(){

  // allow only users who can moderate comments to do this

  $user = wp_get_current_user();

    'name'     => 'alt_comment_user',
    'selected' => $user->ID,


When the form gets processed, check if an user has been selected and change the comment data before it gets inserted in the database:

add_filter('preprocess_comment', function($input){

  if(current_user_can('moderate_comments') && isset($_POST['alt_comment_user'])){    

    $user = get_user_by('id', (int)$_POST['alt_comment_user']);

    $my_fields = array(
      'comment_author'       => empty($user->display_name) ? $user->user_login : $user->display_name,
      'comment_author_email' => $user->user_email,
      'comment_author_url'   => $user->user_url,
      'user_ID'              => $user->ID,

    // escape for db input
    foreach($my_fields as &$field)
      $field = $GLOBALS['wpdb']->escape($field);

    $input = $my_fields + $input;   

  return $input;

ref: wp_dropdown_users

share|improve this answer
Thank you very much, this works for me! Is it also possible to include this function to the WP backend in the comments section when I reply to a comment? Example – user1706680 Oct 4 '12 at 14:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.