Sprache wechseln
wpseek auf Twitter


Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren




switch_theme [ ]

switch_theme ( $stylesheet )
Parameter:
  • (string) $stylesheet Stylesheet name
Nutzt:
Definiert in:
Codex



Switches the theme.

Accepts one argument: $stylesheet of the theme. It also accepts an additional function signature of two arguments: $template then $stylesheet. This is for backwards compatibility.

Quellcode

function switch_theme( $stylesheet ) {
	global $wp_theme_directories, $sidebars_widgets;

	if ( is_array( $sidebars_widgets ) )
		set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $sidebars_widgets ) );

	$old_theme  = wp_get_theme();
	$new_theme = wp_get_theme( $stylesheet );

	if ( func_num_args() > 1 ) {
		$template = $stylesheet;
		$stylesheet = func_get_arg( 1 );
	} else {
		$template = $new_theme->get_template();
	}

	update_option( 'template', $template );
	update_option( 'stylesheet', $stylesheet );

	if ( count( $wp_theme_directories ) > 1 ) {
		update_option( 'template_root', get_raw_theme_root( $template, true ) );
		update_option( 'stylesheet_root', get_raw_theme_root( $stylesheet, true ) );
	} else {
		delete_option( 'template_root' );
		delete_option( 'stylesheet_root' );
	}

	$new_name  = $new_theme->get('Name');

	update_option( 'current_theme', $new_name );

	if ( is_admin() && false === get_option( 'theme_mods_' . $stylesheet ) ) {
		$default_theme_mods = (array) get_option( 'mods_' . $new_name );
		add_option( "theme_mods_$stylesheet", $default_theme_mods );
	}

	update_option( 'theme_switched', $old_theme->get_stylesheet() );
	do_action( 'switch_theme', $new_name, $new_theme );
}

Beispiele [ wp-snippets.com ]

Top Google Suchergebnisse

Mehr ...

0 Nutzerkommentare

Noch keine. Sei der Erste!

Neu hinzufügen ...