Opened 5 years ago
Closed 5 years ago
#51376 closed defect (bug) (fixed)
wp_get_shortlink produces PHP Notice on unregistered post type
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| 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:
- Create a custom post type.
- Add new post of custom post type to database.
- Unregister/disable custom post type.
- Call
wp_get_shortlinkwith 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)
Change History (6)
Note: See
TracTickets for help on using
tickets.
51376 - alternative patch