Make WordPress Core

Opened 2 years ago

Closed 20 months ago

Last modified 20 months ago

#60947 closed defect (bug) (fixed)

calling get_post_type_object in wp-admin/includes/post.php may return null

Reported by: pcarvalho's profile pcarvalho Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.7 Priority: normal
Severity: minor Version: 3.6
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:

Description

There's no guard to check the return of get_post_type_object, going straight to use labels and then all_items

/wp-admin/includes/post.php:1816

$sendback_text = get_post_type_object( $post->post_type )->labels->all_items;

get_post_type_object returns:

WP_Post_Type|null WP_Post_Type object if it exists, null otherwise.

if valid, i can provide a patch.

Change History (7)

#1 in reply to: ↑ description @SergeyBiryukov
20 months ago

  • Milestone changed from Awaiting Review to 6.7
  • Version changed from 6.6 to 3.6

Replying to pcarvalho:

if valid, i can provide a patch.

Hi there, thanks for the ticket! This does seem valid, would you be interested in working on a patch?

Introduced in [24527] / #24547.

This ticket was mentioned in PR #7280 on WordPress/wordpress-develop by @akshat2802.


20 months ago
#2

  • Keywords has-patch added

This PR adds a check for the function get_post_type_object not returning null.
https://core.trac.wordpress.org/ticket/60947

#3 @SergeyBiryukov
20 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 58983:

Posts, Post Types: Check if the post type exists in _admin_notice_post_locked().

This adds a guard to verify the result of get_post_type_object() before retrieving the all_items label, as the function returns null if the post type does not exist.

Follow-up to [24527].

Props pcarvalho, akshat280, mukesh27, SergeyBiryukov.
Fixes #60947.

@SergeyBiryukov commented on PR #7280:


20 months ago
#4

Thanks for the PR! Merged in r58983.

#5 follow-ups: @akshat2802
20 months ago

Hi @SergeyBiryukov ,

Thank you for the mention in this ticket. However, it seems that my username has been listed incorrectly as "akshat280." My correct username is "akshat2802." Could you kindly update the reference?

Regards
Akshat

#6 in reply to: ↑ 5 @sabernhardt
20 months ago

My correct username is "akshat2802."

It's corrected in Core Props.

#7 in reply to: ↑ 5 @SergeyBiryukov
20 months ago

Replying to akshat2802:

Thank you for the mention in this ticket. However, it seems that my username has been listed incorrectly as "akshat280."

Sorry for the typo, and thanks to @sabernhardt for correcting it :)

Note: See TracTickets for help on using tickets.