This repository has been archived by the owner on Jan 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathfunctions.php
279 lines (264 loc) · 9.15 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?php
/**
* Functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Gesso
* @since 1.0.0
*/
if ( ! function_exists( 'gesso_theme_setup' ) ) :
/**
* Initialize basic theme customizations for Gesso theme.
*
* @return void
*/
function gesso_theme_setup() {
// add support for WP menus.
add_theme_support( 'menus' );
// Support featured images.
add_theme_support( 'post-thumbnails' );
// Support wide alignment.
add_theme_support( 'align-wide' );
// Support editor styles.
add_theme_support( 'editor-styles' );
// Disable WordPress's block patterns.
// Comment out if you want to use them.
remove_theme_support( 'core-block-patterns' );
// Enable block template parts.
add_theme_support( 'block-template-parts' );
// Enable responsive embeds.
add_theme_support( 'responsive-embeds' );
// Auto-output the page's title tag in the header.
add_theme_support( 'title-tag' );
// Define featured image sizes.
add_image_size( 'large_cropped', 800, 600, true );
add_image_size( 'large', 700, '', true ); // Large Thumbnail.
add_image_size( 'medium', 250, '', true ); // Medium Thumbnail.
add_image_size( 'small', 120, '', true ); // Small Thumbnail.
}
add_action( 'after_setup_theme', 'gesso_theme_setup' );
endif;
/**
* Enqueue and register required scripts and stylesheets for the Gesso theme.
*
* @return void
*/
function gesso_theme_scripts() {
// Enqueue Google Fonts.
/**
* Google font preconnect setup doesn't work when version is specified.
*
* phpcs:disable WordPress.WP.EnqueuedResourceParameters.MissingVersion
*/
wp_enqueue_style( 'google-fonts-preconnect-api', 'https://fonts.googleapis.com', array(), null );
wp_enqueue_style( 'google-fonts-preconnect', 'https://fonts.gstatic.com', array( 'google-fonts-preconnect-api' ), null );
wp_enqueue_style( 'google-fonts', 'https://fonts.googleapis.com/css2?family=Source+Sans+Pro:ital,wght@0,300;0,400;0,600;0,700;1,300;1,400;1,600;1,700&display=swap', array( 'google-fonts-preconnect' ), null );
// phpcs:enable
$style_asset_file = include 'build/css/styles.asset.php';
wp_enqueue_style( 'style', get_stylesheet_directory_uri() . '/build/css/styles.css', $style_asset_file['dependencies'], $style_asset_file['version'], 'all' );
// WP doesn't support enqueuing scripts by block at the theme level yet.
// Maybe in 6.0.
$search_script_asset_file = include 'build/js/search.asset.php';
wp_enqueue_script( 'gesso-search', get_stylesheet_directory_uri() . '/build/js/search.js', $search_script_asset_file['dependencies'], $search_script_asset_file['version'] );
wp_enqueue_script( 'responsive-menu', get_stylesheet_directory_uri() . '/build/js/responsiveMenu.es6.js', array(), '1.0', true );
}
add_action( 'wp_enqueue_scripts', 'gesso_theme_scripts' );
/**
* Register block styles custom to Gesso theme.
*
* @return void
*/
function gesso_block_assets() {
if ( function_exists( 'f1_block_library_register_blocks' ) ) {
wp_enqueue_block_style(
'f1-block-library/back-to-top',
array(
'handle' => 'gesso-back-to-top',
'src' => get_theme_file_uri( 'build/css/back-to-top.css' ),
'ver' => filemtime( get_theme_file_path( 'build/css/back-to-top.css' ) ),
)
);
wp_enqueue_block_style(
'f1-block-library/featured-cards',
array(
'handle' => 'gesso-cards',
'src' => get_theme_file_uri( 'build/css/cards.css' ),
'ver' => filemtime( get_theme_file_path( 'build/css/cards.css' ) ),
)
);
wp_enqueue_block_style(
'f1-block-library/query-cards',
array(
'handle' => 'gesso-cards',
'src' => get_theme_file_uri( 'build/css/cards.css' ),
'ver' => filemtime( get_theme_file_path( 'build/css/cards.css' ) ),
)
);
wp_enqueue_block_style(
'f1-block-library/manual-cards',
array(
'handle' => 'gesso-cards',
'src' => get_theme_file_uri( 'build/css/cards.css' ),
'ver' => filemtime( get_theme_file_path( 'build/css/cards.css' ) ),
)
);
wp_enqueue_block_style(
'f1-block-library/skiplinks',
array(
'handle' => 'gesso-skiplinks',
'src' => get_theme_file_uri( 'build/css/skiplinks.css' ),
'ver' => filemtime( get_theme_file_path( 'build/css/skiplinks.css' ) ),
)
);
wp_enqueue_block_style(
'f1-block-library/standalone-link',
array(
'handle' => 'gesso-standalone-link',
'src' => get_theme_file_uri( 'build/css/standalone-link.css' ),
'ver' => filemtime( get_theme_file_path( 'build/css/standalone-link.css' ) ),
)
);
wp_enqueue_block_style(
'f1-block-library/slider',
array(
'handle' => 'gesso-slider',
'src' => get_theme_file_uri( 'build/css/slider.css' ),
'ver' => filemtime( get_theme_file_path( 'build/css/slider.css' ) ),
)
);
}
}
add_action( 'after_setup_theme', 'gesso_block_assets' );
/**
* Filter enqueue styles.
*
* @param string $tag The link tag for the enqueued style.
* @param string $handle The style's registered handle.
* @param string $href The stylesheet's source URL.
* @param string $media The stylesheet's media attribute.
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter) $media does not need to be checked or used in this case.
*
* @return string
*/
function gesso_google_font_enqueued_styles( $tag, $handle, $href, $media ) {
$handles = array( 'google-fonts-preconnect', 'google-fonts-preconnect-api' );
// Google font preconnect rewrite.
if ( in_array( $handle, $handles ) ) {
$tag = '<link rel="preconnect" href="' . $href . '" />';
if ( boolval( strpos( $href, 'gstatic' ) ) ) {
$tag = '<link rel="preconnect" href="' . $href . '" crossorigin />';
}
}
return $tag;
}
add_filter( 'style_loader_tag', 'gesso_google_font_enqueued_styles', 10, 4 );
/**
* Enqueue Wordpress editor specific scripts.
*
* @return void
*/
function gesso_editor_scripts() {
$script_asset_file = include 'build/js/editor-scripts.asset.php';
wp_enqueue_script( 'editor-script', get_stylesheet_directory_uri() . '/build/js/editor-scripts.js', array_merge( $script_asset_file['dependencies'], array( 'wp-edit-post' ) ), $script_asset_file['version'] );
}
add_action( 'enqueue_block_editor_assets', 'gesso_editor_scripts' );
/**
* Enqueue Wordpress editor specific styles.
*
* @return void
*/
function gesso_editor_styles() {
add_editor_style( 'https://fonts.googleapis.com/css2?family=Source+Sans+Pro:ital,wght@0,300;0,400;0,600;0,700;1,300;1,400;1,600;1,700&display=swap' );
add_editor_style( './build/css/editor-styles.css' );
}
add_action( 'admin_init', 'gesso_editor_styles' );
/**
* Customizes meta data for Wordpress blocks.
*
* @param array<mixed> $metadata Array of Wordpress block data.
* @return array<mixed>
*/
function gesso_block_metadata_registration( $metadata ) {
if ( 'core/button' === $metadata['name'] ) {
// Disables the color and radius selector for buttons,
// so buttons will be limited to the available styles.
$metadata['supports']['color'] = false;
$metadata['supports']['__experimentalBorder'] = false;
}
return $metadata;
}
add_filter( 'block_type_metadata', 'gesso_block_metadata_registration' );
/**
* Register block patterns custom to the Gesso theme.
*
* @return void
*/
function gesso_block_patterns() {
register_block_pattern_category(
'gesso',
array(
'label' => __( 'Gesso' ),
),
);
register_block_pattern_category(
'templates_only',
array(
'label' => __( 'For Templates Only' ),
)
);
}
add_action( 'init', 'gesso_block_patterns' );
/**
* Render collapsible search block if contains the required class name.
*
* @param string $block_content String contents of the block.
* @param array<object> $block Array containing search block-specific details.
* @return string
*/
function gesso_collapsed_search( $block_content, $block ) {
if ( ! empty( $block['attrs']['className'] ) &&
strpos( $block['attrs']['className'], 'is-style-collapsed' ) !== false ) {
return '<div class="collapsed-search"><button type="button" class="collapsed-search__toggle"><svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="currentColor"
width="24px"
height="24px"
>
<path d="M0 0h24v24H0z" fill="none" />
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" />
</svg></button><div class="collapsed-search__content">' . $block_content . '</div></div>';
}
return $block_content;
}
add_filter( 'render_block_core/search', 'gesso_collapsed_search', 10, 2 );
/**
* Adding this in hides the theme options unless you are an admin.
*
* @return void
*/
function gesso_hide_fse_items() {
$user = wp_get_current_user();
$allowed_roles = array( 'administrator' );
if ( is_admin() && ! array_intersect( $allowed_roles, $user->roles ) ) {
remove_submenu_page( 'themes.php', 'theme_options' );
remove_submenu_page( 'themes.php', 'themes.php' );
}
}
add_action( 'admin_menu', 'gesso_hide_fse_items' );
/**
* Register menu locations.
*
* @return void
*/
function gesso_register_menus() {
register_nav_menus(
array(
'primary-menu' => __( 'Primary Menu' ),
'secondary-menu' => __( 'Secondary Menu' ),
)
);
}
add_action( 'init', 'gesso_register_menus' );