WordPress.org

Make WordPress Core

Opened 9 months ago

Closed 9 months ago

#51376 closed defect (bug) (fixed)

wp_get_shortlink produces PHP Notice on unregistered post type

Reported by: apedog Owned by: SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:

Description

Calling wp_get_shortlink with an existing ID of an unregistered custom post type, the following PHP notice is shown:
Notice: Trying to get property 'public' of non-object in \wp-includes\link-template.php on line 3913

Step to reproduce:

  1. Create a custom post type.
  2. Add new post of custom post type to database.
  3. Unregister/disable custom post type.
  4. Call wp_get_shortlink with ID from step 2

Problem is due to get_post( $id ) returning object regardless if registered or not. So $post_id is not empty.
However get_post_type_object returns null with no sanity checks before $post_type->public is tested.

Attachments (2)

51376.diff (928 bytes) - added by apedog 9 months ago.
51376.alt.diff (874 bytes) - added by apedog 9 months ago.
51376 - alternative patch

Download all attachments as: .zip

Change History (6)

@apedog
9 months ago

#1 @apedog
9 months ago

  • Keywords has-patch added

@apedog
9 months ago

51376 - alternative patch

#2 @sabernhardt
9 months ago

  • Component changed from General to Posts, Post Types

#3 @SergeyBiryukov
9 months ago

  • Milestone changed from Awaiting Review to 5.6
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#4 @SergeyBiryukov
9 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 49067:

Posts, Post Types: Avoid a PHP notice in wp_get_shortlink() if the post type is no longer registered.

Props apedog.
Fixes #51376.

Note: See TracTickets for help on using tickets.