WordPress PHP Cross Reference Blogging Systems

Source: /wp-comments-post.php - 55 lines - 1477 bytes - Text - Print

Description: Handles Comment Post to WordPress and prevents duplicate comment posting.

   1  <?php
   2  /**
   3   * Handles Comment Post to WordPress and prevents duplicate comment posting.
   4   *
   5   * @package WordPress
   6   */
   7  
   8  if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {
   9      header('Allow: POST');
  10      header('HTTP/1.1 405 Method Not Allowed');
  11      header('Content-Type: text/plain');
  12      exit;
  13  }
  14  
  15  /** Sets up the WordPress Environment. */
  16  require( dirname(__FILE__) . '/wp-load.php' );
  17  
  18  nocache_headers();
  19  
  20  $comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
  21  if ( is_wp_error( $comment ) ) {
  22      $data = intval( $comment->get_error_data() );
  23      if ( ! empty( $data ) ) {
  24          wp_die( '<p>' . $comment->get_error_message() . '</p>', __( 'Comment Submission Failure' ), array( 'response' => $data, 'back_link' => true ) );
  25      } else {
  26          exit;
  27      }
  28  }
  29  
  30  $user = wp_get_current_user();
  31  
  32  /**
  33   * Perform other actions when comment cookies are set.
  34   *
  35   * @since 3.4.0
  36   *
  37   * @param WP_Comment $comment Comment object.
  38   * @param WP_User    $user    User object. The user may not exist.
  39   */
  40  do_action( 'set_comment_cookies', $comment, $user );
  41  
  42  $location = empty( $_POST['redirect_to'] ) ? get_comment_link( $comment ) : $_POST['redirect_to'] . '#comment-' . $comment->comment_ID;
  43  
  44  /**
  45   * Filters the location URI to send the commenter after posting.
  46   *
  47   * @since 2.0.5
  48   *
  49   * @param string     $location The 'redirect_to' URI sent via $_POST.
  50   * @param WP_Comment $comment  Comment object.
  51   */
  52  $location = apply_filters( 'comment_post_redirect', $location, $comment );
  53  
  54  wp_safe_redirect( $location );
  55  exit;

title

Description

title

Description

title

Description

title

title

Body