[wp-trac] [WordPress Trac] #61969: Post guid for custom post type being modified

WordPress Trac noreply at wordpress.org
Mon Sep 2 16:07:07 UTC 2024


#61969: Post guid for custom post type being modified
-------------------------------+-----------------------------
 Reporter:  peter8nss          |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:  6.6.1
 Severity:  minor              |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 I understand that a post's guid should generally be invariant, i.e. once
 set it should not normally be changed. WordPress core seems to violate
 this for custom post types.

 When creating a post for a custom post type the guid created is (now) of
 the form:
   <domain>/?post_type=<custom post type>&=p=<post id>
 When that post is first updated the guid gets changed to
   <domain>/?post_type=<custom post type>&p=<post id>
 I think this is happening because of the filter added on post_guid calling
 esc_url (see wp-includes/default-filters.php) which is called when
 updating the post but not when originally creating it.

 Note the creating logic sets guid using get_permalink which in turn calls
 get_post_permalink and does not include any use of esc_url.

 You can recreate the problem, providing you have a custom post type
 available, by the following WP CLI commands:
   wp post create --post_title='Initial create' --post_type=<custom post
 type>
 guid will be set as described above
   wp post update <post id> --post_title='Updated title'
 guid will be revised as described above
 And you can use "wp post get <post id>" to see the different guid values

 Naively, I would suggest two ways of fixing this:
 1) Remove the default filter on post_guid that calls esc_url
 2) Wrap the call to get_permalink in wp_insert_post in a call to esc_url

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


More information about the wp-trac mailing list