Skip to content

Commit 8173124

Browse files
author
Nikola Miljković
committed
Release 2.15.11
2 parents a460565 + d47768b commit 8173124

13 files changed

Lines changed: 282 additions & 158 deletions

includes/admin/class-sm-admin-settings.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ public static function save() {
167167
* Pass any false value to `sm_clear_feed_transients` filter to skip clearing transients.
168168
*/
169169
if ( 'podcast' === $current_tab && apply_filters( 'sm_clear_feed_transients', true ) ) {
170+
/* @noinspection SqlNoDataSourceInspection */
171+
172+
/* @noinspection SqlResolve */
170173
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_feed_%') OR `option_name` LIKE ('_transient_timeout_feed_%')" );
171174
}
172175

@@ -301,7 +304,7 @@ public static function output_fields( $options, $values = array() ) {
301304
class="<?php echo esc_attr( $value['class'] ); ?>"
302305
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
303306
size="<?php echo esc_attr( $value['size'] ); ?>"
304-
<?php if ( $value['disabled'] ): ?>
307+
<?php if ( $value['disabled'] ) : ?>
305308
disabled="disabled"
306309
<?php endif; ?>
307310
<?php echo implode( ' ', $custom_attributes ); ?>
@@ -331,7 +334,7 @@ class="<?php echo esc_attr( $value['class'] ); ?>"
331334
value="<?php echo esc_attr( $option_value ); ?>"
332335
class="<?php echo esc_attr( $value['class'] ); ?>colorpick"
333336
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
334-
<?php if ( $value['disabled'] ): ?>
337+
<?php if ( $value['disabled'] ) : ?>
335338
disabled="disabled"
336339
<?php endif; ?>
337340
<?php echo implode( ' ', $custom_attributes ); ?>
@@ -361,7 +364,7 @@ class="<?php echo esc_attr( $value['class'] ); ?>colorpick"
361364
class="<?php echo esc_attr( $value['class'] ); ?>"
362365
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
363366
<?php echo implode( ' ', $custom_attributes ); ?>
364-
<?php if ( $value['disabled'] ): ?>
367+
<?php if ( $value['disabled'] ) : ?>
365368
disabled="disabled"
366369
<?php endif; ?>
367370
><?php echo esc_textarea( $option_value ); ?></textarea>
@@ -387,7 +390,7 @@ class="<?php echo esc_attr( $value['class'] ); ?>"
387390
class="<?php echo esc_attr( $value['class'] ); ?>"
388391
<?php echo implode( ' ', $custom_attributes ); ?>
389392
<?php echo ( 'multiselect' == $value['type'] ) ? 'multiple="multiple"' : ''; ?>
390-
<?php if ( $value['disabled'] ): ?>
393+
<?php if ( $value['disabled'] ) : ?>
391394
disabled="disabled"
392395
<?php endif; ?>
393396
>
@@ -424,7 +427,7 @@ class="<?php echo esc_attr( $value['class'] ); ?>"
424427
</th>
425428
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ); ?>">
426429
<fieldset
427-
<?php if ( $value['disabled'] ): ?>
430+
<?php if ( $value['disabled'] ) : ?>
428431
disabled="disabled"
429432
<?php endif; ?>
430433
>
@@ -482,7 +485,7 @@ class="<?php echo esc_attr( $value['class'] ); ?>"
482485
<th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ); ?></th>
483486
<td class="forminp forminp-checkbox">
484487
<fieldset
485-
<?php if ( $value['disabled'] ): ?>
488+
<?php if ( $value['disabled'] ) : ?>
486489
disabled="disabled"
487490
<?php endif; ?>
488491
>
@@ -532,7 +535,7 @@ class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?
532535
value="<?php echo esc_attr( $option_value ); ?>"
533536
class="<?php echo esc_attr( $value['class'] ); ?>"
534537
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
535-
<?php if ( $value['disabled'] ): ?>
538+
<?php if ( $value['disabled'] ) : ?>
536539
disabled="disabled"
537540
<?php endif; ?>
538541
<?php echo implode( ' ', $custom_attributes ); ?>
@@ -543,7 +546,8 @@ class="<?php echo esc_attr( $value['class'] ); ?>"
543546
class="button upload-image"
544547
title="Choose Default Image">
545548
<img
546-
src="<?php echo admin_url(); ?>/images/media-button.png"
549+
src="<?php echo admin_url( '/images/media-button.png' ); ?>"
550+
alt="Upload Default Image"
547551
width="15"
548552
height="15"
549553
class="upload_image_button"

includes/admin/views/html-admin-settings.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
</form>
4444
</div>
4545
<div class="settings-side">
46+
<?php if ( ! defined('SMP_SM_VERSION') ) : ?>
4647
<div class="postbox sm-box" style="background: #f6fbff;">
4748
<h3><span>Sermon Manager Pro</span>
4849
</h3>
@@ -80,7 +81,7 @@ class="button-primary">
8081
</div>
8182
</div>
8283
</div>
83-
84+
<?php endif; ?>
8485
<div class="postbox sm-box">
8586
<h3>
8687
<span><?php esc_html_e( 'Frequently Asked Questions', 'sermon-manager-for-wordpress' ); ?></span>

includes/class-sm-dates-wp.php

Lines changed: 139 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ public static function get_the_date( $the_date = '', $d = '', $post = null ) {
4040
*/
4141
public static function hook() {
4242
add_action( 'save_post_wpfc_sermon', array( get_class(), 'maybe_update_date' ), 10, 3 );
43-
add_action( 'save_post_wpfc_sermon', array( get_class(), 'save_series_date' ), 20, 3 );
44-
add_action( 'save_post_wpfc_sermon', array( get_class(), 'update_series_date' ), 30 );
45-
add_action( 'pre_post_update', array( get_class(), 'get_original_series' ) );
43+
add_action( 'save_post_wpfc_sermon', array( get_class(), 'save_terms_dates' ), 20, 3 );
44+
add_action( 'pre_post_update', array( get_class(), 'get_original_terms' ) );
4645
add_action( 'pre_post_update', array( get_class(), 'get_original_date' ) );
4746
add_filter( 'cmb2_override_sermon_date_meta_remove', '__return_true' );
4847
add_filter( 'cmb2_override_sermon_date_meta_save', '__return_true' );
@@ -62,11 +61,46 @@ public static function hook() {
6261
*
6362
* @param int $post_ID Post ID.
6463
*
65-
* @since 2.8
64+
* @since 2.8
65+
*
66+
* @deprecated 2.15.11 - in favor of SM_Dates_WP::get_original_terms()
67+
* @see SM_Dates_WP::get_original_terms()
6668
*/
6769
public static function get_original_series( $post_ID ) {
68-
if ( get_post_type( $post_ID ) === 'wpfc_sermon' ) {
69-
$GLOBALS['sm_original_series'] = wp_get_object_terms( $post_ID, 'wpfc_sermon_series' );
70+
self::get_original_terms( $post_ID );
71+
}
72+
73+
/**
74+
* Used to save terms dates that were there before sermon update, for later comparison.
75+
*
76+
* @param int $post_ID Post ID.
77+
*
78+
* @since 2.15.11
79+
*/
80+
public static function get_original_terms( $post_ID ) {
81+
if ( get_post_type( $post_ID ) !== 'wpfc_sermon' ) {
82+
return;
83+
}
84+
85+
$data = array();
86+
87+
foreach ( sm_get_taxonomies() as $taxonomy ) {
88+
// Create an empty taxonomy.
89+
$data[ $taxonomy ] = array();
90+
91+
// Get taxonomy terms.
92+
$terms = wp_get_object_terms( $post_ID, $taxonomy );
93+
94+
// Fill out the terms, if any.
95+
foreach ( $terms as $term ) {
96+
$data[ $taxonomy ][] = $term->term_id;
97+
}
98+
99+
// New format. taxonomy => array(...terms).
100+
$GLOBALS['sm_original_terms'] = $data;
101+
102+
// Back-compat.
103+
$GLOBALS[ 'sm_original_' . $taxonomy ] = $terms;
70104
}
71105
}
72106

@@ -77,99 +111,133 @@ public static function get_original_series( $post_ID ) {
77111
* @param WP_Post $post Post object.
78112
* @param bool $update Whether this is an existing post being updated or not.
79113
*
80-
* @since 2.8
114+
* @since 2.8
115+
*
116+
* @deprecated 2.15.11 - in favor of SM_Dates_WP::save_terms_dates()
117+
* @see SM_Dates_WP::save_terms_dates()
81118
*/
82119
public static function save_series_date( $post_ID, $post, $update ) {
120+
self::save_terms_dates( $post_ID, $post, $update );
121+
}
122+
123+
/**
124+
* Saves sermon date as term meta for all terms for that sermon, used for ordering.
125+
*
126+
* @param int $post_ID Post ID.
127+
* @param WP_Post $post Post object.
128+
* @param bool $update Whether this is an existing post being updated or not.
129+
*
130+
* @since 2.15.11
131+
*/
132+
public static function save_terms_dates( $post_ID, $post, $update ) {
83133
if ( ! isset( $_POST['tax_input'] ) ) {
84134
return;
85135
}
86136

87-
$series = $_POST['tax_input']['wpfc_sermon_series'];
88-
$orig_series = $GLOBALS['sm_original_series'];
137+
$original_terms = $GLOBALS['sm_original_terms'];
138+
$updated_terms = isset( $_POST['tax_input'] ) ? $_POST['tax_input'] : null;
89139

90-
if ( $update ) {
91-
foreach ( $orig_series as $term ) {
92-
delete_term_meta( $term->term_id, 'sermon_date' );
93-
}
140+
$updated_terms += array_fill_keys( sm_get_taxonomies(), array() );
141+
142+
if ( ! $updated_terms ) {
143+
return;
94144
}
95145

96-
if ( ! empty( $series ) ) {
97-
foreach ( $orig_series as $term_id ) {
98-
update_term_meta( $term_id, 'sermon_date_' . $post_ID, get_post_meta( $post_ID, 'sermon_date', true ) );
146+
foreach ( sm_get_taxonomies() as $taxonomy ) {
147+
$new_terms = $updated_terms[ $taxonomy ];
148+
$orig_terms = $original_terms[ $taxonomy ];
149+
150+
// Remove the date of the current sermon from removed terms.
151+
foreach ( $orig_terms as $term ) {
152+
if ( ! in_array( $term, $new_terms ) ) {
153+
delete_term_meta( $term, 'sermon_date_' . $post_ID );
154+
}
155+
}
156+
157+
// Add the date of the current sermon to its terms.
158+
if ( ! empty( $new_terms ) ) {
159+
foreach ( $new_terms as $term ) {
160+
update_term_meta( $term, 'sermon_date_' . $post_ID, get_post_meta( $post_ID, 'sermon_date', true ) );
161+
}
99162
}
163+
164+
// Update the main date.
165+
self::update_term_dates( $taxonomy, $orig_terms + $new_terms );
100166
}
101167
}
102168

103169
/**
104-
* Left here for backwards-compatibility reasons.
105-
* Does exactly the same as - self::update_term_dates();
170+
* Loops through taxonomies and terms and sets latest available sermon date.
106171
*
107-
* @since 2.8
108-
* @deprecated
109-
*/
110-
public static function update_series_date() {
111-
self::update_term_dates();
112-
}
113-
114-
/**
115-
* Loops through all terms and sets latest available sermon date.
172+
* @param string $taxonomy The taxonomy to update. Default all.
173+
* @param array|string $terms The term(s) to update. Default all.
116174
*
117175
* @since 2.13.0 - extended to all terms
176+
* @since 2.15.11 - added parameters
118177
*/
119-
public static function update_term_dates() {
120-
foreach (
121-
get_terms( array(
122-
'taxonomy' => array(
123-
'wpfc_sermon_series',
124-
'wpfc_preacher',
125-
'wpfc_sermon_topics',
126-
'wpfc_bible_book',
127-
'wpfc_service_type',
128-
),
129-
'hide_empty' => true,
130-
) ) as $term
131-
) {
132-
$term_meta = get_term_meta( $term->term_id );
133-
134-
if ( empty( $term_meta['sermon_date'] ) ) {
178+
public static function update_term_dates( $taxonomy = '', $terms = array() ) {
179+
$taxonomies = $taxonomy ? array( $taxonomy ) : sm_get_taxonomies();
180+
181+
foreach ( $taxonomies as $taxonomy ) {
182+
$the_terms = ! empty( $terms ) ? (array) $terms : null;
183+
184+
if ( null === $the_terms ) {
185+
$get_terms = get_terms(
186+
array(
187+
'taxonomy' => $taxonomy,
188+
'hide_empty' => false,
189+
)
190+
);
191+
192+
foreach ( $get_terms as $term ) {
193+
$the_terms[] = $term->term_id;
194+
}
195+
}
196+
197+
// Save the most recent sermon date to the term.
198+
foreach ( $the_terms as $term ) {
199+
$meta = get_term_meta( $term );
135200
$dates = array();
136-
foreach ( $term_meta as $name => $value ) {
137-
if ( strpos( $name, 'sermon_date_' ) !== false ) {
138-
$dates[] = $value[0];
201+
202+
// Gather all of the dates.
203+
foreach ( $meta as $meta_key => $meta_value ) {
204+
if ( substr( $meta_key, 0, 12 ) !== 'sermon_date_' ) {
205+
continue;
139206
}
140-
}
141207

142-
if ( ! empty( $dates ) ) {
143-
arsort( $dates );
144-
$date = $dates[0];
145-
} else {
146-
$query = new WP_Query( array(
147-
'post_type' => 'wpfc_sermon',
148-
'posts_per_page' => 1,
149-
'meta_key' => 'sermon_date',
150-
'meta_value_num' => time(),
151-
'meta_compare' => '<=',
152-
'orderby' => 'meta_value_num',
153-
'tax_query' => array(
154-
array(
155-
'taxonomy' => $term->taxonomy,
156-
'field' => 'term_id',
157-
'terms' => $term->term_id,
158-
),
159-
),
160-
) );
161-
if ( $query->have_posts() ) {
162-
$date = get_post_meta( $query->posts[0]->ID, 'sermon_date', true );
163-
} else {
164-
$date = 0;
208+
$sermon_date = intval( $meta_value[0] );
209+
210+
if ( $sermon_date ) {
211+
$dates[] = $sermon_date;
165212
}
166213
}
167214

168-
update_term_meta( $term->term_id, 'sermon_date', $date );
215+
// If we can't find a date, remove the existing.
216+
if ( empty( $dates ) ) {
217+
delete_term_meta( $term, 'sermon_date' );
218+
continue;
219+
}
220+
221+
// Sort the dates by newest first (DESC).
222+
rsort( $dates );
223+
224+
// Update the date.
225+
update_term_meta( $term, 'sermon_date', $dates[0] );
169226
}
170227
}
171228
}
172229

230+
/**
231+
* Left here for backwards-compatibility reasons.
232+
* Does exactly the same as - self::update_term_dates();
233+
*
234+
* @since 2.8
235+
* @deprecated 2.13.0
236+
*/
237+
public static function update_series_date() {
238+
self::update_term_dates();
239+
}
240+
173241
/**
174242
* Used to save date that was there before sermon update, for later comparison.
175243
*

0 commit comments

Comments
 (0)