[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/ -> wp-comments-post.php (source)

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


Generated: Sat Dec 16 01:00:03 2017 Cross-referenced by PHPXref 0.7.1