Carbon_Fields\Widget\Widget::setup PHP Method

setup() public method

A wrapper around the default WP widget constructor.
public setup ( string $title, string $description, array $fields, string $classname = '' )
$title string Widget name
$description string Widget description
$fields array Array of fields
$classname string String of CSS classes
    public function setup($title, $description, $fields, $classname = '')
    {
        // require title
        if (!$title) {
            Incorrect_Syntax_Exception::raise('Enter widget title');
        }
        // add custom fields
        $this->add_fields($fields);
        # Generate Widget ID
        $widget_ID = 'carbon_' . preg_replace('~\\s+~', '_', strtolower(trim(preg_replace('/[^a-zA-Z0-9]+/u', '', remove_accents($title)))));
        # Generate Classes
        if (!is_array($classname)) {
            $classname = (array) $classname;
        }
        $classname[] = $widget_ID;
        $classname = implode(' ', $classname);
        $widget_options = compact('description', 'classname', 'widget_ID');
        $this->verify_unique_widget_id($widget_ID);
        parent::__construct($widget_ID, $title, $widget_options, $this->form_options);
    }