Plugin Directory

Changeset 2948258

Timestamp:
08/06/2023 11:06:07 PM (12 months ago)
Author:
celloexpressions
Message:

Sheet Music Library: Improve conditional logic for sheet music piece date modified determination.

File:
1 edited

Legend:

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

    r2892031 r2948258  
    5959
    6060// Returns markup for last updated text for sheet music PDFs. Displays the newer date of the score and parts attachment files.
     61
    6162function sml_sheet_music_last_updated_text( $score_url = false, $parts_url = false ) {
    6263    if ( ! $score_url ) {
     
    6566        $score_attachment_id = absint( attachment_url_to_postid( $score_url ) );
    6667    }
    67     $score_date = get_the_modified_date( 'U', $score_attachment_id );
     68    // Handle empty attachment.
     69    if ( $score_attachment_id ) {
     70        $score_date = get_the_modified_date( 'U', $score_attachment_id );
     71    } else {
     72        $score_date = 0;
     73    }
    6874
    6975    if ( ! $parts_url ) {
     
    7278        $parts_attachment_id = absint( attachment_url_to_postid( $parts_url ) );
    7379    }
    74     $parts_date = get_the_modified_date( 'U', $parts_attachment_id );
     80    // Handle empty attachment.
     81    if ( $parts_attachment_id ) {
     82        $parts_date = get_the_modified_date( 'U', $parts_attachment_id );   
     83    } else {
     84        $parts_date = 0;
     85    }
     86
     87    // Ensure that the modified date is not before the piece publish date.
     88    $post_publish = absint( get_the_date( 'U', get_the_ID() ) );
    7589
    7690    // Report the more recent attachment modified date. Note this is not necessarily the file-modified date, but any other attachment modify triggers are unlikely.
    77     if ( $score_date > $parts_date ) {
     91    // Falls back to the post published date if both attachments are missing.
     92    if ( $post_publish > $score_date && $post_publish > $parts_date ) {
     93        $date = get_the_date( 'F j, Y', get_the_id() );
     94    } elseif ( $score_date > $parts_date ) {
    7895        $date = get_the_modified_date( 'F j, Y', $score_attachment_id );
    7996    } else {
Note: See TracChangeset for help on using the changeset viewer.