-
Notifications
You must be signed in to change notification settings - Fork 5
/
functions.php
67 lines (53 loc) · 1.88 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace BasePlate;
function frontend_error($message, $subtitle = '', $title = '')
{
$title = $title ?: __('BasePlate › Error', 'sage');
$message = "<h1>{$title}<br><small>{$subtitle}</small></h1><p>{$message}</p>";
wp_die($message, $title);
};
function backend_error($message, $subtitle = '', $title = '')
{
$title = $title ?: __('BasePlate › Error', 'sage');
$message = "<div class='error'><h2>{$title}<br><small>{$subtitle}</small></h2><p>{$message}</p></div>";
add_action('admin_notices', function () use ($message) {
echo $message;
});
};
// Send notice to user if Timber Class cannot be found
if (!class_exists('Timber\Timber')) {
// Notice on admin pages
backend_error('Timber not activated. Make sure to composer require timber/timber');
// Notice on front pages
add_filter('template_include', function () {
frontend_error(__('Timber not activated. Make sure to composer require timber/timber', 'BasePlate'));
});
return 0;
}
$timber = new \Timber\Timber();
$baseplate_includes = [
'lib/cleanup.php', // Theme setup
'lib/assets.php', // Theme asset functions
'lib/setup.php', // Theme setup
'lib/timber.php', // Theme setup
'lib/lazyload.php', // lazyload functionality
'lib/blocks.php', // Gutengerb blocks
'lib/bootstrap_navwalker.php', // navwalker
'lib/extras.php', // Custom functions
'lib/sidebars.php' // Theme sidebars
];
foreach ($baseplate_includes as $file) {
if (!($filepath = locate_template($file))) {
frontend_error(sprintf(__('Error locating %s for inclusion', 'BasePlate'), $file));
}
require_once $filepath;
}
unset($file, $filepath);
/**
* Model autoloader
*
* Include all custom post types and block defintions automamagically
*/
foreach (glob(get_template_directory() . '/lib/models/*.php') as $filename) {
include $filename;
}