Skip to content

Commit

Permalink
Release 2.15.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikola Miljković committed Dec 7, 2018
2 parents a460565 + d47768b commit 8173124
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 158 deletions.
20 changes: 12 additions & 8 deletions includes/admin/class-sm-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ public static function save() {
* Pass any false value to `sm_clear_feed_transients` filter to skip clearing transients.
*/
if ( 'podcast' === $current_tab && apply_filters( 'sm_clear_feed_transients', true ) ) {
/* @noinspection SqlNoDataSourceInspection */

/* @noinspection SqlResolve */
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_feed_%') OR `option_name` LIKE ('_transient_timeout_feed_%')" );
}

Expand Down Expand Up @@ -301,7 +304,7 @@ public static function output_fields( $options, $values = array() ) {
class="<?php echo esc_attr( $value['class'] ); ?>"
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
size="<?php echo esc_attr( $value['size'] ); ?>"
<?php if ( $value['disabled'] ): ?>
<?php if ( $value['disabled'] ) : ?>
disabled="disabled"
<?php endif; ?>
<?php echo implode( ' ', $custom_attributes ); ?>
Expand Down Expand Up @@ -331,7 +334,7 @@ class="<?php echo esc_attr( $value['class'] ); ?>"
value="<?php echo esc_attr( $option_value ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>colorpick"
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
<?php if ( $value['disabled'] ): ?>
<?php if ( $value['disabled'] ) : ?>
disabled="disabled"
<?php endif; ?>
<?php echo implode( ' ', $custom_attributes ); ?>
Expand Down Expand Up @@ -361,7 +364,7 @@ class="<?php echo esc_attr( $value['class'] ); ?>colorpick"
class="<?php echo esc_attr( $value['class'] ); ?>"
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
<?php echo implode( ' ', $custom_attributes ); ?>
<?php if ( $value['disabled'] ): ?>
<?php if ( $value['disabled'] ) : ?>
disabled="disabled"
<?php endif; ?>
><?php echo esc_textarea( $option_value ); ?></textarea>
Expand All @@ -387,7 +390,7 @@ class="<?php echo esc_attr( $value['class'] ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>"
<?php echo implode( ' ', $custom_attributes ); ?>
<?php echo ( 'multiselect' == $value['type'] ) ? 'multiple="multiple"' : ''; ?>
<?php if ( $value['disabled'] ): ?>
<?php if ( $value['disabled'] ) : ?>
disabled="disabled"
<?php endif; ?>
>
Expand Down Expand Up @@ -424,7 +427,7 @@ class="<?php echo esc_attr( $value['class'] ); ?>"
</th>
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ); ?>">
<fieldset
<?php if ( $value['disabled'] ): ?>
<?php if ( $value['disabled'] ) : ?>
disabled="disabled"
<?php endif; ?>
>
Expand Down Expand Up @@ -482,7 +485,7 @@ class="<?php echo esc_attr( $value['class'] ); ?>"
<th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ); ?></th>
<td class="forminp forminp-checkbox">
<fieldset
<?php if ( $value['disabled'] ): ?>
<?php if ( $value['disabled'] ) : ?>
disabled="disabled"
<?php endif; ?>
>
Expand Down Expand Up @@ -532,7 +535,7 @@ class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?
value="<?php echo esc_attr( $option_value ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>"
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
<?php if ( $value['disabled'] ): ?>
<?php if ( $value['disabled'] ) : ?>
disabled="disabled"
<?php endif; ?>
<?php echo implode( ' ', $custom_attributes ); ?>
Expand All @@ -543,7 +546,8 @@ class="<?php echo esc_attr( $value['class'] ); ?>"
class="button upload-image"
title="Choose Default Image">
<img
src="<?php echo admin_url(); ?>/images/media-button.png"
src="<?php echo admin_url( '/images/media-button.png' ); ?>"
alt="Upload Default Image"
width="15"
height="15"
class="upload_image_button"
Expand Down
3 changes: 2 additions & 1 deletion includes/admin/views/html-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
</form>
</div>
<div class="settings-side">
<?php if ( ! defined('SMP_SM_VERSION') ) : ?>
<div class="postbox sm-box" style="background: #f6fbff;">
<h3><span>Sermon Manager Pro</span>
</h3>
Expand Down Expand Up @@ -80,7 +81,7 @@ class="button-primary">
</div>
</div>
</div>

<?php endif; ?>
<div class="postbox sm-box">
<h3>
<span><?php esc_html_e( 'Frequently Asked Questions', 'sermon-manager-for-wordpress' ); ?></span>
Expand Down
210 changes: 139 additions & 71 deletions includes/class-sm-dates-wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ public static function get_the_date( $the_date = '', $d = '', $post = null ) {
*/
public static function hook() {
add_action( 'save_post_wpfc_sermon', array( get_class(), 'maybe_update_date' ), 10, 3 );
add_action( 'save_post_wpfc_sermon', array( get_class(), 'save_series_date' ), 20, 3 );
add_action( 'save_post_wpfc_sermon', array( get_class(), 'update_series_date' ), 30 );
add_action( 'pre_post_update', array( get_class(), 'get_original_series' ) );
add_action( 'save_post_wpfc_sermon', array( get_class(), 'save_terms_dates' ), 20, 3 );
add_action( 'pre_post_update', array( get_class(), 'get_original_terms' ) );
add_action( 'pre_post_update', array( get_class(), 'get_original_date' ) );
add_filter( 'cmb2_override_sermon_date_meta_remove', '__return_true' );
add_filter( 'cmb2_override_sermon_date_meta_save', '__return_true' );
Expand All @@ -62,11 +61,46 @@ public static function hook() {
*
* @param int $post_ID Post ID.
*
* @since 2.8
* @since 2.8
*
* @deprecated 2.15.11 - in favor of SM_Dates_WP::get_original_terms()
* @see SM_Dates_WP::get_original_terms()
*/
public static function get_original_series( $post_ID ) {
if ( get_post_type( $post_ID ) === 'wpfc_sermon' ) {
$GLOBALS['sm_original_series'] = wp_get_object_terms( $post_ID, 'wpfc_sermon_series' );
self::get_original_terms( $post_ID );
}

/**
* Used to save terms dates that were there before sermon update, for later comparison.
*
* @param int $post_ID Post ID.
*
* @since 2.15.11
*/
public static function get_original_terms( $post_ID ) {
if ( get_post_type( $post_ID ) !== 'wpfc_sermon' ) {
return;
}

$data = array();

foreach ( sm_get_taxonomies() as $taxonomy ) {
// Create an empty taxonomy.
$data[ $taxonomy ] = array();

// Get taxonomy terms.
$terms = wp_get_object_terms( $post_ID, $taxonomy );

// Fill out the terms, if any.
foreach ( $terms as $term ) {
$data[ $taxonomy ][] = $term->term_id;
}

// New format. taxonomy => array(...terms).
$GLOBALS['sm_original_terms'] = $data;

// Back-compat.
$GLOBALS[ 'sm_original_' . $taxonomy ] = $terms;
}
}

Expand All @@ -77,99 +111,133 @@ public static function get_original_series( $post_ID ) {
* @param WP_Post $post Post object.
* @param bool $update Whether this is an existing post being updated or not.
*
* @since 2.8
* @since 2.8
*
* @deprecated 2.15.11 - in favor of SM_Dates_WP::save_terms_dates()
* @see SM_Dates_WP::save_terms_dates()
*/
public static function save_series_date( $post_ID, $post, $update ) {
self::save_terms_dates( $post_ID, $post, $update );
}

/**
* Saves sermon date as term meta for all terms for that sermon, used for ordering.
*
* @param int $post_ID Post ID.
* @param WP_Post $post Post object.
* @param bool $update Whether this is an existing post being updated or not.
*
* @since 2.15.11
*/
public static function save_terms_dates( $post_ID, $post, $update ) {
if ( ! isset( $_POST['tax_input'] ) ) {
return;
}

$series = $_POST['tax_input']['wpfc_sermon_series'];
$orig_series = $GLOBALS['sm_original_series'];
$original_terms = $GLOBALS['sm_original_terms'];
$updated_terms = isset( $_POST['tax_input'] ) ? $_POST['tax_input'] : null;

if ( $update ) {
foreach ( $orig_series as $term ) {
delete_term_meta( $term->term_id, 'sermon_date' );
}
$updated_terms += array_fill_keys( sm_get_taxonomies(), array() );

if ( ! $updated_terms ) {
return;
}

if ( ! empty( $series ) ) {
foreach ( $orig_series as $term_id ) {
update_term_meta( $term_id, 'sermon_date_' . $post_ID, get_post_meta( $post_ID, 'sermon_date', true ) );
foreach ( sm_get_taxonomies() as $taxonomy ) {
$new_terms = $updated_terms[ $taxonomy ];
$orig_terms = $original_terms[ $taxonomy ];

// Remove the date of the current sermon from removed terms.
foreach ( $orig_terms as $term ) {
if ( ! in_array( $term, $new_terms ) ) {
delete_term_meta( $term, 'sermon_date_' . $post_ID );
}
}

// Add the date of the current sermon to its terms.
if ( ! empty( $new_terms ) ) {
foreach ( $new_terms as $term ) {
update_term_meta( $term, 'sermon_date_' . $post_ID, get_post_meta( $post_ID, 'sermon_date', true ) );
}
}

// Update the main date.
self::update_term_dates( $taxonomy, $orig_terms + $new_terms );
}
}

/**
* Left here for backwards-compatibility reasons.
* Does exactly the same as - self::update_term_dates();
* Loops through taxonomies and terms and sets latest available sermon date.
*
* @since 2.8
* @deprecated
*/
public static function update_series_date() {
self::update_term_dates();
}

/**
* Loops through all terms and sets latest available sermon date.
* @param string $taxonomy The taxonomy to update. Default all.
* @param array|string $terms The term(s) to update. Default all.
*
* @since 2.13.0 - extended to all terms
* @since 2.15.11 - added parameters
*/
public static function update_term_dates() {
foreach (
get_terms( array(
'taxonomy' => array(
'wpfc_sermon_series',
'wpfc_preacher',
'wpfc_sermon_topics',
'wpfc_bible_book',
'wpfc_service_type',
),
'hide_empty' => true,
) ) as $term
) {
$term_meta = get_term_meta( $term->term_id );

if ( empty( $term_meta['sermon_date'] ) ) {
public static function update_term_dates( $taxonomy = '', $terms = array() ) {
$taxonomies = $taxonomy ? array( $taxonomy ) : sm_get_taxonomies();

foreach ( $taxonomies as $taxonomy ) {
$the_terms = ! empty( $terms ) ? (array) $terms : null;

if ( null === $the_terms ) {
$get_terms = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
)
);

foreach ( $get_terms as $term ) {
$the_terms[] = $term->term_id;
}
}

// Save the most recent sermon date to the term.
foreach ( $the_terms as $term ) {
$meta = get_term_meta( $term );
$dates = array();
foreach ( $term_meta as $name => $value ) {
if ( strpos( $name, 'sermon_date_' ) !== false ) {
$dates[] = $value[0];

// Gather all of the dates.
foreach ( $meta as $meta_key => $meta_value ) {
if ( substr( $meta_key, 0, 12 ) !== 'sermon_date_' ) {
continue;
}
}

if ( ! empty( $dates ) ) {
arsort( $dates );
$date = $dates[0];
} else {
$query = new WP_Query( array(
'post_type' => 'wpfc_sermon',
'posts_per_page' => 1,
'meta_key' => 'sermon_date',
'meta_value_num' => time(),
'meta_compare' => '<=',
'orderby' => 'meta_value_num',
'tax_query' => array(
array(
'taxonomy' => $term->taxonomy,
'field' => 'term_id',
'terms' => $term->term_id,
),
),
) );
if ( $query->have_posts() ) {
$date = get_post_meta( $query->posts[0]->ID, 'sermon_date', true );
} else {
$date = 0;
$sermon_date = intval( $meta_value[0] );

if ( $sermon_date ) {
$dates[] = $sermon_date;
}
}

update_term_meta( $term->term_id, 'sermon_date', $date );
// If we can't find a date, remove the existing.
if ( empty( $dates ) ) {
delete_term_meta( $term, 'sermon_date' );
continue;
}

// Sort the dates by newest first (DESC).
rsort( $dates );

// Update the date.
update_term_meta( $term, 'sermon_date', $dates[0] );
}
}
}

/**
* Left here for backwards-compatibility reasons.
* Does exactly the same as - self::update_term_dates();
*
* @since 2.8
* @deprecated 2.13.0
*/
public static function update_series_date() {
self::update_term_dates();
}

/**
* Used to save date that was there before sermon update, for later comparison.
*
Expand Down
Loading

0 comments on commit 8173124

Please sign in to comment.