check_theme_switched

Checks if a theme has been changed and runs 'after_switch_theme' hook on the next WP load.

Description

check_theme_switched(); 

See .


Usage

  1. if ( !function_exists( 'check_theme_switched' ) ) { 
  2. require_once ABSPATH . WPINC . '/theme.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = check_theme_switched(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/theme.php  
  1. function check_theme_switched() { 
  2. if ( $stylesheet = get_option( 'theme_switched' ) ) { 
  3. $old_theme = wp_get_theme( $stylesheet ); 
  4.  
  5. // Prevent retrieve_widgets() from running since Customizer already called it up front 
  6. if ( get_option( 'theme_switched_via_customizer' ) ) { 
  7. update_option( 'theme_switched_via_customizer', false ); 
  8.  
  9. if ( $old_theme->exists() ) { 
  10. /** 
  11. * Fires on the first WP load after a theme switch if the old theme still exists. 
  12. * This action fires multiple times and the parameters differs 
  13. * according to the context, if the old theme exists or not. 
  14. * If the old theme is missing, the parameter will be the slug 
  15. * of the old theme. 
  16. * @since 3.3.0 
  17. * @param string $old_name Old theme name. 
  18. * @param WP_Theme $old_theme WP_Theme instance of the old theme. 
  19. */ 
  20. do_action( 'after_switch_theme', $old_theme->get( 'Name' ), $old_theme ); 
  21. } else { 
  22. /** This action is documented in wp-includes/theme.php */ 
  23. do_action( 'after_switch_theme', $stylesheet ); 
  24.  
  25. update_option( 'theme_switched', false );