-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
255 lines (236 loc) · 8.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
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
<?php
if ( !defined('CSS_JS_VERSION') ) define( 'CSS_JS_VERSION', '1.02');
if ( !defined('TEMPLATE_PATH') ) define( 'TEMPLATE_PATH', get_bloginfo('stylesheet_directory'));
if ( !defined('TEMPLATE_IMAGE_PATH') ) define( 'TEMPLATE_IMAGE_PATH', get_bloginfo('stylesheet_directory') . '/assets/img');
function pr($r) {
echo '<pre>';
print_r($r);
echo '</pre>';
}
function pd($r) {
echo '<pre>';
print_r($r);
echo '</pre>';
die();
}
/**
* Custom body classes.
*/
function ccm_body_class($classes) {
global $post;
// homepage or not
if (is_front_page() == FALSE) {
$classes[] = 'not-home';
}
// has hero?
$hero = get_field('hero');
if (isset($hero['type']) && $hero['type'] != 'none') {
$classes[] = 'with-hero';
}
// post type
$classes[] = sprintf('post-type-%s', $post->post_type);
// page slug
$post_slug = $post->post_name;
$classes[] = sprintf('page-%s', $post_slug);
// permalink classes
$permalink = str_replace(home_url(), '', get_permalink());
$permalink_parts = explode('/', $permalink);
foreach($permalink_parts as $part) {
if (!empty($part)) {
$classes[] = sprintf('page-%s', $part);
}
}
// user logged in status
if (is_user_logged_in()) {
$classes[] = 'logged-in';
}
// user role
$current_user = wp_get_current_user();
if ($current_user && in_array('administrator', $current_user->roles)) {
$classes[] = 'is-admin';
}
return $classes;
}
add_filter('body_class', 'ccm_body_class');
// add css and javascript
function ccm_css_js() {
wp_enqueue_script("jquery-ol", "https://code.jquery.com/jquery-3.7.1.min.js");
wp_enqueue_script( 'flickity-js', 'https://unpkg.com/flickity@2/dist/flickity.pkgd.min.js', array(), '', true );
wp_enqueue_script( 'flickity-js-fade', 'https://cdn.jsdelivr.net/npm/flickity-fade@1/flickity-fade.js', array('flickity-js'), '', true);
wp_enqueue_script( 'parallax-js', get_template_directory_uri() . '/assets/js/parallax.js', array("jquery-ol"), '1.0.0', true );
wp_enqueue_script( 'headroom-js', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/headroom.min.js', array(), '', true );
wp_enqueue_script( 'global', get_stylesheet_directory_uri() . '/assets/js/global.min.js', array("jquery-ol"), CSS_JS_VERSION, true );
// wp_enqueue_script( 'pages', get_template_directory_uri() . '/assets/js/pages.min.js', array("jquery-core-js"), CSS_JS_VERSION, true );
// css
wp_enqueue_style( 'flickity-css', 'https://unpkg.com/flickity@2/dist/flickity.min.css', array(), '', 'all' );
wp_enqueue_style( 'flickity-css-fade', 'https://cdn.jsdelivr.net/npm/flickity-fade@1/flickity-fade.css', array(), '', 'all' );
wp_enqueue_style( 'app', get_stylesheet_directory_uri() . '/assets/css/app.css', array(), CSS_JS_VERSION, 'all' );
}
add_action('wp_enqueue_scripts', 'ccm_css_js');
// disable emojis
function ccm_disable_wp_emoji() {
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
// filter to remove TinyMCE emojis
add_filter( 'tiny_mce_plugins', 'ccm_disable_emoji_tinymce' );
}
function ccm_disable_emoji_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}
add_action( 'init', 'ccm_disable_wp_emoji' );
add_filter( 'emoji_svg_url', '__return_false' );
// add title tag
function ccm_theme_support() {
add_theme_support( 'title-tag' );
}
add_action( 'after_setup_theme', 'ccm_theme_support' );
add_theme_support('post-thumbnails');
// add_image_size( 'press_image', 610, 740, TRUE);
// add_image_size( 'person_image', 610, 480, TRUE);
add_theme_support( 'menus' );
// add acf global content page
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Global Content',
'menu_title' => 'Global Content',
));
// acf_add_options_page(array(
// 'page_title' => 'Theme Settings',
// 'menu_title' => 'Theme Settings',
// ));
}
// editor css for blocks preview styling
add_editor_style( 'assets/css/editor.css' );
add_theme_support( 'editor-styles' );
// blocks
add_action('acf/init', 'ccm_acf_init_block_types');
function ccm_acf_init_block_types() {
if( function_exists('acf_register_block_type') ) {
acf_register_block_type(
array(
'name' => 'text',
'title' => __('Text'),
'render_template' => 'blocks/text.php',
'category' => 'calvin-custom-theme',
'icon' => 'buddicons-buddypress-logo',
'keywords' => array( 'text' ),
'mode' => 'edit',
'supports' => array('mode' => TRUE, 'anchor' => TRUE),
)
);
acf_register_block_type(
array(
'name' => 'media',
'title' => __('Media'),
'render_template' => 'blocks/media.php',
'category' => 'calvin-custom-theme',
'icon' => 'buddicons-buddypress-logo',
'keywords' => array( 'media' ),
'mode' => 'edit',
'supports' => array('mode' => TRUE, 'anchor' => TRUE),
)
);
acf_register_block_type(
array(
'name' => 'text-columns',
'title' => __('Text Columns'),
'render_template' => 'blocks/text-columns.php',
'category' => 'calvin-custom-theme',
'icon' => 'buddicons-buddypress-logo',
'keywords' => array( 'text-columns' ),
'mode' => 'edit',
'supports' => array('mode' => TRUE, 'anchor' => TRUE),
)
);
acf_register_block_type(
array(
'name' => 'image-carousel',
'title' => __('Image Carousel'),
'render_template' => 'blocks/image-carousel.php',
'category' => 'calvin-custom-theme',
'icon' => 'buddicons-buddypress-logo',
'keywords' => array( 'image carousel' ),
'mode' => 'edit',
'supports' => array('mode' => TRUE, 'anchor' => TRUE),
)
);
acf_register_block_type(
array(
'name' => 'image-grid',
'title' => __('Image Grid'),
'render_template' => 'blocks/image-grid.php',
'category' => 'calvin-custom-theme',
'icon' => 'buddicons-buddypress-logo',
'keywords' => array( 'image grid' ),
'mode' => 'edit',
'supports' => array('mode' => TRUE, 'anchor' => TRUE),
)
);
acf_register_block_type(
array(
'name' => 'content-index',
'title' => __('Content Index'),
'render_template' => 'blocks/content-index.php',
'category' => 'calvin-custom-theme',
'icon' => 'buddicons-buddypress-logo',
'keywords' => array( 'content index' ),
'mode' => 'edit',
'supports' => array('mode' => TRUE, 'anchor' => TRUE),
)
);
acf_register_block_type(
array(
'name' => 'content-accordion',
'title' => __('Content Accordion'),
'render_template' => 'blocks/content-accordion.php',
'category' => 'calvin-custom-theme',
'icon' => 'buddicons-buddypress-logo',
'keywords' => array( 'content accordion' ),
'mode' => 'edit',
'supports' => array('mode' => TRUE, 'anchor' => TRUE),
)
);
}
}
// hide core blocks from editor
function ccm_allowed_block_types( $allowed_blocks, $editor_context ) {
return array(
'acf/text',
'acf/media',
'acf/text-columns',
'acf/image-carousel',
'acf/image-grid',
'acf/content-index',
'acf/content-accordion',
);
}
add_filter( 'allowed_block_types_all', 'ccm_allowed_block_types', 10, 2);
add_filter( 'gform_disable_form_theme_css', '__return_true' );
function ccm_custom_new_menu() {
register_nav_menus(
array(
'main-navigation' => __( 'Main Navigation' ),
)
);
}
add_action( 'init', 'ccm_custom_new_menu' );
function ccm_redirect_to_first_child() {
global $post;
$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
$firstchild = is_array($pagekids) && count($pagekids) > 0 ? $pagekids[0] : null;
if ($firstchild) {
wp_redirect(get_permalink($firstchild->ID));
exit;
}
}
require_once(__DIR__.'/functions-theme.php');
require_once(__DIR__.'/shortcodes.php');