Replace deprecated utf8_encode() in the CSV importer for PHP 8.2#485
Open
thisismyurl wants to merge 1 commit into
Open
Replace deprecated utf8_encode() in the CSV importer for PHP 8.2#485thisismyurl wants to merge 1 commit into
thisismyurl wants to merge 1 commit into
Conversation
utf8_encode() is deprecated as of PHP 8.2 and fires a deprecation notice on the CSV import path when the source encoding is not UTF-8. mb_convert_encoding( $data, 'UTF-8', 'ISO-8859-1' ) is the documented one-to-one replacement (utf8_encode is defined as ISO-8859-1 to UTF-8), so the converted output is unchanged.
There was a problem hiding this comment.
Pull request overview
Updates the SportsPress admin CSV importer to avoid PHP 8.2 deprecation notices by replacing the deprecated utf8_encode() call in the CSV data formatting path.
Changes:
- Replace
utf8_encode()withmb_convert_encoding()for ISO-8859-1 → UTF-8 conversion informat_data_from_csv().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
229
to
231
| function format_data_from_csv( $data, $enc ) { | ||
| return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data ); | ||
| return ( $enc == 'UTF-8' ) ? $data : mb_convert_encoding( $data, 'UTF-8', 'ISO-8859-1' ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PHP 8.2 housekeeping for the CSV importer.
format_data_from_csv()callsutf8_encode(), which is deprecated as of PHP 8.2 and throws a deprecation notice on that import path when the source encoding isn't UTF-8.mb_convert_encoding( $data, 'UTF-8', 'ISO-8859-1' )is the documented one-to-one replacement (utf8_encode()is defined as exactly an ISO-8859-1 to UTF-8 conversion), so the converted bytes are identical. mbstring is effectively always present in a WordPress environment.Thanks for keeping SportsPress going. It's an impressively deep plugin to maintain.
(full disclosure: AI helped me trace this and confirm the equivalence; the change and this note are mine.)