Opened 7 years ago
Last modified 4 years ago
#41788 new defect (bug)
PHP Fatal error: Call to a member function has_cap() on a non-object in wp-includes/comment.php
Reported by: | kirbyde | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.8.1 |
Component: | Comments | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
if ( ! empty( $commentdata['user_id'] ) ) {
$user = get_userdata( $commentdata['user_id'] );
$post_author = $wpdb->get_var( $wpdb->prepare(
"SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1",
$commentdata['comment_post_ID']
) );
}
if ( isset( $user ) && ( $commentdata['user_id'] == $post_author || $user->has_cap( 'moderate_comments' ) ) ) {
If get_userdata() returns false, this code can lead to a fatal error.
Change History (2)
Note: See
TracTickets for help on using
tickets.
Thanks for your report, @kirbyde, and welcome to WordPress Trac.
This is from the
wp_allow_comment()
function. Can you let us know under what condition this situation can occur? Do you have a plugin or theme on your site which customises the way comments are submitted?