Make WordPress Core

Changeset 34583


Ignore:
Timestamp:
09/26/2015 06:40:39 AM (9 years ago)
Author:
wonderboymusic
Message:

Comments: add __get() and __set() to WP_Comment to provide BC for plugins that are grabbing post properties from the comment object due to an (unintended?) side effect of JOINing with the posts table in WP_Comment_Query, see [17667]. 'fields' used to default to *, so the JOIN would grab every field from both tables. #YOLO

Since [34310], these properties no longer exist. We can lazy load them for plugins with the magic methods.

Fixes #27571.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-comment.php

    r34569 r34583  
    321321        return false;
    322322    }
     323
     324    /**
     325     * Whether a comment has post from which to retrieve magic properties
     326     *
     327     * @since 4.4.0
     328     * @access public
     329     *
     330     * @param string $name
     331     * @return bool
     332     */
     333    public function __isset( $name ) {
     334        if (
     335            0 === (int) $this->comment_post_ID
     336            || property_exists( $this, $name )
     337        ) {
     338            return;
     339        }
     340
     341        $post = get_post( $this->comment_post_ID );
     342        if ( $post ) {
     343            return property_exists( $post, $name );
     344        }
     345    }
     346
     347    /**
     348     * Magic getter for $post properties
     349     *
     350     * @since 4.4.0
     351     * @access public
     352     *
     353     * @param string $name
     354     * @return mixed
     355     */
     356    public function __get( $name ) {
     357        $post = get_post( $this->comment_post_ID );
     358        if ( $post ) {
     359            return $post->$name;
     360        }
     361    }
    323362}
Note: See TracChangeset for help on using the changeset viewer.