Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
417b389
Ensure term_id property exists on object
westonruter Feb 28, 2026
366a685
Ensure ID property exists before attempting to read it in get_post()
westonruter Feb 28, 2026
20cf57e
Indicate that WP_Comment accepts a plain object as its parameter
westonruter Feb 28, 2026
d3407f2
Use object instead of WP_Post in get_post()
westonruter Mar 1, 2026
f9e371f
Use object as arg type for WP_Comment constructor
westonruter Mar 1, 2026
917ccfc
Fix parameter description formatting in post.php
westonruter Mar 1, 2026
92952de
Add comprehensive unit tests for get_post()
westonruter Mar 2, 2026
a0adb6a
Update param type for WP_Post constructor to be just object
westonruter Mar 2, 2026
3736bea
Taxonomy: Add comprehensive unit tests for sanitize_term()
westonruter Mar 3, 2026
9fc4723
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter Mar 3, 2026
5fbfeed
Fix alignment of get_post() params
westonruter Mar 3, 2026
cbddb78
Tests: Use console.log() instead of document.write() in sanitization …
westonruter Mar 3, 2026
31984a0
Tests: Refactor filter assertion in get_post() tests
westonruter Mar 3, 2026
888ba44
Tests: Remove redundant assertNotNull in get_post() tests
westonruter Mar 3, 2026
6816649
Merge branch 'trunk' into add/isset-checks
westonruter Mar 3, 2026
93006ad
Use generic object as param for WP_Term constructor
westonruter Mar 3, 2026
07d76fd
Use object for WP_Site constructor
westonruter Mar 3, 2026
2e67166
Simplify WP_User param type to object
westonruter Mar 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static function get_instance( $id ) {
*
* @since 4.4.0
*
* @param WP_Comment $comment Comment object.
* @param WP_Comment|object $comment Comment object.
Comment thread
westonruter marked this conversation as resolved.
Outdated
*/
public function __construct( $comment ) {
foreach ( get_object_vars( $comment ) as $key => $value ) {
Expand Down
4 changes: 3 additions & 1 deletion src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -1159,8 +1159,10 @@ function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) {
$_post = new WP_Post( $_post );
} elseif ( 'raw' === $post->filter ) {
$_post = new WP_Post( $post );
} else {
} elseif ( isset( $post->ID ) ) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would mean that $post is no instance of WP_Post(we're in the else of line 1154).

PHPdoc for $post says @param int|WP_Post|null $post Optional. Post ID or post object.

So if you expect this to be a generic object, that is formed like WP_Post, the PHPDoc Block is wrong.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, the PHPDoc needs to be updated to add object as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or I guess, object should be used instead of WP_Post given our other conversation.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How/why is it possible that an object that mimics WP_Post is passed here? Doesn’t look like solid architecture

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's when post data is passed straight from a database query.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in d3407f2

$_post = WP_Post::get_instance( $post->ID );
} else {
$_post = null;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess some test coverage here would be good.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 92952de

}
} else {
$_post = WP_Post::get_instance( $post );
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@ function sanitize_term( $term, $taxonomy, $context = 'display' ) {

$do_object = is_object( $term );

$term_id = $do_object ? $term->term_id : ( $term['term_id'] ?? 0 );
$term_id = $do_object ? ( $term->term_id ?? 0 ) : ( $term['term_id'] ?? 0 );
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage here too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 3736bea


foreach ( (array) $fields as $field ) {
if ( $do_object ) {
Expand Down
Loading