Make WordPress Core

Ticket #22075: 22075.3.diff

File 22075.3.diff, 4.8 KB (added by ericlewis, 11 years ago)
  • src/wp-includes/post-template.php

     
    14461446 * Retrieve an attachment page link using an image or icon, if possible.
    14471447 *
    14481448 * @since 2.5.0
    1449  * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
    14501449 *
    1451  * @param int|WP_Post $id Optional. Post ID or post object.
    1452  * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
    1453  * @param bool $permalink Optional, default is false. Whether to add permalink to image.
    1454  * @param bool $icon Optional, default is false. Whether to include icon.
    1455  * @param string|bool $text Optional, default is false. If string, then will be link text.
     1450 * @param array $args {
     1451 *     An array of arguments. Optional.
     1452 *
     1453 *     @type int|WP_Post $ID Optional.                Post ID or post object.
     1454 *     @type string      $image_size                  Optional, default is 'thumbnail'. Size of image, either array or string.
     1455 *     @type bool        $include_permalink_in_anchor Optional, default is false. Whether to add permalink to the anchor.
     1456 *     @type bool        $display_media_icon          Optional, default is false. Whether to include icon.
     1457 *     @type string|bool $link_content                Optional, default is false. If string, then will be link text.
     1458 * }
    14561459 * @return string HTML content.
    14571460 */
    1458 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) {
    1459         $id = intval( $id );
     1461function wp_get_attachment_link( $args = array() ) {
     1462        // Backward compatibility. Convert deprecated function parameters into an options hash.
     1463        if ( ! is_array( $args ) || func_num_args() > 1 ) {
     1464                _deprecated_argument( __FUNCTION__, '4.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.' ), __FUNCTION__, __FILE__ ) );
     1465
     1466                $old_parameters = array( 'ID', 'image_size', 'include_permalink_in_anchor', 'display_media_icon', 'link_content' );
     1467                $func_args = func_get_args();
     1468                $args = array_combine( array_slice( $old_parameters, 0, count( $func_args ) ), $func_args );
     1469        }
     1470        $args = wp_parse_args( $args, array(
     1471                'ID'                          => 0,
     1472                'image_size'                  => 'thumbnail',
     1473                'include_permalink_in_anchor' => false,
     1474                'display_media_icon'          => false,
     1475                'link_content'                => false,
     1476        ) );
     1477
     1478        $id = intval( $args['ID'] );
    14601479        $_post = get_post( $id );
    14611480
    14621481        if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) )
    14631482                return __( 'Missing Attachment' );
    14641483
    1465         if ( $permalink )
     1484        if ( $args['include_permalink_in_anchor'] )
    14661485                $url = get_attachment_link( $_post->ID );
    14671486
    1468         if ( $text )
    1469                 $link_text = $text;
    1470         elseif ( $size && 'none' != $size )
    1471                 $link_text = wp_get_attachment_image( $id, $size, $icon );
    1472         else
    1473                 $link_text = '';
     1487        $link_content = '';
     1488        if ( $args['link_content'] )
     1489                $link_content .= $args['link_content'];
     1490        elseif ( $args['image_size'] && 'none' != $args['image_size'] )
     1491                $link_content .= wp_get_attachment_image( $id, $args['image_size'], $args['display_media_icon'] );
    14741492
    1475         if ( trim( $link_text ) == '' )
    1476                 $link_text = $_post->post_title;
     1493        if ( trim( $link_content ) == '' )
     1494                $link_content = $_post->post_title;
    14771495
    14781496        /**
    14791497         * Filter a retrieved attachment page link.
    14801498         *
    14811499         * @since 2.7.0
    14821500         *
    1483          * @param string      $link_html The page link HTML output.
    1484          * @param int         $id        Post ID.
    1485          * @param string      $size      Image size. Default 'thumbnail'.
    1486          * @param bool        $permalink Whether to add permalink to image. Default false.
    1487          * @param bool        $icon      Whether to include an icon. Default false.
    1488          * @param string|bool $text      If string, will be link text. Default false.
     1501         * @param string      $link_html                           The page link HTML output.
     1502         * @param int         $id                                  Post ID.
     1503         * @param string      $args['image_size']                  Image size. Default 'thumbnail'.
     1504         * @param bool        $args['include_permalink_in_anchor'] Whether to add permalink in the anchor. Default false.
     1505         * @param bool        $args['display_media_icon']          Whether to include an icon. Default false.
     1506         * @param string|bool $args['link_content']                Content of the anchor. Default false.
    14891507         */
    1490         return apply_filters( 'wp_get_attachment_link', "<a href='$url'>$link_text</a>", $id, $size, $permalink, $icon, $text );
     1508        return apply_filters( 'wp_get_attachment_link', "<a href='$url'>$link_content</a>", $id, $args['image_size'], $args['include_permalink_in_anchor'], $args['display_media_icon'], $args['link_content'] );
    14911509}
    14921510
    14931511/**