Skip to content
This repository was archived by the owner on Sep 13, 2019. It is now read-only.

Update template on theme switch and on plugin update #4

@brasofilo

Description

@brasofilo

My intention was to make a pull request, but I'm having issues with my fork triggering headers already sent on activation.

I gave up, deleted the fork, and will leave the tips here. Curiously, I used your technique in a plugin of mine without any glitches...

Here's how I used it:

Theme switch

public function switching_theme( $new_name, $new_theme )
{
    $old_theme = get_option( 'theme_switched' );

    $template_path_app = get_theme_root( $old_theme ) . "/$old_theme/template-example.php";    
    if( file_exists( $template_path_app ) )
        unlink( $template_path_app );

    $this->register_project_template();
}
add_action( 'switch_theme', array( $this, 'switching_theme' ), 10, 2 );

Plugin update
In case our plugin is updatable via some repo.

// In the constructor
$this->plugin_slug   = plugin_basename( __FILE__ );

public function refresh_template(  $true, $hook_extra, $result ) {

    if( isset( $hook_extra['plugin'] ) &&  $hook_extra['plugin'] == $this->plugin_slug  ) {

        $this->register_project_template();
        $this->deregister_project_template();

    }

    return $true; 
} 
add_filter( 'upgrader_post_install', array( $this, 'refresh_template' ), 10, 3 );

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions