wp/wp-includes/class-wp-comment.php
changeset 21 48c4eec2b7e6
parent 18 be944660c56a
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    10 /**
    10 /**
    11  * Core class used to organize comments as instantiated objects with defined members.
    11  * Core class used to organize comments as instantiated objects with defined members.
    12  *
    12  *
    13  * @since 4.4.0
    13  * @since 4.4.0
    14  */
    14  */
       
    15 #[AllowDynamicProperties]
    15 final class WP_Comment {
    16 final class WP_Comment {
    16 
    17 
    17 	/**
    18 	/**
    18 	 * Comment ID.
    19 	 * Comment ID.
    19 	 *
    20 	 *
   216 			$this->$key = $value;
   217 			$this->$key = $value;
   217 		}
   218 		}
   218 	}
   219 	}
   219 
   220 
   220 	/**
   221 	/**
   221 	 * Convert object to array.
   222 	 * Converts object to array.
   222 	 *
   223 	 *
   223 	 * @since 4.4.0
   224 	 * @since 4.4.0
   224 	 *
   225 	 *
   225 	 * @return array Object as array.
   226 	 * @return array Object as array.
   226 	 */
   227 	 */
   227 	public function to_array() {
   228 	public function to_array() {
   228 		return get_object_vars( $this );
   229 		return get_object_vars( $this );
   229 	}
   230 	}
   230 
   231 
   231 	/**
   232 	/**
   232 	 * Get the children of a comment.
   233 	 * Gets the children of a comment.
   233 	 *
   234 	 *
   234 	 * @since 4.4.0
   235 	 * @since 4.4.0
   235 	 *
   236 	 *
   236 	 * @param array $args {
   237 	 * @param array $args {
   237 	 *     Array of arguments used to pass to get_comments() and determine format.
   238 	 *     Array of arguments used to pass to get_comments() and determine format.
   299 
   300 
   300 		return $children;
   301 		return $children;
   301 	}
   302 	}
   302 
   303 
   303 	/**
   304 	/**
   304 	 * Add a child to the comment.
   305 	 * Adds a child to the comment.
   305 	 *
   306 	 *
   306 	 * Used by `WP_Comment_Query` when bulk-filling descendants.
   307 	 * Used by `WP_Comment_Query` when bulk-filling descendants.
   307 	 *
   308 	 *
   308 	 * @since 4.4.0
   309 	 * @since 4.4.0
   309 	 *
   310 	 *
   312 	public function add_child( WP_Comment $child ) {
   313 	public function add_child( WP_Comment $child ) {
   313 		$this->children[ $child->comment_ID ] = $child;
   314 		$this->children[ $child->comment_ID ] = $child;
   314 	}
   315 	}
   315 
   316 
   316 	/**
   317 	/**
   317 	 * Get a child comment by ID.
   318 	 * Gets a child comment by ID.
   318 	 *
   319 	 *
   319 	 * @since 4.4.0
   320 	 * @since 4.4.0
   320 	 *
   321 	 *
   321 	 * @param int $child_id ID of the child.
   322 	 * @param int $child_id ID of the child.
   322 	 * @return WP_Comment|false Returns the comment object if found, otherwise false.
   323 	 * @return WP_Comment|false Returns the comment object if found, otherwise false.
   328 
   329 
   329 		return false;
   330 		return false;
   330 	}
   331 	}
   331 
   332 
   332 	/**
   333 	/**
   333 	 * Set the 'populated_children' flag.
   334 	 * Sets the 'populated_children' flag.
   334 	 *
   335 	 *
   335 	 * This flag is important for ensuring that calling `get_children()` on a childless comment will not trigger
   336 	 * This flag is important for ensuring that calling `get_children()` on a childless comment will not trigger
   336 	 * unneeded database queries.
   337 	 * unneeded database queries.
   337 	 *
   338 	 *
   338 	 * @since 4.4.0
   339 	 * @since 4.4.0
   342 	public function populated_children( $set ) {
   343 	public function populated_children( $set ) {
   343 		$this->populated_children = (bool) $set;
   344 		$this->populated_children = (bool) $set;
   344 	}
   345 	}
   345 
   346 
   346 	/**
   347 	/**
   347 	 * Check whether a non-public property is set.
   348 	 * Determines whether a non-public property is set.
   348 	 *
   349 	 *
   349 	 * If `$name` matches a post field, the comment post will be loaded and the post's value checked.
   350 	 * If `$name` matches a post field, the comment post will be loaded and the post's value checked.
   350 	 *
   351 	 *
   351 	 * @since 4.4.0
   352 	 * @since 4.4.0
   352 	 *
   353 	 *
   365 	 *
   366 	 *
   366 	 * If `$name` matches a post field, the comment post will be loaded and the post's value returned.
   367 	 * If `$name` matches a post field, the comment post will be loaded and the post's value returned.
   367 	 *
   368 	 *
   368 	 * @since 4.4.0
   369 	 * @since 4.4.0
   369 	 *
   370 	 *
   370 	 * @param string $name
   371 	 * @param string $name Property name.
   371 	 * @return mixed
   372 	 * @return mixed
   372 	 */
   373 	 */
   373 	public function __get( $name ) {
   374 	public function __get( $name ) {
   374 		if ( in_array( $name, $this->post_fields, true ) ) {
   375 		if ( in_array( $name, $this->post_fields, true ) ) {
   375 			$post = get_post( $this->comment_post_ID );
   376 			$post = get_post( $this->comment_post_ID );