Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. } elseif ( ! $status_obj->public && ! $status_obj->private ) {
  2. /**
  3. * Fires when a comment is attempted on a post in draft mode.
  4. *
  5. * @since 1.5.1
  6. *
  7. * @param int $comment_post_ID Post ID.
  8. */
  9. do_action( 'comment_on_draft', $comment_post_ID );
  10. exit;
  11. }
  12.  
  13. add_action( 'comment_on_draft', function( $comment_post_ID ) {
  14.  
  15. do_action( 'pre_comment_on_post', $comment_post_ID );
  16.  
  17. $comment_author = ( isset($_POST['author']) ) ? trim(strip_tags($_POST['author'])) : null;
  18. $comment_author_email = ( isset($_POST['email']) ) ? trim($_POST['email']) : null;
  19. $comment_author_url = ( isset($_POST['url']) ) ? trim($_POST['url']) : null;
  20. $comment_content = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;
  21.  
  22. // If the user is logged in
  23. $user = wp_get_current_user();
  24. if ( $user->exists() ) {
  25. if ( empty( $user->display_name ) )
  26. $user->display_name=$user->user_login;
  27. $comment_author = wp_slash( $user->display_name );
  28. $comment_author_email = wp_slash( $user->user_email );
  29. $comment_author_url = wp_slash( $user->user_url );
  30. if ( current_user_can( 'unfiltered_html' ) ) {
  31. if ( ! isset( $_POST['_wp_unfiltered_html_comment'] )
  32. || ! wp_verify_nonce( $_POST['_wp_unfiltered_html_comment'], 'unfiltered-html-comment_' . $comment_post_ID )
  33. ) {
  34. kses_remove_filters(); // start with a clean slate
  35. kses_init_filters(); // set up the filters
  36. }
  37. }
  38. } else {
  39. if ( get_option( 'comment_registration' ) || 'private' == $status ) {
  40. wp_die( __( 'Sorry, you must be logged in to post a comment.' ), 403 );
  41. }
  42. }
  43.  
  44. $comment_type = '';
  45.  
  46. if ( get_option('require_name_email') && !$user->exists() ) {
  47. if ( 6 > strlen( $comment_author_email ) || '' == $comment_author ) {
  48. wp_die( __( '<strong>ERROR</strong>: please fill the required fields (name, email).' ), 200 );
  49. } else if ( ! is_email( $comment_author_email ) ) {
  50. wp_die( __( '<strong>ERROR</strong>: please enter a valid email address.' ), 200 );
  51. }
  52. }
  53.  
  54. if ( '' == $comment_content ) {
  55. wp_die( __( '<strong>ERROR</strong>: please type a comment.' ), 200 );
  56. }
  57.  
  58. $comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
  59.  
  60. $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
  61.  
  62. $comment_id = wp_new_comment( $commentdata );
  63. if ( ! $comment_id ) {
  64. wp_die( __( "<strong>ERROR</strong>: The comment could not be saved. Please try again later." ) );
  65. }
  66.  
  67. $comment = get_comment( $comment_id );
  68.  
  69. /**
  70. * Perform other actions when comment cookies are set.
  71. *
  72. * @since 3.4.0
  73. *
  74. * @param object $comment Comment object.
  75. * @param WP_User $user User object. The user may not exist.
  76. */
  77. do_action( 'set_comment_cookies', $comment, $user );
  78.  
  79. $location = empty($_POST['redirect_to']) ? get_comment_link($comment_id) : $_POST['redirect_to'] . '#comment-' . $comment_id;
  80.  
  81. /**
  82. * Filter the location URI to send the commenter after posting.
  83. *
  84. * @since 2.0.5
  85. *
  86. * @param string $location The 'redirect_to' URI sent via $_POST.
  87. * @param object $comment Comment object.
  88. */
  89. $location = apply_filters( 'comment_post_redirect', $location, $comment );
  90.  
  91. wp_safe_redirect( $location );
  92. exit;
  93.  
  94. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement