Last active
January 10, 2025 03:58
Revisions
-
justintadlock revised this gist
Jan 16, 2024 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,9 +36,6 @@ } ); // Filter the default template types, adding your own. add_filter( 'default_template_types', function( $templates ) { return array_merge( $templates, [ 'changelog' => [ -
justintadlock revised this gist
Jan 16, 2024 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,4 @@ <?php // This filter specifically checks whether a theme has a `changelog` template. // If not, it looks for a fallback template in the plugin. -
justintadlock revised this gist
Jan 16, 2024 . 1 changed file with 9 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,14 @@ # Bootstrap the theme. add_action( 'after_setup_theme', __NAMESPACE__ . '\\theme', PHP_INT_MIN ); // This filter specifically checks whether a theme has a `changelog` template. // If not, it looks for a fallback template in the plugin. add_filter( 'template_include', function( $template ) { // I'm just testing a query string here for demonstration/testing // purposes, but you'll want to add a check for your registered query // var with WordPress. For now, you can test with `?changelog=anything`. if ( ! isset( $_GET['changelog'] ) ) { return $template; } -
justintadlock created this gist
Jan 15, 2024 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ <?php // This is specifically looking for a "changelog" template type add_filter( 'template_include', function( $template ) { // Probably want to check a query var here. if ( ! isset( $GLOBALS['changelog'] ) ) { return $template; } // Custom hierarchy of templates. $templates = [ 'changelog.php', 'index.php' ]; // First, search for PHP templates, which block themes can also use. $template = locate_template( $templates ); // Pass the result into the block template locator and let it figure // out whether block templates are supported and this template exists. $template = locate_block_template( $template, 'changelog', $templates ); // If the template is found, use it. Otherwise, fall back to the plugin // template. It's worth noting that the wrapping block template markup // and block processing wouldn't be available to the plugin template. // The plugin would have to handle all of this on its end and probably // add a few actions/filters that WP would normally add. // // I'd recommend digging through `wp-includes/template-canvas.php` and // the `locate_block_template()` function for building this fallback. return $template ?: '/path/to/plugin/fallback-template.php'; } ); // Filter the default template types, adding your own. // // Note: I did run into some trouble adding custom types at some point in the // past, but I could never figure out why. This seems to work on 6.5/trunk. add_filter( 'default_template_types', function( $templates ) { return array_merge( $templates, [ 'changelog' => [ 'title' => 'Changelog', 'description' => 'A custom changelog template.' ] ] ); } );