-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
98 lines (83 loc) · 2.82 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
93
94
95
96
97
98
<?php
namespace k1;
/**
* Load and initialize k1kit if not done already
*
*/
if (!class_exists('\k1\App')) {
if (is_dir(WP_PLUGIN_DIR . '/k1kit')) {
require_once WP_PLUGIN_DIR . '/k1kit/src/php/init.php';
} else {
throw new \Exception("k1kit wasn't found. The theme can't be used without it.");
}
}
foreach (glob(dirname(__FILE__) . "/lib/*.php") as $filename) {
require_once($filename);
}
foreach (glob(dirname(__FILE__) . "/classes/class.*.php") as $filename) {
require_once($filename);
}
function app($options = []) {
return App::init($options);
}
$app = app([
'blocks' => glob(__DIR__ . '/blocks/*.php'),
'templates' => glob(__DIR__ . '/templates/*.php'),
'languageSlugs' => ['en'],
'manifests' => [
'client' => __DIR__ . '/dist/client-manifest.json',
'admin' => __DIR__ . '/dist/admin-manifest.json'
],
]);
$siteurl = get_site_url();
$strings = [
'Font-size: Normal' => 'Normal',
'Font-size: Large' => 'Large',
'Pagination: Previous' => 'Previous',
'Pagination: Next' => 'Next',
'ACF: Avoid hiding' => 'Avoid hiding elements if possible, and provide an alternate element, visible only to that breakpoint.',
'Title: News' => 'News',
'Title: Category' => 'Category',
'Title: Tag' => 'Tag',
'Title: Archive' => 'Archive',
'Breadcrumb: Home' => 'Home',
'Placeholder: Find from page' => 'Find from page',
];
foreach ($strings as $k => $v) {
$app->i18n->registerString($k, $v);
}
/**
* Pass useful data to the frontend, instead of crawling these from the DOM.
* Path can be used for dynamic imports, and wpurl for making HTTP requests,
* if you absolutely have to have absolute urls in your code.
*/
$localizeData = [
'lang' => $app->i18n->getLanguage(),
'path' => str_replace($siteurl, '', get_stylesheet_directory_uri()),
'wpurl' => $siteurl
];
add_action('wp_enqueue_scripts', function() use ($app, $localizeData) {
$jshandle = $app->manifests['client']->enqueue('client.js');
\wp_enqueue_style(
'k1-google-fonts',
'https://fonts.googleapis.com/css?family=Montserrat:700|Source+Sans+Pro:400,700&display=swap',
[],
null
);
$csshandle = $app->manifests['client']->enqueue('client.css');
wp_localize_script($jshandle, 'wptheme', array_merge($localizeData, [
'corejs' => $app->manifests['client']->getAssetFilename('corejs.js'),
'regeneratorRuntime' => $app->manifests['client']->getAssetFilename('regeneratorRuntime.js'),
]));
});
add_action('admin_enqueue_scripts', function() use ($app, $localizeData) {
$jshandle = $app->manifests['admin']->enqueue('admin.js');
\wp_enqueue_style(
'k1-google-fonts',
'https://fonts.googleapis.com/css?family=Montserrat:700|Source+Sans+Pro:400,700&display=swap',
[],
null
);
$csshandle = $app->manifests['admin']->enqueue('admin.css');
wp_localize_script($jshandle, 'wptheme', $localizeData);
});