Skip to content

Commit

Permalink
Merge pull request #127 from WP-for-Church/dev
Browse files Browse the repository at this point in the history
Release 2.8.4
  • Loading branch information
Nikola Miljković authored Oct 7, 2017
2 parents 3553701 + 0b0b107 commit c1a20b0
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 139 deletions.
42 changes: 1 addition & 41 deletions includes/class-sm-background-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,6 @@ class SM_Background_Updater extends WP_Background_Process {
*/
protected $action = 'sm_updater';

/**
* Dispatch updater.
*
* Updater will still run via cron job if this fails for any reason.
*/
public function dispatch() {
parent::dispatch();
}

/**
* Handle cron healthcheck
*
* Restart the background process if not already running
* and data exists in the queue.
*/
public function handle_cron_healthcheck() {
if ( $this->is_process_running() ) {
// Background process already running.
return;
}

if ( $this->is_queue_empty() ) {
// No data to process.
$this->clear_scheduled_event();

return;
}

$this->handle();
}

/**
* Schedule fallback event.
*/
protected function schedule_event() {
if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
wp_schedule_event( time() + 10, $this->cron_interval_identifier, $this->cron_hook_identifier );
}
}

/**
* Is the updater running?
*
Expand All @@ -85,7 +45,7 @@ protected function task( $callback ) {
define( 'SM_UPDATING', true );
}

include_once( dirname( __FILE__ ) . '/sm-update-functions.php' );
include_once 'sm-update-functions.php';

if ( is_callable( $callback ) ) {
call_user_func( $callback );
Expand Down
33 changes: 18 additions & 15 deletions includes/class-sm-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
class SM_Install {
/** @var array DB updates and callbacks that need to be run per version */
private static $db_updates = array(
'2.8' => array(
'2.8' => array(
'sm_update_28_revert_old_dates',
'sm_update_28_convert_dates_to_unix',
'sm_update_28_fill_out_empty_dates',
'sm_update_28_fill_out_series_dates',
'sm_update_28_save_sermon_render_into_post_content',
'sm_update_28_reset_recovery',
),
'2.8.3' => array(
'sm_update_283_resave_sermons'
'2.8.4' => array(
'sm_update_284_resave_sermons'
)
);

Expand Down Expand Up @@ -98,12 +98,15 @@ private static function _install() {
* Push all needed DB updates to the queue for processing.
*/
private static function _update() {
$current_db_version = get_option( 'sm_version' );
$update_queued = false;
if ( self::$background_updater->is_updating() ) {
return;
}

$update_queued = false;

foreach ( self::_get_db_update_callbacks() as $version => $update_callbacks ) {
if ( version_compare( $current_db_version, $version, '<' ) ) {
foreach ( $update_callbacks as $update_callback ) {
foreach ( $update_callbacks as $update_callback ) {
if ( ! get_option( 'wp_sm_updater_' . $update_callback . '_done' ) ) {
self::$background_updater->push_to_queue( $update_callback );
$update_queued = true;
}
Expand All @@ -124,14 +127,6 @@ private static function _get_db_update_callbacks() {
return self::$db_updates;
}

/**
* Init background updates
*/
public static function init_background_updater() {
include_once 'class-sm-background-updater.php';
self::$background_updater = new SM_Background_Updater();
}

/**
* Update DB version to current.
*
Expand All @@ -142,6 +137,14 @@ public static function update_db_version( $version = null ) {
add_option( 'sm_version', is_null( $version ) ? SM_VERSION : $version );
}

/**
* Init background updates
*/
public static function init_background_updater() {
include_once 'class-sm-background-updater.php';
self::$background_updater = new SM_Background_Updater();
}

/**
* Add more cron schedules
*
Expand Down
1 change: 1 addition & 0 deletions includes/libraries/wp-background-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ protected function handle() {
$batch->data[ $key ] = $task;
} else {
unset( $batch->data[ $key ] );
update_option('wp_sm_updater_' . $value . '_done', 1 );
}

if ( $this->time_exceeded() || $this->memory_exceeded() ) {
Expand Down
100 changes: 59 additions & 41 deletions includes/options.php

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions includes/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public function displayImages( $atts = array() ) {
$args = shortcode_atts( $args, $atts, 'sermon_images' );

// convert to bool
$args['show_description'] = boolval( $args['show_description'] );
$args['show_description'] = (bool) $args['show_description'];

// check if we are using a SM taxonomy, and if we are, convert to valid taxonomy name
if ( $this->convertTaxonomyName( $args['display'], true ) ) {
Expand Down Expand Up @@ -425,11 +425,11 @@ function displayLatestSeriesImage( $atts = array() ) {
$image = wp_get_attachment_image( $series_image_id, $args['size'], false, array( 'class' => $image_class ) );

$title = $description = '';
if ( boolval( $args['show_title'] ) === true ) {
if ( (bool) $args['show_title'] === true ) {
$title = $latest_series->name;
$title = '<' . $args['title_wrapper'] . ' class="' . $title_class . '">' . $title . '</' . $args['title_wrapper'] . '>';
}
if ( boolval( $args['show_desc'] ) === true ) {
if ( (bool) $args['show_desc'] === true ) {
$description = '<div class="latest-series-description">' . wpautop( $latest_series->description ) . '</div>';
}

Expand Down
13 changes: 0 additions & 13 deletions includes/sm-legacy-php-functions.php

This file was deleted.

17 changes: 10 additions & 7 deletions includes/sm-update-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,27 @@ function sm_update_28_fill_out_series_dates() {
*/
function sm_update_28_save_sermon_render_into_post_content() {
global $wpdb;
global $post;

$original_post = $post;

// All sermons
$sermons = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_date FROM $wpdb->posts WHERE post_type = %s", 'wpfc_sermon' ) );

foreach ( $sermons as $sermon ) {
wp_update_post( array(
'ID' => $sermon->ID,
'post_content' => wpfc_sermon_single( true, $sermon )
) );
$post = $sermon;
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_content = '%s' WHERE ID = $sermon->ID", wpfc_sermon_single( true ) ) );
}

$post = $original_post;

// clear all cached data
wp_cache_flush();
}

/**
* <source> element was not included in 2.8 save. We allowed it and it will work now
* We had a bug from 2.8 to 2.8.3, so we will do it again
*/
function sm_update_283_resave_sermons(){
function sm_update_284_resave_sermons() {
sm_update_28_save_sermon_render_into_post_content();
}
}
8 changes: 7 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: church, sermon, sermons, preaching, podcasting, manage, managing, podcasts
Requires at least: 4.5
Tested up to: 4.8.2
Requires PHP: 5.3
Stable tag: 2.8.3
Stable tag: 2.8.4
License: GPLv2
License URI: https://www.gnu.org/licenses/gpl-2.0.html

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

## Changelog ##
### 2.8.4 ###
* Fix sermons having to be resaved to work
* Fix fatal error when using plugin views
* Fix update functions being executed multiple times
* Fix update functions not being executed for users who skip versions

### 2.8.3 ###
* Fix sermon audio not showing up
* Fix sermon not updating on first save
Expand Down
9 changes: 3 additions & 6 deletions sermons.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Sermon Manager for WordPress
* Plugin URI: https://www.wpforchurch.com/products/sermon-manager-for-wordpress/
* Description: Add audio and video sermons, manage speakers, series, and more.
* Version: 2.8.3
* Version: 2.8.4
* Author: WP for Church
* Author URI: https://www.wpforchurch.com/
* Requires at least: 4.5
Expand Down Expand Up @@ -124,7 +124,6 @@ private function _includes() {
'includes/class-sm-install.php', // Install and update functions
'includes/sm-deprecated-functions.php', // Deprecated SM functions
'includes/sm-core-functions.php', // Deprecated SM functions
'includes/sm-legacy-php-functions.php', // Old PHP compatibility fixes
'includes/sm-cmb-functions.php', // CMB2 Meta Fields functions
'includes/taxonomy-images/taxonomy-images.php', // Images for Custom Taxonomies
'includes/entry-views.php', // Entry Views Tracking
Expand Down Expand Up @@ -385,10 +384,8 @@ public function render_sermon_into_content( $post_ID, $post ) {
define( 'SM_SAVING_POST', 1 );
}

wp_update_post( array(
'ID' => $post_ID,
'post_content' => wpfc_sermon_single( true )
) );
global $wpdb;
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_content = '%s' WHERE ID = $post_ID", wpfc_sermon_single( true ) ) );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions views/archive-wpfc_sermon.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@

<div class="entry-utility">
<span class="comments-link">
<?php $comment_count = wp_count_comments( $post->ID ); ?>
<?php comments_popup_link( esc_html__( 'Leave a comment', 'sermon-manager-for-wordpress' ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', 1, 'sermon-manager-for-wordpress' ) ), number_format_i18n( 1 ) ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', $approved_comments_count = intval( $comment_count['approved'] ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?>
<?php $comment_count = (object) wp_count_comments( $post->ID ); ?>
<?php comments_popup_link( esc_html__( 'Leave a comment', 'sermon-manager-for-wordpress' ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', 1, 'sermon-manager-for-wordpress' ) ), number_format_i18n( 1 ) ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', $approved_comments_count = intval( $comment_count->approved ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?>
</span>
<?php edit_post_link( esc_html__( 'Edit', 'sermon-manager-for-wordpress' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
</div>
Expand Down
4 changes: 2 additions & 2 deletions views/taxonomy-wpfc_bible_book.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ class="meta-sep"> by </span> <?php echo the_terms( $post->ID, 'wpfc_preacher', '
</div><!-- .entry-content -->

<div class="entry-utility">
<?php $comment_count = wp_count_comments( $post->ID ); ?>
<?php $comment_count = (object) wp_count_comments( $post->ID ); ?>
<span
class="comments-link"><?php comments_popup_link( esc_html__( 'Leave a comment', 'sermon-manager-for-wordpress' ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', 1, 'sermon-manager-for-wordpress' ) ), number_format_i18n( 1 ) ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', $approved_comments_count = intval( $comment_count['approved'] ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?></span>
class="comments-link"><?php comments_popup_link( esc_html__( 'Leave a comment', 'sermon-manager-for-wordpress' ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', 1, 'sermon-manager-for-wordpress' ) ), number_format_i18n( 1 ) ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', $approved_comments_count = intval( $comment_count->approved ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?></span>
<?php edit_post_link( esc_html__( 'Edit', 'sermon-manager-for-wordpress' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-utility -->
</div><!-- #post-## -->
Expand Down
4 changes: 2 additions & 2 deletions views/taxonomy-wpfc_preacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class="meta-sep"> by </span> <?php echo the_terms( $post->ID, 'wpfc_preacher', '
</div><!-- .entry-content -->

<div class="entry-utility">
<?php $comment_count = wp_count_comments( $post->ID ); ?>
<?php $comment_count = (object) wp_count_comments( $post->ID ); ?>
<span
class="comments-link"><?php comments_popup_link( esc_html__( 'Leave a comment', 'sermon-manager-for-wordpress' ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', 1, 'sermon-manager-for-wordpress' ) ), number_format_i18n( 1 ) ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', $approved_comments_count = intval( $comment_count['approved'] ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?></span>
class="comments-link"><?php comments_popup_link( esc_html__( 'Leave a comment', 'sermon-manager-for-wordpress' ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', 1, 'sermon-manager-for-wordpress' ) ), number_format_i18n( 1 ) ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', $approved_comments_count = intval( $comment_count->approved ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?></span>
<?php edit_post_link( esc_html__( 'Edit', 'sermon-manager-for-wordpress' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-utility -->
</div><!-- #post-## -->
Expand Down
4 changes: 2 additions & 2 deletions views/taxonomy-wpfc_sermon_series.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ class="meta-sep"> by </span> <?php echo the_terms( $post->ID, 'wpfc_preacher', '
</div><!-- .entry-content -->

<div class="entry-utility">
<?php $comment_count = wp_count_comments( $post->ID ); ?>
<?php $comment_count = (object) wp_count_comments( $post->ID ); ?>
<span
class="comments-link"><?php comments_popup_link( esc_html__( 'Leave a comment', 'sermon-manager-for-wordpress' ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', 1, 'sermon-manager-for-wordpress' ) ), number_format_i18n( 1 ) ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', $approved_comments_count = intval( $comment_count['approved'] ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?></span>
class="comments-link"><?php comments_popup_link( esc_html__( 'Leave a comment', 'sermon-manager-for-wordpress' ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', 1, 'sermon-manager-for-wordpress' ) ), number_format_i18n( 1 ) ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', $approved_comments_count = intval( $comment_count->approved ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?></span>
<?php edit_post_link( esc_html__( 'Edit', 'sermon-manager-for-wordpress' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-utility -->
</div><!-- #post-## -->
Expand Down
4 changes: 2 additions & 2 deletions views/taxonomy-wpfc_sermon_topics.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ class="meta-sep"> by </span> <?php echo the_terms( $post->ID, 'wpfc_preacher', '
</div><!-- .entry-content -->

<div class="entry-utility">
<?php $comment_count = wp_count_comments( $post->ID ); ?>
<?php $comment_count = (object) wp_count_comments( $post->ID ); ?>
<span
class="comments-link"><?php comments_popup_link( esc_html__( 'Leave a comment', 'sermon-manager-for-wordpress' ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', 1, 'sermon-manager-for-wordpress' ) ), number_format_i18n( 1 ) ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', $approved_comments_count = intval( $comment_count['approved'] ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?></span>
class="comments-link"><?php comments_popup_link( esc_html__( 'Leave a comment', 'sermon-manager-for-wordpress' ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', 1, 'sermon-manager-for-wordpress' ) ), number_format_i18n( 1 ) ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', $approved_comments_count = intval( $comment_count->approved ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?></span>
<?php edit_post_link( esc_html__( 'Edit', 'sermon-manager-for-wordpress' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-utility -->
</div><!-- #post-## -->
Expand Down
4 changes: 2 additions & 2 deletions views/taxonomy-wpfc_service_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ class="meta-sep"> by </span> <?php echo the_terms( $post->ID, 'wpfc_preacher', '
</div><!-- .entry-content -->

<div class="entry-utility">
<?php $comment_count = wp_count_comments( $post->ID ); ?>
<?php $comment_count = (object) wp_count_comments( $post->ID ); ?>
<span
class="comments-link"><?php comments_popup_link( esc_html__( 'Leave a comment', 'sermon-manager-for-wordpress' ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', 1, 'sermon-manager-for-wordpress' ) ), number_format_i18n( 1 ) ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', $approved_comments_count = intval( $comment_count['approved'] ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?></span>
class="comments-link"><?php comments_popup_link( esc_html__( 'Leave a comment', 'sermon-manager-for-wordpress' ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', 1, 'sermon-manager-for-wordpress' ) ), number_format_i18n( 1 ) ), wp_sprintf( esc_html( _n( '%s comment', '%s comments', $approved_comments_count = intval( $comment_count->approved ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?></span>
<?php edit_post_link( esc_html__( 'Edit', 'sermon-manager-for-wordpress' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-utility -->
</div><!-- #post-## -->
Expand Down

0 comments on commit c1a20b0

Please sign in to comment.