Site logo

Archived topic

PHP 8 warning for FILTER_SANITIZE_STRING

4 replies · Started by roadlink on November 24, 2022

Viewing posts 1–5 of 5

Hi there,

I have like thousands of lines in error.log file about this function.

PHP Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /wordpress/mu-plugins/atomic-platform.php on line 559

I have checked with hosting and they told me that it is related with my theme.
I have searched for FILTER_SANITIZE_STRING in theme files and find below results.

generatepress\inc\meta-box.php (4 hits)
	Line 231: 	$sidebar_layout_value = filter_input( INPUT_POST, $sidebar_layout_key, FILTER_SANITIZE_STRING );
	Line 240: 	$footer_widget_value = filter_input( INPUT_POST, $footer_widget_key, FILTER_SANITIZE_STRING );
	Line 250: 	$page_builder_container_value = filter_input( INPUT_POST, $page_builder_container_key, FILTER_SANITIZE_STRING );
	Line 261: 	$disable_content_title_value = filter_input( INPUT_POST, $disable_content_title_key, FILTER_SANITIZE_STRING );

here are some search results about this.
https://stackoverflow.com/questions/69207368/constant-filter-sanitize-string-is-deprecated
https://laxmariappan.com/filter_sanitize_string-is-deprecated-what-to-use-instead/

Another plugin solved it like below according to their comment.

/*
     * Replacer for FILTER_SANITIZE_STRING deprecated with PHP 8.1
     */
    public static function filter_string_polyfill(string $string): string {
        
        $str = preg_replace('/\x00|<[^>]*>?/', '', $string);
        return str_replace(["'", '"'], [''', '"'], $str);
        
    }
    // end of filter_string_polyfill()

Hi Leo,

Yes both GP and GPP are latest versions.

FILTER_SANITIZE_STRING is deprecated and this file still has it. generatepress\inc\meta-box.php

I don't see any point to disable others plugins and check again.

Hi there,

thanks for reporting that we will take a look at getting that replaced.

This archived topic is closed to new replies.