WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 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:
PR Number:

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 (1)

#1 @johnbillion
2 years ago

  • Keywords reporter-feedback added

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?

Note: See TracTickets for help on using tickets.