WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#11452 closed enhancement (wontfix)

Stop using _wp_attached_file

Reported by: scribu Owned by: scribu
Milestone: Priority: normal
Severity: normal Version: 2.9
Component: Media Keywords: has-patch needs-testing
Focuses: Cc:

Description

Currently, the relative path of each attachment is stored twice in wp_postmeta:

Once in the '_wp_attached_file' and once in '_wp_attachment_metadata'.

I propose that we get rid of '_wp_attached_file'.

Attachments (3)

_wp_attached_file.diff (1.8 KB) - added by scribu 5 years ago.
Replace get_post_meta($id, '_wp_attached_file') with get_attached file()
_wp_attached_file.2.diff (2.9 KB) - added by scribu 5 years ago.
Use '_wp_attachment_metadata' internally
_wp_attached_file.3.diff (2.9 KB) - added by scribu 5 years ago.
Pass $unfiltered to wp_get_attachment_metadata()

Download all attachments as: .zip

Change History (14)

@scribu5 years ago

Replace get_post_meta($id, '_wp_attached_file') with get_attached file()

comment:1 @scribu5 years ago

  • Keywords needs-testing added

Working fine on localhost. Haven't tested wp-app.php though.

comment:2 @scribu5 years ago

  • Owner set to scribu
  • Status changed from new to accepted

@scribu5 years ago

Use '_wp_attachment_metadata' internally

comment:3 follow-up: @Denis-de-Bernardy5 years ago

I'm a bit biased, since the idea would break my uploads folder plugin. So -1/2. :-)

It seems to me that, many times when manipulating this, WP and plugins want an unfiltered value. Example:

http://plugins.trac.wordpress.org/browser/uploads-folder/trunk/

comment:4 in reply to: ↑ 3 @scribu5 years ago

Replying to Denis-de-Bernardy:

I'm a bit biased, since the idea would break my uploads folder plugin. So -1/2. :-)

That's what you get for not using the API. :P

It seems to me that, many times when manipulating this, WP and plugins want an unfiltered value. Example:

http://plugins.trac.wordpress.org/browser/uploads-folder/trunk/

We could pass $unfiltered = true to wp_get_attachment_metadata().

There's an opposite solution: remove the 'file' field from _wp_attachment_metadata.

comment:5 @scribu5 years ago

_wp_attached_file.3.diff allows you to get the raw value using get_attached_file().

comment:6 @scribu5 years ago

  • Cc scribu@… added

@scribu5 years ago

Pass $unfiltered to wp_get_attachment_metadata()

comment:7 follow-up: @Denis-de-Bernardy5 years ago

For the sake of quickly accessing attached files, however, I feel that we should be dropping the attached file field in the array instead.

comment:8 @scribu5 years ago

From a performance perspective, it doesn't matter which way we go, since both are cached.

comment:9 follow-up: @hakre5 years ago

_wp_attached_file.3.diff still applies clean. any idea how to test? Any boundaries to check for?

comment:10 in reply to: ↑ 9 @xibe5 years ago

Replying to hakre:

_wp_attached_file.3.diff still applies clean. any idea how to test? Any boundaries to check for?

Would be nice to have testing instructions, yes.

comment:11 in reply to: ↑ 7 @scribu5 years ago

  • Milestone 3.0 deleted
  • Resolution set to wontfix
  • Status changed from accepted to closed

Replying to Denis-de-Bernardy:

For the sake of quickly accessing attached files, however, I feel that we should be dropping the attached file field in the array instead.

I've reached that conclusion too.

Note: See TracTickets for help on using tickets.