help to fix Warning: Invalid argument supplied for foreach() in

Hi,
i get Warning in the next code, so it would be great to get some help to fix this Warning.
the Warning is:
Warning: Invalid argument supplied for foreach() in public_html/wp-admin/includes/plugin.php on line 1401

the code is:

$theme = wp_get_theme();
if ('Twenty Fourteen' == $theme->name) {
function remove_custom_menu_page() {
global $submenu;
unset($submenu['themes.php'][6]);
  }
	add_action( 'admin_menu', 'remove_custom_menu_page' );

the problem come from this line:

$theme = wp_get_theme();
if ('Twenty Fourteen' == $theme->name) {