-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
120 lines (94 loc) · 3.25 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* This file adds functions to the WordPress theme.
*
* @package bts
* @author Amor Kumar
* @license GNU General Public License v2 or later
* @link https://itsamoreh.dev
*/
namespace bts;
if ( ! function_exists( 'setup' ) ) {
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook.
*/
function setup() {
// Make theme available for translation.
load_theme_textdomain( 'bts', get_template_directory() . '/languages' );
// Disable loading core block inline styles.
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
// Remove the block directory.
remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );
// Remove core block patterns.
remove_theme_support( 'core-block-patterns' );
// Don't install bundled themes when WordPress updates.
define( 'CORE_UPGRADE_SKIP_NEW_BUNDLED', true );
}
}
add_action( 'after_setup_theme', __NAMESPACE__ . '\\setup' );
/**
* Enqueue theme frontend scripts and styles.
*/
function enqueue_frontend_scripts() {
$dir = dirname( __FILE__ );
// Register and enqueue frontend scripts.
$frontend_script_asset_path = "$dir/build/assets/frontend.asset.php";
if ( ! file_exists( $frontend_script_asset_path ) ) {
throw new \Error(
'Missing frontend script assets! Please follow the setup instructions in the theme README.md.'
);
}
$frontend_script_asset = require( $frontend_script_asset_path );
wp_register_script(
'bts-frontend-js',
get_template_directory_uri() . '/build/assets/frontend.js',
$frontend_script_asset['dependencies'],
$frontend_script_asset['version'],
);
wp_register_style(
'bts-frontend-css',
get_template_directory_uri() . '/build/assets/frontend.css',
[],
$frontend_script_asset['version'],
);
wp_enqueue_script( 'bts-frontend-js' );
wp_enqueue_style( 'bts-frontend-css' );
}
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\enqueue_frontend_scripts' );
/**
* Enqueue theme editor scripts and styles.
*/
function enqueue_editor_scripts() {
$dir = dirname( __FILE__ );
$editor_script_asset_path = "$dir/build/assets/editor.asset.php";
if ( ! file_exists( $editor_script_asset_path ) ) {
throw new \Error(
'You need to build the theme\'s assets by running `npm build`!'
);
}
$editor_script_asset = require( $editor_script_asset_path );
wp_register_script(
'bts-editor-js',
get_template_directory_uri() . '/build/assets/editor.js',
$editor_script_asset['dependencies'],
$editor_script_asset['version'],
);
wp_enqueue_script( 'bts-editor-js' );
add_editor_style( '/build/assets/editor.css' );
}
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\enqueue_editor_scripts' );
/**
* Help admin documentation pages.
*/
include get_template_directory() . '/docs/help-admin-pages.php';
/**
* Hooks and other includes.
*
* include get_template_directory() . '/inc/example-include.php';
*/
include get_template_directory() . '/inc/reset/core-block-styles.php';
include get_template_directory() . '/inc/reset/openverse.php';
include get_template_directory() . '/inc/register-custom-blocks.php';