Opened 6 years ago
Last modified 6 years ago
#44595 new defect (bug)
wp_insert_post() inserts wrong GUID (adds http:// prefix)
Reported by: | Looimaster | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | 2nd-opinion |
Focuses: | Cc: |
Description
I manually set a GUID to e.g. abc123
before calling wp_insert_post()
and it was inserted as http://abc123
to the database.
Expected: abc123
Change History (3)
#2
follow-up:
↓ 3
@
6 years ago
I think this is a bug because:
- Maybe as you say
"...WordPress uses GUIDs as an actual URL for RSS feeds, and so GUIDs need to be a real URL rather than an arbitrary text string..."
and that's fine with me. You can generate http://example.com/
as your GUIDs by default.
- But when a user explicitly sets a GUID to an actual GUID in for example
123e4567-e89b-12d3-a456-426655440000
format then in my opinion that shouldn't be modified by WordPress.
- By definition (and expectation) GUID is a defined concept (https://en.wikipedia.org/wiki/Universally_unique_identifier). WordPress currently uses this concept in an unofficial/arbitrary way if it really uses it as
"...actual URL for RSS feeds..."
.
In the RSS feed I only see <guid isPermaLink="false">http://example.com/?p=123</guid>
so I don't think that GUID must be a URL. It could be anything.
I think GUID should be restricted to being an actual GUID as defined by Wikipedia (because it's a great and useful idea and the only column that I can count on being globally unique and I could use it to for example synchronize the content between multiple sites) and if you need "...actual URL for RSS feeds..."
then that shouldn't be named "GUID" but something else like feed_link
.
So I vote for implementing this fix:
- For new posts inserted like
wp_insert_post( array( "post_title" => "Some title" ) )
generate whatever you like. - But for new posts inserted like
wp_insert_post( array( "post_title" => "Some title", "guid" => "abc123" ) )
(where user explicitly indicates that they want to actually use GUID concept for something) don't modify it.
The process that actually adds the
http://
prefix is theesc_url_raw()
function hooked to thepre_post_guid
filter. This can be found by searching for the filter indefault-filters.php
.I don't believe this is an actual bug. WordPress uses GUIDs as an actual URL for RSS feeds, and so GUIDs need to be a real URL rather than an arbitrary text string. With that said, I'm not going to change the status of this ticket, in case there's other feedback. I found a bit of information related to GUIDs here: https://deliciousbrains.com/wordpress-post-guids-sometimes-update/.
EDIT:
The actual filter is triggered within the
sanitize_post_field()
function in the form of"pre_post_{$field}"
.