Why is ‘is_multisite’ returning true when it’s a single install?

I’ve installed a single site WP. In one of my plugins, I have the following code:

if(is_multisite) {
  $upload_dir = get_upload_dir();
  $_SESSION['root_image_dir'] =  str_replace('\\',"https://wordpress.stackexchange.com/",$upload_dir['basedir']);
  echo 'IS MULTI.'; //<-- this is outputted every time
} else {
  $_SESSION['root_image_dir'] = '';
  echo 'IS NOT MULTI'.$_SESSION['root_image_dir'];
} 

For some reason, the echo statement is triggered every time.

Why is is_multisite not working?.

1 Answer
1

If that’s the code you have in your plugin, you’re writing it wrong. You have if(is_multisite) which is treating the string is_multisite as a constant and evalutation to true. Essentially you’re writing if(true) ...

Remember, is_multisite() is a function. You need the parenthesis at the end for PHP to actually evaluate the function. Change your code to the following:

if( is_multisite() ) {
    $upload_dir = get_upload_dir();
    $_SESSION['root_image_dir'] =  str_replace('\\',"https://wordpress.stackexchange.com/",$upload_dir['basedir']);
    echo 'IS MULTI.'; //<-- this is outputted every time
} else {
    $_SESSION['root_image_dir'] = '';
    echo 'IS NOT MULTI'.$_SESSION['root_image_dir'];
} 

Leave a Comment