switch_theme

Definition:
function switch_theme($template, $stylesheet) {}

Switches current theme to new template and stylesheet names.

Parameters

  • string $template: Template name
  • string $stylesheet: Stylesheet name.

Defined actions

  • switch_theme
    do_action( 'switch_theme', $theme );

Source code

function switch_theme($template, $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 = get_current_theme();



	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));

	}



	delete_option('current_theme');

	$theme = get_current_theme();



	if ( is_admin() && false === get_option( "theme_mods_$stylesheet" ) ) {

		$default_theme_mods = (array) get_option( "mods_$theme" );

		add_option( "theme_mods_$stylesheet", $default_theme_mods );

	}



	update_option( 'theme_switched', $old_theme );

	do_action( 'switch_theme', $theme );

}

2923

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: