WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 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 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 2 years ago.

Download all attachments as: .zip

Change History (10)

@wonderboymusic2 years ago

comment:1 @SergeyBiryukov2 years ago

  • Component changed from General to Media

Related: #22960

comment:2 @johnbillion2 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?

comment:3 @kovshenin2 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.

comment:4 @dd322 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.

comment:5 @danielbachhuber2 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()?

comment:6 @wonderboymusic2 years ago

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

comment:7 @nacin2 years ago

Mostly just a duplicate of #22960.

comment:8 @wonderboymusic2 years ago

  • Component changed from Media to Post Formats

comment:9 @wonderboymusic2 years ago

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

Duplicate of #22960.

Note: See TracTickets for help on using tickets.