Skip to content

Instantly share code, notes, and snippets.

@probil
Created September 14, 2015 14:28
Show Gist options
  • Save probil/1c236aa676e5418d02a3 to your computer and use it in GitHub Desktop.
Save probil/1c236aa676e5418d02a3 to your computer and use it in GitHub Desktop.
Timber theme functions.php boilerplate file
<?php
/**
* This theme using Timber as html-template engine
* See more https://github.com/jarednova/timber
*
*/
if (!class_exists('Timber')){
add_action( 'admin_notices', function(){
echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . admin_url('plugins.php#timber') . '">' . admin_url('plugins.php') . '</a></p></div>';
});
return;
}
foreach (glob(__DIR__ . '/inc/*.php') as $file) {
require_once($file);
}
class InsureTheme extends TimberSite {
public function __construct(){
add_theme_support('post-thumbnails');
add_theme_support('menus');
add_filter('timber_context', array($this, 'add_to_context'));
add_filter('get_twig', array($this, 'add_to_twig'));
add_action('init', array($this, 'register_post_types'));
add_action('init', array($this, 'register_ui_columns'));
add_action('init', array($this, 'register_ajax'));
add_action('init', array($this, 'register_theme_settings'));
parent::__construct();
}
/**
* Post-types registering
*/
public function register_post_types(){
//Register post types here
}
/**
* Register custom columns in UI
*/
public function register_ui_columns(){
//post type columns here
}
/**
* Register setting that could be used by theme
*/
public function register_theme_settings() {
//register theme settings here
}
/**
* Hooks for ajax handling
*/
public function register_ajax(){
//register ajax callback here
}
/**
* Register variables for using in twig template file
*/
public function add_to_context($context){
$context['site'] = $this;
$context['ajax_url'] = admin_url('admin-ajax.php');
return $context;
}
/**
* Register filters and extensions for using
* in twig template file
* @param $twig
* @return mixed
*/
public function add_to_twig($twig){
/* this is where you can add your own functions to twig */
$twig->addExtension(new Twig_Extension_StringLoader());
return $twig;
}
}
new InsureTheme();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment