Skip to content
This repository
Browse code

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
Corey Gilmore authored

Showing 1 changed file with 15 additions and 1 deletion. Show diff stats Hide diff stats

  1. 16  liveblog.php
16  liveblog.php
@@ -55,6 +55,7 @@
55 55
 	private static $post_id               = null;
56 56
 	private static $entry_query           = null;
57 57
 	private static $do_not_cache_response = false;
  58
+	private static $custom_template_path  = null;
58 59
 
59 60
 	/** Load Methods **********************************************************/
60 61
 
@@ -194,6 +195,15 @@ public static function handle_request() {
194 195
 			return;
195 196
 
196 197
 		self::$post_id     = get_the_ID();
  198
+
  199
+		self::$custom_template_path = apply_filters( 'liveblog_template_path', self::$custom_template_path, self::$post_id );
  200
+		if( ! is_dir( self::$custom_template_path ) ) {
  201
+			self::$custom_template_path = null;
  202
+		} else {
  203
+			// realpath is used here to ensure we have an absolute path which is necessary to avoid APC related bugs
  204
+			self::$custom_template_path = untrailingslashit( realpath( self::$custom_template_path ) );
  205
+		}
  206
+
197 207
 		self::$entry_query = new WPCOM_Liveblog_Entry_Query( self::$post_id, self::key );
198 208
 
199 209
 		if ( self::is_initial_page_request() ) {
@@ -649,7 +659,11 @@ private static function get_all_entry_output() {
649 659
 	public static function get_template_part( $template_name, $template_variables = array() ) {
650 660
 		ob_start();
651 661
 		extract( $template_variables );
652  
-		include( dirname( __FILE__ ) . '/templates/' . $template_name );
  662
+		if( self::$custom_template_path && file_exists( self::$custom_template_path . '/' . $template_name ) ) {
  663
+			include( self::$custom_template_path . '/' . $template_name );
  664
+		} else {
  665
+			include( dirname( __FILE__ ) . '/templates/' . $template_name );
  666
+		}
653 667
 		return ob_get_clean();
654 668
 	}
655 669
 

0 notes on commit f0894ae

Please sign in to comment.
Something went wrong with that request. Please try again.