Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 4 years ago

#23593 closed enhancement (duplicate)

Add functions to extract the first image from content, [gallery] a post, or an arbitrary string

Reported by: wonderboymusic's profile wonderboymusic Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Post Formats Keywords: has-patch
Focuses: Cc:

Description

Scenarios

A post has a post format of Image, but the current theme does not support the Image post format but:

  • There's a gallery shortcode in the content and you want the first image
  • There are images attached to the post and you want the first one
  • There is an image tag as the content or in the content and you want the src
  • The content is a URL representing an image
  • The content is a URL representing an image, followed by new line(s), followed by commentary

Introduce the_image(), get_the_image( $post_id = 0 ), get_content_image( &$content, $remove = false ), get_post_images( $post_id = 0 )

Attachments (1)

23593.diff (4.9 KB) - added by wonderboymusic 11 years ago.

Download all attachments as: .zip

Change History (11)

#1 @SergeyBiryukov
11 years ago

  • Component changed from General to Media

Related: #22960

#2 @johnbillion
11 years ago

Justin Tadlock has a plugin with 250,000+ downloads called Get The Image, and its main function is called get_the_image(). We should avoid introducing a function of the same name into core. Maybe get_post_image() (and the corresponding post_image()) instead?

#3 @kovshenin
11 years ago

We should avoid introducing a function of the same name into core.

I disagree. Justin should prefix all the things in his plugins.

#4 @dd32
11 years ago

We should avoid introducing a function of the same name into core.

I disagree. Justin should prefix all the things in his plugins.

I agree that developers should prefix, however, putting the users ahead of ourselves, we should avoid the conflict by not using the same function name as a popular plugin, or by taking over the function from the plugin by deactivating the plugin (as long as our version is compatible).

When core added the Sidebars, there was an existing plugin which didn't prefix, there's some code that we added to disable the plugin when the upgraded version of WordPress was installed, seamless transition from plugin to core feature. Just saying, there's precedent there if we take that route, but would probably require our function becoming pluggable.

#5 @danielbachhuber
11 years ago

Many themes dependent on Justin's plugin use get_the_image() in their template files. Asking everyone to change is a non-starter.

Might I suggest wp_get_the_image()?

#6 @wonderboymusic
11 years ago

yeah, probably all of the format funcs should start for wp_ for this reason

#7 @nacin
11 years ago

Mostly just a duplicate of #22960.

#8 @wonderboymusic
11 years ago

  • Component changed from Media to Post Formats

#9 @wonderboymusic
11 years ago

  • Milestone 3.6 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #22960.

This ticket was mentioned in Slack in #core-editor by mkaz. View the logs.


4 years ago

Note: See TracTickets for help on using tickets.