Introducing The Breakdance Builder Conditions Mode for CodeWP
By James LePage, CodeWP Founder
December 8, 2022
Contents
We're excited to announce a new mode, now available for public alpha testing: Breakdance Builder Conditions.
Breakdance Builder is a powerful page builder for WordPress. One of its features is conditional visibility - depending on specific conditions "ie, if the user is logged in", you can show/hide content. This is great for creating highly dynamic websites.
With CodeWP, you can now prompt for a custom Breakdance Builder Condition generation. This mode will generate a code snippet (using Breakdance's Conditions API) that adds a custom condition to Breakdance.
Ask for the condition you want in plain English
Get the code generated and install it on your (staging first) site
Use the new, custom condition WITHOUT needing to code anything
This platform is in it's alpha testing phase. You can access it free for the duration of the testing period by: 1) signing up, 2) clicking 5 day free trial, 3) entering code isotropic_alpha.
Please note: You MUST trigger the Conditions PHP at init. Including it in a custom plugin or snippet management tool without hooking into init won't work.
This mode is ever-improving and learns from your generation rankings. To benefit everybody, please rate generations:
Let's take a look at some real world Breakdance Builder Conditions, generated by CodeWP.
Be sure that you've switched into the "Breakdance Conditions" mode, as the general modes will not produce accurate results.
Prompt: check if post has specific heading type in content
add_action("breakdance_register_template_types_and_conditions", function () {
BreakdanceConditionsAPIregister([
"supports" => ["element_display"],
"slug" => "post-has-heading-type", // MUST BE UNIQUE
"label" => "Post has heading type",
"category" => "Post",
"operands" => ["equals"],
// providing a dropdown of values is optional. if 'values' is not provided, a text input will be provided instead of a dropdown
"values" => function () {
return [
[
"label" => "Heading type",
"items" => [
["text" => "h1", "value" => "h1"],
["text" => "h2", "value" => "h2"],
["text" => "h3", "value" => "h3"],
["text" => "h4", "value" => "h4"],
["text" => "h5", "value" => "h5"],
["text" => "h6", "value" => "h6"],
],
],
];
},
/*
when specifying possible values for a dropdown,
you can optionally make the dropdown a multiselect
*/
"allowMultiselect" => false,
/*
this function will be called to evaluate the condition
if it returns true, the element will be shown
if it returns false, the element will be hidden
*/
"callback" => function (string $operand, $value) {
$myVal = "h1"; // usually, you'd get $myVal from somewhere, i.e. global $post; $myVal = $post->ID;
/*
if allowMultiselect is false, $value will be a string.
use it like so:
if ($operand === 'equals') {
return $myVal === $value;
}
if ($operand === 'not equals') {
return $myVal !== $value;
}
*/
/*
in our example, allowMultiselect is true, which means $value will be an array of strings
*/
if ($operand === "equals") {
return in_array($myVal, $value);
}
if ($operand === "not equals") {
return !in_array($myVal, $value);
}
return false;
},
]);
});
Generation ID:cmpl-6LLdJ3NSl5h2t8fox079Rr1bhW2Lt
Prompt: total weight of all WooCommerce products in cart (greater than, less than)