Skip to content

Commit

Permalink
Merge pull request #71 from WP-for-Church/dev
Browse files Browse the repository at this point in the history
Release 2.5.0
  • Loading branch information
Nikola Miljković authored Sep 6, 2017
2 parents e01cf13 + 662f9b1 commit 3ae5a06
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 197 deletions.
28 changes: 24 additions & 4 deletions includes/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,23 +540,43 @@ function getLatestSeriesImageId( $series = 0 ) {
}

return null;
}/** @noinspection PhpUnusedParameterInspection */
/** @noinspection PhpUnusedParameterInspection */
}

/**
* Renders sorting HTML.
*
* @param array $atts Shortcode parameters. There are 0 parameters for this shortcode.
* @param array $atts Shortcode parameters.
*
* @type string $series Force specific series to show. Slug only
* @type string $preachers Force specific preacher to show. Slug only
* @type string $topics Force specific topic to show. Slug only
* @type string $books Force specific book to show. Slug only
* @type string $visibility 'none' to hide the forced fields, 'disable' to show them as disabled and 'suggest' to
* just set the default value while allowing user to change it. Default 'suggest'
*
* @return string Sorting HTML
*
* @since 2.5.0 added shortcode parameters
*/
public function displaySermonSorting( $atts = array() ) {
// enqueue scripts and styles
if ( ! defined( 'SM_ENQUEUE_SCRIPTS_STYLES' ) ) {
define( 'SM_ENQUEUE_SCRIPTS_STYLES', true );
}

return render_wpfc_sorting();
// default shortcode options
$args = array(
'series' => '',
'preachers' => '',
'topics' => '',
'books' => '',
'visibility' => 'suggest',
);

// merge default and user options
$args = shortcode_atts( $args, $atts, 'sermon_sort_fields' );

return render_wpfc_sorting( $args );
}

/**
Expand Down
147 changes: 86 additions & 61 deletions includes/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,67 +133,92 @@ function render_wpfc_sermon_archive() {

<?php }

// render sermon sorting
function render_wpfc_sorting() {
/**
* Render sermon sorting
*
* @param array $args Display options. See the 'sermon_sort_fields' shortcode for array items
*
* @see WPFC_Shortcodes->displaySermonSorting()
*
* @return string the HTML
*
* @since 2.5.0 added $args
*/
function render_wpfc_sorting( $args = array() ) {
// reset values
$hidden = '';

// handle current page. We don't need "page" var in URL
if ( is_archive() && get_post_type() === 'wpfc_sermon' ) {
$action = get_site_url() . '/' . generate_wpfc_slug()['slug'];
} else {
$action = '';
}

// we need it for taxonomy name conversion function
$shortcodes = new WPFC_Shortcodes();

// add other filtering fields
foreach ( array( 'wpfc_preacher', 'wpfc_sermon_series', 'wpfc_sermon_topics', 'wpfc_bible_book' ) as $filter ) {
// Force shortcode defined argument if set
if ( ! empty( $args[ $shortcodes->convertTaxonomyName( $filter, false ) ] ) &&
$value = $args[ $shortcodes->convertTaxonomyName( $filter, false ) ] ) {
$hidden .= "<input type='hidden' name='$filter' value='$value'>" . PHP_EOL;

continue;
}

if ( ! empty( get_query_var( $filter ) ) && $value = get_query_var( $filter ) ) {
$hidden .= "<input type='hidden' name='$filter' value='$value'>" . PHP_EOL;
}
}

// Filters HTML fields data
$filters = array(
array(
'className' => 'sortPreacher',
'taxonomy' => 'wpfc_preacher',
'title' => 'Sort by ' . \SermonManager::getOption( 'preacher_label' ) ?: 'Preacher',
),
array(
'className' => 'sortSeries',
'taxonomy' => 'wpfc_sermon_series',
'title' => 'Sort by Series'
),
array(
'className' => 'sortTopics',
'taxonomy' => 'wpfc_sermon_topics',
'title' => 'Sort by Topic'
),
array(
'className' => 'sortBooks',
'taxonomy' => 'wpfc_bible_book',
'title' => 'Sort by Book'
),
);

ob_start(); ?>
<div id="wpfc_sermon_sorting">
<span 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>
</span>
<span 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>
</span>
<span 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>
</span>
<span 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>
</span>
<?php foreach ( $filters as $filter ): ?>
<?php if ( ( ! empty( $args[ $filter['taxonomy'] ] ) && $args['visibility'] !== 'none' ) || empty( $args[ $filter['taxonomy'] ] ) ): ?>
<span class="<?php echo $filter['className'] ?>">
<form action="<?php echo $action; ?>">
<select name="<?php echo $filter['taxonomy'] ?>"
title="<?php echo $filter['title'] ?>"
id="<?php echo $filter['taxonomy'] ?>"
onchange="return this.form.submit()"
<?php echo ! empty( $args[ $filter['taxonomy'] ] ) && $args['visibility'] === 'disable' ? 'disabled' : '' ?>>
<option value=""><?php echo $filter['title'] ?></option>
<?php echo wpfc_get_term_dropdown( $filter['taxonomy'], ! empty( $args[ $filter['taxonomy'] ] ) ? $args[ $filter['taxonomy'] ] : '' ); ?>
</select>
<noscript>
<div><input type="submit" value="Submit"/></div>
</noscript>
<?php echo $hidden; ?>
</form>
</span>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php
return ob_get_clean();
Expand Down Expand Up @@ -363,8 +388,8 @@ function wpfc_sermon_audio() {
// render additional files
function wpfc_sermon_attachments() {
global $post;
$html = '<div id="wpfc-attachments" class="cf">';
$html .= '<p><strong>' . __( 'Download Files', 'sermon-manager' ) . '</strong>';
$html = '<div id="wpfc-attachments" class="cf">';
$html .= '<p><strong>' . __( 'Download Files', 'sermon-manager' ) . '</strong>';
if ( get_wpfc_sermon_meta( 'sermon_audio' ) ) {
$html .= '<a href="' . get_wpfc_sermon_meta( 'sermon_audio' ) . '" class="sermon-attachments" download><span class="dashicons dashicons-media-audio"></span>' . __( 'MP3', 'sermon-manager' ) . '</a>';
}
Expand Down
36 changes: 18 additions & 18 deletions includes/types-taxonomies.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ function wpfc_sermon_metaboxes() {
'desc' => __( 'Type a brief description about this sermon, an outline, or a full manuscript', 'sermon-manager' ),
'id' => 'sermon_description',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 7, 'media_buttons' => false, ),
'options' => array( 'textarea_rows' => 7, 'media_buttons' => true, ),
) );

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

}

// Custom taxonomy terms dropdown function
function wpfc_get_term_dropdown( $taxonomy ) {
$terms = get_terms( $taxonomy );
$current_preacher = get_query_var( 'wpfc_preacher' );
$current_series = get_query_var( 'wpfc_sermon_series' );
$current_topic = get_query_var( 'wpfc_sermon_topics' );
$current_book = get_query_var( 'wpfc_bible_book' );
$html = '';
foreach ( $terms as $term ) {
$term_slug = $term->slug;
$term_name = $term->name;
if ( $term_slug == $current_preacher || $term_slug == $current_series || $term_slug == $current_topic || $term_slug == $current_book ) {
$html .= '<option value="' . $term_slug . '" selected>' . $term_name . '</option>';
} else {
$html .= '<option value="' . $term_slug . '">' . $term_name . '</option>';
}
/**
* Build <option> fields for <select> element
*
* @param string $taxonomy Taxonomy name
* @param string $default Force a default value regardless the query var
*
* @return string HTML <option> fields
*
* @since 2.5.0 added $default
*/
function wpfc_get_term_dropdown( $taxonomy, $default = '' ) {
// reset var
$html = '';

foreach ( get_terms( $taxonomy ) as $term ) {
$html .= '<option value="' . $term->slug . '" ' . ( ( $default === '' ? $term->slug === get_query_var( $taxonomy ) : $term->slug === $default ) ? 'selected' : '' ) . '>' . $term->name . '</option>';
}

return $html;
Expand Down
12 changes: 12 additions & 0 deletions js/dismiss-php.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Modified from: https://wordpress.stackexchange.com/a/251191/111583
jQuery(function ($) {
$(document).on('click', '.notice-wpfc-php .notice-dismiss', function () {
$.ajax(ajaxurl, {
type: 'POST',
data: {
action: 'wpfc_php_notice_handler',
type: $(this).closest('.notice-wpfc-php').data('notice')
}
});
});
});
10 changes: 9 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ 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.11
Stable tag: 2.5.0
Requires PHP: 5.6

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

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

== Changelog ==
= 2.5.0 =
* Add media functions in the sermon editor
* Add options to filtering shortcode
* Fix filtering shortcode sometimes making 404 on filter
* Fix PHP warning not dismissible
* Tweak sermon audio length field description (thanks @macbookandrew)

= 2.4.11 =
* Fix paragraphs in podcast feed description
* Fix podcasts not validating with exotic mp3 file names
Expand Down
Loading

0 comments on commit 3ae5a06

Please sign in to comment.