Make WordPress Core

Opened 6 months ago

Last modified 3 weeks ago

#61179 reviewing defect (bug)

Deprecated messages about passing null in widgets.php

Reported by: presskopp's profile Presskopp Owned by: hellofromtonya's profile hellofromTonya
Milestone: 6.8 Priority: normal
Severity: normal Version: 2.8
Component: Widgets Keywords: php81 has-patch has-unit-tests
Focuses: php-compatibility Cc:

Description

I found the following message in my error logs:

PHP Deprecated: html_entity_decode(): Passing null to parameter #1 ($string) of type string is deprecated in ...\wp-includes\widgets.php on line 1630

This is the latest nightly on PHP8.3, but if you search for "widgets.php on line 1630" in your search engine, you will find online sites having the same issue

Line 1630 is the following:

$desc = html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) );

Change History (7)

This ticket was mentioned in PR #6826 on WordPress/wordpress-develop by @snehapatil02.


5 months ago
#1

  • Keywords has-patch has-unit-tests added

## Ticket
https://core.trac.wordpress.org/ticket/61179

## Description

  • This PR addresses a deprecation warning in the widgets.php file when running WordPress on PHP 8.3. The warning occurs because html_entity_decode() is called with null as its first parameter, which is deprecated in PHP 8.3.

## Changes

  • Updated the html_entity_decode call in widgets.php to use the null coalescing operator (??) to provide an empty string as a default value if $item->get_description() returns null.

## Testing Instructions

  1. Automated Testing:
    • Added unit tests for handling null, empty string, and valid string descriptions.
    • Run the tests with PHPUnit to ensure the changes work as expected.
  1. Manual Testing:
    • Null Description: Modify a widget to return null for its description. Check that no deprecation warnings are logged and the output is correct.
    • Empty String Description: Modify a widget to return an empty string for its description. Verify that no unnecessary output is rendered.
    • Valid String Description: Use a widget with a valid description and ensure it displays correctly on the frontend.

@snehapatil02 commented on PR #6826:


4 months ago
#2

@mukeshpanchal27

Changes made:

  • Modified the RSS widget output function in wp-includes/widgets.php
  • Added a check to ensure the RSS item description is not empty before processing
  • If the description is empty, we set $desc to an empty string
  • This prevents calling html_entity_decode() with a null value

@snehapatil02 commented on PR #6826:


4 months ago
#3

@mukeshpanchal27 Done with the suggested changes.

#4 @hellofromTonya
2 months ago

  • Focuses php-compatibility added
  • Keywords php81 added
  • Milestone changed from Awaiting Review to 6.7
  • Version changed from 6.6 to 2.8

The $item is an instance of SimplePie_Item. It's get_description() method returns a `string` on success, otherwise, it returns `null`.

Thus, yes, defensive logic is needed to avoid passing null to html_entity_decode(). Moving this ticket into 6.7.

Which version of WordPress introduced this issue?

wp_widget_rss_output() was introduced in 2.5.0. However, using SimplePie was introduced in 2.8.0 via [10666]. Changed the Version that introduced the code to 2.8.

Also marking this ticket as php-compatibility focus with php81 keyword to denote when the deprecation was introduced in PHP.

#5 @hellofromTonya
2 months ago

  • Owner set to hellofromTonya
  • Status changed from new to reviewing

Self-assigning to shepherd it forward and for committer review and commit.

This ticket was mentioned in Slack in #core by chaion07. View the logs.


4 weeks ago

#7 @peterwilsoncc
3 weeks ago

  • Milestone changed from 6.7 to 6.8

I've reviewed the linked pull request.

The same issue occurs with empty/missing titles and links so I think the patch needs a little more work to improve the handling of invalid and malformed feeds.

The test suite uses wordpress-org-news.xml to test well formed feeds, I think it needs a second file to test for edge cases for feeds that are not well formed.

As WordPress 6.7 is going in to the RC phase in a few days, I'm going to move this off the milestone for further work in the 6.8 release cycle.

Note: See TracTickets for help on using tickets.