[wp-trac] [WordPress Trac] #41788: PHP Fatal error: Call to a member function has_cap() on a non-object in wp-includes/comment.php

WordPress Trac noreply at wordpress.org
Sun Sep 3 22:16:36 UTC 2017


#41788: PHP Fatal error: Call to a member function has_cap() on a non-object in wp-
includes/comment.php
--------------------------+-----------------------------
 Reporter:  kirbyde       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Comments      |    Version:  4.8.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 {{{#!php
 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.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41788>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list