I am working on a theme (http://lillykauffman.com/wordpress/2017/06/26/hello-world/), which I've done before, but if you try to post a comment, you will be redirected to a blank page. This also happens on the other WP themes such as twentysixteen. Here is the code I have on wp-comments-post.php:
<?php
/**
* Handles Comment Post to WordPress and prevents duplicate comment posting.
*
* @package WordPress
*/
if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {
$protocol = $_SERVER['SERVER_PROTOCOL'];
if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) {
$protocol = 'HTTP/1.0';
}
header('Allow: POST');
header("$protocol 405 Method Not Allowed");
header('Content-Type: text/plain');
exit;
}
/** Sets up the WordPress Environment. */
require( dirname(__FILE__) . '/wp-load.php' );
nocache_headers();
$comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
if ( is_wp_error( $comment ) ) {
$data = intval( $comment->get_error_data() );
if ( ! empty( $data ) ) {
wp_die( '<p>' . $comment->get_error_message() . '</p>', __( 'Comment Submission Failure' ), array( 'response' => $data, 'back_link' => true ) );
} else {
exit;
}
}
$user = wp_get_current_user();
/**
* Perform other actions when comment cookies are set.
*
* @since 3.4.0
*
* @param WP_Comment $comment Comment object.
* @param WP_User $user User object. The user may not exist.
*/
do_action( 'set_comment_cookies', $comment, $user );
$location = empty( $_POST['redirect_to'] ) ? get_comment_link( $comment ) :
$_POST['redirect_to'] . '#comment-' . $comment->comment_ID;
/**
* Filters the location URI to send the commenter after posting.
*
* @since 2.0.5
*
* @param string $location The 'redirect_to' URI sent via $_POST.
* @param WP_Comment $comment Comment object.
*/
$location = apply_filters( 'comment_post_redirect', $location, $comment );
wp_safe_redirect( $location );
exit;
I don't know why this isn't working since it's straight from WP, and other people online had this error because their file was blank, which is not my case. And all of this code looks to be in order. My MySQL version is 5.7 so that shouldn't be the issue, but at this point, I don't even know what's wrong anymore - the code, the installation, my hosting. Any help would be greatly appreciated.
Update: My host advertises full blog, comment and discussion board functionality but I contacted them and they were like, "not really." Apparently they don't support comments or email sending. What a waste. Thanks for everyone's help!
When you look your problem page with inspect manager, you can see that your problem is a 410 code error.
This error can occur in several ways.
Here it's the list of somes checkpoint to help you to find the problem:
1. Enable debugging in wp-config.php
And test to know if your error appear. You'll be able to fix it quickly.
2. Reset permalink
Don't know why but, sometimes, Wordpress have some weird error du to a old permalink.
I suggest you to
Settings -> Permalinks
3. Deactivating all plugins.
if its works, activate plugin one by one to be able to detect which one create this error.
4. Refresh your .htaccess
place the basic wordpress
.htaccess
. Sometimes, some plugins change rules from your.htaccess
and provoke many redirections error.5. Switch your theme for a default theme without modification
It help you to know if a custom rules in your theme create this error.
6. Re-upload the wp-admin and wp-includes from fresh install
7. Reset folders write/read permissions
you can read Changing File permissions in Wordpress to help you to know what you should change and what it should do.
8. ULTIMATELY, Create a fresh install of Wordpress