Make WordPress Core

Opened 5 weeks ago

Last modified 34 hours 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: trunk
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 (1)

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


34 hours 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.
Note: See TracTickets for help on using tickets.