[wp-trac] [WordPress Trac] #51376: wp_get_shortlink produces PHP Notice on unregistered post type

WordPress Trac noreply at wordpress.org
Wed Sep 23 01:16:10 UTC 2020


#51376: wp_get_shortlink produces PHP Notice on unregistered post type
--------------------------+-----------------------------
 Reporter:  apedog        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51376>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list