wp_ajax_replyto_comment

Ajax handler for replying to a comment.

Description

wp_ajax_replyto_comment( (string) $action ); 

Parameters (1)

0. $action (string)
Action to perform.

Usage

  1. if ( !function_exists( 'wp_ajax_replyto_comment' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; 
  3.  
  4. // Action to perform. 
  5. $action = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_ajax_replyto_comment($action); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_replyto_comment( $action ) { 
  2. if ( empty( $action ) ) 
  3. $action = 'replyto-comment'; 
  4.  
  5. check_ajax_referer( $action, '_ajax_nonce-replyto-comment' ); 
  6.  
  7. $comment_post_ID = (int) $_POST['comment_post_ID']; 
  8. $post = get_post( $comment_post_ID ); 
  9. if ( ! $post ) 
  10. wp_die( -1 ); 
  11.  
  12. if ( !current_user_can( 'edit_post', $comment_post_ID ) ) 
  13. wp_die( -1 ); 
  14.  
  15. if ( empty( $post->post_status ) ) 
  16. wp_die( 1 ); 
  17. elseif ( in_array($post->post_status, array('draft', 'pending', 'trash') ) ) 
  18. wp_die( __(ERROR you are replying to a comment on a draft post.') ); 
  19.  
  20. $user = wp_get_current_user(); 
  21. if ( $user->exists() ) { 
  22. $user_ID = $user->ID; 
  23. $comment_author = wp_slash( $user->display_name ); 
  24. $comment_author_email = wp_slash( $user->user_email ); 
  25. $comment_author_url = wp_slash( $user->user_url ); 
  26. $comment_content = trim( $_POST['content'] ); 
  27. $comment_type = isset( $_POST['comment_type'] ) ? trim( $_POST['comment_type'] ) : ''; 
  28. if ( current_user_can( 'unfiltered_html' ) ) { 
  29. if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) ) 
  30. $_POST['_wp_unfiltered_html_comment'] = ''; 
  31.  
  32. if ( wp_create_nonce( 'unfiltered-html-comment' ) != $_POST['_wp_unfiltered_html_comment'] ) { 
  33. kses_remove_filters(); // start with a clean slate 
  34. kses_init_filters(); // set up the filters 
  35. } else { 
  36. wp_die( __( 'Sorry, you must be logged in to reply to a comment.' ) ); 
  37.  
  38. if ( '' == $comment_content ) 
  39. wp_die( __( ERROR please type a comment.' ) ); 
  40.  
  41. $comment_parent = 0; 
  42. if ( isset( $_POST['comment_ID'] ) ) 
  43. $comment_parent = absint( $_POST['comment_ID'] ); 
  44. $comment_auto_approved = false; 
  45. $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID'); 
  46.  
  47. // Automatically approve parent comment. 
  48. if ( !empty($_POST['approve_parent']) ) { 
  49. $parent = get_comment( $comment_parent ); 
  50.  
  51. if ( $parent && $parent->comment_approved === '0' && $parent->comment_post_ID == $comment_post_ID ) { 
  52. if ( ! current_user_can( 'edit_comment', $parent->comment_ID ) ) { 
  53. wp_die( -1 ); 
  54.  
  55. if ( wp_set_comment_status( $parent, 'approve' ) ) 
  56. $comment_auto_approved = true; 
  57.  
  58. $comment_id = wp_new_comment( $commentdata ); 
  59. $comment = get_comment($comment_id); 
  60. if ( ! $comment ) wp_die( 1 ); 
  61.  
  62. $position = ( isset($_POST['position']) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1'; 
  63.  
  64. ob_start(); 
  65. if ( isset( $_REQUEST['mode'] ) && 'dashboard' == $_REQUEST['mode'] ) { 
  66. require_once( ABSPATH . 'wp-admin/includes/dashboard.php' ); 
  67. } else { 
  68. if ( isset( $_REQUEST['mode'] ) && 'single' == $_REQUEST['mode'] ) { 
  69. $wp_list_table = _get_list_table('WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); 
  70. } else { 
  71. $wp_list_table = _get_list_table('WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); 
  72. $wp_list_table->single_row( $comment ); 
  73. $comment_list_item = ob_get_clean(); 
  74.  
  75. $response = array( 
  76. 'what' => 'comment',  
  77. 'id' => $comment->comment_ID,  
  78. 'data' => $comment_list_item,  
  79. 'position' => $position 
  80. ); 
  81.  
  82. $counts = wp_count_comments(); 
  83. $response['supplemental'] = array( 
  84. 'in_moderation' => $counts->moderated,  
  85. 'i18n_comments_text' => sprintf( 
  86. _n( '%s Comment', '%s Comments', $counts->approved ),  
  87. number_format_i18n( $counts->approved ) 
  88. ),  
  89. 'i18n_moderation_text' => sprintf( 
  90. _nx( '%s in moderation', '%s in moderation', $counts->moderated, 'comments' ),  
  91. number_format_i18n( $counts->moderated ) 
  92. ); 
  93.  
  94. if ( $comment_auto_approved ) { 
  95. $response['supplemental']['parent_approved'] = $parent->comment_ID; 
  96. $response['supplemental']['parent_post_id'] = $parent->comment_post_ID; 
  97.  
  98. $x = new WP_Ajax_Response(); 
  99. $x->add( $response ); 
  100. $x->send();