From cc26b6f06852f2d7a1178d983fc0a362f5c2deca Mon Sep 17 00:00:00 2001 From: whyisjake Date: Tue, 8 Jun 2021 23:13:57 +0000 Subject: [PATCH] Media: Add new functions to return the previous/next attachment links. New functions: * get_adjacent_image_link() * get_next_image_link() * get_previous_image_link() Fixes #45708. Props flixos90, DrewAPicture, mor10, antpb, hellofromTonya, whyisjake. Built from https://develop.svn.wordpress.org/trunk@51122 git-svn-id: http://core.svn.wordpress.org/trunk@50731 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 65 ++++++++++++++++++++++++++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index 19fa2b8b9d..4a9849d3ca 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -3376,19 +3376,49 @@ function wp_video_shortcode( $attr, $content = '' ) { } add_shortcode( 'video', 'wp_video_shortcode' ); +/** + * Gets the previous image link that has the same post parent. + * + * @since 5.8.0 + * + * @see get_adjacent_image_link() + * + * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array + * of width and height values in pixels (in that order). Default 'thumbnail'. + * @param string|false $text Optional. Link text. Default false. + * @return string Markup for previous image link. + */ +function get_previous_image_link( $size = 'thumbnail', $text = false ) { + return get_adjacent_image_link( true, $size, $text ); +} + /** * Displays previous image link that has the same post parent. * * @since 2.5.0 * - * @see adjacent_image_link() - * * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array * of width and height values in pixels (in that order). Default 'thumbnail'. * @param string|false $text Optional. Link text. Default false. */ function previous_image_link( $size = 'thumbnail', $text = false ) { - adjacent_image_link( true, $size, $text ); + echo get_previous_image_link( $size, $text ); +} + +/** + * Gets the next image link that has the same post parent. + * + * @since 5.8.0 + * + * @see get_adjacent_image_link() + * + * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array + * of width and height values in pixels (in that order). Default 'thumbnail'. + * @param string|false $text Optional. Link text. Default false. + * @return string Markup for next image link. + */ +function get_next_image_link( $size = 'thumbnail', $text = false ) { + return get_adjacent_image_link( false, $size, $text ); } /** @@ -3396,29 +3426,28 @@ function previous_image_link( $size = 'thumbnail', $text = false ) { * * @since 2.5.0 * - * @see adjacent_image_link() - * * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array * of width and height values in pixels (in that order). Default 'thumbnail'. * @param string|false $text Optional. Link text. Default false. */ function next_image_link( $size = 'thumbnail', $text = false ) { - adjacent_image_link( false, $size, $text ); + echo get_next_image_link( $size, $text ); } /** - * Displays next or previous image link that has the same post parent. + * Gets the next or previous image link that has the same post parent. * * Retrieves the current attachment object from the $post global. * - * @since 2.5.0 + * @since 5.8.0 * * @param bool $prev Optional. Whether to display the next (false) or previous (true) link. Default true. * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array * of width and height values in pixels (in that order). Default 'thumbnail'. * @param bool $text Optional. Link text. Default false. + * @return string Markup for image link. */ -function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) { +function get_adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) { $post = get_post(); $attachments = array_values( get_children( @@ -3473,7 +3502,23 @@ function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) * an array of width and height values in pixels (in that order). * @param string $text Link text. */ - echo apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text ); + return apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text ); +} + +/** + * Displays next or previous image link that has the same post parent. + * + * Retrieves the current attachment object from the $post global. + * + * @since 2.5.0 + * + * @param bool $prev Optional. Whether to display the next (false) or previous (true) link. Default true. + * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array + * of width and height values in pixels (in that order). Default 'thumbnail'. + * @param bool $text Optional. Link text. Default false. + */ +function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) { + echo get_adjacent_image_link( $prev, $size, $text ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index c5d48c54d6..c703db2bdb 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-alpha-51121'; +$wp_version = '5.8-alpha-51122'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.