-
Notifications
You must be signed in to change notification settings - Fork 5
/
functions.php
273 lines (235 loc) · 7.64 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
<?php
/**
* Beavertron Theme
*
* @package beavertron
* @author NeilGee
* @license GPL-2.0
* @link http://wpbeaches.com/
*/
/**
* Custom Image Sizes
* Image sizes - add in required image sizes here. Not working for theme if inside after_setup_theme function
* @since 1.0.0
*/
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'blog-feature', 800, 533, true );
add_image_size( 'medium', 300, 300, true ); // Overwrite default and hard cropping
}
/**
* Filtering the Customizer
* Not working for theme if inside after_setup_theme function - so thats why it is here.
* @since 1.7.0
*/
require_once( get_stylesheet_directory() . '/includes-child/customizer-defaults.php' );
add_action( 'after_setup_theme', 'bt_theme_setup', 15 );
/**
* Beavertron theme set up
*
* @since 1.0.0
*/
function bt_theme_setup() {
/**
* Defines
* Child theme constant settings.
* @since 1.0.0
*/
define( 'CHILD_THEME_NAME', 'beavertron' );
define( 'CHILD_THEME_URL', 'http://wpbeaches.com' );
define( 'CHILD_THEME_VERSION', '1.7.1' );
define( 'FL_CHILD_THEME_DIR', get_stylesheet_directory() );
define( 'FL_CHILD_THEME_URL', get_stylesheet_directory_uri() );
// Allow SVG Upload
define( 'ALLOW_UNFILTERED_UPLOADS', true );
// Fix BB 403 errors via Ajax calls
define( 'FL_BUILDER_MODSEC_FIX', true );
/**
* Clean up WP Head
* @since 1.0.0
*/
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wp_shortlink_wp_head' );
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10 );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
/**
* Load Beaver Builder classes, core class
* @since 1.0.0
*/
require_once( get_stylesheet_directory() . '/classes/class-fl-child-theme.php');
// Actions - BB Default way - This theme calls required files below.
add_action( 'wp_enqueue_scripts', 'FLChildTheme::enqueue_scripts', 1000 );
add_action( 'fl_builder_ui_enqueue_scripts', 'FLChildTheme::enqueue_scripts', 1000 );
/**
* Add Customizer Options and CSS output.
* @since 1.0.0
*/
require_once( get_stylesheet_directory() . '/includes-child/customizer-panels.php' );
require_once( get_stylesheet_directory() . '/includes-child/inline-css-style.php' );
require_once( get_stylesheet_directory() . '/includes-child/inline-css-style-login.php' );
/**
* WOO Customizer Options
* @since 1.0.0
*/
if ( class_exists( 'WooCommerce' ) ) {
include_once( get_stylesheet_directory() . '/includes-child/woocommerce/customizer-woo.php' );
}
/**
* Client Logo for WP Login and backend dashboard admin clean up.
* @since 1.0.0
*/
include_once( get_stylesheet_directory() . '/includes-child/dashboard.php' );
/**
* Remove Default BB Mobile Menu.
* @since 1.0.0
*/
//include_once( get_stylesheet_directory() . '/includes-child/mobile-menu-removal.php' );
/**
* Load in Beaver Builder Plugin functions
* @since 1.0.0
*/
if ( class_exists( 'FLBuilderModel' ) ) {
// BeaverBuilder functions
include_once( get_stylesheet_directory() . '/includes-child/beaverbuilder.php' );
}
/**
* Load in WooCommerce functions
* @since 1.0.0
*/
if ( class_exists( 'WooCommerce' ) ) {
include_once( get_stylesheet_directory() . '/includes-child/woocommerce/woocommerce.php' );
}
/**
* Load in Gravity Forms functions
* @since 1.0.0
*/
if ( class_exists( 'GFCommon' ) ) {
include_once( get_stylesheet_directory() . '/includes-child/gravity.php' );
}
/**
* Load in ACF functions
* @since 1.7.0
*/
if ( class_exists( 'acf' ) ) {
include_once( get_stylesheet_directory() . '/includes-child/acf.php' );
}
/**
* Improve Cache Puging on Runcloud NGINX
* @since 1.0.0
*/
//require_once get_stylesheet_directory() . '/includes-child/cache-buster.php';
/**
* Get the plugins ffrom TGM Plugin Activation
* @since 1.0.0
*/
//require_once get_stylesheet_directory() . '/plugins.php';
/**
* Allow the theme to be translated.
* @since 1.0.0
*/
load_theme_textdomain( 'beavertron', get_stylesheet_directory_uri() . '/languages' );
add_filter( 'intermediate_image_sizes_advanced', 'bt_remove_default_images' );
/**
* Remove default image sizes
* @since 1.0.0
*/
function bt_remove_default_images( $sizes ) {
// unset( $sizes['small']); // 150px
// unset( $sizes['medium']); // 300px
// unset( $sizes['large']); // 1024px
unset( $sizes['medium_large']); // 768px
return $sizes;
}
add_filter( 'upload_mimes', 'bt_add_svg_images' );
/**
* Allow SVG Images Via Media Uploader.
* @since 1.0.0
*/
function bt_add_svg_images( $mimetypes ) {
$mimetypes['svg'] = 'image/svg xml';
return $mimetypes;
}
/**
* Add support for custom logo change the dimensions to suit. Need WordPress 4.5 for this.
* @since 1.0.0
*/
add_theme_support( 'custom-logo', array(
'height' => 100, // set to your dimensions
'width' => 300,// set to your dimensions
'flex-height' => true,
'flex-width' => true,
));
add_shortcode( 'client_logo', 'bt_client_logo' );
/**
* Position the content with a shortcode [client_logo]
* @since 1.0.0
*/
function bt_client_logo() {
ob_start();
if ( function_exists( 'the_custom_logo' ) ) {
echo '<div itemscope itemtype="http://schema.org/Organization">' . get_custom_logo() . '</div>';
}
return ob_get_clean();
}
add_action( 'add_attachment', 'bt_image_meta_upon_image_upload' );
/**
* Automatically set the image Title, Alt-Text, Caption & Description upon upload
* @since 1.0.0
* @link https://brutalbusiness.com/automatically-set-the-wordpress-image-title-alt-text-other-meta/
*/
function bt_image_meta_upon_image_upload( $post_ID ) {
// Check if uploaded file is an image, else do nothing
if ( wp_attachment_is_image( $post_ID ) ) {
$my_image_title = get_post( $post_ID )->post_title;
// Sanitize the title: remove hyphens, underscores & extra spaces:
$my_image_title = preg_replace( '%\s*[-_\s] \s*%', ' ', $my_image_title );
// Sanitize the title: capitalize first letter of every word (other letters lower case):
$my_image_title = ucwords( strtolower( $my_image_title ) );
// Create an array with the image meta (Title, Caption, Description) to be updated
// Note: comment out the Excerpt/Caption or Content/Description lines if not needed
$my_image_meta = array(
'ID' => $post_ID, // Specify the image (ID) to be updated
'post_title' => $my_image_title, // Set image Title to sanitized title
//'post_excerpt' => $my_image_title, // Set image Caption (Excerpt) to sanitized title
//'post_content' => $my_image_title, // Set image Description (Content) to sanitized title
);
// Set the image Alt-Text
update_post_meta( $post_ID, '_wp_attachment_image_alt', $my_image_title );
// Set the image meta (e.g. Title, Excerpt, Content)
wp_update_post( $my_image_meta );
}
}
/**
* Allow shortcode to run in widgets.
* @since 1.0.0
*/
add_filter( 'widget_text', 'do_shortcode' );
//add_filter( 'widget_text','bt_execute_php_widgets' );
/**
* Allow PHP code to run in Widgets.
* @since 1.0.0
*/
function bt_execute_php_widgets( $html ) {
if ( strpos( $html, '<' . '?php' ) !== false ) {
ob_start();
eval( '?' . '>' . $html );
$html = ob_get_contents();
ob_end_clean();
}
return $html;
}
add_filter( 'fl_ace_editor_settings', 'custom_ace_editor' );
/**
* Show line numbers and wrap text in Ace editor
* @since 1.7.0
*/
function custom_ace_editor() {
$change_ace = array(
'showLineNumbers' => true,
'wrap' => true,
);
return $change_ace;
}
} // Closing After Set Up Hook