5
votes

I got this fatal error when I updated wordpress to Newest today. I use Barely Corporate theme. Line 126 is the last line in the code. Have anyone an Idea what this is? The theme do have a Responsive design.

http://themeforest.net/item/barely-corporate-responsive-wordpress-theme/93069?WT.ac=search_item&WT.seg_1=search_item&WT.z_author=ThemeBlvd

Fatal error: Cannot redeclare wp_is_mobile() (previously declared in /home/chilinbk/public_html/kunde/tkh/wp-includes/vars.php:107) in /home/chilinbk/public_html/kunde/tkh/wp-includes/vars.php on line 126

if ( isset($is_mobile) )
    return $is_mobile;

if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
    $is_mobile = false;
} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
    || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
    || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
    || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
    || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
    || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false ) {
        $is_mobile = true;
} else {
    $is_mobile = false;
}

return $is_mobile;

}

4

4 Answers

4
votes

Got it!

In wp-content\plugins\sitepress-multilingual-cms\sitepress.php, there is the following lines

if ( function_exists('is_multisite') && is_multisite() ) {
    include_once( ABSPATH . WPINC . '/vars.php' );
}

This lines include the file /wp-includes/vars.php where the function wp_is_mobile() is declared. Then WordPress include this vars.php file again and produce an logical error.

Before WP 3.4 release there was no visible problem as there was no functions into vars.php. But now there is.

I think wpml doesn't need to include this file as it's already include by WordPress.

So a bypass can be : Comment lines 21-24 in "wp-content\plugins\sitepress-multilingual-cms\sitepress.php"

Hope WPML can fix it more proprely in next plugin release.

2
votes

Not being able to see the code of your theme, I'm guessing your functions.php includes a function declaration like this:

function wp_is_mobile() {
   // ... the code
}

So what you're going to need to do is wrap that function, like this:

if (function_exists('wp_is_mobile')) {
    function wp_is_mobile() {
       // ... the code
    }
}

Either that or simply rip out the duplicate in the theme and use the version in 3.4.

I would guess your theme provider will update that theme, that kind of conflict is nasty. This is why theme developers are encourages to prefix their functions with something unique. Prefix everything.

1
votes

it might not be the theme. in my case was the WPML plugin, but the function wrapping did the job even if modifying core WP file is not ideal...

thanks for the suggestion above though!

1
votes

I had the same problem once I installed the WPML plugin 2.5.1 on WP 3.4 so I wrapped the function and that got rid of that error, then I got another error.

Fatal error: Call to undefined function wp_is_mobile() in /home/MY_USERNAME/public_html/wp-includes/theme.php on line 1606

I don't know what to do next?

--------found a work around---------

As long as you don't network activate the WPML plugins as super admin on the WP multisite install then I don't get the error. Activate them independently.

Would still be nice if network activate could work. WPML says it's multisite compatible: http://wpml.org/documentation/support/multisite-support/