Last active
August 29, 2015 14:22
-
-
Save ginsterbusch/72f5dedfd115501f689b to your computer and use it in GitHub Desktop.
Example of how to implement separate customizable templates for plugins (similar to how eg. WooCommerce uses them)
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 characters
$template_name = 'my_template.php'; | |
$load_template = plugin_dir_path(__FILE__) . 'templates/' . $template_name; | |
/** | |
* See @link http://codex.wordpress.org/Function_Reference/wp_upload_dir#Usage | |
*/ | |
if( file_exists( $upload_dir['basedir'] . '/my_plugin_name/' . $template_name ) ) { | |
$load_template = $upload_dir['basedir'] . '/my_plugin_name/' . $template_name; | |
} else { | |
/** | |
* See @link http://codex.wordpress.org/Function_Reference/load_template#Examples | |
*/ | |
if ( $overridden_template = locate_template( 'some-template.php' ) ) { | |
// locate_template() returns path to file | |
// if either the child theme or the parent theme have overridden the template | |
//load_template( $overridden_template ); | |
$load_template = $overridden_template; | |
} | |
} | |
// avoid instant explosions | |
if( !empty( $load_template) ) { | |
load_template( $load_template ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment