Make WordPress Core

Opened 15 years ago

Last modified 14 months ago

#12634 assigned defect (bug)

Media Library & Permalink Overlap

Reported by: tmoorewp's profile tmoorewp Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.9.1
Component: Permalinks Keywords: has-patch
Focuses: Cc:

Description

The problem is: upload a media item and give it a name, such as 'test'. Create a new page titled 'test' with a permalink that reads http://www.example.org/test/.

The permalink, instead of going to the page, goes to the media item.

For most purposes, I would imagine this behavior should be reversed.

-Tim-

Attachments (1)

12634.diff (955 bytes) - added by solarissmoke 14 years ago.
Check for attachments sharing the same parent as the current page when finding a unique slug

Download all attachments as: .zip

Change History (25)

#1 @tmoorewp
15 years ago

  • Cc tim.moore@… added

#2 @nacin
15 years ago

  • Component changed from Media to Rewrite Rules
  • Milestone changed from 2.9.3 to 3.0
  • Owner set to ryan

#3 @dd32
14 years ago

How did you change the media name to 'test'?

The post_name field which this is based off is supposed to be unique, The only way i could force what you describe to happpen, was to change the post_name field in the database so that they conflicted.

#4 @dd32
14 years ago

  • Keywords reporter-feedback added

#5 @tmoorewp
14 years ago

In the tests I did, the media item was uploaded first and then the page/post was created. I first ran across this problem in a 2.9.1.1 WPMU installation I run at a university, but have also seen it happen on a standalone 2.9.2 WP install.

Also, I haven't modified anything in the database that would effect this. All the tests I ran were strictly uploading media through the Dashboard and creating posts/pages in the Dashboard. No database modification was needed, on my part, to produce this error.

#6 @dremeda
14 years ago

  • Cc dre@… added

I tried recreating this by first uploading a media item, then created a page and do not see the same issue. The page is properly created as expected.

So when you say give it a name like "test" are you speaking to changing the title of the uploaded media item?

#7 @tmoorewp
14 years ago

Dremeda: Yes, it happens when you change the title of the media item to the same name as a page has.

So:

  1. Media Item is uploaded, Title field == 'test'.
  2. A page is created after the media item is created. Page is named 'test' and permalink is example.org/test.
  3. The URL example.org/text goes to the Media Item created in step 1, rather than to the page created in step 2.

I've been able to easily recreate this behavior on my test installs, but I'll go back through and check again.

Thanks!

Tim

#8 @dremeda
14 years ago

Thanks Tim,

I tried recreating this multiple times with pages and posts the same way you outlined and could not recreate the error.

I was working on localhost, I will try and recreate on a dev server today.

#9 @nacin
14 years ago

  • Milestone changed from 3.0 to Unassigned

#10 @nacin
14 years ago

Similar symptoms? #10988

#11 @dremeda
14 years ago

Similar symptoms but not sure its the same thing.

On this ticket, I tried on a dev server after I tested on localhost and could not recreate in either case.

#12 @madtownlems
14 years ago

  • Cc madtownlems added

I can easily replicate this error on both 2.9.1 and 3.0.1. Here's my (overly detailed) write up:

When you upload a media item, it creates a permalink for the piece of media. (you can view the permalink by hovering over View for the media link in the media library)

  • If you upload it from the left menu “Media – Add New” the permalink will look like: blah.com/?attachment_id=57
  • If you upload while creating/editing a page, the permalink will use the structure: blah.com/<path-to-page>/image-title

If the permalink is already taken, say as by an existing page, it will make it unique by appending something like “-2” to the end.

When you create a new page, it generates a permalink in the form of <path-to-parent-page>/page-title

HOWEVER – and herein lies the problem – it does NOT check if the permalink is taken by an existing media item (but it DOES compare it against existing page permalinks).

So, in order to experience the problem, I believe the following all need to be true:
1) You add the media via the Upload/Insert link while creating the page
2) You upload the images BEFORE you create the pages
3) The pages have the same title as the image title

Steps to Recreate Example:
Create page /tool
Create page /tool/hammer
Edit /tool. Add images called hammer.jpg and saw.jpg, link hammer.jpg to /tool/hammer and saw.jpg to /tool/saw
Create page /tool/saw

Expected behavior:
/tool/hammer should take you to the page itself
/tool/saw should display the saw.jpg instead of the page
Desired behavior:
/tool/saw should display the saw page.

#13 @mrmist
14 years ago

  • Keywords reporter-feedback removed
  • Version set to 2.9.1

I can confirm that this is reproducable in 3.0.1.

(Also setting the version to the earliest version I saw mentioned above.)

There doesn't appear to be checking of permalinks against media items when creating a page. The Page equipment / lawnmower will show the media item for "lawnmower".

#14 @nacin
14 years ago

  • Milestone changed from Awaiting Review to Future Release

#15 @nacin
14 years ago

  • Keywords needs-patch added

@solarissmoke
14 years ago

Check for attachments sharing the same parent as the current page when finding a unique slug

#16 @solarissmoke
14 years ago

  • Component changed from Rewrite Rules to Permalinks
  • Keywords has-patch needs-testing added; needs-patch removed

This fixes it for me - we just need to be checking for attachments that share the same parent as the page being edited.

#17 @garyc40
14 years ago

Similar to #15665, although in #15665, the permalink conflict is between attachment and child pages. There's a patch there as well.

Last edited 5 years ago by SergeyBiryukov (previous) (diff)

#18 @ryan
10 years ago

  • Owner ryan deleted
  • Status changed from new to assigned

#19 @zzmonty
9 years ago

This problem still exists in version 4.2.2.

This problem can easily be fixed by simply changing "settings"->"permalinks"->"optional" to add the following data field:

"media base" -> Text edit box.

The problem shows itself when a permalink for a post is

"custom structure" -> "/%postname%/"

Media items should default to http://sample.com/media/picture
Then if a post is set to no date, it can be http://sample.com/picture

It might be too late to change the defaults for existing items, but it should at least be in there for new sites.

The only way to fix this problem with the current GUI would be to change :

"custom structure" -> "/post/%postname%"

This ticket was mentioned in Slack in #core by talldanwp. View the logs.


5 years ago

#21 @talldanwp
5 years ago

#35765 was marked as a duplicate.

#22 @ehtis
5 years ago

  • Keywords needs-testing removed

Hi @tmoorewp, @mrmist, and others who might have experienced this. I understand this ticket is super long, not sure if this is still an issue for you or if you're around.

But, I did some testing and here's how the behavior seems to be:

  1. Upload media, let's name it "flower", so the slug would become yoursite/flower
  2. Create a page, give it the title "flower".
  3. WordPress would detect that a slug "flower" already exists, so it'd auto-assign "flower-2" slug to this page. You will be able to access it at yoursite/flower-2

Now, say you want to force change the slug of the page to "flower" and match with the media. You edit the permalink/slug in the editor and hit "Update". You think the slug of the page has been changed to "flower" from "flower-2".

But, that doesn't really happen. Page slug remains as "flower-2" and media remains as "flower". You can confirm this by refreshing and opening the page in the editor again.

I guess that might have led to some confusion.

If anyone is still experiencing issues, please do reply. But I think what could be done here is better reporting/warning that a permalink change attempt failed.

#23 @SergeyBiryukov
5 years ago

Related: #13459, #15665, #24612, #34972.

Version 0, edited 5 years ago by SergeyBiryukov (next)

This ticket was mentioned in Slack in #core by oglekler. View the logs.


14 months ago

Note: See TracTickets for help on using tickets.