WordPress.org

Make WordPress Core

Ticket #7795: 7795.diff

File 7795.diff, 3.9 KB (added by DD32, 10 years ago)
  • wp-admin/themes.php

     
    1212if ( isset($_GET['action']) ) {
    1313        check_admin_referer('switch-theme_' . $_GET['template']);
    1414
    15         if ('activate' == $_GET['action']) {
    16                 switch_theme($_GET['template'], $_GET['stylesheet']);
     15        if ( 'activate' == $_GET['action'] ) {
     16                wp_redirect( add_query_arg('action', 'theme_activation') );
     17                switch_theme($_GET['template'], $_GET['stylesheet']); //Also runs the deactivation functions.
     18                exit;
     19        } else if ( 'theme_activation' == $_GET['action'] ) {
    1720                wp_redirect('themes.php?activated=true');
     21                run_theme_activation_hook($_GET['template'], $_GET['stylesheet']);
    1822                exit;
    1923        }
    2024}
  • wp-includes/theme.php

     
    914914/**
    915915 * Switches current theme to new template and stylesheet names.
    916916 *
     917 * Also runs the theme Deactivation hooks, See run_theme_deactivation_hook()
     918 *
    917919 * @since unknown
    918920 * @uses do_action() Calls 'switch_theme' action on updated theme display name.
    919921 *
     
    921923 * @param string $stylesheet Stylesheet name.
    922924 */
    923925function switch_theme($template, $stylesheet) {
     926
     927        $current_template = get_template();
     928        $current_stylsheet = get_stylesheet();
     929
    924930        update_option('template', $template);
    925931        update_option('stylesheet', $stylesheet);
    926932        delete_option('current_theme');
    927933        $theme = get_current_theme();
     934
     935        run_theme_deactivation_hook($current_template, $current_stylesheet);
     936
    928937        do_action('switch_theme', $theme);
    929938}
    930939
    931940/**
     941 * Runs the activation hooks for a newly activated theme
     942 *
     943 * @since unknown
     944 * @uses do_action() Calls 'activate_theme-{theme-slug}' action on template and stylesheet
     945 *
     946 * @param string $template Template name
     947 * @param string $stylesheet Stylesheet name
     948 */
     949function run_theme_activation_hook($template, $stylesheet) {
     950        if ( $stylesheet != $template )
     951                do_action('activate_theme-' . $stylesheet);
     952        do_action('activate_theme-' . $template);
     953}
     954
     955/**
     956 * Runs the deactivation hooks for a disabled theme
     957 *
     958 * @since unknown
     959 * @uses do_action() Calls 'activate_theme-{theme-slug}' action on template and stylesheet
     960 *
     961 * @param string $template Template name
     962 * @param string $stylesheet Stylesheet name
     963 */
     964function run_theme_deactivation_hook($template, $stylesheet) {
     965        if ( $template != $stylesheet )         
     966                do_action('deactivate_theme-' . $stylesheet);
     967        do_action('deactivate_theme-' . $template);
     968}
     969
     970/**
     971 * Set the activation hook for a theme.
     972 *
     973 * Warning: Must be called from a file directly within the themes root folder, not a subdir
     974 *
     975 * @since 2.7
     976 *
     977 * @param string $file Filename of a file inside the themes folder
     978 * @param string $function The Activation callback
     979 */
     980function register_theme_activation_hook($file, $function) {
     981        $file = str_replace('\\', '/', $file); //Win32 => unix
     982        $theme = preg_replace('|^.*/|', '', dirname($file)); //greedy replace until final folder remainss
     983       
     984        add_action('activate_theme-' . $theme, $function);
     985}
     986
     987/**
     988 * Set the deactivation hook for a theme.
     989 *
     990 * Warning: Must be called from a file directly within the themes root folder, not a subdir
     991 *
     992 * @since 2.7
     993 *
     994 * @param string $file Filename of a file inside the themes folder
     995 * @param string $function The Activation callback
     996 */
     997function register_theme_deactivation_hook($file, $function) {
     998        $file = str_replace('\\', '/', $file); //Win32 => unix
     999        $theme = preg_replace('|^.*/|', '', dirname($file)); //greedy replace until final folder remainss
     1000        add_action('deactivate_theme-' . $theme, $function);
     1001}
     1002
     1003/**
    9321004 * Checks that current theme files 'index.php' and 'style.css' exists.
    9331005 *
    9341006 * Does not check the 'default' theme. The 'default' theme should always exist