Ipstenu / varnish-http-purge

Proxy Cache Purge
Apache License 2.0
46 stars 48 forks source link

BLOG_ID_CURRENT_SITE what does it mean? #21

Closed jerclarke closed 8 years ago

jerclarke commented 8 years ago

Hey, this one I'm not sure how to interpret, but we're getting a regular stream of notices on our non-subdomain multisite install. It dates back to the dark ages of WPMU when path-based multisite wasn't considered insane.

Here's the notice:

Notice: Use of undefined constant BLOG_ID_CURRENT_SITE - assumed 'BLOG_ID_CURRENT_SITE' in /SITE/wp-content/plugins/varnish-http-purge/varnish-http-purge.php on line 92

Here's the code:

if (...
            ( is_multisite() && !current_user_can('manage_network') && ( SUBDOMAIN_INSTALL || ( !SUBDOMAIN_INSTALL && ( BLOG_ID_CURRENT_SITE != $blog_id ) ) ) )
...)

The code assumes that based on the other conditions (!SUBDOMAIN_INSTALL), BLOG_ID_CURRENT_SITE will already be set, but in our case it clearly isn't. I tried looking up BLOG_ID_CURRENT_SITE but couldn't find anything useful.

My inclination is to submit a PR where we validate BLOG_ID_CURRENT_SITE before using it, but I don't know if that would significantly change the behavior of your plugin. Here's what I'd think is right:

$blog_id_current_site = null;
if (defined('BLOG_ID_CURRENT_SITE')) :
    $blog_id_current_site = BLOG_ID_CURRENT_SITE;
endif;

Above the if statement, then using $blog_id_current_site in the test. Does that make sense to you?

Ipstenu commented 8 years ago

BLOG_ID_CURRENT_SITE is used mostly with multi networks, but should exist even on some really old WPMU instances, if you've upgraded them to the modern era... How weird.

I think this would work:

$blog_id_current_site = 1;
if (defined('BLOG_ID_CURRENT_SITE')) {
    $blog_id_current_site = BLOG_ID_CURRENT_SITE;
}

Why the 1? Well, that's actually the default, and it's only if you've changed it would be different.

But have you updated this site? Is it on 4.6+

jerclarke commented 8 years ago

Okay. Well I'm willing to define it manually if you say that 1 is a safe default for single-network multisite :) Just wasn't sure and couldn't find any references. This particular WPMU has always been an odd duck.

It's on 4.5.3 still (upgrading everything after our big move to Ubuntu 16.04/php7). No idea if that would solve this issue but sounds like it goes back a lot farther.

Thanks for the feedback.