Plugin Directory

Changeset 2892031

Timestamp:
04/01/2023 11:31:37 PM (16 months ago)
Author:
celloexpressions
Message:

Sheet Music Library: Additional handling to merge class names and address functions that run in both block and non-block contexts. General QC updates.

Location:
sheet-music-library/trunk/template
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sheet-music-library/trunk/template/template-filters.php

    r2886954 r2892031  
    1717    $no_download_message = get_post_meta( get_the_ID(), 'no-download-message', true );
    1818    $button_text = ( $no_download_message ) ? __( 'View Piece →', 'sheet-music-library' ) : __( 'View & Download →', 'sheet-music-library' );
    19    
     19
    2020    ob_start();
    2121    ?>
     
    7171
    7272    $video_url = esc_url( get_post_meta( get_the_ID(), 'piece-video-url', true ) );
    73    
     73
    7474    $no_download_message = get_post_meta( get_the_ID(), 'no-download-message', true );
    7575    $no_download_message = wp_kses( $no_download_message, array(
     
    134134// Filter post titles in archive contexts
    135135function sml_post_title_filter( $title, $post_id ) {
    136     if ( 'sheet_music' === get_post_type() && ! current_theme_supports( 'sheet_music_library' ) ) {
    137         if ( ! is_singular() ) {
    138             $no_download_message = get_post_meta( $post_id, 'no-download-message', true );
    139             if ( $no_download_message ) {
    140                 if ( ! is_admin() ) {
    141                     $title = '<span class="sml-restricted"></span>' . $title;
    142                 } else {
    143                     $title = '* ' . $title;
    144                 }
     136    if ( 'sheet_music' === get_post_type( $post_id ) ) {
     137        $no_download_message = get_post_meta( $post_id, 'no-download-message', true );
     138        if ( $no_download_message ) {
     139            if ( ! is_admin() ) {
     140                $title = '<span class="sml-restricted"></span>' . $title;
     141            } else {
     142                $title = '* ' . $title;
    145143            }
    146144        }
     
    151149// All sheet music shortcode.
    152150function sml_shortcode_all_sheet_music() {
    153     $pieces = get_posts( array( 
     151    $pieces = get_posts( array(
    154152        'numberposts' => '-1',
    155153        'post_type' => 'sheet_music',
     
    163161        'number' => 10,
    164162    ), $attrs );
    165     $pieces = get_posts( array( 
     163    $pieces = get_posts( array(
    166164        'numberposts' => absint( $a['number'] ),
    167165        'post_type' => 'sheet_music',
  • sheet-music-library/trunk/template/template-parts.php

    r2886952 r2892031  
    1919
    2020// Returns markup for the download buttons and terms.
    21 function sml_sheet_music_download_box( $score_url, $parts_url, $no_download_message ) {
     21function sml_sheet_music_download_box( $score_url, $parts_url, $no_download_message ) {
    2222   
    2323    // Block wrapper element attributes if called as a block render callback, or empty string when called in other contexts.
    24     $wrapper_attributes = get_block_wrapper_attributes();
    25 
    26     ob_start();
    27     ?><div class="download-box" <?php echo $wrapper_attributes; ?>>
     24    if ( null === $block_attributes ) {
     25        $wrapper_attributes = 'class="download-box"';
     26    } else {
     27        $wrapper_attributes = get_block_wrapper_attributes(['class' => 'download-box']);
     28    }
     29
     30    ob_start();
     31    ?><div <?php echo $wrapper_attributes; ?>>
    2832        <?php
    2933    if ( '' === $score_url && '' === $parts_url && '' === $no_download_message ) {
     
    8185
    8286// Returns markup for the download buttons and terms for the current post.
    83 function sml_sheet_music_download_box_current() {
     87// Block attributes is provided when this is run as a block render_callback.
     88function sml_sheet_music_download_box_current( $block_attributes = null ) {
    8489
    8590    // Get post meta fields' data.
     
    105110    ) );
    106111
    107     return sml_sheet_music_download_box( $score_url, $parts_url, $no_download_message );
     112    return sml_sheet_music_download_box( $score_url, $parts_url, $no_download_message );
    108113}
    109114
    110115
    111116// Returns markup for a linked preview image for the current sheet music piece.
    112 function sml_score_preview_current() {
    113 
    114     // Block wrapper element attributes if called as a block render callback, or empty string when called in other contexts.
    115     $wrapper_attributes = get_block_wrapper_attributes();
     117function sml_score_preview_current( $block_attributes = null ) {
     118
     119    // Block wrapper element attributes if called as a block render callback, or empty string when called in other contexts.
     120    if ( null === $block_attributes ) {
     121        $wrapper_attributes = 'class="piece-preview"';
     122    } else {
     123        $wrapper_attributes = get_block_wrapper_attributes(['class' => 'piece-preview']);
     124    }
    116125
    117126    // Get post meta fields' data.
     
    128137
    129138    if ( $image_url && ! $no_download_message ) { ?>
    130         <div class="piece-preview" <?php echo $wrapper_attributes; ?>>
     139        <div <?php echo $wrapper_attributes; ?>>
    131140            <a href="<?php echo $score_url; ?>" target="_blank"><img class="score-preview" src="<?php echo $image_url; ?>" alt="score preview"/></a>
    132141        </div>
     
    135144        // Dynamic blocks in the editor are rendered through REST API, frontend blocks are called directly.
    136145        elseif ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { ?>
    137         <div class="piece-preview" <?php echo $wrapper_attributes; ?>>
     146        <div <?php echo $wrapper_attributes; ?>>
    138147            <div class="score-preview placeholder">
    139148                <?php
     
    155164
    156165// Returns markup for a button-link to a single piece from an archive excerpt view.
    157 function sml_excerpt_button_current() {
    158     // Block wrapper element attributes if called as a block render callback, or empty string when called in other contexts.
    159     $wrapper_attributes = get_block_wrapper_attributes();
     166function sml_excerpt_button_current( $block_attributes = null ) {
     167
     168    // Block wrapper element attributes if called as a block render callback, or empty string when called in other contexts.
     169    if ( null === $block_attributes ) {
     170        $wrapper_attributes = 'class="download-box"';
     171    } else {
     172        $wrapper_attributes = get_block_wrapper_attributes(['class' => 'download-box']);
     173    }
    160174
    161175    // Get post meta fields' data.
     
    166180    ?>
    167181
    168     <div class="download-box" <?php echo $wrapper_attributes; ?>>
     182    <div <?php echo $wrapper_attributes; ?>>
    169183        <a class="button" href="<?php the_permalink(); ?>"><?php echo $button_text; ?></a>
    170184    </div>
     
    179193
    180194// Returns markup for a search form based on the html5 version of `get_search_form()`, scoped to the sheet music post type.
    181 function sml_sheet_music_search_form() {
    182     // Block wrapper element attributes if called as a block render callback, or empty string when called in other contexts.
    183     $wrapper_attributes = get_block_wrapper_attributes();
     195function sml_sheet_music_search_form( $block_attributes = null ) {
     196
     197    // Block wrapper element attributes if called as a block render callback, or empty string when called in other contexts.
     198    if ( null === $block_attributes ) {
     199        $wrapper_attributes = '';
     200    } else {
     201        $wrapper_attributes = get_block_wrapper_attributes();
     202    }
    184203
    185204    ob_start();
     
    203222
    204223// Returns markup for audio and/or video players for the current sheet music post.
    205 function sml_sheet_music_audio_video_current( $block_attributes = false ) {
    206     // Block wrapper element attributes if called as a block render callback, or empty string when called in other contexts.
    207     $wrapper_attributes = get_block_wrapper_attributes();
     224function sml_sheet_music_audio_video_current( $block_attributes = null ) {
     225
     226    // Block wrapper element attributes if called as a block render callback, or empty string when called in other contexts.
     227    if ( null === $block_attributes ) {
     228        $wrapper_attributes = 'class="piece-recording"';
     229    } else {
     230        $wrapper_attributes = get_block_wrapper_attributes(['class' => 'piece-recording']);
     231    }
    208232
    209233    $audio_attachment_id = absint( get_post_meta( get_the_ID(), 'audio-attachment-id', true ) );
     
    223247    ob_start();
    224248    ?>
    225     <div <?php echo $wrapper_attributes; ?> class="piece-recording"><?php
     249    <div <?php echo $wrapper_attributes; ?>><?php
    226250        if ( $audio_url ) {
    227251            // Embedded audio player.
Note: See TracChangeset for help on using the changeset viewer.