From 21ccbcbc0ece681ac40c171db93c52eb0d4b1acd Mon Sep 17 00:00:00 2001 From: Nikola Date: Sat, 7 Oct 2017 14:52:55 +0200 Subject: [PATCH 1/6] Fix sermons having to be resaved to work --- includes/class-sm-background-updater.php | 42 +----------------------- includes/class-sm-install.php | 26 ++++++++------- includes/sm-update-functions.php | 17 ++++++---- readme.txt | 3 ++ sermons.php | 6 ++-- 5 files changed, 31 insertions(+), 63 deletions(-) diff --git a/includes/class-sm-background-updater.php b/includes/class-sm-background-updater.php index ebe6189..d18e52a 100644 --- a/includes/class-sm-background-updater.php +++ b/includes/class-sm-background-updater.php @@ -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? * @@ -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 ); diff --git a/includes/class-sm-install.php b/includes/class-sm-install.php index 640ee5d..03d76f7 100644 --- a/includes/class-sm-install.php +++ b/includes/class-sm-install.php @@ -9,7 +9,7 @@ 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', @@ -17,8 +17,8 @@ class SM_Install { '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' ) ); @@ -98,6 +98,10 @@ private static function _install() { * Push all needed DB updates to the queue for processing. */ private static function _update() { + if ( self::$background_updater->is_updating() ) { + return; + } + $current_db_version = get_option( 'sm_version' ); $update_queued = false; @@ -124,14 +128,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. * @@ -142,6 +138,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 * diff --git a/includes/sm-update-functions.php b/includes/sm-update-functions.php index 765826c..2474dc8 100644 --- a/includes/sm-update-functions.php +++ b/includes/sm-update-functions.php @@ -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(); } /** - * 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(); -} +} \ No newline at end of file diff --git a/readme.txt b/readme.txt index 78a3269..e77a0b6 100755 --- a/readme.txt +++ b/readme.txt @@ -93,6 +93,9 @@ 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 + ### 2.8.3 ### * Fix sermon audio not showing up * Fix sermon not updating on first save diff --git a/sermons.php b/sermons.php index 94c0476..ba13159 100755 --- a/sermons.php +++ b/sermons.php @@ -385,10 +385,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 ) ) ); } /** From 2c0c8b3bca9a44caccdc98c6281bac5383c3f8a0 Mon Sep 17 00:00:00 2001 From: Nikola Date: Sat, 7 Oct 2017 15:02:21 +0200 Subject: [PATCH 2/6] Fix fatal error for comment count rendering --- readme.txt | 1 + views/archive-wpfc_sermon.php | 4 ++-- views/taxonomy-wpfc_bible_book.php | 4 ++-- views/taxonomy-wpfc_preacher.php | 4 ++-- views/taxonomy-wpfc_sermon_series.php | 4 ++-- views/taxonomy-wpfc_sermon_topics.php | 4 ++-- views/taxonomy-wpfc_service_type.php | 4 ++-- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/readme.txt b/readme.txt index e77a0b6..63e157f 100755 --- a/readme.txt +++ b/readme.txt @@ -95,6 +95,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man ## Changelog ## ### 2.8.4 ### * Fix sermons having to be resaved to work +* Fix fatal error when using plugin views ### 2.8.3 ### * Fix sermon audio not showing up diff --git a/views/archive-wpfc_sermon.php b/views/archive-wpfc_sermon.php index 5d07242..4b53045 100644 --- a/views/archive-wpfc_sermon.php +++ b/views/archive-wpfc_sermon.php @@ -56,8 +56,8 @@
- ID ); ?> - + ID ); ?> + approved ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?> | ', '' ); ?>
diff --git a/views/taxonomy-wpfc_bible_book.php b/views/taxonomy-wpfc_bible_book.php index ce8bdd2..9496af8 100644 --- a/views/taxonomy-wpfc_bible_book.php +++ b/views/taxonomy-wpfc_bible_book.php @@ -84,9 +84,9 @@ class="meta-sep"> by ID, 'wpfc_preacher', '
- ID ); ?> + ID ); ?> + class="comments-link">approved ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?> | ', '' ); ?>
diff --git a/views/taxonomy-wpfc_preacher.php b/views/taxonomy-wpfc_preacher.php index 436835f..e815023 100644 --- a/views/taxonomy-wpfc_preacher.php +++ b/views/taxonomy-wpfc_preacher.php @@ -90,9 +90,9 @@ class="meta-sep"> by ID, 'wpfc_preacher', '
- ID ); ?> + ID ); ?> + class="comments-link">approved ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?> | ', '' ); ?>
diff --git a/views/taxonomy-wpfc_sermon_series.php b/views/taxonomy-wpfc_sermon_series.php index a6d186b..27c18b8 100644 --- a/views/taxonomy-wpfc_sermon_series.php +++ b/views/taxonomy-wpfc_sermon_series.php @@ -91,9 +91,9 @@ class="meta-sep"> by ID, 'wpfc_preacher', '
- ID ); ?> + ID ); ?> + class="comments-link">approved ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?> | ', '' ); ?>
diff --git a/views/taxonomy-wpfc_sermon_topics.php b/views/taxonomy-wpfc_sermon_topics.php index 09273de..ecc1433 100644 --- a/views/taxonomy-wpfc_sermon_topics.php +++ b/views/taxonomy-wpfc_sermon_topics.php @@ -91,9 +91,9 @@ class="meta-sep"> by ID, 'wpfc_preacher', '
- ID ); ?> + ID ); ?> + class="comments-link">approved ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?> | ', '' ); ?>
diff --git a/views/taxonomy-wpfc_service_type.php b/views/taxonomy-wpfc_service_type.php index 923d1e7..7595f32 100644 --- a/views/taxonomy-wpfc_service_type.php +++ b/views/taxonomy-wpfc_service_type.php @@ -84,9 +84,9 @@ class="meta-sep"> by ID, 'wpfc_preacher', '
- ID ); ?> + ID ); ?> + class="comments-link">approved ), 'sermon-manager-for-wordpress' ) ), number_format_i18n( $approved_comments_count ) ) ); ?> | ', '' ); ?>
From 43e9a534ff1e71e7885937f16b8174a991c60164 Mon Sep 17 00:00:00 2001 From: Nikola Date: Sat, 7 Oct 2017 15:04:23 +0200 Subject: [PATCH 3/6] Update versions --- readme.txt | 2 +- sermons.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.txt b/readme.txt index 63e157f..575f3a5 100755 --- a/readme.txt +++ b/readme.txt @@ -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 diff --git a/sermons.php b/sermons.php index ba13159..fc1e15f 100755 --- a/sermons.php +++ b/sermons.php @@ -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 From bb14286210e92f142ced93b7ec89c89a016f363b Mon Sep 17 00:00:00 2001 From: Nikola Date: Sat, 7 Oct 2017 15:08:11 +0200 Subject: [PATCH 4/6] Update changelog --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index 575f3a5..55ae461 100755 --- a/readme.txt +++ b/readme.txt @@ -96,6 +96,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man ### 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 ### 2.8.3 ### * Fix sermon audio not showing up From a14fad754329a5f4a453d0929dc262a274df2e01 Mon Sep 17 00:00:00 2001 From: Nikola Date: Sat, 7 Oct 2017 15:17:57 +0200 Subject: [PATCH 5/6] Execute all update functions in order --- includes/class-sm-install.php | 7 +++---- includes/libraries/wp-background-process.php | 1 + readme.txt | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/includes/class-sm-install.php b/includes/class-sm-install.php index 03d76f7..c2c5e7c 100644 --- a/includes/class-sm-install.php +++ b/includes/class-sm-install.php @@ -102,12 +102,11 @@ private static function _update() { return; } - $current_db_version = get_option( 'sm_version' ); - $update_queued = false; + $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; } diff --git a/includes/libraries/wp-background-process.php b/includes/libraries/wp-background-process.php index 1323ee5..f3f59a0 100644 --- a/includes/libraries/wp-background-process.php +++ b/includes/libraries/wp-background-process.php @@ -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() ) { diff --git a/readme.txt b/readme.txt index 55ae461..e4945d1 100755 --- a/readme.txt +++ b/readme.txt @@ -97,6 +97,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * 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 From 0b0b10797e43f4ca4a102edb3873679541b6ecc4 Mon Sep 17 00:00:00 2001 From: Nikola Date: Sat, 7 Oct 2017 15:22:31 +0200 Subject: [PATCH 6/6] Remove boolval because some scripts reported SM as not compatible with PHP <=5.4 --- includes/options.php | 100 ++++++++++++++++----------- includes/shortcodes.php | 6 +- includes/sm-legacy-php-functions.php | 13 ---- sermons.php | 1 - 4 files changed, 62 insertions(+), 58 deletions(-) delete mode 100644 includes/sm-legacy-php-functions.php diff --git a/includes/options.php b/includes/options.php index f5b8cb1..a101275 100755 --- a/includes/options.php +++ b/includes/options.php @@ -26,11 +26,11 @@ static function wpfc_validate_options( $input ) { unset( $input['sm_do_not_catch'] ); } else { update_option( '_sm_recovery_do_not_catch', '0' ); - } + } - if ( SermonManager::getOption( 'archive_slug' ) != $input['archive_slug'] || - SermonManager::getOption( 'common_base_slug' ) != $input['common_base_slug'] || - SermonManager::getOption( 'preacher_label' ) != $input['preacher_label'] ) { + if ( SermonManager::getOption( 'archive_slug' ) != $input['archive_slug'] || + SermonManager::getOption( 'common_base_slug' ) != $input['common_base_slug'] || + SermonManager::getOption( 'preacher_label' ) != $input['preacher_label'] ) { update_option( 'sm_flush_rewrite_rules', '1' ); } @@ -43,7 +43,7 @@ static function wpfc_validate_options( $input ) { * @since 2.5.2 */ function maybe_flush_rewrite_rules() { - if ( boolval( get_option( 'sm_flush_rewrite_rules' ) ) ) { + if ( (bool) get_option( 'sm_flush_rewrite_rules' ) ) { flush_rewrite_rules(); update_option( 'sm_flush_rewrite_rules', '0' ); } @@ -167,17 +167,21 @@ function wpfc_sermon_options_render_form() { -

+

+

@@ -186,13 +190,16 @@ function wpfc_sermon_options_render_form() {
-

+

+

' . esc_html__( 'Sign up', 'sermon-manager-for-wordpress' ) . '' ); ?>

  - + target="_blank" + class="button-secondary">  +
@@ -201,7 +208,9 @@ function wpfc_sermon_options_render_form() {
-

+

+ +

- ' . esc_html__( 'knowledge base', 'sermon-manager-for-wordpress' ) . '' ); ?> + ' . esc_html__( 'knowledge base', 'sermon-manager-for-wordpress' ) . '' ); ?>
-

+

+ +

+ target="_blank" + class="button-secondary">
@@ -241,7 +253,9 @@ function wpfc_sermon_options_render_form() {
-

+

+ +

@@ -279,7 +293,7 @@ function wpfc_sermon_options_render_form() {
@@ -371,7 +385,9 @@ function wpfc_sermon_options_render_form() {
-

+

+ +

@@ -411,11 +427,11 @@ function wpfc_sermon_options_render_form() { ESV', - 'NET', - 'KJV', - 'LEB', - '' . esc_html__( 'bib.ly', 'sermon-manager-for-wordpress' ) . '' ); ?> + 'ESV', + 'NET', + 'KJV', + 'LEB', + '' . esc_html__( 'bib.ly', 'sermon-manager-for-wordpress' ) . '' ); ?>
ESV' ); ?>
@@ -426,7 +442,9 @@ function wpfc_sermon_options_render_form() {
-

+

+ +

@@ -462,7 +480,7 @@ function wpfc_sermon_options_render_form() {
@@ -472,7 +490,7 @@ function wpfc_sermon_options_render_form() { @@ -482,7 +500,7 @@ function wpfc_sermon_options_render_form() { @@ -492,12 +510,12 @@ function wpfc_sermon_options_render_form() { @@ -517,7 +535,7 @@ function wpfc_sermon_options_render_form() { @@ -540,7 +558,7 @@ function wpfc_sermon_options_render_form() {

- ' . htmlspecialchars( '©' ) . ''); ?> + ' . htmlspecialchars( '©' ) . '' ); ?>

@@ -553,7 +571,7 @@ function wpfc_sermon_options_render_form() { + placeholder="">

@@ -565,7 +583,7 @@ function wpfc_sermon_options_render_form() {
@@ -578,7 +596,7 @@ function wpfc_sermon_options_render_form() { @@ -676,11 +694,11 @@ class="itunes_cover_image_field"
+ $archive_slug = $options['archive_slug']; + if ( empty( $archive_slug ) ) { + $archive_slug = 'sermons'; + } + echo home_url( '/' ) . $archive_slug; ?>/feed/"/>

' . esc_html__( 'Feed Validator', 'sermon-manager-for-wordpress' ) . '' ); ?> diff --git a/includes/shortcodes.php b/includes/shortcodes.php index b0a8914..988f880 100755 --- a/includes/shortcodes.php +++ b/includes/shortcodes.php @@ -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 ) ) { @@ -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 . ''; } - if ( boolval( $args['show_desc'] ) === true ) { + if ( (bool) $args['show_desc'] === true ) { $description = '

' . wpautop( $latest_series->description ) . '
'; } diff --git a/includes/sm-legacy-php-functions.php b/includes/sm-legacy-php-functions.php deleted file mode 100644 index 6cb377c..0000000 --- a/includes/sm-legacy-php-functions.php +++ /dev/null @@ -1,13 +0,0 @@ -