mgsisk / webcomic

Comic publishing power for the web. Turn your WordPress-powered site into a comic publishing platform with Webcomic.
http://wordpress.org/plugins/webcomic
GNU General Public License v2.0
110 stars 29 forks source link

"PHP Warning: Trying to access array offset on value of type int" Across 6 Files #387

Open DerekPadula opened 3 months ago

DerekPadula commented 3 months ago

Expected Behavior\ That the plugin would not generate warnings on each page load for this situation because there wouldn't be errors.

Current Behavior\ My site's PHP error logs are generating a PHP warning across 6 files each time a visitor requests a Webcomic page that states the following: "PHP Warning: Trying to access array offset on value of type int". The content loads as it should, but this error still occurs. Here are the 5 files:

PHP Warning: Trying to access array offset on value of type int in /home/websitedomain/public_html/wp-content/plugins/webcomic/lib/collection/widget/class-webcomiclink.php on line 295 [22-May-2024 13:50:30 UTC] PHP Warning: Trying to access array offset on value of type int in /home/websitedomain/public_html/wp-content/plugins/webcomic/lib/collection/widget/class-webcomiccollectionlink.php on line 173 [22-May-2024 13:50:30 UTC] PHP Warning: Trying to access array offset on value of type int in /home/websitedomain/public_html/wp-content/plugins/webcomic/lib/taxonomy/widget/class-webcomictermlink.php on line 258 [22-May-2024 13:50:30 UTC] PHP Warning: Trying to access array offset on value of type int in /home/websitedomain/public_html/wp-content/plugins/webcomic/lib/commerce/widget/class-webcomiccollectioncartlink.php on line 161 [22-May-2024 13:50:30 UTC] PHP Warning: Trying to access array offset on value of type int in /home/websitedomain/public_html/wp-content/plugins/webcomic/lib/commerce/widget/class-webcomiccollectiondonationlink.php on line 161 [22-May-2024 13:50:30 UTC] PHP Warning: Trying to access array offset on value of type int in /home/websitedomain/public_html/wp-content/plugins/webcomic/lib/transcribe/widget/class-webcomictranscriptslink.php on line 169

Reproduction Steps\

Each error is related to this type of foreach loop, in the "if" section:

foreach ( $widgets as $key => $widget ) { if ( $post !== $widget['media'] ) { continue; }

        $widgets[ $key ]['media'] = 0;
    }

^ This was in /lib/transcribe/widget/class-webcomictranscriptslink.php on line 169

Suggested Fix\ I'm not sure how to fix this one.

Context\ Since you're not actively working on this plugin, can you provide a single fix here so that your users can make the edits as needed to the files?

Thank you.

ykyu commented 3 months ago

This implies that $widget is sometimes an integer? which is weird. I'm not super familiar with the function that is setting $widgets, but a basic array check should fix this error, which is pretty low stakes anyway. Let me know if this works.

foreach ( $widgets as $key => $widget ) {
            if ( is_array($widget) && $post !== $widget['media'] ) {
                continue;
            }
DerekPadula commented 3 months ago

Same as my other recent bug report, this PHP error has stopped appearing in my log without having made your suggested change. There might be something else on the site that triggers the error that I'm unaware of.

For now, you can close this, or do so a couple weeks from now just to be sure. Thank you.