PHP code example of nsrosenqvist / cmb2-widget

1. Go to this page and download the library: Download nsrosenqvist/cmb2-widget library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nsrosenqvist / cmb2-widget example snippets


use NSRosenqvist\CMB2\Widgets\CMB2_Widget;

class MyWidget extends CMB2_Widget
{
    protected $fields = [
        // You can set ID both as the key and in the array
        'title' => [
			'name' 			   => __('Title', 'theme'),
			'type'             => 'text',
		],
    ];

    function __construct($id_base, $name, $widget_options = [], $control_options = [])
    {
        parent::__construct(
            // Base ID of widget
            'my_widget'
            // Widget name will appear in UI
            'My Widget',
            // Widget description
            $widget_options,
            // Widget options
            $control_options
        );
    }
}