Skip to content

Commit 3ae5a06

Browse files
author
Nikola Miljković
authored
Merge pull request #71 from WP-for-Church/dev
Release 2.5.0
2 parents e01cf13 + 662f9b1 commit 3ae5a06

7 files changed

Lines changed: 257 additions & 197 deletions

File tree

includes/shortcodes.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,23 +540,43 @@ function getLatestSeriesImageId( $series = 0 ) {
540540
}
541541

542542
return null;
543-
}/** @noinspection PhpUnusedParameterInspection */
544-
/** @noinspection PhpUnusedParameterInspection */
543+
}
545544

546545
/**
547546
* Renders sorting HTML.
548547
*
549-
* @param array $atts Shortcode parameters. There are 0 parameters for this shortcode.
548+
* @param array $atts Shortcode parameters.
549+
*
550+
* @type string $series Force specific series to show. Slug only
551+
* @type string $preachers Force specific preacher to show. Slug only
552+
* @type string $topics Force specific topic to show. Slug only
553+
* @type string $books Force specific book to show. Slug only
554+
* @type string $visibility 'none' to hide the forced fields, 'disable' to show them as disabled and 'suggest' to
555+
* just set the default value while allowing user to change it. Default 'suggest'
550556
*
551557
* @return string Sorting HTML
558+
*
559+
* @since 2.5.0 added shortcode parameters
552560
*/
553561
public function displaySermonSorting( $atts = array() ) {
554562
// enqueue scripts and styles
555563
if ( ! defined( 'SM_ENQUEUE_SCRIPTS_STYLES' ) ) {
556564
define( 'SM_ENQUEUE_SCRIPTS_STYLES', true );
557565
}
558566

559-
return render_wpfc_sorting();
567+
// default shortcode options
568+
$args = array(
569+
'series' => '',
570+
'preachers' => '',
571+
'topics' => '',
572+
'books' => '',
573+
'visibility' => 'suggest',
574+
);
575+
576+
// merge default and user options
577+
$args = shortcode_atts( $args, $atts, 'sermon_sort_fields' );
578+
579+
return render_wpfc_sorting( $args );
560580
}
561581

562582
/**

includes/template-tags.php

Lines changed: 86 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -133,67 +133,92 @@ function render_wpfc_sermon_archive() {
133133

134134
<?php }
135135

136-
// render sermon sorting
137-
function render_wpfc_sorting() {
136+
/**
137+
* Render sermon sorting
138+
*
139+
* @param array $args Display options. See the 'sermon_sort_fields' shortcode for array items
140+
*
141+
* @see WPFC_Shortcodes->displaySermonSorting()
142+
*
143+
* @return string the HTML
144+
*
145+
* @since 2.5.0 added $args
146+
*/
147+
function render_wpfc_sorting( $args = array() ) {
148+
// reset values
149+
$hidden = '';
150+
151+
// handle current page. We don't need "page" var in URL
152+
if ( is_archive() && get_post_type() === 'wpfc_sermon' ) {
153+
$action = get_site_url() . '/' . generate_wpfc_slug()['slug'];
154+
} else {
155+
$action = '';
156+
}
157+
158+
// we need it for taxonomy name conversion function
159+
$shortcodes = new WPFC_Shortcodes();
160+
161+
// add other filtering fields
162+
foreach ( array( 'wpfc_preacher', 'wpfc_sermon_series', 'wpfc_sermon_topics', 'wpfc_bible_book' ) as $filter ) {
163+
// Force shortcode defined argument if set
164+
if ( ! empty( $args[ $shortcodes->convertTaxonomyName( $filter, false ) ] ) &&
165+
$value = $args[ $shortcodes->convertTaxonomyName( $filter, false ) ] ) {
166+
$hidden .= "<input type='hidden' name='$filter' value='$value'>" . PHP_EOL;
167+
168+
continue;
169+
}
170+
171+
if ( ! empty( get_query_var( $filter ) ) && $value = get_query_var( $filter ) ) {
172+
$hidden .= "<input type='hidden' name='$filter' value='$value'>" . PHP_EOL;
173+
}
174+
}
175+
176+
// Filters HTML fields data
177+
$filters = array(
178+
array(
179+
'className' => 'sortPreacher',
180+
'taxonomy' => 'wpfc_preacher',
181+
'title' => 'Sort by ' . \SermonManager::getOption( 'preacher_label' ) ?: 'Preacher',
182+
),
183+
array(
184+
'className' => 'sortSeries',
185+
'taxonomy' => 'wpfc_sermon_series',
186+
'title' => 'Sort by Series'
187+
),
188+
array(
189+
'className' => 'sortTopics',
190+
'taxonomy' => 'wpfc_sermon_topics',
191+
'title' => 'Sort by Topic'
192+
),
193+
array(
194+
'className' => 'sortBooks',
195+
'taxonomy' => 'wpfc_bible_book',
196+
'title' => 'Sort by Book'
197+
),
198+
);
199+
138200
ob_start(); ?>
139201
<div id="wpfc_sermon_sorting">
140-
<span 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-
</span>
155-
<span 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-
</span>
169-
<span 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-
</span>
183-
<span 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-
</span>
202+
<?php foreach ( $filters as $filter ): ?>
203+
<?php if ( ( ! empty( $args[ $filter['taxonomy'] ] ) && $args['visibility'] !== 'none' ) || empty( $args[ $filter['taxonomy'] ] ) ): ?>
204+
<span class="<?php echo $filter['className'] ?>">
205+
<form action="<?php echo $action; ?>">
206+
<select name="<?php echo $filter['taxonomy'] ?>"
207+
title="<?php echo $filter['title'] ?>"
208+
id="<?php echo $filter['taxonomy'] ?>"
209+
onchange="return this.form.submit()"
210+
<?php echo ! empty( $args[ $filter['taxonomy'] ] ) && $args['visibility'] === 'disable' ? 'disabled' : '' ?>>
211+
<option value=""><?php echo $filter['title'] ?></option>
212+
<?php echo wpfc_get_term_dropdown( $filter['taxonomy'], ! empty( $args[ $filter['taxonomy'] ] ) ? $args[ $filter['taxonomy'] ] : '' ); ?>
213+
</select>
214+
<noscript>
215+
<div><input type="submit" value="Submit"/></div>
216+
</noscript>
217+
<?php echo $hidden; ?>
218+
</form>
219+
</span>
220+
<?php endif; ?>
221+
<?php endforeach; ?>
197222
</div>
198223
<?php
199224
return ob_get_clean();
@@ -363,8 +388,8 @@ function wpfc_sermon_audio() {
363388
// render additional files
364389
function wpfc_sermon_attachments() {
365390
global $post;
366-
$html = '<div id="wpfc-attachments" class="cf">';
367-
$html .= '<p><strong>' . __( 'Download Files', 'sermon-manager' ) . '</strong>';
391+
$html = '<div id="wpfc-attachments" class="cf">';
392+
$html .= '<p><strong>' . __( 'Download Files', 'sermon-manager' ) . '</strong>';
368393
if ( get_wpfc_sermon_meta( 'sermon_audio' ) ) {
369394
$html .= '<a href="' . get_wpfc_sermon_meta( 'sermon_audio' ) . '" class="sermon-attachments" download><span class="dashicons dashicons-media-audio"></span>' . __( 'MP3', 'sermon-manager' ) . '</a>';
370395
}

includes/types-taxonomies.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ function wpfc_sermon_metaboxes() {
296296
'desc' => __( 'Type a brief description about this sermon, an outline, or a full manuscript', 'sermon-manager' ),
297297
'id' => 'sermon_description',
298298
'type' => 'wysiwyg',
299-
'options' => array( 'textarea_rows' => 7, 'media_buttons' => false, ),
299+
'options' => array( 'textarea_rows' => 7, 'media_buttons' => true, ),
300300
) );
301301

302302
$cmb2 = new_cmb2_box( array(
@@ -320,7 +320,7 @@ function wpfc_sermon_metaboxes() {
320320
) );
321321
$cmb2->add_field( array(
322322
'name' => __( 'MP3 Duration', 'sermon-manager' ),
323-
'desc' => __( 'Length in minutes (if left blank, will attempt to calculate automatically when you save)', 'sermon-manager' ),
323+
'desc' => __( 'Length in <code>hh:mm:ss</code> format (if left blank, will attempt to calculate automatically when you save)', 'sermon-manager' ),
324324
'id' => '_wpfc_sermon_duration',
325325
'type' => 'text',
326326
) );
@@ -358,22 +358,22 @@ function wpfc_sermon_metaboxes() {
358358

359359
}
360360

361-
// Custom taxonomy terms dropdown function
362-
function wpfc_get_term_dropdown( $taxonomy ) {
363-
$terms = get_terms( $taxonomy );
364-
$current_preacher = get_query_var( 'wpfc_preacher' );
365-
$current_series = get_query_var( 'wpfc_sermon_series' );
366-
$current_topic = get_query_var( 'wpfc_sermon_topics' );
367-
$current_book = get_query_var( 'wpfc_bible_book' );
368-
$html = '';
369-
foreach ( $terms as $term ) {
370-
$term_slug = $term->slug;
371-
$term_name = $term->name;
372-
if ( $term_slug == $current_preacher || $term_slug == $current_series || $term_slug == $current_topic || $term_slug == $current_book ) {
373-
$html .= '<option value="' . $term_slug . '" selected>' . $term_name . '</option>';
374-
} else {
375-
$html .= '<option value="' . $term_slug . '">' . $term_name . '</option>';
376-
}
361+
/**
362+
* Build <option> fields for <select> element
363+
*
364+
* @param string $taxonomy Taxonomy name
365+
* @param string $default Force a default value regardless the query var
366+
*
367+
* @return string HTML <option> fields
368+
*
369+
* @since 2.5.0 added $default
370+
*/
371+
function wpfc_get_term_dropdown( $taxonomy, $default = '' ) {
372+
// reset var
373+
$html = '';
374+
375+
foreach ( get_terms( $taxonomy ) as $term ) {
376+
$html .= '<option value="' . $term->slug . '" ' . ( ( $default === '' ? $term->slug === get_query_var( $taxonomy ) : $term->slug === $default ) ? 'selected' : '' ) . '>' . $term->name . '</option>';
377377
}
378378

379379
return $html;

js/dismiss-php.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Modified from: https://wordpress.stackexchange.com/a/251191/111583
2+
jQuery(function ($) {
3+
$(document).on('click', '.notice-wpfc-php .notice-dismiss', function () {
4+
$.ajax(ajaxurl, {
5+
type: 'POST',
6+
data: {
7+
action: 'wpfc_php_notice_handler',
8+
type: $(this).closest('.notice-wpfc-php').data('notice')
9+
}
10+
});
11+
});
12+
});

readme.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ 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.11
7+
Stable tag: 2.5.0
8+
Requires PHP: 5.6
89

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

@@ -83,6 +84,13 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man
8384
2. Sermon Files
8485

8586
== Changelog ==
87+
= 2.5.0 =
88+
* Add media functions in the sermon editor
89+
* Add options to filtering shortcode
90+
* Fix filtering shortcode sometimes making 404 on filter
91+
* Fix PHP warning not dismissible
92+
* Tweak sermon audio length field description (thanks @macbookandrew)
93+
8694
= 2.4.11 =
8795
* Fix paragraphs in podcast feed description
8896
* Fix podcasts not validating with exotic mp3 file names

0 commit comments

Comments
 (0)