WP-for-Church / Sermon-Manager

Sermon Manager for WordPress is the #1 plugin for churches who want to manage their sermons easily and missionally.
https://wordpress.org/plugins/sermon-manager-for-wordpress/
GNU General Public License v2.0
44 stars 34 forks source link

Unable to open sermon due to fatal error in `sermons.php` #291

Open tstephen opened 3 years ago

tstephen commented 3 years ago

Expected Behaviour

Able to open a sermon to edit from sermon list.

Actual Behaviour

Error Details
=============
An error of type E_ERROR was caused in line 628 of the file /home/deleted/public_html/wp-content/plugins/sermon-manager-for-wordpress/sermons.php. Error message: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, bool given in /home/deleted/public_html/wp-content/plugins/sermon-manager-for-wordpress/sermons.php:628

Stack trace:
#0 /home/deleted/public_html/wp-includes/class-wp-hook.php(305): SermonManager->{closure}()
#1 /home/deleted/public_html/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters()
#2 /home/deleted/public_html/wp-includes/plugin.php(470): WP_Hook->do_action()
#3 /home/deleted/public_html/wp-includes/post.php(3207): do_action()
#4 /home/deleted/public_html/wp-includes/revision.php(458): wp_delete_post()
#5 /home/deleted/public_html/wp-admin/edit-form-blocks.php(209): wp_delete_post_revision()
#6 /home/deleted/public_html/wp-admin/post.php(187): require('/home/deleted/...')
#7 {main}
  thrown

Platform

WordPress Version: WordPress version 5.8 PHP Version: 8.0.9 Sermon Manager Version: Current plugin: Sermon Manager for WordPress (version 2.16.8)

Any Additional Info

Whilst I don't know what causes the array to be empty testing and, if empty, initialising $sermons_array resolves the problem. At the least this would appear to be a good defensive approach don't you think?

626  foreach ( $sermon_messages as $offset0 => $sermons_array ) {
627    $sermons_array = empty($sermons_array) ? array() : $sermons_array; // DEFENSIVE FIX
628    if(count($sermons_array)>0){
629      foreach ( $sermons_array as $offset1 => $value ) {
630        if ( $value['new_id'] == $id ) {
631          unset( $sermons_array[ $offset1 ] );
632          update_option( 0 === $offset0 ? '_sm_import_se_messages' : '_sm    _import_sb_messages', $sermons_array );
633 
634          return;
635        }
636      }
637    }
638 
639  }
tstephen commented 3 years ago

Submitted PR: https://github.com/WP-for-Church/Sermon-Manager/pull/292