Dynamik notice in general.php on line 719

This notice is filling up my error log on one of my Dynamik sites:
Notice: Undefined offset: 1 in /home/xxx/public_html/wp-content/themes/dynamik-gen/lib/functions/general.php on line 719

Occurs about 3-4 times a day at random times. The site is running the latest version of WP/Genesis/Dynamik. Is it something that can be addressed/fixed or should I just ignore it?

Here's the code in question (I marked line 719):

// Browser specific classes
		if( preg_match( '/Chrome/', $browser ) )
		{
			$classes[] = 'chrome';
		}
		elseif( preg_match( '/Safari/', $browser ) )
		{
			$classes[] = 'safari';
	
			preg_match( '/Version\/(\d.\d)/si', $browser, $matches );
	
			if( isset( $matches[0] ) && isset( $matches[0][1] ) )
			  $sf_version = 'sf' . str_replace( '.', '-', $matches[1] );
			else
			  $sf_version = '';
	
			$classes[] = $sf_version;
		}
		elseif( preg_match( '/Opera/', $browser ) )
		{
			$classes[] = 'opera';
	
			preg_match( '/Opera\/(\d.\d)/si', $browser, $matches );
			/*line 719*/$op_version = 'op' . str_replace( '.', '-', $matches[1] );
			$classes[] = $op_version;
		}

Seems to relate to the Opera browser?

Thanks!
Sarah

Hey Sarah,

I believe I fixed the issue by tweaking the code, but it would be great if you could test it out and confirm that it works before I push it out in an update. I'll just post the entire Dynamik classes function below so you can simply replace your version of that function with the fixed one:

function dynamik_body_classes( $classes )
{
	if( !empty( $_SERVER['HTTP_USER_AGENT'] ) )
	{
		$browser = $_SERVER['HTTP_USER_AGENT'];
	
		// OS specific classes
		if( preg_match( '/Mac/', $browser ) )
			$classes[] = 'mac';
		elseif( preg_match( '/Windows/', $browser ) )
			$classes[] = 'windows';
		elseif( preg_match( '/Linux/', $browser ) )
			$classes[] = 'linux';
		else
			$classes[] = 'unknown-os';
	
		// Browser specific classes
		if( preg_match( '/Chrome/', $browser ) )
		{
			$classes[] = 'chrome';
		}
		elseif( preg_match( '/Safari/', $browser ) )
		{
			$classes[] = 'safari';
	
			preg_match( '/Version\/(\d.\d)/si', $browser, $matches );
	
			if( isset( $matches[0] ) && isset( $matches[0][1] ) )
			  $sf_version = 'sf' . str_replace( '.', '-', $matches[1] );
			else
			  $sf_version = '';
	
			$classes[] = $sf_version;
		}
		elseif( preg_match( '/Opera/', $browser ) )
		{
			$classes[] = 'opera';
	
			preg_match( '/Opera\/(\d.\d)/si', $browser, $matches );

			if( isset( $matches[0] ) && isset( $matches[0][1] ) )
			  $op_version = 'op' . str_replace( '.', '-', $matches[1] );
			else
			  $op_version = '';

			$classes[] = $op_version;
		}
		elseif( preg_match( '/MSIE/', $browser ) )
		{
			$classes[] = 'msie';
	
			if( preg_match( '/MSIE 6.0/', $browser ) )
					$classes[] = 'ie6';
			elseif( preg_match( '/MSIE 7.0/', $browser ) )
					$classes[] = 'ie7';
			elseif( preg_match( '/MSIE 8.0/', $browser ) )
					$classes[] = 'ie8';
			elseif( preg_match( '/MSIE 9.0/', $browser ) )
					$classes[] = 'ie9';
			elseif( preg_match( '/MSIE 10.0/', $browser ) )
					$classes[] = 'ie10';
		}
		elseif( '!!navigator.userAgent.match(/Trident.*rv\:11\./)' )
		{
			$classes[] = 'ie11';
		}
		elseif( preg_match( '/Firefox/', $browser ) && preg_match( '/Gecko/', $browser ) )
		{
			$classes[] = 'firefox';
	
			preg_match( '/Firefox\/(\d)/si', $browser, $matches );

			if( isset( $matches[0] ) && isset( $matches[0][1] ) )
			  $ff_version = 'ff' . str_replace( '.', '-', $matches[1] );
			else
			  $ff_version = '';

			$classes[] = $ff_version;
		}
		else
		{
			$classes[] = 'unknown-browser';
		}
	}

	if( is_front_page() && dynamik_get_design_alt( 'ez_home_slider_display' ) )
	{
		$classes[] = 'ez-home-slider';

		if( dynamik_get_design_alt( 'ez_home_slider_location' ) == 'inside' )
		{
			$classes[] = 'slider-inside';
		}
	}

	if( is_front_page() && dynamik_get_design_alt( 'dynamik_homepage_type' ) == 'static_home' &&
		dynamik_get_design_alt( 'ez_homepage_select' ) )
	{
		$classes[] = 'ez-home';

		if( dynamik_get_design_alt( 'ez_static_home_sb_display' ) )
		{
			$classes[] = 'ez-home-sidebar';
		}

		if( dynamik_get_design_alt( 'ez_static_home_sb_location' ) == 'left' )
		{
			$classes[] = 'home-sidebar-left';
		}
	}

	if( dynamik_get_design_alt( 'ez_feature_top_position' ) == 'outside_inner' )
		$classes[] = 'feature-top-outside';

	if( dynamik_get_design_alt( 'ez_fat_footer_position' ) == 'inside_inner' )
		$classes[] = 'fat-footer-inside';

	if( dynamik_get_design_alt( 'wrap_structure' ) == 'fluid' )
		$classes[] = 'site-fluid';

	if( is_singular() && dynamik_get_custom_field( '_dyn_labels', false, true ) != '' )
	{
		foreach ( dynamik_get_custom_field( '_dyn_labels', false, true ) as $key => $value )
		{
			$classes[] = 'label-' . $key;
		}
	}

	if( defined( 'DYNAMIK_LABEL_WIDTH' ) )
		$classes[] = DYNAMIK_LABEL_WIDTH;

	$classes[] = 'override';

	return $classes;
}

Thanks, Eric! I've replaced the code and will keep an eye on the error log over the next few days to see if the issue is resolved. I'll post back soon.

Sounds good. 🙂

Almost a week now and no more error! I think your fix did the job. Thanks!!

I just noticed that a notice I'm getting on my sites running Genesis Extender (Notice: Undefined offset: 1 in /home/SITE/public_html/wp-content/plugins/genesis-extender/lib/functions/general.php on line 55) corresponds to the exact same "Browser specific classes" code.

Should your fix for Dynamik also work for Extender?

Log in to reply