Showing this error msg after upgrading to php 8.1 in wordpress
Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /public_html/wp-includes/functions.wp-styles.php on line 90
Here is the function which i found in the functions.wp-styles.php
function wp_add_inline_style( $handle, $data ) {
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
if ( false !== stripos( $data, '</style>' ) ) {
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: 1: <style>, 2: wp_add_inline_style() */
__( 'Do not pass %1$s tags to %2$s.' ),
'<code><style></code>',
'<code>wp_add_inline_style()</code>'
),
'3.7.0'
);
$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) );
}
return wp_styles()->add_inline_style( $handle, $data );
}
Here is the 90 number line inside this code which causes the error,
if ( false !== stripos( $data, '</style>' ) ) {
I upgraded to php 8.1 and then i got this error message, i want to solve this problem.
2
Answers
It means that
$data
isnull
and you cannot passnull
to string methods since 8.1.You should investigate why
$data
isnull
first, and fix that as this may be alluding you to a real issue.However, if you’re after a quick-fix you can just change:
to
This will ensure that a string is always provided as the first parameter, even if
$data
isnull
or unset.This is a WordPress core problem. For best results use php 8.0 or earlier with WordPress, or turn off WP_DEBUG.
Your site works fine with deprecation notices, they are just a nuisance.
Avoid changing core code on your site if possible.
In the core team, work to eliminate php 8.x deprecation notices is ongoing. Read this.