Skip to content

Commit 08a89eb

Browse files
author
Nikola Miljković
authored
Merge pull request #63 from WP-for-Church/dev
Release 2.4.9
2 parents d27cb59 + 2f1476e commit 08a89eb

File tree

5 files changed

+143
-89
lines changed

5 files changed

+143
-89
lines changed

includes/shortcodes.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,9 @@ function displaySermons( $atts = array() ) {
624624
'post_type' => 'wpfc_sermon',
625625
'posts_per_page' => $args['per_page'],
626626
'order' => $args['order'],
627+
'meta_key' => 'sermon_date',
628+
'meta_value_num' => time(),
629+
'meta_compare' => '<=',
627630
'paged' => $my_page,
628631
);
629632

@@ -640,7 +643,12 @@ function displaySermons( $atts = array() ) {
640643
$args['orderby'] = 'date';
641644
}
642645

643-
$query_args['orderby'] = $args['orderby'];
646+
// set the ordering options
647+
if ( $args['orderby'] === 'date' ) {
648+
$query_args['orderby'] = 'meta_value_num';
649+
} else {
650+
$query_args['orderby'] = $args['orderby'];
651+
}
644652

645653
// if we should show just specific sermons
646654
if ( $args['sermons'] ) {
@@ -699,6 +707,26 @@ function displaySermons( $atts = array() ) {
699707
}
700708
}
701709

710+
foreach ( array( 'wpfc_preacher', 'wpfc_sermon_series', 'wpfc_sermon_topics', 'wpfc_bible_book' ) as $filter ) {
711+
if ( ! empty( $_GET[ $filter ] ) ) {
712+
if ( empty( $query_args['tax_query']['custom'] ) || empty( $query_args['tax_query'] ) ) {
713+
$query_args['tax_query'] = array();
714+
}
715+
716+
$query_args['tax_query'][0][] = array(
717+
'taxonomy' => $filter,
718+
'field' => 'slug',
719+
'terms' => sanitize_title_for_query( $_GET[ $filter ] ),
720+
);
721+
722+
$query_args['tax_query']['custom'] = true;
723+
}
724+
}
725+
726+
if ( ! empty( $query_args['tax_query'] ) && count( $query_args['tax_query'] ) > 1 && ! empty( $query_args['tax_query']['custom'] ) ) {
727+
unset( $query_args['tax_query']['custom'] );
728+
}
729+
702730
$listing = new WP_Query( $query_args );
703731

704732
if ( $listing->have_posts() ) {
@@ -747,4 +775,4 @@ function displaySermons( $atts = array() ) {
747775
}
748776

749777
$WPFC_Shortcodes = new WPFC_Shortcodes;
750-
$WPFC_Shortcodes->init();
778+
$WPFC_Shortcodes->init();

includes/sm-deprecated-functions.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Place where functions come to die.
4+
*
5+
* @since 2.4.9
6+
*/
7+
8+
9+
/**
10+
* Searches WP_Query for sermon_date meta sort and removes it.
11+
* `sermon_date` meta has been removed in 2.4.7.
12+
*
13+
* @param WP_Query $data Query instance
14+
*
15+
* @return WP_Query
16+
*
17+
* @since 2.4.9
18+
*/
19+
function sm_modify_wp_query( $data ) {
20+
// If it's not a sermon, bail out
21+
if ( empty( $data->query_vars['post_type'] ) || $data->query_vars['post_type'] !== 'wpfc_sermon' ) {
22+
return $data;
23+
}
24+
25+
foreach ( array( 'query' => $data->query, 'query_vars' => $data->query_vars ) as $type => $vars ) {
26+
// Modify ordering
27+
if ( ! empty( $vars['orderby'] ) && in_array( $vars['orderby'], array(
28+
'meta_value',
29+
'meta_value_num'
30+
) ) && $vars['meta_key'] === 'sermon_date' ) {
31+
$vars['orderby'] = 'date';
32+
unset( $vars['meta_key'], $vars['meta_value_num'], $vars['meta_compare'] );
33+
34+
// save modified data to original query
35+
$data->{$type} = $vars;
36+
}
37+
}
38+
39+
return $data;
40+
}
41+
42+
add_filter( 'pre_get_posts', 'sm_modify_wp_query' );

includes/template-tags.php

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -135,64 +135,68 @@ function render_wpfc_sermon_archive() {
135135

136136
// render sermon sorting
137137
function render_wpfc_sorting() {
138-
$html = '';
139-
$html .= '<div id="wpfc_sermon_sorting">';
140-
$html .= '<span class="sortPreacher">';
141-
$html .= '<form action="';
142-
$html .= home_url();
143-
$html .= '" method="get">';
144-
$html .= '<select name="wpfc_preacher" id="wpfc_preacher" onchange="return this.form.submit()">';
145-
$html .= '<option value="">';
146-
$html .= 'Sort by ' . ( \SermonManager::getOption( 'preacher_label' ) ?: 'Preacher' );
147-
$html .= '</option>';
148-
$html .= wpfc_get_term_dropdown( 'wpfc_preacher' );
149-
$html .= '</select>';
150-
$html .= '<noscript><div><input type="submit" value="Submit" /></div></noscript>';
151-
$html .= '</form>';
152-
$html .= '</span>';
153-
$html .= '<span class="sortSeries">';
154-
$html .= '<form action="';
155-
$html .= home_url();
156-
$html .= '" method="get">';
157-
$html .= '<select name="wpfc_sermon_series" id="wpfc_sermon_series" onchange="return this.form.submit()">';
158-
$html .= '<option value="">';
159-
$html .= 'Sort by Series';
160-
$html .= '</option>';
161-
$html .= wpfc_get_term_dropdown( 'wpfc_sermon_series' );
162-
$html .= '</select>';
163-
$html .= '<noscript><div><input type="submit" value="Submit" /></div></noscript>';
164-
$html .= '</form>';
165-
$html .= '</span>';
166-
$html .= '<span class="sortTopics">';
167-
$html .= '<form action="';
168-
$html .= home_url();
169-
$html .= '" method="get">';
170-
$html .= '<select name="wpfc_sermon_topics" id="wpfc_sermon_topics" onchange="return this.form.submit()">';
171-
$html .= '<option value="">';
172-
$html .= 'Sort by Topic';
173-
$html .= '</option>';
174-
$html .= wpfc_get_term_dropdown( 'wpfc_sermon_topics' );
175-
$html .= '</select>';
176-
$html .= '<noscript><div><input type="submit" value="Submit" /></div></noscript>';
177-
$html .= '</form>';
178-
$html .= '</span>';
179-
$html .= '<span class="sortBooks">';
180-
$html .= '<form action="';
181-
$html .= home_url();
182-
$html .= '" method="get">';
183-
$html .= '<select name="wpfc_bible_book" id="wpfc_bible_book" onchange="return this.form.submit()">';
184-
$html .= '<option value="">';
185-
$html .= 'Sort by Book';
186-
$html .= '</option>';
187-
$html .= wpfc_get_term_dropdown( 'wpfc_bible_book' );
188-
$html .= '</select>';
189-
$html .= '</select>';
190-
$html .= '<noscript><div><input type="submit" value="Submit" /></div></noscript>';
191-
$html .= '</form>';
192-
$html .= '</span>';
193-
$html .= '</div>';
194-
195-
return $html;
138+
ob_start(); ?>
139+
<div id="wpfc_sermon_sorting">
140+
<div class="sortPreacher">
141+
<form>
142+
<select name="wpfc_preacher"
143+
title="Sort by <?php echo \SermonManager::getOption( 'preacher_label' ) ?: 'Preacher'; ?>"
144+
id="wpfc_preacher" onchange="return this.form.submit()">
145+
<option value="">
146+
Sort by <?php echo \SermonManager::getOption( 'preacher_label' ) ?: 'Preacher'; ?>
147+
</option>
148+
<?php echo wpfc_get_term_dropdown( 'wpfc_preacher' ); ?>
149+
</select>
150+
<noscript>
151+
<div><input type="submit" value="Submit"/></div>
152+
</noscript>
153+
</form>
154+
</div>
155+
<div class="sortSeries">
156+
<form>
157+
<select title="Sort by Series" name="wpfc_sermon_series" id="wpfc_sermon_series"
158+
onchange="return this.form.submit()">
159+
<option value="">
160+
Sort by Series
161+
</option>
162+
<?php echo wpfc_get_term_dropdown( 'wpfc_sermon_series' ); ?>
163+
</select>
164+
<noscript>
165+
<div><input type="submit" value="Submit"/></div>
166+
</noscript>
167+
</form>
168+
</div>
169+
<div class="sortTopics">
170+
<form>
171+
<select title="Sort by Topic" name="wpfc_sermon_topics" id="wpfc_sermon_topics"
172+
onchange="return this.form.submit()">
173+
<option value="">
174+
Sort by Topic
175+
</option>
176+
<?php echo wpfc_get_term_dropdown( 'wpfc_sermon_topics' ); ?>
177+
</select>
178+
<noscript>
179+
<div><input type="submit" value="Submit"/></div>
180+
</noscript>
181+
</form>
182+
</div>
183+
<div class="sortBooks">
184+
<form>
185+
<select title="Sort by Book" name="wpfc_bible_book" id="wpfc_bible_book"
186+
onchange="return this.form.submit()">
187+
<option value="">
188+
Sort by Book
189+
</option>
190+
<?php echo wpfc_get_term_dropdown( 'wpfc_bible_book' ); ?>
191+
</select>
192+
<noscript>
193+
<div><input type="submit" value="Submit"/></div>
194+
</noscript>
195+
</form>
196+
</div>
197+
</div>
198+
<?php
199+
return ob_get_clean();
196200
}
197201

198202
// echo any sermon meta

readme.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: http://wpforchurch.com/
44
Tags: church, sermon, sermons, preaching, podcasting
55
Requires at least: 4.5
66
Tested up to: 4.8.1
7-
Stable tag: 2.4.8
7+
Stable tag: 2.4.9
88

99
Add audio and video sermons, manage speakers, series, and more to your church website.
1010

@@ -83,6 +83,11 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man
8383
2. Sermon Files
8484

8585
== Changelog ==
86+
= 2.4.9 =
87+
* Fix new sermons not appearing
88+
* Fix couple PHP warnings
89+
* Fix filtering in shortcode
90+
8691
= 2.4.8 =
8792
* Fix featured image not working
8893

sermons.php

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Sermon Manager for WordPress
44
Plugin URI: http://www.wpforchurch.com/products/sermon-manager-for-wordpress/
55
Description: Add audio and video sermons, manage speakers, series, and more. Visit <a href="http://wpforchurch.com" target="_blank">Wordpress for Church</a> for tutorials and support.
6-
Version: 2.4.8
6+
Version: 2.4.9
77
Author: WP for Church
88
Contributors: wpforchurch, jprummer, jamzth
99
Author URI: http://www.wpforchurch.com/
@@ -55,8 +55,6 @@ public function __construct() {
5555
add_filter( 'post_class', array( $this, 'add_additional_sermon_classes' ), 10, 3 );
5656
// Add Sermon Manager image sizes
5757
add_action( 'after_setup_theme', array( $this, 'add_image_sizes' ) );
58-
// Fix Sermon ordering
59-
add_action( 'pre_get_posts', array( $this, 'fix_sermons_ordering' ), 9999 );
6058
// no idea... better not touch it for now.
6159
add_filter( 'sermon-images-disable-public-css', '__return_true' );
6260

@@ -167,7 +165,8 @@ private function includes() {
167165
'/includes/widgets.php', // Widgets
168166
'/includes/template-tags.php', // Template Tags
169167
'/includes/podcast-functions.php', // Podcast Functions
170-
'/includes/helper-functions.php' // Global Helper Functions
168+
'/includes/helper-functions.php', // Global Helper Functions
169+
'/includes/sm-deprecated-functions.php', // Deprecated SM functions
171170
);
172171

173172
/**
@@ -319,30 +318,6 @@ public static function add_additional_sermon_classes( $classes, $class, $ID ) {
319318
return $classes;
320319
}
321320

322-
/**
323-
* Fixes Sermons ordering. Uses `sermon_date` meta instead of post's published date
324-
*
325-
* @param WP_Query $query
326-
*
327-
* @return void
328-
*/
329-
public static function fix_sermons_ordering( $query ) {
330-
if ( ! is_admin() && $query->is_main_query() ) {
331-
if ( is_post_type_archive( 'wpfc_sermon' ) ||
332-
is_tax( 'wpfc_preacher' ) ||
333-
is_tax( 'wpfc_sermon_topics' ) ||
334-
is_tax( 'wpfc_sermon_series' ) ||
335-
is_tax( 'wpfc_bible_book' )
336-
) {
337-
$query->set( 'meta_key', 'sermon_date' );
338-
$query->set( 'meta_value', time() );
339-
$query->set( 'meta_compare', '<=' );
340-
$query->set( 'orderby', 'meta_value_num' );
341-
$query->set( 'order', 'DESC' );
342-
}
343-
}
344-
}
345-
346321
/**
347322
* Add images sizes for Series and Speakers
348323
*

0 commit comments

Comments
 (0)