/** * This function sets up the Twig environment * * @since 1.0.0 */ public function setup_twig_environment() { # Include the Twig Autoloader and register Twig # MODIFICATION: changed from WP_CONTENT_DIR to dirname(__FILE__) require_once dirname(__FILE__) . '/Twig/Autoloader.php'; # MODIFICATION: Added require for Twig Proxy Class require_once dirname(__FILE__) . '/class-twig-proxy.php'; Twig_Autoloader::register(); # Setup options for the Twig environment self::setup_twig_environment_options(); # Now we load the TWIG filesystem and environment self::$twig_loader = new Twig_Loader_Filesystem(get_stylesheet_directory() . '/twigs'); self::$twig_environment = new Twig_Environment(self::$twig_loader, self::$twig_environment_settings); self::$twig_environment->addExtension(new Twig_Extension_Debug()); # MODIFICATIONS: Added functions to aid in grabbing Wordpress posts $wpposts = new Twig_SimpleFunction("posts", function ($args = array()) { global $wp_query; if ($args == null) { return $wp_query->posts; } else { $query = get_posts($args); return $query; } }); $wppostdata = new Twig_SimpleFunction("the_post", function ($args) { global $post; $this->wp_query()->in_the_loop = true; if ($this->wp_query()->current_post == -1) { do_action_ref_array('loop_start', array(&$this)); } $post = $args; setup_postdata($post); }); self::$twig_environment->addFunction($wpposts); self::$twig_environment->addFunction($wppostdata); # MODIFICATION: Removed variables and functions loader self::$twig_proxy = new Twig_Proxy(); }