New! TypeRocket v5 is now available. See docs.
Access all of Typerocket. Get Pro.
Widgets
( v4 )
Create custom widgets with TypeRocket fields.
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!