Skip to content

Instantly share code, notes, and snippets.

@beaverbuilder
beaverbuilder / cli-command.txt
Last active September 6, 2019 17:18
These snippets are used in the following knowledge base article – <https://kb.wpbeaverbuilder.com/article/220-installl-beaver-builder-via-composer
composer config --global repositories.beaver-builder composer https://composer.wpbeaverbuilder.com/KEY
<?php // Do not copy this line, start from line 3 onwards
function check_field_connections( $is_visible, $node ) {
if ( isset( $node->settings->connections ) ) {
foreach ( $node->settings->connections as $key => $connection ) {
if ( ! empty( $connection ) && empty( $node->settings->$key ) ) {
return false;
}
}
<?php
class FLExampleModule extends FLBuilderModule {
public function __construct() {
parent::__construct( array(
'name' => 'Example',
) );
}
public function filter_settings( $settings ) {
<?php
/**
* Render a single rule for a single device size.
*/
FLBuilderCSS::rule( array(
'selector' => ".fl-node-$id .some-element",
'media' => 'max-width: 980px', // Optional. Can be `default`, `medium`, `responsive` or a custom statement.
'enabled' => 'bar' === $settings->foo, // Optional.
'props' => array(
'background-image' => $settings->bg_image_src,
<?php
'my_text' => array(
'type' => 'text',
'label' => 'My Text',
'preview' => array(
'type' => 'attribute',
'attribute' => 'data-foo',
'selector' => '.my-selector',
'format_callback' => '', // Optional JS format callback.
),
<?php
'text_color' => array(
'type' => 'color',
'label' => 'Text Color',
'preview' => array(
'type' => 'css',
'selector' => '.my-selector',
'property' => 'color',
'important' => true,
),
function myPreviewCallback( args ) {
/**
* Use `args` for any kind of preview logic you can dream of!
*/
console.log( args )
}
<?php
'my_color' => array(
'type' => 'color',
'label' => 'My Color',
'preview' => array(
'type' => 'callback',
'callback' => 'myPreviewCallback',
),
),
<?php
'my_text' => array(
'type' => 'text',
'label' => 'My Text',
'inline_editor' => false,
),
<?php
'my_section' => array(
'title' => 'My Section',
'collapsed' => true,
'fields' => array( ... ),
),