<?php
function external_resources()
{
wp_enqueue_style('style', get_stylesheet_uri());
wp_enqueue_style('main_styles', get_template_directory_uri() . '/styles/main.css', false, '', 'screen');
if ($_ENV['ENVIRONMENT'] == 'dev') {
wp_enqueue_script('system', home_url() . '/src/scripts/vendor/system.js', array(), '', true);
wp_enqueue_script('config', home_url() . '/src/scripts/config.js', array(), '', true);
} else {
wp_enqueue_script('main', get_template_directory_uri() . '/js/main.js', array(), '', true);
}
}
add_action('wp_enqueue_scripts', 'external_resources');
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="' . esc_url(admin_url('plugins.php#timber')) . '">' . esc_url(admin_url('plugins.php')) . '</a></p></div>';
});
add_filter('template_include', function ($template) {
return get_stylesheet_directory() . 'no-timber.html';
});
return;
}
Timber::$dirname = array('templates', 'views');
class jswApp extends TimberSite
{
function __construct()
{
add_theme_support('post-formats');
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_taxonomies'));
parent::__construct();
}
function register_post_types()
{
function projects() {
$labels = array(
'name' => _x('Projects', 'Post Type General Name', 'projects'),
'singular_name' => _x('Project', 'Post Type Singular Name', 'projects'),
'menu_name' => __('Projects', 'projects'),
'name_admin_bar' => __('Projects', 'projects'),
'archives' => __('Project Archives', 'projects'),
'attributes' => __('Project Attributes', 'projects'),
'parent_item_colon' => __('Parent Project:', 'projects'),
'all_items' => __('All Projects', 'projects'),
'add_new_item' => __('Add New Project', 'projects'),
'add_new' => __('Add New Project', 'projects'),
'new_item' => __('New Project', 'projects'),
'edit_item' => __('Edit Project', 'projects'),
'update_item' => __('Update Project', 'projects'),
'view_item' => __('View Project', 'projects'),
'view_items' => __('View Projects', 'projects'),
'search_items' => __('Search Projects', 'projects'),
'not_found' => __('Not found', 'projects'),
'not_found_in_trash' => __('Not found in Trash', 'projects'),
'featured_image' => __('Featured Image', 'projects'),
'set_featured_image' => __('Set featured image', 'projects'),
'remove_featured_image' => __('Remove featured image', 'projects'),
'use_featured_image' => __('Use as featured image', 'projects'),
'insert_into_item' => __('Insert into project', 'projects'),
'uploaded_to_this_item' => __('Uploaded to this project', 'projects'),
'items_list' => __('Projects list', 'projects'),
'items_list_navigation' => __('Projects list navigation', 'projects'),
'filter_items_list' => __('Filter projects list', 'projects'),
);
$args = array(
'label' => __('Project', 'projects'),
'description' => __('STEAM Project', 'projects'),
'labels' => $labels,
'supports' => array('title', 'author', 'thumbnail', 'comments', 'revisions', ),
'taxonomies' => array('project_type', 'post_tag'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-hammer',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'show_in_rest' => true,
);
register_post_type('project', $args);
}
projects();
function makerspaces()
{
$labels = array(
'name' => _x('Makerspaces', 'Post Type General Name', 'makerspaces'),
'singular_name' => _x('Makerspace', 'Post Type Singular Name', 'makerspaces'),
'menu_name' => __('Makerspaces', 'makerspaces'),
'name_admin_bar' => __('Makerspaces', 'makerspaces'),
'archives' => __('Makerspace Archives', 'makerspaces'),
'attributes' => __('Makerspace Attributes', 'makerspaces'),
'parent_item_colon' => __('Parent Makerspace:', 'makerspaces'),
'all_items' => __('All Makerspaces', 'makerspaces'),
'add_new_item' => __('Add New Makerspace', 'makerspaces'),
'add_new' => __('Add New Makerspace', 'makerspaces'),
'new_item' => __('New Makerspace', 'makerspaces'),
'edit_item' => __('Edit Makerspace', 'makerspaces'),
'update_item' => __('Update Makerspace', 'makerspaces'),
'view_item' => __('View Makerspace', 'makerspaces'),
'view_items' => __('View Makerspaces', 'makerspaces'),
'search_items' => __('Search Makerspaces', 'makerspaces'),
'not_found' => __('Not found', 'makerspaces'),
'not_found_in_trash' => __('Not found in Trash', 'makerspaces'),
'featured_image' => __('Featured Image', 'makerspaces'),
'set_featured_image' => __('Set featured image', 'makerspaces'),
'remove_featured_image' => __('Remove featured image', 'makerspaces'),
'use_featured_image' => __('Use as featured image', 'makerspaces'),
'insert_into_item' => __('Insert into project', 'makerspaces'),
'uploaded_to_this_item' => __('Uploaded to this makerspace', 'makerspaces'),
'items_list' => __('Makerspaces list', 'makerspaces'),
'items_list_navigation' => __('Makerspaces list navigation', 'makerspaces'),
'filter_items_list' => __('Filter projects list', 'makerspaces'),
);
$args = array(
'label' => __('Makerspace', 'makerspaces'),
'description' => __('Makerspace locations', 'makerspaces'),
'labels' => $labels,
'supports' => array('title', 'author', 'thumbnail', 'comments', 'revisions', ),
'taxonomies' => array('space_type', 'post_tag'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-location',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'show_in_rest' => true,
);
register_post_type('makerspace', $args);
}
makerspaces();
}
function register_taxonomies()
{
function project_type()
{
$labels = array(
'name' => _x('Project Types', 'Taxonomy General Name', 'project_type'),
'singular_name' => _x('Project Type', 'Taxonomy Singular Name', 'project_type'),
'menu_name' => __('Project Types', 'project_type'),
'all_items' => __('All Project Types', 'project_type'),
'parent_item' => __('Parent Project Type', 'project_type'),
'parent_item_colon' => __('Parent Project Type:', 'project_type'),
'new_item_name' => __('New Project Type', 'project_type'),
'add_new_item' => __('Add New Project Type', 'project_type'),
'edit_item' => __('Edit Project Type', 'project_type'),
'update_item' => __('Update Project Type', 'project_type'),
'view_item' => __('View Project Type', 'project_type'),
'separate_items_with_commas' => __('Separate project types with commas', 'project_type'),
'add_or_remove_items' => __('Add or remove project types', 'project_type'),
'choose_from_most_used' => __('Choose from the most used', 'project_type'),
'popular_items' => __('Popular Items', 'project_type'),
'search_items' => __('Search Items', 'project_type'),
'not_found' => __('Not Found', 'project_type'),
'no_terms' => __('No items', 'project_type'),
'items_list' => __('Project types list', 'project_type'),
'items_list_navigation' => __('Project types list navigation', 'project_type'),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => false,
'show_in_rest' => true,
);
register_taxonomy('project_type', array('projects'), $args);
}
project_type();
function space_type()
{
$labels = array(
'name' => _x('Makerspace Types', 'Taxonomy General Name', 'space_type'),
'singular_name' => _x('Makerspace Type', 'Taxonomy Singular Name', 'space_type'),
'menu_name' => __('Makerspace Types', 'space_type'),
'all_items' => __('All Makerspace Types', 'space_type'),
'parent_item' => __('Parent Makerspace Type', 'space_type'),
'parent_item_colon' => __('Parent Makerspace Type:', 'space_type'),
'new_item_name' => __('New Makerspace Type', 'space_type'),
'add_new_item' => __('Add New Makerspace Type', 'space_type'),
'edit_item' => __('Edit Makerspace Type', 'space_type'),
'update_item' => __('Update Makerspace Type', 'space_type'),
'view_item' => __('View Makerspace Type', 'space_type'),
'separate_items_with_commas' => __('Separate makerspace types with commas', 'space_type'),
'add_or_remove_items' => __('Add or remove makerspace types', 'space_type'),
'choose_from_most_used' => __('Choose from the most used', 'space_type'),
'popular_items' => __('Popular Items', 'space_type'),
'search_items' => __('Search Items', 'space_type'),
'not_found' => __('Not Found', 'space_type'),
'no_terms' => __('No items', 'space_type'),
'items_list' => __('Makerspace types list', 'space_type'),
'items_list_navigation' => __('Makerspace types list navigation', 'space_type'),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
'show_in_rest' => true,
);
register_taxonomy('space_type', array('makerspaces'), $args);
}
space_type();
}
function add_to_context($context)
{
$context['foo'] = 'bar';
$context['stuff'] = 'I am a value set in your functions.php file';
$context['notes'] = 'These values are available everytime you call Timber::get_context();';
$context['menu'] = new TimberMenu();
$context['site'] = $this;
return $context;
}
function myfoo($text)
{
$text .= ' bar!';
return $text;
}
function add_to_twig($twig)
{
/* this is where you can add your own functions to twig */
$twig->addExtension(new Twig_Extension_StringLoader());
$twig->addFilter('myfoo', new Twig_SimpleFilter('myfoo', array($this, 'myfoo')));
return $twig;
}
}
new jswApp();