Making WordPress.org

Changeset 13984


Ignore:
Timestamp:
08/20/2024 04:23:12 AM (7 weeks ago)
Author:
coffee2code
Message:

Photo Directory, Template Tags: Adapt Admin::output_photo_in_metabox() into a more generic function suitable for use in more places.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/template-tags.php

    r12552 r13984  
    327327    return $output;
    328328}
     329
     330/**
     331 * Returns markup for a photo intended to be shown in a grid.
     332 *
     333 * Used at least by `Admin::meta_box_photos_by_contributor()` and `Uploads::output_user_recent_submissions()`.
     334 *
     335 * @param WP_Post      $post      Photo post object.
     336 * @param string|int[] $size      Image size. Accepts any registered image size name, or an
     337 *                                array of width and height values in pixels (in that order).
     338 * @param bool         $link_type What should the link go? One of: 'image' (direct to image),
     339 *                                'edit' (to edit the photo post), 'post' (to published photo post).
     340 *                                Default 'post';
     341 * @return string
     342 */
     343function get_photo_as_grid_item( $post, $size, $link_type = 'post' ) {
     344    $image_id = get_post_thumbnail_id( $post );
     345    if ( ! $image_id ) {
     346        return '';
     347    }
     348
     349    $pending_notice = '';
     350    $classes = 'photo-thumbnail';
     351
     352    if ( Photo::is_controversial( $image_id ) ) {
     353        $classes .= ' blurred';
     354    }
     355
     356    if ( 'pending' === $post->post_status ) {
     357        $classes .= ' pending';
     358        if ( 'edit' === $link_type ) {
     359            $pending_notice = '<div class="pending-notice">' . esc_html__( 'Pending', 'wporg-photos' ) . '</div>';
     360        }
     361    }
     362
     363    if ( 'fullsize' === $link_type ) {
     364        $link_url = wp_get_attachment_url( $image_id );
     365        $label = __( 'View full-sized version of the photo.', 'wporg-photos' );
     366    } elseif ( 'edit' === $link_type ) {
     367        $link_url = get_edit_post_link( $post );
     368        /* translators: %s: Post title. */
     369        $label = sprintf( __( 'Edit photo post &#8220;%s&#8221;', 'wporg-photos' ), $post->post_title );
     370    } else {
     371        $link_url = get_permalink( $post );
     372        $label = __( 'View the photo.', 'wporg-photos' );
     373    }
     374
     375    return sprintf(
     376        '<span><a class="photos-photo-link row-title" href="%s" aria-label="%s"><img class="%s" src="%s" alt="" /></a>%s</span>',
     377        esc_url( $link_url ),
     378        esc_attr( $label ),
     379        esc_attr( $classes ),
     380        esc_url( get_the_post_thumbnail_url( $post->ID, $size ) ),
     381        $pending_notice
     382    );
     383}
Note: See TracChangeset for help on using the changeset viewer.