Skip to content

Fix fatal error when another the_content filter callback returns null instead of a string #1283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 6, 2024

Conversation

westonruter
Copy link
Member

In a support topic, a user reported a fatal error:

Uncaught TypeError: webp_uploads_update_image_references(): Argument #1 ($content) must be of type string, null given
#0 /home/******/public_html/wp-includes/class-wp-hook.php(324): webp_uploads_update_image_references() 
#1 /home/******/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters() 
#2 /home/******/public_html/wp-includes/formatting.php(3992): apply_filters() 
#3 /home/******/public_html/wp-includes/class-wp-hook.php(324): wp_trim_excerpt() 
#4 /home/******/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters() 
#5 /home/******/public_html/wp-includes/post-template.php(434): apply_filters() 
#6 /home/******/public_html/wp-content/plugins/seo-by-rank-math/includes/opengraph/class-opengraph.php(148): get_the_excerpt() 
#7 /home/******/public_html/wp-content/plugins/seo-by-rank-math/includes/opengraph/class-opengraph.php(125): RankMath\OpenGraph\OpenGraph->fallback_description() 
#8 /home/******/public_html/wp-content/plugins/seo-by-rank-math/includes/opengraph/class-facebook.php(200): RankMath\OpenGraph\OpenGraph->get_description() 
#9 /home/******/public_html/wp-includes/class-wp-hook.php(324): RankMath\OpenGraph\Facebook->description() 
#10 /home/******/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() 
#11 /home/******/public_html/wp-includes/plugin.php(565): WP_Hook->do_action() 
#12 /home/******/public_html/wp-content/plugins/seo-by-rank-math/includes/traits/class-hooker.php(90): do_action_ref_array() 
#13 /home/******/public_html/wp-content/plugins/seo-by-rank-math/includes/opengraph/class-opengraph.php(74): RankMath\OpenGraph\OpenGraph->do_action() 
#14 /home/******/public_html/wp-includes/class-wp-hook.php(324): RankMath\OpenGraph\OpenGraph->output_tags() 
#15 /home/******/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() 
#16 /home/******/public_html/wp-includes/plugin.php(565): WP_Hook->do_action() 
#17 /home/******/public_html/wp-content/plugins/seo-by-rank-math/includes/traits/class-hooker.php(90): do_action_ref_array() 
#18 /home/******/public_html/wp-content/plugins/seo-by-rank-math/includes/frontend/class-head.php(180): RankMath\Frontend\Head->do_action() 
#19 /home/******/public_html/wp-includes/class-wp-hook.php(324): RankMath\Frontend\Head->head() 
#20 /home/******/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() 
#21 /home/******/public_html/wp-includes/plugin.php(517): WP_Hook->do_action() 
#22 /home/******/public_html/wp-includes/general-template.php(3050): do_action() 
#23 /home/******/public_html/wp-content/themes/elessi-theme/header.php(24): wp_head() 
#24 /home/******/public_html/wp-includes/template.php(810): require_once(‘…’) 
#25 /home/******/public_html/wp-includes/template.php(745): load_template() 
#26 /home/******/public_html/wp-includes/general-template.php(48): locate_template() 
#27 /home/******/public_html/wp-content/themes/elessi-theme/woocommerce/single-product.php(20): get_header() 
#28 /home/******/public_html/wp-includes/template-loader.php(106): include(‘…’) 
#29 /home/******/public_html/wp-blog-header.php(19): require_once(‘…’) 
#30 /home//public_html/index.php(17): require(‘…’) 
#31 {main} thrown in /home//public_html/wp-content/plugins/webp-uploads/hooks.php on line 525

It appears there is some other plugin which adds a the_content filter which returns null instead of a string. Since webp_uploads_update_image_references() is added as a filter, it should be updated to guard against this case by allowing mixed as the input, as we've done for other filters. This stems from work in #775.

@westonruter westonruter added the [Type] Bug An existing feature is broken label Jun 6, 2024
@westonruter westonruter added this to the webp-uploads n.e.x.t milestone Jun 6, 2024
@westonruter
Copy link
Member Author

Build for testing: webp-uploads.zip

Copy link

github-actions bot commented Jun 6, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <[email protected]>
Co-authored-by: adamsilverstein <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@westonruter westonruter changed the title Fix/webp uploads type error Fix fatal error when another the_content filter callback returns null instead of a string Jun 6, 2024
Comment on lines -853 to -866
/**
* Tests that the fallback script is not added when a post with no updated images is rendered.
*/
public function test_it_should_not_add_fallback_script_if_content_has_no_updated_images(): void {
remove_all_actions( 'wp_footer' );

apply_filters( 'the_content', '<p>no image</p>' );

$this->assertFalse( has_action( 'wp_footer', 'webp_uploads_webp_fallback' ) );

$footer = get_echo( 'wp_footer' );
$this->assertStringNotContainsString( 'webp;base64,UklGR', $footer );
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been removed as part of #1269

@westonruter westonruter merged commit c6fe7bd into trunk Jun 6, 2024
14 checks passed
@westonruter westonruter deleted the fix/webp-uploads-type-error branch June 6, 2024 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature is broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants