Skip to content

Commit a1fd0a4

Browse files
author
Nikola Miljkovic
committed
Merge branch 'release/2.15.15'
2 parents c8374a4 + 831b427 commit a1fd0a4

7 files changed

Lines changed: 181 additions & 65 deletions

File tree

assets/js/admin/settings/conditionals.js

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ if ( typeof sm_conditionals !== 'undefined' ) {
6666
*/
6767
let selected_value = this.value;
6868

69+
6970
// Hide or show the elements.
70-
sm_hide_show_elements( target_value, selected_value, not, table_row );
71+
sm_hide_show_elements( target_value, conditional_element.closest( 'tr' ).hasClass( 'hidden' ) ? false : selected_value, not, table_row );
7172
}
7273
);
7374

7475
// Call the function first time.
75-
sm_hide_show_elements( target_value, conditional_element.val(), not, table_row );
76+
sm_hide_show_elements( target_value, conditional_element.closest( 'tr' ).hasClass( 'hidden' ) ? false : conditional_element.val(), not, table_row );
7677
}
7778
);
7879
}
@@ -122,9 +123,14 @@ function sm_hide_show_elements( target_value, current_value, not, table_row ) {
122123
if ( is_ajax ) {
123124
sm_reset_option_value( element, ! table_row.hasClass( 'hidden' ) );
124125

126+
// The GET parameters.
127+
let $_GET = sm_get_query_params( document.location.search );
128+
125129
let data = {
126130
'action': 'sm_settings_get_select_data',
127-
'id': current_value,
131+
'category': current_value,
132+
'option_id': table_row.find( 'select' ).attr( 'id' ),
133+
'podcast_id': $_GET[ 'post' ],
128134
};
129135

130136
// Request element data.
@@ -162,12 +168,24 @@ function sm_hide_show_elements( target_value, current_value, not, table_row ) {
162168
jQuery( this.remove() );
163169
}
164170
);
171+
165172
jQuery.each(
166-
response,
173+
response.options,
167174
function ( id, item ) {
168175
table_row.find( 'select' ).append( jQuery( '<option/>' ).val( id ).text( item ) );
169176
}
170177
);
178+
179+
if ( response.selected ) {
180+
table_row.find( 'select' ).val( response.selected ).change();
181+
} else {
182+
table_row.find( 'select' ).prop( "selectedIndex", 0 );
183+
}
184+
185+
if ( Object.keys( response.options ).length === 0 ) {
186+
table_row.addClass( 'hidden' );
187+
return;
188+
}
171189
break;
172190
}
173191
}
@@ -221,3 +239,22 @@ function sm_isset( value ) {
221239
return false
222240
}
223241
}
242+
243+
/**
244+
* Gets query parameters from the URL (GET for example).
245+
*
246+
* @param {string} qs Query string.
247+
*/
248+
function sm_get_query_params( qs ) {
249+
qs = qs.split( "+" ).join( " " );
250+
var params = {},
251+
tokens,
252+
re = /[?&]?([^=]+)=([^&]*)/g;
253+
254+
while ( tokens = re.exec( qs ) ) {
255+
params[ decodeURIComponent( tokens[ 1 ] ) ]
256+
= decodeURIComponent( tokens[ 2 ] );
257+
}
258+
259+
return params;
260+
}

assets/js/admin/settings/conditionals.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/sm-template-functions.php

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
350351
function 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
/**

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Tags: church, sermon, sermons, preaching, podcasting, manage, managing, podcasts
55
Requires at least: 4.7.0
66
Tested up to: 5.1
77
Requires PHP: 5.3
8-
Stable tag: 2.15.14
8+
Stable tag: 2.15.15
99
License: GPLv2
1010
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1111

@@ -122,6 +122,9 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man
122122
2. Sermon Files
123123

124124
## Changelog ##
125+
### 2.15.15 ###
126+
* Fix: RSS feed not working
127+
125128
### 2.15.14 ###
126129
* New: Add compatibility for Pro theme
127130
* New: Add a setting to change default sermon ordering (in "Display" tab)

sermons.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Sermon Manager for WordPress
44
* Plugin URI: https://www.wpforchurch.com/products/sermon-manager-for-wordpress/
55
* Description: Add audio and video sermons, manage speakers, series, and more.
6-
* Version: 2.15.14
6+
* Version: 2.15.15
77
* Author: WP for Church
88
* Author URI: https://www.wpforchurch.com/
99
* Requires at least: 4.5
@@ -866,11 +866,14 @@ function () {
866866
}
867867
);
868868

869-
add_action( 'wp_ajax_sm_settings_get_select_data', function () {
870-
echo json_encode( apply_filters( 'sm_settings_get_select_data', array(), $_POST['id'] ) );
869+
add_action(
870+
'wp_ajax_sm_settings_get_select_data',
871+
function () {
872+
echo json_encode( apply_filters( 'sm_settings_get_select_data', array(), $_POST['category'], $_POST['podcast_id'], $_POST['option_id'] ) );
871873

872-
wp_die();
873-
} );
874+
wp_die();
875+
}
876+
);
874877
}
875878
}
876879

views/partials/content-sermon-archive.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,9 @@
112112
<?php endif; ?>
113113
</div>
114114

115-
<?php if ( \SermonManager::getOption( 'archive_player' ) && ( get_wpfc_sermon_meta( 'sermon_audio' ) || get_wpfc_sermon_meta( 'sermon_audio_id' ) ) ) : ?>
116-
<?php
117-
$sermon_audio_id = get_wpfc_sermon_meta( 'sermon_audio_id' );
118-
$sermon_audio_url_wp = $sermon_audio_id ? wp_get_attachment_url( intval( $sermon_audio_id ) ) : false;
119-
$sermon_audio_url = $sermon_audio_id && $sermon_audio_url_wp ? $sermon_audio_url_wp : get_wpfc_sermon_meta( 'sermon_audio' );
120-
?>
115+
<?php if ( \SermonManager::getOption( 'archive_player' ) ) : ?>
121116
<div class="wpfc-sermon-audio">
122-
<?php echo wpfc_render_audio( $sermon_audio_url ); ?>
117+
<?php echo wpfc_render_audio( $post->ID ); ?>
123118
</div>
124119
<?php endif; ?>
125120
<?php else : ?>

views/wpfc-podcast-feed.php

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
if ( isset( $GLOBALS['sm_podcast_data'] ) && is_array( $GLOBALS['sm_podcast_data'] ) ) {
1313
$settings = $GLOBALS['sm_podcast_data'];
14+
$is_pro = true;
1415
} else {
1516
$settings = array();
17+
$is_pro = false;
1618
}
1719

1820
// Option ID => escape function.
@@ -180,16 +182,64 @@
180182

181183
$sermon_podcast_query = new WP_Query( $args );
182184

183-
$categories = array(
184-
'0' => '',
185-
'1' => 'Buddhism',
186-
'2' => 'Christianity',
187-
'3' => 'Hinduism',
188-
'4' => 'Islam',
189-
'5' => 'Judaism',
190-
'6' => 'Other',
191-
'7' => 'Spirituality',
192-
);
185+
if ( ! $is_pro ) {
186+
$categories = array(
187+
'0' => '',
188+
'1' => 'Buddhism',
189+
'2' => 'Christianity',
190+
'3' => 'Hinduism',
191+
'4' => 'Islam',
192+
'5' => 'Judaism',
193+
'6' => 'Other',
194+
'7' => 'Spirituality',
195+
);
196+
197+
$category = 'Religion &amp; Spirituality';
198+
$subcategory = esc_attr( ! empty( $categories[ $settings['itunes_sub_category'] ] ) ? $categories[ $settings['itunes_sub_category'] ] : 'Christianity' );
199+
$category_override = false;
200+
} else {
201+
if ( function_exists( 'smp_get_itunes_categories' ) && function_exists( 'smp_get_itunes_subcategories' ) ) {
202+
$category_override = PHP_EOL;
203+
$all_categories = smp_get_itunes_categories();
204+
$all_subcategories = smp_get_itunes_subcategories();
205+
206+
for ( $i = 1; $i <= 3; $i ++ ) {
207+
$category = isset( $settings[ 'itunes_category_' . $i ] ) ? $settings[ 'itunes_category_' . $i ] : '';
208+
$category = $category ? ( isset( $all_categories[ $category ] ) ? $all_categories[ $category ] : '' ) : '';
209+
$category = str_replace( '&', '&amp;', $category );
210+
$subcategory = isset( $settings[ 'itunes_category_' . $i . '_subcategory' ] ) ? $settings[ 'itunes_category_' . $i . '_subcategory' ] : '';
211+
$subcategory = str_replace( '&', '&amp;', $subcategory );
212+
213+
if ( $subcategory ) {
214+
foreach ( $all_subcategories as $cat_id => $cat_subs ) {
215+
foreach ( $cat_subs as $cat_sub_id => $cat_sub_name ) {
216+
if ( $cat_sub_id === $subcategory ) {
217+
$subcategory = $cat_sub_name;
218+
break 2;
219+
}
220+
}
221+
}
222+
}
223+
224+
if ( ! $category ) {
225+
continue;
226+
}
227+
228+
$category_override .= '<itunes:category text="' . $category . '">' . PHP_EOL;
229+
230+
if ( $subcategory ) {
231+
$category_override .= ' <itunes:category text="' . $subcategory . '"/>' . PHP_EOL;
232+
}
233+
234+
$category_override .= '</itunes:category>' . PHP_EOL;
235+
}
236+
237+
unset( $category );
238+
unset( $subcategory );
239+
240+
$category_override .= PHP_EOL;
241+
}
242+
}
193243

194244
$title = $settings['title'];
195245
$link = $settings['website_link'];
@@ -203,7 +253,6 @@
203253
$owner_name = $settings['itunes_owner_name'];
204254
$owner_email = $settings['itunes_owner_email'];
205255
$cover_image_url = $settings['itunes_cover_image'];
206-
$subcategory = esc_attr( ! empty( $categories[ $settings['itunes_sub_category'] ] ) ? $categories[ $settings['itunes_sub_category'] ] : 'Christianity' );
207256

208257
?>
209258
<rss version="2.0"
@@ -236,9 +285,13 @@
236285
<itunes:image href="<?php echo $cover_image_url; ?>"/>
237286
<?php endif; ?>
238287

239-
<itunes:category text="Religion &amp; Spirituality">
240-
<itunes:category text="<?php echo $subcategory; ?>"/>
241-
</itunes:category>
288+
<?php if ( ! $category_override ) : ?>
289+
<itunes:category text="<?php echo $category; ?>">
290+
<itunes:category text="<?php echo $subcategory; ?>"/>
291+
</itunes:category>
292+
<?php else : ?>
293+
<?php echo $category_override; ?>
294+
<?php endif; ?>
242295
<?php
243296
if ( $sermon_podcast_query->have_posts() ) :
244297
while ( $sermon_podcast_query->have_posts() ) :

0 commit comments

Comments
 (0)