How to display message (with switch_theme hook) after deactivating My theme?

I’m able to display a message by activation of my theme with the ‘new’ after_switch_theme hook this way:

function themeActivationFunction($oldname, $oldtheme=false) {
$msg = '
    <div class="error">
        <p>The ' . get_option( 'current_theme' ) . ' theme has been ACTIVATED.</p>
    </div>';
    add_action( 'admin_notices', $c = create_function( '', 'echo "' . addcslashes( $msg, '"' ) . '";' ) );

}
add_action("after_switch_theme", "themeActivationFunction", 10 ,  2);

But it does not work with the swith_theme hook for deactivation of my theme. I think because by switching the theme to another one to default WordPress message overwrites my message stucking in the theme that gets deactivated and the reload of the screen deletes everything.

Read More
function themeDeactivationFunction($theme) {
// Lets let the admin know whats going on.
        $msg = '
    <div class="error">
        <p>Your theme has been DEACTIVATED</p>
    </div>';
    add_action( 'admin_notices', $c = create_function( '', 'echo "' . addcslashes( $msg, '"' ) . '";' ) );
}
add_action("switch_theme", "themeDeactivationFunction", 10 , 2);

I’m looking for a ‘work around’ to notify a user about deactivating my theme and the setup routine after it.

Related posts

Leave a Reply

1 comment

  1. It’s impossible, because after deactivation your theme isn’t even loaded!

    It’s possible, but hacky. Essentially, we unset the action param, load in the themes admin page & then exit before the redirect-on-success occurs.

    add_action( 'switch_theme', 'wpse_60972_theme_deactivate_message' );
    function wpse_60972_theme_deactivate_message()
    {
        $msg = '
        <div class="error">
            <p>Your theme has been DEACTIVATED</p>
        </div>';
    
        add_action( 'admin_notices', create_function( '', 'echo "' . addcslashes( $msg, '"' ) . '";' ) );
    
        unset( $_GET['action'] );
        require ABSPATH . 'wp-admin/themes.php';
        exit;
    }
    

    If the code you posted is verbatim, may I ask why you want do as such? WordPress has it’s own notices for activation & deactivation.