@@ -94,7 +94,7 @@ function render_wpfc_sorting( $args = array() ) {
9494 'wpfc_preacher ' => 'hide_preachers ' ,
9595 'wpfc_bible_book ' => 'hide_books ' ,
9696 'wpfc_service_type ' => 'hide_service_types ' ,
97- 'wpfc_dates ' => 'hide_dates ' ,
97+ 'wpfc_dates ' => 'hide_dates ' ,
9898 ) );
9999
100100 // Save orig args for filters.
@@ -115,7 +115,7 @@ function render_wpfc_sorting( $args = array() ) {
115115 'hide_preachers ' => '' ,
116116 'hide_books ' => '' ,
117117 'hide_service_types ' => SermonManager::getOption ( 'service_type_filtering ' ) ? '' : 'yes ' ,
118- 'hide_dates ' => '' ,
118+ 'hide_dates ' => '' ,
119119 'hide_filters ' => ! SermonManager::getOption ( 'hide_filters ' ),
120120 'action ' => 'none ' ,
121121 );
@@ -340,59 +340,84 @@ function wpfc_render_video( $url = '', $seek = true ) {
340340/**
341341 * Renders the audio player.
342342 *
343- * @param string| int $source The URL or the attachment ID of the audio file.
344- * @param int $seek Allows seeking to specific second in audio file.
343+ * @param int|string $source The ID of the sermon, or alternatively, the URL or the attachment ID of the audio file.
344+ * @param int $seek Seek to specific second in audio file.
345345 *
346346 * @since 2.12.3 added $seek
347+ * @since 2.15.15 The sermon can be used as first parameter
347348 *
348- * @return string Audio player HTML.
349+ * @return string|false Audio player HTML or false if sermon has no audio .
349350 */
350351function wpfc_render_audio ( $ source = '' , $ seek = null ) {
351- if ( is_int ( $ source ) || is_numeric ( $ source ) ) {
352- $ source = wp_get_attachment_url ( intval ( $ source ) ) ;
352+ // For later filtering.
353+ $ source_orig = $ source ;
353354
354- if ( ! $ source ) {
355- return '' ;
355+ // Check if it's a sermon or attachment ID.
356+ if ( is_numeric ( $ source ) ) {
357+ $ object = get_post ( $ source );
358+
359+ if ( ! $ object ) {
360+ return false ;
356361 }
357- } elseif ( is_string ( $ source ) ) {
358- if ( '' === trim ( $ source ) ) {
359- return '' ;
362+
363+ switch ( $ object ->post_type ) {
364+ case 'wpfc_sermon ' :
365+ $ sermon_audio_id = get_wpfc_sermon_meta ( 'sermon_audio_id ' );
366+ $ sermon_audio_url = get_wpfc_sermon_meta ( 'sermon_audio ' );
367+ $ sermon_audio_url_wp = $ sermon_audio_id ? wp_get_attachment_url ( intval ( $ sermon_audio_id ) ) : false ;
368+
369+ $ source = $ sermon_audio_id && $ sermon_audio_url_wp ? $ sermon_audio_url_wp : $ sermon_audio_url ;
370+ break ;
371+ case 'attachment ' :
372+ $ source = wp_get_attachment_url ( $ object ->ID );
373+ break ;
360374 }
361- } else {
362- return '' ;
363375 }
364376
377+ // Check if set.
378+ if ( ! $ source ) {
379+ return false ;
380+ }
381+
382+ // Get the current player.
365383 $ player = strtolower ( \SermonManager::getOption ( 'player ' ) ?: 'plyr ' );
366384
367- if ( strtolower ( 'WordPress ' ) === $ player ) {
368- $ attr = array (
369- 'src ' => $ source ,
370- 'preload ' => 'none ' ,
371- );
385+ switch ( strtolower ( $ player ) ) {
386+ case 'wordpress ' : // phpcs:ignore
387+ $ attr = array (
388+ 'src ' => $ source ,
389+ 'preload ' => 'none ' ,
390+ );
372391
373- $ output = wp_audio_shortcode ( $ attr );
374- } else {
375- $ extra_settings = '' ;
392+ $ output = wp_audio_shortcode ( $ attr );
393+ break ;
394+ default :
395+ $ extra_settings = '' ;
376396
377- if ( is_numeric ( $ seek ) ) {
378- // Sanitation just in case.
379- $ extra_settings = 'data-plyr_seek= \'' . intval ( $ seek ) . '\'' ;
380- }
397+ if ( is_numeric ( $ seek ) ) {
398+ // Sanitation just in case.
399+ $ extra_settings = 'data-plyr_seek= \'' . intval ( $ seek ) . '\'' ;
400+ }
401+
402+ $ output = '' ;
381403
382- $ output = '' ;
404+ $ output .= '<audio controls preload="metadata" class="wpfc-sermon-player ' . ( 'mediaelement ' === $ player ? 'mejs__player ' : '' ) . '" ' . $ extra_settings . '> ' ;
405+ $ output .= '<source src=" ' . $ source . '" type="audio/mp3"> ' ;
406+ $ output .= '</audio> ' ;
383407
384- $ output .= '<audio controls preload="metadata" class="wpfc-sermon-player ' . ( 'mediaelement ' === $ player ? 'mejs__player ' : '' ) . '" ' . $ extra_settings . '> ' ;
385- $ output .= '<source src=" ' . $ source . '" type="audio/mp3"> ' ;
386- $ output .= '</audio> ' ;
408+ break ;
387409 }
388410
389411 /**
390412 * Allows changing of the audio player to any HTML.
391413 *
392- * @param string $output Audio player HTML.
393- * @param string $source Audio source URL.
414+ * @param string $output Audio player HTML.
415+ * @param string $source Audio source URL.
416+ * @param int|string $source_orig The original source parameter.
417+ *
418+ * @since 2.15.15 Added $source_orig.
394419 */
395- return apply_filters ( 'sm_audio_player ' , $ output , $ source );
420+ return apply_filters ( 'sm_audio_player ' , $ output , $ source, $ source_orig );
396421}
397422
398423/**
0 commit comments