Skip to content

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

@tstephen

Description

@tstephen

Expected Behaviour

Able to open a sermon to edit from sermon list.

Actual Behaviour

  • Some sermons will not open. It may be co-incidental but I note that it has happened when the sermon does not have a preached date (which is an optional field).
  • Although it may not be the root cause the WordPress fatal error reporter lists this stack trace:
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  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions