@@ -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
364389function 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 }
0 commit comments