TypeRocket v1 Pro users can now upgrade to TypeRocket v5 at their convenience.
Widgets
( v1 )
Getting Started
To create custom widgets with fields, you will need to extend the \TypeRocket\Register\BaseWidget
class.
class TR_Widget extends \TypeRocket\Register\BaseWidget {
/**
* Sets up the widgets name etc
*/
public function __construct() {
parent::__construct( 'tr_widget', 'Tr Widget', [
'classname' => 'Tr_Widget',
'description' => 'Tr Widget is awesome'
] );
}
public function backend($fields)
{
echo $this->form->text('Title');
echo $this->form->date('Date');
}
public function frontend($args, $fields)
{
// make frontend code
}
public function save($new_fields, $old_fields)
{
// You will want to sanitize your $new_fields data
return $new_fields;
}
}
Then register it in WordPress.
add_action( 'widgets_init', function(){
register_widget( 'TR_Widget' );
});
Found a typo? Something is wrong in this documentation? Fork and edit it!