-1

I've created a custom element for the WPBakery plugin. I have mapped out a simple checkbox for this element:

array(
    'type' => 'checkbox',
    'heading' => esc_html__( 'Add box shadow?', 'js_composer' ),
    'param_name' => 'add_boxShadow',
    'value' => array('Yes' => 'true'),
    'std' => false,
    'description' => esc_html__('Ticking this will add a shadow below the row.'),
    'group' => __( 'Custom', 'my-text-domain' ),
)

And I have initialised it like so:

$output = ""; 
extract(
      shortcode_atts(
        array(
          'add_boxShadow' => false,
          // 'add_boxShadow' => '', have also tried this
        ),
      $atts
      )
    );

And outputting like this:

<?php 
$shadowBottom = "";
($add_boxShadow = true ? $shadowBottom = "shadow__bottom" : ""); 

$output .= '<div class="wrapper'.$shadowBottom.' "> test </div>';
return $output;
?>

With the above, I'm having the following issues:

  1. A var_dump($add_boxShadow) returns bool(false) bool(false). My guess that's because when the var is initialised, the $add_boxShadow is set to false ('add_boxShadow' => false). However, I've done this so that the checkbox is unticked my default.

  2. In the WPBakery page builder, this is how the field looks:

enter image description here

Which is good, it's unchecked by default which is what I want. However, if I then tick the checkbox, save and update the page, when I go back to that blocks setting, the checkbox is still unticked. Almost as if it's always being rendered false?

Community
  • 1
  • 1
Freddy
  • 683
  • 4
  • 35
  • 114

1 Answers1

0

std options will be false by default. So you dont need to write the false one. Another thing I found that you missid out the shorcode name in shortcode_atts method, which may be another reasons for your problem. Please find the below code which helps :

   array(
        'type' => 'checkbox',
        'heading' => esc_html__( 'Add box shadow?', 'js_composer' ),
        'param_name' => 'add_boxShadow',
        'value' => array('Yes' => 'true'),
        'description' => esc_html__('Ticking this will add a shadow below the row.'),
        'group' => __( 'Custom', 'my-text-domain' ),
    )

    extract( shortcode_atts( array(
                    'add_boxShadow'=>'',
                ), $atts,'<shrotcodename>' ) );


  if($ze_coming_soon_days=='Yes') //code for yes
  {
    //code
  }
Tristup
  • 3,603
  • 1
  • 14
  • 26