Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#60947 closed defect (bug) (fixed)

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

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

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
2 years ago

  • Milestone Awaiting Review → 6.7
  • Version 6.6 → 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.


2 years 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
2 years ago

  • Owner set to SergeyBiryukov
  • Resolution → fixed
  • Status new → 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:


2 years ago
#4

Thanks for the PR! Merged in r58983.

#5 follow-ups: @akshat2802
2 years 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
2 years ago

My correct username is "akshat2802."

It's corrected in Core Props.

#7 in reply to: ↑ 5 @SergeyBiryukov
2 years 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.