Skip to content

Instantly share code, notes, and snippets.

@nathaningram
Last active April 14, 2024 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathaningram/9d383bb36096f5a0df7edbaad7ab0ca4 to your computer and use it in GitHub Desktop.
Save nathaningram/9d383bb36096f5a0df7edbaad7ab0ca4 to your computer and use it in GitHub Desktop.
Creating a Starter Site 2022 - Custom Functions - Beaver Builder
<?php
/*
Plugin Name: Custom Functions for Beaver Builder
Plugin URI: https://nathaningram.com
Description: Extend and Customize Beaver Builder
Version: 2023.11
Author: Nathan Ingram
Author URI: https://nathaningram.com
License: GPL2
*/
// Allow Beaver Builder modules to use custom image sizes
add_filter('image_size_names_choose', 'ni_insert_custom_image_sizes');
function ni_insert_custom_image_sizes($sizes) {
global $_wp_additional_image_sizes;
if (empty($_wp_additional_image_sizes)) {
return $sizes;
}
foreach ($_wp_additional_image_sizes as $id => $data) {
if (!isset($sizes[$id])) {
$sizes[$id] = ucfirst(str_replace('-', ' ', $id));
}
}
return $sizes;
}
// Enable SVG Uploads in Beaver Builder Modules
add_filter( 'fl_module_upload_regex', function( $regex, $type, $ext, $file ) {
$regex['photo'] = '#(jpe?g|png|gif|bmp|tiff?|svg)#i';
return $regex;
}, 10, 4 );
// Add a Notes Field to BvB Modules
function ni_register_notes( $form, $slug ) {
if ( 'module_advanced' === $slug ) {
$form[ 'sections' ][ 'css_selectors' ][ 'fields' ][ 'bt_notes' ] = [
'type' => 'textarea',
'label' => 'Your Notes (Not displayed on website)',
'placeholder' => 'Notes',
'rows' => '6'
];
}
if ( 'col' === $slug || 'row' === $slug ) {
$form[ 'tabs' ][ 'advanced' ][ 'sections' ][ 'css_selectors' ][ 'fields' ][ 'bt_notes' ] = [
'type' => 'textarea',
'label' => 'Your Notes (Not displayed on website)',
'placeholder' => 'Notes',
'rows' => '6'
];
}
return $form;
}
add_filter( 'fl_builder_register_settings_form', 'ni_register_notes', 100, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment