Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: Cannot redeclare wp_is_mobile()

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;

}

like image 467
andrrs Avatar asked Jun 15 '12 06:06

andrrs


2 Answers

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.

like image 109
Paul PAYEN Avatar answered Oct 27 '22 10:10

Paul PAYEN


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.

like image 37
artlung Avatar answered Oct 27 '22 11:10

artlung