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
This commit is contained in:
whyisjake 2021-06-08 23:13:57 +00:00
parent bb041c2503
commit cc26b6f068
2 changed files with 56 additions and 11 deletions

View File

@ -3376,19 +3376,49 @@ function wp_video_shortcode( $attr, $content = '' ) {
} }
add_shortcode( 'video', 'wp_video_shortcode' ); 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. * Displays previous image link that has the same post parent.
* *
* @since 2.5.0 * @since 2.5.0
* *
* @see adjacent_image_link()
*
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array * @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'. * of width and height values in pixels (in that order). Default 'thumbnail'.
* @param string|false $text Optional. Link text. Default false. * @param string|false $text Optional. Link text. Default false.
*/ */
function previous_image_link( $size = 'thumbnail', $text = 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 * @since 2.5.0
* *
* @see adjacent_image_link()
*
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array * @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'. * of width and height values in pixels (in that order). Default 'thumbnail'.
* @param string|false $text Optional. Link text. Default false. * @param string|false $text Optional. Link text. Default false.
*/ */
function next_image_link( $size = 'thumbnail', $text = 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. * 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 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 * @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'. * of width and height values in pixels (in that order). Default 'thumbnail'.
* @param bool $text Optional. Link text. Default false. * @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(); $post = get_post();
$attachments = array_values( $attachments = array_values(
get_children( 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). * an array of width and height values in pixels (in that order).
* @param string $text Link text. * @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 );
} }
/** /**

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.