Permalink
Browse files

reasonable compromise

  • Loading branch information...
alexkingorg committed May 27, 2012
1 parent 2a7683a commit 3e8dcf62850397da99a6caad0eabd4d5a65a1071
Showing with 7 additions and 1 deletion.
  1. +7 −1 utility.php
View
@@ -311,7 +311,13 @@ function cfct_template($dir, $keys = array()) {
**/
function cfct_template_file($dir, $file, $data = array()) {
// bring in expected globals so that templates don't need to bring them in
- global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
+ // added in version 3.4 - can be overridden via filter
+ $global_vars = apply_filters('cfct_template_file_globals', array('posts', 'post', 'wp_did_header', 'wp_did_template_redirect', 'wp_query', 'wp_rewrite', 'wpdb', 'wp_version', 'wp', 'id', 'comment', 'user_ID'));
+ if (count($global_vars)) {

This comment has been minimized.

Show comment
Hide comment
@emzo

emzo May 30, 2012

Nitpicking here, but I think the semantics of what you're asking here would be better implied by if (!empty($global_vars)). While probably insignificant in this case, the !empty method also has some performance benefits since it doesn't have to compute the length of the array. See this question on StackOverflow for details.

@emzo

emzo May 30, 2012

Nitpicking here, but I think the semantics of what you're asking here would be better implied by if (!empty($global_vars)). While probably insignificant in this case, the !empty method also has some performance benefits since it doesn't have to compute the length of the array. See this question on StackOverflow for details.

This comment has been minimized.

Show comment
Hide comment
@bigdawggi

bigdawggi May 30, 2012

Contributor

Along those same lines, PHP doesn't throw an error or notice if you foreach over an empty array, and b/c it's a filter we should double-check that we're getting back the type we want b/c that's all that really matters. I suggest simply doing if (is_array($global_vars))

@bigdawggi

bigdawggi May 30, 2012

Contributor

Along those same lines, PHP doesn't throw an error or notice if you foreach over an empty array, and b/c it's a filter we should double-check that we're getting back the type we want b/c that's all that really matters. I suggest simply doing if (is_array($global_vars))

+ foreach ($global_vars as $global_var) {
+ global $$global_var;
+ }
+ }
$path = '';
if (!empty($file)) {
$file = basename($file, '.php');

0 comments on commit 3e8dcf6

Please sign in to comment.