Skip to content

PHP Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated #863

@renatonascalves

Description

@renatonascalves

Description

Currently, if one does not set a default_value field, it defaults to null, and a site returns this following PHP deprecation error.


[27-Jan-2024 18:07:59 UTC] PHP Deprecated:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/site/wp-includes/formatting.php on line 4715

The issue happens here:

Which calls https://github.com/WordPress/wordpress-develop/blob/94e6fe9f8ad05571d810c4a7fc2afdeeea1c0fee/src/wp-includes/formatting.php#L4732

Use Case

A site with fields that extend Fieldmanager_Field:


add_action( 'fm_post_post', function() {
	$fm_title = new Fieldmanager_Textarea(
		[
			'name' => 'newsletter_excerpt',
			'description' => __( 'Excerpt to be included in json feed for use in newsletters', 'example-site' ),
		]
	);
	$fm_title->add_meta_box( __( 'Newsletter Excerpt', 'example-site' ), $post_types, 'normal', 'high' );
} );

Acceptance Criteria

  • Modify the logic that prints the field in WP admin so that if a default value is not set, and it returns null, then esc_textarea does not receive a value of null (either use a ternary to print an empty string, or pass an empty string to esc_textarea - do not modify the default value generally, since that could have other effects elsewhere that we want to avoid).

Metadata

Metadata

Labels

enhancementNew feature or requestphpRequires understanding PHP

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions