Apprezziamo il tuo aiuto nel condividere le nostre sezioni sull'informatica.
Cambia il tema.
Descrizione
Accetta un argomento: $stylesheet del tema. Accetta anche una firma di funzione aggiuntiva di due argomenti: $template e $stylesheet. Questo è per la compatibilità con il passato.
Parametri
- $stylesheet
-
(stringa)(Richiesto)Nome del foglio di stile.
Fonte
File: wp-includes/theme.php
functionswitch_theme($stylesheet){global$wp_theme_directories,$wp_customize,$sidebars_widgets;$requirements=validate_theme_requirements($stylesheet);if(is_wp_error($requirements)){wp_die($requirements);}$_sidebars_widgets=null;if('wp_ajax_customize_save'===current_action()){$old_sidebars_widgets_data_setting=$wp_customize->get_setting('old_sidebars_widgets_data');if($old_sidebars_widgets_data_setting){$_sidebars_widgets=$wp_customize->post_value($old_sidebars_widgets_data_setting);}}elseif(is_array($sidebars_widgets)){$_sidebars_widgets=$sidebars_widgets;}if(is_array($_sidebars_widgets)){set_theme_mod('sidebars_widgets',array('time'=>time(),'data'=>$_sidebars_widgets,));}$nav_menu_locations=get_theme_mod('nav_menu_locations');update_option('theme_switch_menu_locations',$nav_menu_locations);if(func_num_args()>1){$stylesheet=func_get_arg(1);}$old_theme=wp_get_theme();$new_theme=wp_get_theme($stylesheet);$template=$new_theme->get_template();if(wp_is_recovery_mode()){$paused_themes=wp_paused_themes();$paused_themes->delete($old_theme->get_stylesheet());$paused_themes->delete($old_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);// Migrate from the old mods_{name} option to theme_mods_{slug}.if(is_admin()&&false===get_option('theme_mods_'$stylesheet)){$default_theme_mods=(array)get_option('mods_'$new_name);if(!empty($nav_menu_locations)&&empty($default_theme_mods['nav_menu_locations'])){$default_theme_mods['nav_menu_locations']=$nav_menu_locations;}add_option("theme_mods_$stylesheet",$default_theme_mods);}else{/* * Since retrieve_widgets() is called when initializing a theme in the Customizer, * we need to remove the theme mods to avoid overwriting changes made via * the Customizer when accessing wp-admin/widgets.php. */if('wp_ajax_customize_save'===current_action()){remove_theme_mod('sidebars_widgets');}}update_option('theme_switched',$old_theme->get_stylesheet());/** * Fires after the theme is switched. * * @since 1.5.0 * @since 4.5.0 Introduced the `$old_theme` parameter. * * @param string $new_name Name of the new theme. * @param WP_Theme $new_theme WP_Theme instance of the new theme. * @param WP_Theme $old_theme WP_Theme instance of the old theme. */do_action('switch_theme',$new_name,$new_theme,$old_theme);}
Correlato
Utilizzi
Usi | Descrizione |
---|---|
wp-includes/theme.php: validate_theme_requirements() |
Convalida i requisiti del tema per la versione di WordPress e la versione di PHP. |
wp-includes/load.php: wp_is_recovery_mode() |
WordPress è in modalità di recupero. |
wp-includes/error-protection.php: wp_paused_themes() |
Ottenere l'istanza per memorizzare le estensioni in pausa. |
wp-includes/theme.php: set_theme_mod() |
Aggiorna il valore di modifica del tema per il tema corrente. |
wp-includes/theme.php: remove_theme_mod() |
Rimuove il nome della modifica del tema dall'elenco dei temi correnti. |
wp-includes/theme.php: get_theme_mod() |
Recupera il valore di modifica del tema per il tema corrente. |
wp-includes/theme.php: get_raw_theme_root() |
Ottiene la radice grezza del tema relativa alla cartella dei contenuti, senza filtri applicati. |
wp-includes/theme.php: switch_theme |
Si attiva dopo che il tema è stato cambiato. |
wp-includes/theme.php: wp_get_theme() |
Ottiene un oggetto WP_Theme per un tema. |
wp-includes/load.php: is_admin() |
Determina se la richiesta corrente è per una pagina di interfaccia amministrativa. |
wp-includes/functions.php: wp_die() |
Uccide l'esecuzione di WordPress e visualizza una pagina HTML con un messaggio di errore. |
wp-includes/plugin.php: current_action() |
Recupera il nome dell'azione corrente. |
wp-includes/plugin.php: do_action() |
Esegue le funzioni agganciate a un gancio di azione specifico. |
wp-includes/option.php: update_option() |
Aggiorna il valore di un'opzione già aggiunta. |
wp-includes/option.php: delete_option() |
Rimuove l'opzione per nome. Impedisce la rimozione delle opzioni protette di WordPress. |
wp-includes/option.php: add_option() |
Aggiunge una nuova opzione. |
wp-includes/option.php: get_option() |
Recupera il valore di un'opzione in base al suo nome. |
wp-includes/load.php: is_wp_error() |
Controlla se la variabile data è un errore di WordPress. |
Utilizzato da
Usato da | Descrizione |
---|---|
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::save_changeset_post() |
Salva il post per il changeset caricato. |
wp-admin/includes/class-theme-upgrader.php: Theme_Upgrader::current_after() |
Disattiva la modalità di manutenzione dopo l'aggiornamento del tema corrente. |
wp-includes/theme.php: validate_current_theme() |
Controlla che il tema corrente abbia i file 'index.php' e 'style.css'. |
Changelog
Versione | Descrizione |
---|---|
2.5.0 | Introdotto. |
Puoi aggiungere valore ai nostri contenuti informativi rendendo omaggio alla tua esperienza nelle note.