Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add support for a custom template path. #89

Merged
merged 1 commit into from

2 participants

Corey Gilmore Nikolay Bachiyski
Corey Gilmore

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.

Corey Gilmore cfg 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.
f0894ae
Nikolay Bachiyski
Owner

Looks good. Good thinking about the realpath.

Why are you running this on handle_request? It sounds arbitrary. It looks like this should be done on init, but that's usually when your plugin will hook to the filter and there's a chance that it will run earlier than liveblog's init.

So, how about we run the filter on demand in get_template_part() and cache it? A method like get_templates_path() or even get_template_path( $template_file ) can do a good job. What do you think?

Nikolay Bachiyski
Owner
nb commented

It's good enough for now.

Nikolay Bachiyski nb merged commit a5d0a20 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 29, 2013
  1. Corey Gilmore

    Add support for a custom template path.

    cfg authored
    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.
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 1 deletion.
  1. +15 −1 liveblog.php
16 liveblog.php
View
@@ -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();
}
Something went wrong with that request. Please try again.