-
Notifications
You must be signed in to change notification settings - Fork 6
/
functions.php
92 lines (76 loc) · 2.63 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* Tofino includes
*
* The $tofino_includes array determines the code library included in your theme.
* Add or remove files to the array as needed.
*
* Missing files will produce a fatal error.
*
*/
$tofino_includes = [
"inc/lib/vite.php",
"inc/lib/AjaxForm.php",
"inc/lib/init.php",
"inc/lib/assets.php",
"inc/lib/helpers.php",
"inc/lib/clean.php",
"inc/lib/shortcodes.php",
];
foreach ($tofino_includes as $file) {
if (!$filepath = locate_template($file)) {
trigger_error(sprintf(__('Error locating %s for inclusion', 'tofino'), $file), E_USER_ERROR);
}
if (!class_exists('acf') && $GLOBALS['pagenow'] != 'wp-login.php' && !is_admin()) {
wp_die(missing_acf_plugin_notice(), __('An error occured.', 'tofino'));
}
if (class_exists('acf')) {
require_once $filepath;
}
}
unset($file, $filepath);
/**
* Composer dependencies
*
* External dependencies are defined in the composer.json and autoloaded.
* Use 'composer dump-autoload -o' after adding new files.
*
*/
if (file_exists(get_template_directory() . '/vendor/autoload.php')) { // Check composer autoload file exists. Result is cached by PHP.
require_once 'vendor/autoload.php';
} else {
if (is_admin()) {
add_action('admin_notices', composer_error_notice());
} else {
wp_die(composer_error_notice(), __('An error occured.', 'tofino'));
}
}
// Check for missing dist directory. Result is cached by PHP.
if (!is_dir(get_template_directory() . '/dist')) {
if (is_admin()) {
add_action('admin_notices', 'missing_dist_error_notice');
} else {
wp_die(missing_dist_error_notice(), __('An error occured.', 'tofino'));
}
}
// Check for ACF Plugin.
if (!class_exists('acf')) {
if (is_admin()) {
add_action('admin_notices', 'missing_acf_plugin_notice');
}
}
// Admin notice for missing composer autoload.
function composer_error_notice()
{
echo '<div class="error notice"><p><strong>' . __('Theme Error', 'tofino') . '</strong> - ' . __('Composer autoload file not found. Run composer install on the command line.', 'tofino') . '</p></div>';
}
// Admin notice for missing dist directory.
function missing_dist_error_notice()
{
echo '<div class="error notice"><p><strong>' . __('Theme Error', 'tofino') . '</strong> - ' . __('/dist directory not found. You probably want to run npm install and npm run prod on the command line.', 'tofino') . '</p></div>';
}
// Admin notice for missing ACF plugin.
function missing_acf_plugin_notice()
{
echo '<div class="error notice"><p><strong>' . __('Missing Plugin', 'tofino') . '</strong> - ' . __('Advanced Custom Fields Pro plugin not found. Please install it.', 'tofino') . '</p></div>';
}