This snippet will add a new Month condition, in the Date & Time section:
add_action("breakdance_register_template_types_and_conditions", function () {
\Breakdance\ConditionsAPI\register([
"supports" => ["element_display", "templating"],
"slug" => "bd-month-condition", // MUST BE UNIQUE
"label" => "Month (WordPress)",
"category" => "Date & Time",
"operands" => [OPERAND_ONE_OF, OPERAND_NONE_OF],
"values" => function () {
return [
[
"label" => "Month",
"items" => [
["text" => "January", "value" => "January"],
["text" => "February", "value" => "February"],
["text" => "March", "value" => "March"],
["text" => "April", "value" => "April"],
["text" => "May", "value" => "May"],
["text" => "June", "value" => "June"],
["text" => "July", "value" => "July"],
["text" => "August", "value" => "August"],
["text" => "September", "value" => "September"],
["text" => "October", "value" => "October"],
["text" => "November", "value" => "November"],
["text" => "December", "value" => "December"],
],
],
];
},
"allowMultiselect" => true,
"callback" => function ($operand, $values): bool {
$month = wp_date("F");
switch ($operand) {
case OPERAND_ONE_OF:
return in_array($month, $values);
case OPERAND_NONE_OF:
return !in_array($month, $values);
default:
return false;
}
return false;
},
]);
});
\Breakdance\ConditionsAPI\register([
"supports" => ["element_display", "templating"],
"slug" => "bd-month-condition", // MUST BE UNIQUE
"label" => "Month (WordPress)",
"category" => "Date & Time",
"operands" => [OPERAND_ONE_OF, OPERAND_NONE_OF],
"values" => function () {
return [
[
"label" => "Month",
"items" => [
["text" => "January", "value" => "January"],
["text" => "February", "value" => "February"],
["text" => "March", "value" => "March"],
["text" => "April", "value" => "April"],
["text" => "May", "value" => "May"],
["text" => "June", "value" => "June"],
["text" => "July", "value" => "July"],
["text" => "August", "value" => "August"],
["text" => "September", "value" => "September"],
["text" => "October", "value" => "October"],
["text" => "November", "value" => "November"],
["text" => "December", "value" => "December"],
],
],
];
},
"allowMultiselect" => true,
"callback" => function ($operand, $values): bool {
$month = wp_date("F");
switch ($operand) {
case OPERAND_ONE_OF:
return in_array($month, $values);
case OPERAND_NONE_OF:
return !in_array($month, $values);
default:
return false;
}
return false;
},
]);
});