0

I keep getting these PHP error warnings.

Warning: Illegal string offset 'plugin_name' in /home/customer/www/website.com/public_html/wp-admin/includes/class-wp-privacy-policy-content.php on line 96

Warning: Illegal string offset 'policy_text' in /home/customer/www/website.com/public_html/wp-admin/includes/class-wp-privacy-policy-content.php on line 97

The code is as shown below:

foreach ( $old as $key => $data ) {
            if ( ! empty( $data['removed'] ) ) {
                unset( $old[ $key ] );
                continue;
            }

            $old[ $key ] = array(
                'plugin_name' => $data['plugin_name'],
                'policy_text' => $data['policy_text'],
            );
        }

How do i fix this? Thank you in advance!

Pudding
  • 3
  • 1

2 Answers2

0

My guess is that $data is in fact a string rather than an array. Accessing a string in the way that you do will result in 'Warning: Illegal string offset' in PHP versions prior to 8.0.0beta.

See this eval.

Ro Achterberg
  • 2,504
  • 2
  • 17
  • 17
0

This may be a bug in one of the WP plugin's that you've downloaded. Turn off one plugin in turn and see which stops the error appearing to find which WP Plugin is the cause. The issue looks like something is passing a non-array value into a $var that is intended to be an array.

As stated by Ro, it looks like the code is trying to process a string as an array. In this case there is an easy optout you can put into the code to ignore if it's not an array.

While this will solve your problem directly, I would HIGHLY RECOMMEND finding the source of the $data values and correcting the issue at source at that point (as stated, probably in a plugin).

foreach ( $old as $key => $data ) {

    if(!is_array($data)){
        continue; // if data is not an array then 
                  // carry on to the next iteration.
    }
    if ( ! empty( $data['removed'] ) ) {
            unset( $old[ $key ] );
            continue;
        }

        $old[ $key ] = array(
            'plugin_name' => $data['plugin_name'],
            'policy_text' => $data['policy_text'],
        );
    }
Martin
  • 22,212
  • 11
  • 70
  • 132