Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions src/wp-admin/includes/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,10 @@ function _post_states( $post, $display = true ) {
*/
function get_post_states( $post ) {
$post_states = array();
if ( ! $post instanceof WP_Post ) {
return $post_states;
}

$post_status = $_REQUEST['post_status'] ?? '';

if ( ! empty( $post->post_password ) ) {
Expand Down
10 changes: 6 additions & 4 deletions src/wp-includes/nav-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,12 @@ function wp_setup_nav_menu_item( $menu_item ) {
$menu_item->type_label = $object->labels->singular_name;
// Denote post states for special pages (only in the admin).
if ( function_exists( 'get_post_states' ) ) {
$menu_post = get_post( $menu_item->object_id );
$post_states = get_post_states( $menu_post );
if ( $post_states ) {
$menu_item->type_label = wp_strip_all_tags( implode( ', ', $post_states ) );
$menu_post = get_post( $menu_item->object_id );
if ( $menu_post instanceof WP_Post ) {
$post_states = get_post_states( $menu_post );
if ( $post_states ) {
$menu_item->type_label = wp_strip_all_tags( implode( ', ', $post_states ) );
}
}
}
} else {
Expand Down
16 changes: 16 additions & 0 deletions tests/phpunit/tests/admin/includesTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,4 +494,20 @@ public function test_wp_add_dashboard_widget() {
// This doesn't actually get removed due to the invalid priority.
remove_meta_box( 'dashboard2', 'dashboard', 'normal' );
}

/**
* Tests that get_post_states() handles a null value gracefully.
*
* This can happen when get_post() returns null (e.g., when a post
* doesn't exist) and that result is passed to get_post_states()
* without being checked first.
*
* @ticket 58932
*
* @covers ::get_post_states
*/
public function test_get_post_states_with_null_returns_empty_array() {
$result = get_post_states( null );
$this->assertSame( array(), $result, 'get_post_states() should return an empty array when WP_Post is not supplied.' );
}
}
Loading