Make WordPress Core

Opened 3 months ago

Last modified 4 weeks ago

#61179 new defect (bug)

Deprecated messages about passing null in widgets.php

Reported by: presskopp's profile Presskopp Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.6
Component: Widgets Keywords: has-patch has-unit-tests
Focuses: 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 (3)

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


6 weeks 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 weeks 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 weeks ago
#3

@mukeshpanchal27 Done with the suggested changes.

Note: See TracTickets for help on using tickets.