page-template-example
page-template-example copied to clipboard
Update template on theme switch and on plugin update
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 );
@brasofilo thanks for sharing this. when I have more time, I'll revisit this and take a look for integration into the plugin (as well as the headers already sent message).
In the mean time, I'm going to leave this issue open.
Is this integrated?
@klihelp No.
Once I finish the initial rewrite, I'll come back to this and see if it's not something that can be easily and quickly incorporated.