Skip to content

Commit

Permalink
Merge pull request #63 from WP-for-Church/dev
Browse files Browse the repository at this point in the history
Release 2.4.9
  • Loading branch information
Nikola Miljković authored Aug 17, 2017
2 parents d27cb59 + 2f1476e commit 08a89eb
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 89 deletions.
32 changes: 30 additions & 2 deletions includes/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@ function displaySermons( $atts = array() ) {
'post_type' => 'wpfc_sermon',
'posts_per_page' => $args['per_page'],
'order' => $args['order'],
'meta_key' => 'sermon_date',
'meta_value_num' => time(),
'meta_compare' => '<=',
'paged' => $my_page,
);

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

$query_args['orderby'] = $args['orderby'];
// set the ordering options
if ( $args['orderby'] === 'date' ) {
$query_args['orderby'] = 'meta_value_num';
} else {
$query_args['orderby'] = $args['orderby'];
}

// if we should show just specific sermons
if ( $args['sermons'] ) {
Expand Down Expand Up @@ -699,6 +707,26 @@ function displaySermons( $atts = array() ) {
}
}

foreach ( array( 'wpfc_preacher', 'wpfc_sermon_series', 'wpfc_sermon_topics', 'wpfc_bible_book' ) as $filter ) {
if ( ! empty( $_GET[ $filter ] ) ) {
if ( empty( $query_args['tax_query']['custom'] ) || empty( $query_args['tax_query'] ) ) {
$query_args['tax_query'] = array();
}

$query_args['tax_query'][0][] = array(
'taxonomy' => $filter,
'field' => 'slug',
'terms' => sanitize_title_for_query( $_GET[ $filter ] ),
);

$query_args['tax_query']['custom'] = true;
}
}

if ( ! empty( $query_args['tax_query'] ) && count( $query_args['tax_query'] ) > 1 && ! empty( $query_args['tax_query']['custom'] ) ) {
unset( $query_args['tax_query']['custom'] );
}

$listing = new WP_Query( $query_args );

if ( $listing->have_posts() ) {
Expand Down Expand Up @@ -747,4 +775,4 @@ function displaySermons( $atts = array() ) {
}

$WPFC_Shortcodes = new WPFC_Shortcodes;
$WPFC_Shortcodes->init();
$WPFC_Shortcodes->init();
42 changes: 42 additions & 0 deletions includes/sm-deprecated-functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Place where functions come to die.
*
* @since 2.4.9
*/


/**
* Searches WP_Query for sermon_date meta sort and removes it.
* `sermon_date` meta has been removed in 2.4.7.
*
* @param WP_Query $data Query instance
*
* @return WP_Query
*
* @since 2.4.9
*/
function sm_modify_wp_query( $data ) {
// If it's not a sermon, bail out
if ( empty( $data->query_vars['post_type'] ) || $data->query_vars['post_type'] !== 'wpfc_sermon' ) {
return $data;
}

foreach ( array( 'query' => $data->query, 'query_vars' => $data->query_vars ) as $type => $vars ) {
// Modify ordering
if ( ! empty( $vars['orderby'] ) && in_array( $vars['orderby'], array(
'meta_value',
'meta_value_num'
) ) && $vars['meta_key'] === 'sermon_date' ) {
$vars['orderby'] = 'date';
unset( $vars['meta_key'], $vars['meta_value_num'], $vars['meta_compare'] );

// save modified data to original query
$data->{$type} = $vars;
}
}

return $data;
}

add_filter( 'pre_get_posts', 'sm_modify_wp_query' );
120 changes: 62 additions & 58 deletions includes/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,64 +135,68 @@ function render_wpfc_sermon_archive() {

// render sermon sorting
function render_wpfc_sorting() {
$html = '';
$html .= '<div id="wpfc_sermon_sorting">';
$html .= '<span class="sortPreacher">';
$html .= '<form action="';
$html .= home_url();
$html .= '" method="get">';
$html .= '<select name="wpfc_preacher" id="wpfc_preacher" onchange="return this.form.submit()">';
$html .= '<option value="">';
$html .= 'Sort by ' . ( \SermonManager::getOption( 'preacher_label' ) ?: 'Preacher' );
$html .= '</option>';
$html .= wpfc_get_term_dropdown( 'wpfc_preacher' );
$html .= '</select>';
$html .= '<noscript><div><input type="submit" value="Submit" /></div></noscript>';
$html .= '</form>';
$html .= '</span>';
$html .= '<span class="sortSeries">';
$html .= '<form action="';
$html .= home_url();
$html .= '" method="get">';
$html .= '<select name="wpfc_sermon_series" id="wpfc_sermon_series" onchange="return this.form.submit()">';
$html .= '<option value="">';
$html .= 'Sort by Series';
$html .= '</option>';
$html .= wpfc_get_term_dropdown( 'wpfc_sermon_series' );
$html .= '</select>';
$html .= '<noscript><div><input type="submit" value="Submit" /></div></noscript>';
$html .= '</form>';
$html .= '</span>';
$html .= '<span class="sortTopics">';
$html .= '<form action="';
$html .= home_url();
$html .= '" method="get">';
$html .= '<select name="wpfc_sermon_topics" id="wpfc_sermon_topics" onchange="return this.form.submit()">';
$html .= '<option value="">';
$html .= 'Sort by Topic';
$html .= '</option>';
$html .= wpfc_get_term_dropdown( 'wpfc_sermon_topics' );
$html .= '</select>';
$html .= '<noscript><div><input type="submit" value="Submit" /></div></noscript>';
$html .= '</form>';
$html .= '</span>';
$html .= '<span class="sortBooks">';
$html .= '<form action="';
$html .= home_url();
$html .= '" method="get">';
$html .= '<select name="wpfc_bible_book" id="wpfc_bible_book" onchange="return this.form.submit()">';
$html .= '<option value="">';
$html .= 'Sort by Book';
$html .= '</option>';
$html .= wpfc_get_term_dropdown( 'wpfc_bible_book' );
$html .= '</select>';
$html .= '</select>';
$html .= '<noscript><div><input type="submit" value="Submit" /></div></noscript>';
$html .= '</form>';
$html .= '</span>';
$html .= '</div>';

return $html;
ob_start(); ?>
<div id="wpfc_sermon_sorting">
<div class="sortPreacher">
<form>
<select name="wpfc_preacher"
title="Sort by <?php echo \SermonManager::getOption( 'preacher_label' ) ?: 'Preacher'; ?>"
id="wpfc_preacher" onchange="return this.form.submit()">
<option value="">
Sort by <?php echo \SermonManager::getOption( 'preacher_label' ) ?: 'Preacher'; ?>
</option>
<?php echo wpfc_get_term_dropdown( 'wpfc_preacher' ); ?>
</select>
<noscript>
<div><input type="submit" value="Submit"/></div>
</noscript>
</form>
</div>
<div class="sortSeries">
<form>
<select title="Sort by Series" name="wpfc_sermon_series" id="wpfc_sermon_series"
onchange="return this.form.submit()">
<option value="">
Sort by Series
</option>
<?php echo wpfc_get_term_dropdown( 'wpfc_sermon_series' ); ?>
</select>
<noscript>
<div><input type="submit" value="Submit"/></div>
</noscript>
</form>
</div>
<div class="sortTopics">
<form>
<select title="Sort by Topic" name="wpfc_sermon_topics" id="wpfc_sermon_topics"
onchange="return this.form.submit()">
<option value="">
Sort by Topic
</option>
<?php echo wpfc_get_term_dropdown( 'wpfc_sermon_topics' ); ?>
</select>
<noscript>
<div><input type="submit" value="Submit"/></div>
</noscript>
</form>
</div>
<div class="sortBooks">
<form>
<select title="Sort by Book" name="wpfc_bible_book" id="wpfc_bible_book"
onchange="return this.form.submit()">
<option value="">
Sort by Book
</option>
<?php echo wpfc_get_term_dropdown( 'wpfc_bible_book' ); ?>
</select>
<noscript>
<div><input type="submit" value="Submit"/></div>
</noscript>
</form>
</div>
</div>
<?php
return ob_get_clean();
}

// echo any sermon meta
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: http://wpforchurch.com/
Tags: church, sermon, sermons, preaching, podcasting
Requires at least: 4.5
Tested up to: 4.8.1
Stable tag: 2.4.8
Stable tag: 2.4.9

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

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

== Changelog ==
= 2.4.9 =
* Fix new sermons not appearing
* Fix couple PHP warnings
* Fix filtering in shortcode

= 2.4.8 =
* Fix featured image not working

Expand Down
31 changes: 3 additions & 28 deletions sermons.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Sermon Manager for WordPress
Plugin URI: http://www.wpforchurch.com/products/sermon-manager-for-wordpress/
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.
Version: 2.4.8
Version: 2.4.9
Author: WP for Church
Contributors: wpforchurch, jprummer, jamzth
Author URI: http://www.wpforchurch.com/
Expand Down Expand Up @@ -55,8 +55,6 @@ public function __construct() {
add_filter( 'post_class', array( $this, 'add_additional_sermon_classes' ), 10, 3 );
// Add Sermon Manager image sizes
add_action( 'after_setup_theme', array( $this, 'add_image_sizes' ) );
// Fix Sermon ordering
add_action( 'pre_get_posts', array( $this, 'fix_sermons_ordering' ), 9999 );
// no idea... better not touch it for now.
add_filter( 'sermon-images-disable-public-css', '__return_true' );

Expand Down Expand Up @@ -167,7 +165,8 @@ private function includes() {
'/includes/widgets.php', // Widgets
'/includes/template-tags.php', // Template Tags
'/includes/podcast-functions.php', // Podcast Functions
'/includes/helper-functions.php' // Global Helper Functions
'/includes/helper-functions.php', // Global Helper Functions
'/includes/sm-deprecated-functions.php', // Deprecated SM functions
);

/**
Expand Down Expand Up @@ -319,30 +318,6 @@ public static function add_additional_sermon_classes( $classes, $class, $ID ) {
return $classes;
}

/**
* Fixes Sermons ordering. Uses `sermon_date` meta instead of post's published date
*
* @param WP_Query $query
*
* @return void
*/
public static function fix_sermons_ordering( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( is_post_type_archive( 'wpfc_sermon' ) ||
is_tax( 'wpfc_preacher' ) ||
is_tax( 'wpfc_sermon_topics' ) ||
is_tax( 'wpfc_sermon_series' ) ||
is_tax( 'wpfc_bible_book' )
) {
$query->set( 'meta_key', 'sermon_date' );
$query->set( 'meta_value', time() );
$query->set( 'meta_compare', '<=' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'DESC' );
}
}
}

/**
* Add images sizes for Series and Speakers
*
Expand Down

0 comments on commit 08a89eb

Please sign in to comment.