CodeWP

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.

  1. Ask for the condition you want in plain English
  2. Get the code generated and install it on your (staging first) site
  3. 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.

Already Logged In? Click Here To Launch Breakdance Conditions Mode

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:

Learn about why this is important

Breakdance Builder Conditions Mode Prompt Examples

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)

add_action("breakdance_register_template_types_and_conditions", function () { BreakdanceConditionsAPIregister([ "supports" => ["element_display"], "slug" => "wc-cart-weight-condition", // MUST BE UNIQUE "label" => "WooCommerce Cart Weight Condition", "category" => "WooCommerce", "operands" => ["greater than", "less than"], "values" => function () { return [ [ "label" => "Weight", "items" => [ ["text" => "1", "value" => "1"], ["text" => "2", "value" => "2"], ["text" => "3", "value" => "3"], ["text" => "4", "value" => "4"], ["text" => "5", "value" => "5"], ["text" => "6", "value" => "6"], ["text" => "7", "value" => "7"], ["text" => "8", "value" => "8"], ["text" => "9", "value" => "9"], ["text" => "10", "value" => "10"], ], ], ]; }, "allowMultiselect" => false, "callback" => function (string $operand, $value) { if (!function_exists("WC")) { return false; } $cart_weight = 0; foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { $product = $cart_item["data"]; $cart_weight += $product->get_weight() * $cart_item["quantity"]; } if ($operand === "greater than") { return $cart_weight > $value; } if ($operand === "less than") { return $cart_weight < $value; } return false; }, ]); }); Generation ID:cmpl-6LLsAXbXuA0NwasV3USzFFPZtbHS8

Using Breakdance Builder Conditions CodeWP Generations

Using the generation is easy. First, let's export it. Do that by clicking the export button in the generator. (Learn more about the export feature here)

Then, install it on a testing website by importing the snippet to a code snippet management plugin. (Learn more about testing snippets - DO NOT SKIP THIS STEP or you may break your production site)

Finally, head into the Breakdance Conditions builder, choose your new condition, and check the front end to see if it works.

This new feature, and dozens more
php
PHP, JS or jQuery
select_all
AI models trained for WordPress & popular plugins
switch_access_shortcut
Unlimited generations
card_giftcard
100% free trial
Start For Free
link