Skip to content
Browse files

reasonable compromise

  • Loading branch information...
1 parent 2a7683a commit 3e8dcf62850397da99a6caad0eabd4d5a65a1071 @alexkingorg alexkingorg committed May 27, 2012
Showing with 7 additions and 1 deletion.
  1. +7 −1 utility.php
8 utility.php
@@ -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)) {
emzo added a note 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.

bigdawggi added a note May 30, 2012

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))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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.
Something went wrong with that request. Please try again.