-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
330 lines (305 loc) · 12 KB
/
functions.php
File metadata and controls
330 lines (305 loc) · 12 KB
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<?php
/**
* Elayne functions and definitions
*
* @package Elayne
* @since 0.1.0
*/
namespace Elayne;
/**
* Set up theme defaults and register various WordPress features.
*/
function elayne_setup() {
// Make theme available for translation.
load_theme_textdomain( 'elayne', get_template_directory() . '/languages' );
// Enqueue editor styles.
add_editor_style( 'style.css' );
// Remove core block patterns.
remove_theme_support( 'core-block-patterns' );
}
add_action( 'after_setup_theme', __NAMESPACE__ . '\elayne_setup' );
/**
* Register custom template part areas.
*
* @param array $areas Existing template part areas.
* @return array Modified template part areas.
*/
function elayne_template_part_areas( $areas ) {
$areas[] = array(
'area' => 'menu',
'area_tag' => 'nav',
'label' => __( 'Menu', 'elayne' ),
'description' => __( 'The Menu template part area is used for navigation menus.', 'elayne' ),
'icon' => 'navigation',
);
$areas[] = array(
'area' => 'sidebar',
'area_tag' => 'aside',
'label' => __( 'Sidebar', 'elayne' ),
'description' => __( 'The Sidebar template part area is used for sidebar content.', 'elayne' ),
'icon' => 'layout',
);
return $areas;
}
add_filter( 'default_wp_template_part_areas', __NAMESPACE__ . '\elayne_template_part_areas' );
/**
* Enqueue styles.
*/
function elayne_enqueue_styles() {
wp_enqueue_style(
'elayne-style',
get_template_directory_uri() . '/style.css',
array(),
wp_get_theme()->get( 'Version' )
);
}
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\elayne_enqueue_styles' );
/**
* Register pattern categories.
*/
function elayne_pattern_categories() {
$block_pattern_categories = array(
'elayne/hero' => array( 'label' => __( 'Hero', 'elayne' ) ),
'elayne/banner' => array( 'label' => __( 'Banners', 'elayne' ) ),
'elayne/features' => array( 'label' => __( 'Features', 'elayne' ) ),
'elayne/call-to-action' => array( 'label' => __( 'Call To Action', 'elayne' ) ),
'elayne/testimonial' => array( 'label' => __( 'Testimonials', 'elayne' ) ),
'elayne/team' => array( 'label' => __( 'Team', 'elayne' ) ),
'elayne/statistics' => array( 'label' => __( 'Statistics', 'elayne' ) ),
'elayne/contact' => array( 'label' => __( 'Contact', 'elayne' ) ),
'elayne/card' => array( 'label' => __( 'Cards', 'elayne' ) ),
'elayne/card-simple' => array( 'label' => __( 'Cards: Simple', 'elayne' ) ),
'elayne/card-extended' => array( 'label' => __( 'Cards: Extended', 'elayne' ) ),
'elayne/card-profiles' => array( 'label' => __( 'Cards: Profiles', 'elayne' ) ),
'elayne/events' => array( 'label' => __( 'Events', 'elayne' ) ),
'elayne/portfolio' => array( 'label' => __( 'Portfolio', 'elayne' ) ),
'elayne/pages' => array( 'label' => __( 'Pages', 'elayne' ) ),
'elayne/posts' => array( 'label' => __( 'Posts', 'elayne' ) ),
'elayne/spa' => array( 'label' => __( 'Spa & Wellness', 'elayne' ) ),
'elayne/legal' => array( 'label' => __( 'Legal Services', 'elayne' ) ),
'elayne/fintech' => array( 'label' => __( 'Fintech & Technology', 'elayne' ) ),
'elayne/salon' => array( 'label' => __( 'Beauty & Salon', 'elayne' ) ),
'elayne/retail' => array( 'label' => __( 'Retail & E-commerce', 'elayne' ) ),
'elayne/food-beverage' => array( 'label' => __( 'Food & Beverage', 'elayne' ) ),
);
foreach ( $block_pattern_categories as $name => $properties ) {
register_block_pattern_category( $name, $properties );
}
}
add_action( 'init', __NAMESPACE__ . '\elayne_pattern_categories', 9 );
/**
* Add custom image sizes for professional layouts.
*/
function elayne_custom_image_sizes() {
// Portrait image sizes for grid/archive layouts.
add_image_size( 'elayne-portrait-xs', 350, 525, true ); // 2:3 aspect ratio (extra small).
add_image_size( 'elayne-portrait-small', 380, 570, true ); // 2:3 aspect ratio.
add_image_size( 'elayne-portrait-medium', 380, 507, true ); // 3:4 aspect ratio.
add_image_size( 'elayne-portrait-large', 380, 475, true ); // 4:5 aspect ratio.
// Landscape hero image for single post/page templates.
add_image_size( 'elayne-single-hero', 700, 400, true ); // 16:9-ish.
}
add_action( 'after_setup_theme', __NAMESPACE__ . '\elayne_custom_image_sizes' );
/**
* Load custom block styles only when the block is used.
*/
function elayne_enqueue_custom_block_styles() {
// Scan our styles folder to locate block styles.
$files = glob( get_template_directory() . '/assets/styles/*.css' );
if ( ! $files ) {
return;
}
foreach ( $files as $file ) {
// Get the filename and core block name.
$filename = basename( $file, '.css' );
$block_name = str_replace( 'core-', 'core/', $filename );
wp_enqueue_block_style(
$block_name,
array(
'handle' => "elayne-block-{$filename}",
'src' => get_theme_file_uri( "assets/styles/{$filename}.css" ),
'path' => get_theme_file_path( "assets/styles/{$filename}.css" ),
)
);
}
}
add_action( 'init', __NAMESPACE__ . '\elayne_enqueue_custom_block_styles' );
/**
* Register CSS effect block styles.
*/
function elayne_register_effect_block_styles() {
$block_styles = array(
'core/button' => array(
'arrow-slide' => __( 'Arrow Slide', 'elayne' ),
'gradient-shift' => __( 'Gradient Shift', 'elayne' ),
'shimmer' => __( 'Shimmer', 'elayne' ),
'glow' => __( 'Glow', 'elayne' ),
'border-draw' => __( 'Border Draw', 'elayne' ),
'slide-up' => __( 'Slide Up', 'elayne' ),
),
'core/group' => array(
'elevate-hover' => __( 'Elevate on Hover', 'elayne' ),
'glow-border' => __( 'Glow Border', 'elayne' ),
'image-zoom' => __( 'Image Zoom', 'elayne' ),
'tilt-card' => __( 'Tilt Card', 'elayne' ),
'scale-hover' => __( 'Scale Hover', 'elayne' ),
'border-pulse' => __( 'Border Pulse', 'elayne' ),
'slide-border' => __( 'Slide Border', 'elayne' ),
),
'core/image' => array(
'zoom-hover' => __( 'Zoom Hover', 'elayne' ),
'grayscale-hover' => __( 'Grayscale Hover', 'elayne' ),
'rotate-icon' => __( 'Rotate Icon', 'elayne' ),
'blur-hover' => __( 'Blur Hover', 'elayne' ),
'brightness-hover' => __( 'Brightness Hover', 'elayne' ),
'sepia-hover' => __( 'Sepia Hover', 'elayne' ),
'lift-shadow' => __( 'Lift Shadow', 'elayne' ),
'border-reveal' => __( 'Border Reveal', 'elayne' ),
'tilt-3d' => __( 'Tilt 3D', 'elayne' ),
),
'core/paragraph' => array(
'animated-underline' => __( 'Animated Underline', 'elayne' ),
'animated-underline-center' => __( 'Animated Underline Center', 'elayne' ),
'highlight-fade' => __( 'Highlight Fade', 'elayne' ),
'link-hover-shift' => __( 'Link Hover Shift', 'elayne' ),
'fade-in' => __( 'Fade In', 'elayne' ),
),
'core/heading' => array(
'gradient-text' => __( 'Gradient Text', 'elayne' ),
'gradient-text-animated' => __( 'Gradient Text Animated', 'elayne' ),
'underline-slide' => __( 'Underline Slide', 'elayne' ),
'logo-link' => __( 'Logo Link', 'elayne' ),
),
'core/list' => array(
'animated-markers' => __( 'Animated Markers', 'elayne' ),
),
);
foreach ( $block_styles as $block => $styles ) {
foreach ( $styles as $style_name => $style_label ) {
register_block_style(
$block,
array(
'name' => $style_name,
'label' => $style_label,
)
);
}
}
}
add_action( 'init', __NAMESPACE__ . '\elayne_register_effect_block_styles' );
/**
* Register plumbing block style variations and enqueue their CSS on demand.
*
* CSS files live in assets/styles/block-styles/ and load only on pages where
* the corresponding block style is used — not globally.
*/
function elayne_register_plumbing_block_styles() {
$styles = array(
'core/group' => array(
'plumbing-service-card' => __( 'Plumbing Service Card', 'elayne' ),
'plumbing-featured-card' => __( 'Plumbing Featured Card', 'elayne' ),
'plumbing-badge' => __( 'Plumbing Badge', 'elayne' ),
'plumbing-years-badge' => __( 'Plumbing Years Badge', 'elayne' ),
'plumbing-stat-block' => __( 'Plumbing Stat Block', 'elayne' ),
'plumbing-check-icon' => __( 'Plumbing Check Icon', 'elayne' ),
'plumbing-why-item' => __( 'Plumbing Why Item', 'elayne' ),
'plumbing-avatar' => __( 'Plumbing Avatar', 'elayne' ),
'plumbing-contact-icon' => __( 'Plumbing Contact Icon', 'elayne' ),
'plumbing-cta-call-pill' => __( 'Plumbing CTA Call Pill', 'elayne' ),
'plumbing-cta-actions' => __( 'Plumbing CTA Actions', 'elayne' ),
),
'core/paragraph' => array(
'plumbing-section-label' => __( 'Plumbing Section Label', 'elayne' ),
),
'core/button' => array(
'plumbing-call-btn' => __( 'Plumbing Call Button', 'elayne' ),
),
);
foreach ( $styles as $block => $variations ) {
foreach ( $variations as $name => $label ) {
register_block_style(
$block,
array(
'name' => $name,
'label' => $label,
)
);
$css_file = "assets/styles/block-styles/{$name}.css";
if ( file_exists( get_theme_file_path( $css_file ) ) ) {
wp_enqueue_block_style(
$block,
array(
'handle' => "elayne-{$name}",
'src' => get_theme_file_uri( $css_file ),
'path' => get_theme_file_path( $css_file ),
)
);
}
}
}
// CSS for plumbing header components (topbar phone pill, nav CTA pill).
// Uses wp_enqueue_block_style() rather than plumbing-variation.css because
// it injects into the editor iframe after the editor's own stylesheet, so
// unscoped selectors win without needing .editor-styles-wrapper hacks.
// Note: loads on every page (core/group is ubiquitous) regardless of the
// active style variation — selectors are harmlessly inert on non-plumbing sites.
$header_components = array( 'plumbing-topbar-phone', 'plumbing-header-cta' );
foreach ( $header_components as $name ) {
$css_file = "assets/styles/block-styles/{$name}.css";
if ( file_exists( get_theme_file_path( $css_file ) ) ) {
wp_enqueue_block_style(
'core/group',
array(
'handle' => "elayne-{$name}",
'src' => get_theme_file_uri( $css_file ),
'path' => get_theme_file_path( $css_file ),
)
);
}
}
}
add_action( 'init', __NAMESPACE__ . '\elayne_register_plumbing_block_styles' );
/**
* Add a body class matching the active style variation slug.
*
* Reads `settings.custom.styleVariation` from the merged theme.json data
* (base theme.json + active variation JSON), so when plumbing.json is active
* the body gets class `style-variation-plumbing`.
*
* @param array $classes Existing body classes.
* @return array Modified body classes.
*/
function elayne_style_variation_body_class( array $classes ): array {
$custom = wp_get_global_settings( array( 'custom' ) );
if ( ! empty( $custom['styleVariation'] ) ) {
$classes[] = 'style-variation-' . sanitize_html_class( $custom['styleVariation'] );
}
return $classes;
}
add_filter( 'body_class', __NAMESPACE__ . '\elayne_style_variation_body_class' );
/**
* Enqueue the plumbing style variation stylesheet.
*
* Uses enqueue_block_assets so the file loads in both the frontend and the
* FSE editor iframe. Only enqueued when the plumbing variation is active.
* Styles are scoped under `.style-variation-plumbing` (frontend/iframe) and
* `.editor-styles-wrapper` (editor-only grid fixes), so there is zero impact
* on other style variations or pages.
*/
function elayne_enqueue_plumbing_variation_styles(): void {
$custom = wp_get_global_settings( array( 'custom' ) );
if ( empty( $custom['styleVariation'] ) || 'plumbing' !== $custom['styleVariation'] ) {
return;
}
wp_enqueue_style(
'elayne-plumbing-variation',
get_template_directory_uri() . '/assets/styles/plumbing-variation.css',
array(),
wp_get_theme()->get( 'Version' )
);
}
add_action( 'enqueue_block_assets', __NAMESPACE__ . '\elayne_enqueue_plumbing_variation_styles' );
/**
* Include block extensions.
*/
require_once get_template_directory() . '/inc/block-extensions.php';