関数 switch_theme()
2014/12/17
関数 switch_theme()
定義ファイル :/blog/wp-includes/theme.php 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | function switch_theme( $stylesheet ) { global $wp_theme_directories, $wp_customize, $sidebars_widgets; $_sidebars_widgets = null; if ( 'wp_ajax_customize_save' === current_action() ) { $_sidebars_widgets = $wp_customize->post_value( $wp_customize->get_setting( 'old_sidebars_widgets_data' ) ); } 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 ) ); } $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 ); // 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 ); add_option( "theme_mods_$stylesheet", $default_theme_mods ); } else { if ( 'wp_ajax_customize_save' === current_action() ) { remove_theme_mod( 'sidebars_widgets' ); } } update_option( 'theme_switched', $old_theme->get_stylesheet() ); do_action( 'switch_theme', $new_name, $new_theme ); } |