block_name, $blocks ) ) {
return;
}
// Define the block, name and icon.
$this->block = $blocks[ $this->block_name ];
$this->name = esc_html( $this->block['title'] );
$this->icon_path = CONVERTKIT_PLUGIN_PATH . '/' . $this->block['icon'];
}
/**
* Defines the fields that can be configured for this Module
*
* @since 2.5.6
*/
public function get_fields() {
// Bail if no block.
if ( is_wp_error( $this->block ) ) {
return array();
}
// Bail if the block is false.
// This happens on Divi 5 theme activation.
if ( ! $this->block ) {
return array();
}
// Bail if no fields i.e. this is a frontend request.
if ( ! array_key_exists( 'fields', $this->block ) ) {
return array();
}
if ( ! is_array( $this->block['fields'] ) ) {
return array();
}
// Build fields.
$fields = array();
foreach ( $this->block['fields'] as $field_name => $field ) {
// Start building field definition.
$fields[ $field_name ] = array(
'type' => $field['type'],
'default' => $this->get_default_value( $field ),
'description' => ( isset( $field['description'] ) ? $field['description'] : '' ),
'label' => $field['label'],
'toggle_slug' => 'main_content',
);
// Add field condition, if defined.
if ( isset( $field['display_if'] ) ) {
// Define value as 'on' or 'off' if it's 1 or 0 and the comparison field is a toggle field.
$value = $field['display_if']['value'];
if ( $this->block['fields'][ $field['display_if']['key'] ]['type'] === 'toggle' ) {
$value = ( ( $value === '1' ) || ( $value === 1 ) ? 'on' : 'off' );
}
// Add the comparison condition.
$fields[ $field_name ]['show_if'] = array(
$field['display_if']['key'] => $value,
);
}
// Add/change field parameters depending on the field's type.
switch ( $field['type'] ) {
/**
* Number
*/
case 'number':
$fields[ $field_name ] = array_merge(
$fields[ $field_name ],
array(
'type' => 'range',
'range_settings' => array(
'min' => $field['min'],
'max' => $field['max'],
'step' => $field['step'],
),
'unitless' => true,
)
);
break;
/**
* Select
*/
case 'resource':
case 'select':
// For select dropdowns, Divi treats the first