Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for a custom template path.

Using the `liveblog_template_path` filter developers can provide a new path for template files. If a template file is not found, the default template will be used.
  • Loading branch information...
commit f0894ae708406223f7336e9d5d64661f1496ed11 1 parent 167d167
@cfg cfg authored
Showing with 15 additions and 1 deletion.
  1. +15 −1 liveblog.php
View
16 liveblog.php
@@ -55,6 +55,7 @@
private static $post_id = null;
private static $entry_query = null;
private static $do_not_cache_response = false;
+ private static $custom_template_path = null;
/** Load Methods **********************************************************/
@@ -194,6 +195,15 @@ public static function handle_request() {
return;
self::$post_id = get_the_ID();
+
+ self::$custom_template_path = apply_filters( 'liveblog_template_path', self::$custom_template_path, self::$post_id );
+ if( ! is_dir( self::$custom_template_path ) ) {
+ self::$custom_template_path = null;
+ } else {
+ // realpath is used here to ensure we have an absolute path which is necessary to avoid APC related bugs
+ self::$custom_template_path = untrailingslashit( realpath( self::$custom_template_path ) );
+ }
+
self::$entry_query = new WPCOM_Liveblog_Entry_Query( self::$post_id, self::key );
if ( self::is_initial_page_request() ) {
@@ -649,7 +659,11 @@ private static function get_all_entry_output() {
public static function get_template_part( $template_name, $template_variables = array() ) {
ob_start();
extract( $template_variables );
- include( dirname( __FILE__ ) . '/templates/' . $template_name );
+ if( self::$custom_template_path && file_exists( self::$custom_template_path . '/' . $template_name ) ) {
+ include( self::$custom_template_path . '/' . $template_name );
+ } else {
+ include( dirname( __FILE__ ) . '/templates/' . $template_name );
+ }
return ob_get_clean();
}
Please sign in to comment.
Something went wrong with that request. Please try again.