Make WordPress Core


Ignore:
Timestamp:
10/20/2020 03:12:07 AM (4 years ago)
Author:
helen
Message:

Media: Indicate if item is or was used as a site option in the details modal.

Props Mista-Flo, melchoyce.
Fixes #42063.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/template.php

    r49205 r49223  
    22382238 *
    22392239 * @since 3.2.0
     2240 * @since 5.6.0 Added the `$echo` parameter.
    22402241 *
    22412242 * @param WP_Post $post The attachment post to retrieve states for.
    2242  */
    2243 function _media_states( $post ) {
     2243 * @param bool    $echo Optional. Whether to echo the post states as an HTML string. Default true.
     2244 * @return string Media states string.
     2245 */
     2246function _media_states( $post, $echo = true ) {
     2247    $media_states = get_media_states( $post );
     2248    $media_states_string = '';
     2249
     2250    if ( ! empty( $media_states ) ) {
     2251        $state_count = count( $media_states );
     2252        $i           = 0;
     2253
     2254        $media_states_string .= ' — ';
     2255
     2256        foreach ( $media_states as $state ) {
     2257            $sep = ( ++$i === $state_count ) ? '' : ', ';
     2258
     2259            $media_states_string .= "<span class='post-state'>$state$sep</span>";
     2260        }
     2261    }
     2262
     2263    if ( $echo ) {
     2264        echo $media_states_string;
     2265    }
     2266
     2267    return $media_states_string;
     2268}
     2269
     2270/**
     2271 * Retrieves an array of media states from an attachment.
     2272 *
     2273 * @since 5.6.0
     2274 *
     2275 * @param WP_Post $post The attachment to retrieve states for.
     2276 * @return string[] Array of media state labels keyed by their state.
     2277 */
     2278function get_media_states( $post ) {
    22442279    static $header_images;
    22452280
     
    23112346     * @param WP_Post  $post         The current attachment object.
    23122347     */
    2313     $media_states = apply_filters( 'display_media_states', $media_states, $post );
    2314 
    2315     if ( ! empty( $media_states ) ) {
    2316         $state_count = count( $media_states );
    2317         $i           = 0;
    2318 
    2319         echo ' &mdash; ';
    2320 
    2321         foreach ( $media_states as $state ) {
    2322             $sep = ( ++$i === $state_count ) ? '' : ', ';
    2323 
    2324             echo "<span class='post-state'>$state$sep</span>";
    2325         }
    2326     }
     2348     return apply_filters( 'display_media_states', $media_states, $post );
    23272349}
    23282350
Note: See TracChangeset for help on using the changeset viewer.