-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
467 lines (404 loc) · 16.3 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
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
<?php
/**
* Understrap Child Theme functions and definitions
*
* @package UnderstrapChild
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* Removes the parent themes stylesheet and scripts from inc/enqueue.php
*/
function understrap_remove_scripts() {
wp_dequeue_style( 'understrap-styles' );
wp_deregister_style( 'understrap-styles' );
wp_dequeue_script( 'understrap-scripts' );
wp_deregister_script( 'understrap-scripts' );
}
add_action( 'wp_enqueue_scripts', 'understrap_remove_scripts', 20 );
/**
* Enqueue our stylesheet and javascript file
*/
function theme_enqueue_styles() {
// Get the theme data.
$the_theme = wp_get_theme();
$theme_version = $the_theme->get( 'Version' );
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
// Grab asset urls.
$theme_styles = "/css/child-theme{$suffix}.css";
$theme_scripts = "/js/child-theme{$suffix}.js";
$css_version = $theme_version . '.' . filemtime( get_stylesheet_directory() . $theme_styles );
wp_enqueue_style( 'child-understrap-styles', get_stylesheet_directory_uri() . $theme_styles, array(), $css_version );
wp_enqueue_script( 'jquery' );
$js_version = $theme_version . '.' . filemtime( get_stylesheet_directory() . $theme_scripts );
wp_enqueue_script( 'child-understrap-scripts', get_stylesheet_directory_uri() . $theme_scripts, array(), $js_version, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
/**
* Load the child theme's text domain
*/
function add_child_theme_textdomain() {
load_child_theme_textdomain( 'understrap-child', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'add_child_theme_textdomain' );
/**
* We use WordPress's init hook to make sure
* our blocks are registered early in the loading
* process.
*
* @link https://developer.wordpress.org/reference/hooks/init/
*/
function cppchild_register_acf_blocks() {
/**
* We register our blocks with WordPress's handy
* register_block_type();
*
* @link https://developer.wordpress.org/reference/functions/register_block_type/
*/
if( ! function_exists( 'cppchild_register_acf_blocks' ) )
return;
register_block_type( __DIR__ . '/blocks/two-column' );
register_block_type( __DIR__ . '/blocks/three-column' );
register_block_type( __DIR__ . '/blocks/testimonial' );
}
// Here we call our cppchild_register_acf_block() function on init.
add_action( 'init', 'cppchild_register_acf_blocks' );
/**
* Overrides the theme_mod to default to Bootstrap 5
*
* This function uses the `theme_mod_{$name}` hook and
* can be duplicated to override other theme settings.
*
* @return string
*/
function understrap_default_bootstrap_version() {
return 'bootstrap5';
}
add_filter( 'theme_mod_understrap_bootstrap_version', 'understrap_default_bootstrap_version', 20 );
/**
* Loads javascript for showing customizer warning dialog.
*/
function understrap_child_customize_controls_js() {
wp_enqueue_script(
'understrap_child_customizer',
get_stylesheet_directory_uri() . '/js/customizer-controls.js',
array( 'customize-preview' ),
'20130508',
true
);
}
add_action( 'customize_controls_enqueue_scripts', 'understrap_child_customize_controls_js' );
// Add shortcode to insert PHP date() in any widget
// Just add: [current_date] to display the current year.
function current_date_shortcode( ) {
return date('Y');
}
add_shortcode( 'current_date', 'current_date_shortcode' );
// Add shortcode to insert Site Name in any widget
// Just add: [site_name] to display the site name.
function site_name_shortcode( ) {
$site_title = get_bloginfo( 'name');
return $site_title;
}
add_shortcode( 'site_name', 'site_name_shortcode' );
// Used to add class to custom logo
add_filter( 'wp_get_attachment_image_attributes', function( $attr )
{
if( isset( $attr['class'] ) && 'custom-logo' === $attr['class'] )
$attr['class'] = 'custom-logo img-logo';
return $attr;
} );
// adds excerpts ability to pages
add_post_type_support( 'page', 'excerpt' );
/*
// Changing excerpt more
function new_excerpt_more($more) {
global $post;
remove_filter('excerpt_more', 'new_excerpt_more');
return ' <a class="read_more" href="'. get_permalink($post->ID) . '">' . ' do whatever you want to update' . '</a>';
}
add_filter('excerpt_more','new_excerpt_more',11); */
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
// builds a list of pages and displays with a shortcode
function display_subset_of_pages() {
// Define the query arguments
$args = array(
'post_type' => 'page',
'posts_per_page' => 6, // Number of pages to display
'orderby' => 'date', // Order by date
'order' => 'DESC', // Order descending
'post__in' => array(187, 189, 195, 296, 352, 368) // Array of specific page IDs to include
);
// Custom query
$query = new WP_Query($args);
// Check if the query has pages
if ($query->have_posts()) {
$output = '<div class="page-subset">';
// Loop through the pages
while ($query->have_posts()) {
$query->the_post();
$output .= '<div class="page-item">';
if (has_post_thumbnail()) {
$output .= '<div class="featured-image">' . get_the_post_thumbnail(get_the_ID(), 'medium') . '</div>';
}
$output .= '<p class="title">' . get_the_title() . '</p>';
$output .= '<div class="page-content">' . get_the_excerpt() . '</div>';
$output .= '<a href="' . get_permalink() . '" class="read-more"><i class="fa fa-arrow-circle-right"><span class="read-more-text">Read more</span></i></a>';
$output .= '</div>';
}
$output .= '</div>';
// Restore original Post Data
wp_reset_postdata();
} else {
$output = '<p>No pages found.</p>';
}
return $output;
}
// Register the shortcode
add_shortcode('subset_of_pages', 'display_subset_of_pages');
// Two Column Block start
// Register ACF block type
function acf_two_column_block_register_block() {
// Check if function exists.
if( function_exists('acf_register_block_type') ) {
// Register a two-column block.
acf_register_block_type(array(
'name' => 'two-column-block',
'title' => __('Two Column Block'),
'description' => __('A custom two-column block.'),
'render_callback' => 'acf_two_column_block_render_callback',
'category' => 'formatting',
'icon' => 'columns',
'keywords' => array( 'columns', 'two columns' ),
'enqueue_assets' => function(){
wp_enqueue_style( 'acf-two-column-block-style', plugin_dir_url( __FILE__ ) . 'style.css' );
}
));
}
}
add_action('acf/init', 'acf_two_column_block_register_block');
// Render callback function
function acf_two_column_block_render_callback( $block ) {
// Get field values
$column_1_content = get_field('column_1_content') ?: '';
$column_1_background_image = get_field('column_1_background_image');
$column_1_background_color = get_field('column_1_background_color') ?: '';
$column_1_button_text = get_field('column_1_button_text') ?: '';
$column_1_button_link = get_field('column_1_button_link') ?: '';
$column_2_content = get_field('column_2_content') ?: '';
$column_2_background_image = get_field('column_2_background_image');
$column_2_background_color = get_field('column_2_background_color') ?: '';
$column_2_button_text = get_field('column_2_button_text') ?: '';
$column_2_button_link = get_field('column_2_button_link') ?: '';
$image_side = get_field('image_side') ?: 'right';
// Prepare column content
$column_1_style = '';
if ($column_1_background_image) {
$column_1_style .= "background-image: url(" . esc_url($column_1_background_image) . ");";
}
if ($column_1_background_color) {
$column_1_style .= "background-color: " . esc_attr($column_1_background_color) . ";";
}
$column_2_style = '';
if ($column_2_background_image) {
$column_2_style .= "background-image: url(" . esc_url($column_2_background_image) . ");";
}
if ($column_2_background_color) {
$column_2_style .= "background-color: " . esc_attr($column_2_background_color) . ";";
}
$column_with_image = sprintf(
'<div class="wp-block-column" style="%s">
%s
%s
</div>',
esc_attr($column_2_style),
$column_2_content,
$column_2_button_text ? sprintf('<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="%s">%s</a></div>
</div>', esc_url($column_2_button_link), esc_html($column_2_button_text)) : ''
);
$column_without_image = sprintf(
'<div class="wp-block-column" style="%s">
%s
%s
</div>',
esc_attr($column_1_style),
$column_1_content,
$column_1_button_text ? sprintf('<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="%s">%s</a></div>
</div>', esc_url($column_1_button_link), esc_html($column_1_button_text)) : ''
);
// Render columns based on image side
if ($image_side === 'left') {
echo '<div class="full-width-two-column">' . $column_with_image . $column_without_image . '</div>';
} else {
echo '<div class="full-width-two-column">' . $column_without_image . $column_with_image . '</div>';
}
}
// ACF fields
function acf_two_column_block_fields() {
if( function_exists('acf_add_local_field_group') ) {
acf_add_local_field_group(array(
'key' => 'group_two_column_block',
'title' => 'Two Column Block',
'fields' => array(
// Tab for Column 1
array(
'key' => 'field_tab_column_1',
'label' => 'Column 1',
'type' => 'tab',
'placement' => 'top',
'wrapper' => array(
'width' => '50',
),
),
array(
'key' => 'field_column_1_content',
'label' => 'Column 1 Content',
'name' => 'column_1_content',
'type' => 'wysiwyg',
'instructions' => 'Add content for the first column.',
'wrapper' => array(
'width' => '100',
),
),
array(
'key' => 'field_column_1_background_image',
'label' => 'Column 1 Background Image',
'name' => 'column_1_background_image',
'type' => 'image',
'instructions' => 'Select a background image for the first column.',
'return_format' => 'url',
'wrapper' => array(
'width' => '100',
),
),
array(
'key' => 'field_column_1_background_color',
'label' => 'Column 1 Background Color',
'name' => 'column_1_background_color',
'type' => 'color_picker',
'instructions' => 'Select a background color for the first column.',
'wrapper' => array(
'width' => '100',
),
),
array(
'key' => 'field_column_1_button_text',
'label' => 'Column 1 Button Text',
'name' => 'column_1_button_text',
'type' => 'text',
'instructions' => 'Add text for the button in the first column.',
'wrapper' => array(
'width' => '100',
),
),
array(
'key' => 'field_column_1_button_link',
'label' => 'Column 1 Button Link',
'name' => 'column_1_button_link',
'type' => 'url',
'instructions' => 'Add the link for the button in the first column.',
'wrapper' => array(
'width' => '100',
),
),
// Tab for Column 2
array(
'key' => 'field_tab_column_2',
'label' => 'Column 2',
'type' => 'tab',
'placement' => 'top',
'wrapper' => array(
'width' => '50',
),
),
array(
'key' => 'field_column_2_content',
'label' => 'Column 2 Content',
'name' => 'column_2_content',
'type' => 'wysiwyg',
'instructions' => 'Add content for the second column.',
'wrapper' => array(
'width' => '100',
),
),
array(
'key' => 'field_column_2_background_image',
'label' => 'Column 2 Background Image',
'name' => 'column_2_background_image',
'type' => 'image',
'instructions' => 'Select a background image for the second column.',
'return_format' => 'url',
'wrapper' => array(
'width' => '100',
),
),
array(
'key' => 'field_column_2_background_color',
'label' => 'Column 2 Background Color',
'name' => 'column_2_background_color',
'type' => 'color_picker',
'instructions' => 'Select a background color for the second column.',
'wrapper' => array(
'width' => '100',
),
),
array(
'key' => 'field_column_2_button_text',
'label' => 'Column 2 Button Text',
'name' => 'column_2_button_text',
'type' => 'text',
'instructions' => 'Add text for the button in the second column.',
'wrapper' => array(
'width' => '100',
),
),
array(
'key' => 'field_column_2_button_link',
'label' => 'Column 2 Button Link',
'name' => 'column_2_button_link',
'type' => 'url',
'instructions' => 'Add the link for the button in the second column.',
'wrapper' => array(
'width' => '100',
),
),
// Image Side Field
array(
'key' => 'field_image_side',
'label' => 'Image Side',
'name' => 'image_side',
'type' => 'select',
'instructions' => 'Choose which side the background image will be on.',
'choices' => array(
'left' => 'Left',
'right' => 'Right',
),
'default_value' => 'right',
'allow_null' => 0,
'multiple' => 0,
'ui' => 1,
'return_format' => 'value',
'wrapper' => array(
'width' => '100',
),
),
),
'location' => array(
array(
array(
'param' => 'block',
'operator' => '==',
'value' => 'acf/two-column-block',
),
),
),
));
}
}
add_action('acf/init', 'acf_two_column_block_fields');
// Two Column Block end