wordpress-seo icon indicating copy to clipboard operation
wordpress-seo copied to clipboard

Fatal Errors 500 - Need to check arrays

Open christopher-silvey opened this issue 10 years ago • 5 comments

What did you expect to happen?

My multisite to load.

What happened instead?

Crashed with 500 errors

How can we reproduce this behavior?

Maybe a multisite setup?

We run a multisite wp blog. I have noticed the sites go down a lot. After checking the logs I found this plugin to be the issue. Here are the fatal errors:

[15-Apr-2016 15:14:35 UTC] PHP Warning: Illegal string offset 'ms_defaults_set' in /home/xxx/public_html/wp-content/plugins/wordpress-seo/inc/options/class-wpseo-options.php on line 348
[15-Apr-2016 15:14:35 UTC] PHP Fatal error: Cannot unset string offsets in /home/xxx/public_html/wp-content/plugins/wordpress-seo/inc/class-upgrade.php on line 135

This is what I did to resolve them. I changed wordpress-seo/inc/options/class-wpseo-options.php on line 348 from:

        if ( is_multisite() ) {
            if($option['ms_defaults_set'] === false ) {
                self::reset_ms_blog( get_current_blog_id() );
                self::initialize();
                        }
            else if ( $force_init === true ) {
                self::initialize();
            }
        }

To:

        if ( is_multisite() ) {
            if ( is_array($option) && isset($option['ms_defaults_set']) ) {
                if($option['ms_defaults_set'] === false ) {
                    self::reset_ms_blog( get_current_blog_id() );
                    self::initialize();
                }
            }
            else if ( $force_init === true ) {
                self::initialize();
            }
        }

And then I changed wordpress-seo/inc/class-upgrade.php on line 135 from:

unset( $options['yoast_tracking'], $options['tracking_popup_done'] , $options['seen_about'], $options['ignore_tour']  );

To:

        if ( is_array($options) && isset($options['yoast_tracking']) ) {
            unset( $options['yoast_tracking'] );
        }
        if ( is_array($options) && isset($options['tracking_popup_done']) ) {
            unset( $options['tracking_popup_done'] );
        }
        if ( is_array($options) && isset($options['seen_about']) ) {
            unset( $options['seen_about'] );
        }
        if ( is_array($options) && isset($options['ignore_tour']) ) {
            unset( $options['ignore_tour'] );
        }

Technical info

  • WordPress version: 4.5
  • Yoast SEO version: 3.1.2

christopher-silvey avatar Apr 15 '16 15:04 christopher-silvey

Hmmm... I don't disagree with checks, but this is quite bizarre.

Why would get_option( 'wpseo' ) return string in your system?

Rarst avatar Apr 15 '16 15:04 Rarst

I'm not sure but in this case it did.

Thanks @Rarst

christopher-silvey avatar Apr 15 '16 16:04 christopher-silvey

Does the plugin even work at all? I mean if whole options are borked.

Rarst avatar Apr 15 '16 16:04 Rarst

Now that you mention it I can't save changes in the admin and I don't see the separator. Weird. I wonder what is causing that. I'll let you know if I discover what is causing that as it may be leading to the failures on this plugin.

Either way some pre-checks are probably still warranted.

Thanks!

christopher-silvey avatar Apr 15 '16 16:04 christopher-silvey

Had never seen another report for this and really can't think of normal operation scenario that will lead to string in settings. Closing as very edge case for now.

Rarst avatar Dec 26 '16 18:12 Rarst