PHPackages                             boospot/boo-widget-helper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. boospot/boo-widget-helper

ActiveLibrary

boospot/boo-widget-helper
=========================

Helper class that lets you create, save and sanitize widget fields without dealing with WordPress Widgets API.

151PHP

Since Feb 17Pushed 5y agoCompare

[ Source](https://github.com/boospot/boo-widget-helper)[ Packagist](https://packagist.org/packages/boospot/boo-widget-helper)[ RSS](/packages/boospot-boo-widget-helper/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Boo Widgets Helper
==================

[](#boo-widgets-helper)

This is a helper class to create widgets easily and effectively using WordPress Widgets API

- Sanitization is done automatically.
- Ability to override callback
- Ability to override sanitize\_callback for fields

Hook the class in `widgets_init`
--------------------------------

[](#hook-the-class-in-widgets_init)

`require` the class file (sample code below) and then hook into `widgets_init`

```
add_action( 'widgets_init', function(){

	register_widget( 'Plugin_Name_My_Widget' );

} );

```

Sample Widget Class using Helper Class
--------------------------------------

[](#sample-widget-class-using-helper-class)

```
/**
 * Sample Widget using Helper Class
 *
 * @package    Plugin_Name
 * @subpackage Plugin_Name/includes
 * @author     Rao
 */
if ( ! class_exists( 'Plugin_Name_My_Widget' ) ) {

	class Plugin_Name_My_Widget extends Boo_Widget_Helper {

		public function __construct() {

			$configuration = array(

				// widget id
				'id'     => 'my_awesome_widget',

				// widget-name
				'name'   => __( 'Awesome Widget', 'plugin-name' ),

				// widget description
				'desc'   => __( 'Widget Using Helper Class', 'plugin-name' ),

				// widget css class
				'class'  => 'my_awesome_css_class_for_widget',

				// widget fields array
				'fields' => $this->get_fields_array()

			);

			parent::__construct( $configuration );

		}

		/**
		* Fields for widget settings array
		*
		* @return array $fields_array
		*/
		public function get_fields_array() {

			$fields_array = array(
				'title'       => array(
					'label' => __( 'Title:', 'plugin-name' ),
					'desc'  => 'this is title description',
				),
				'limit'       => array(
					'type'  => 'number',
					'label' => __( 'Limit:', 'plugin-name' ),
					'desc'  => 'this is number field description',
				),
				'color1'      => array(
					'label'   => __( 'Color Field', 'plugin-name' ),
					'type'    => 'color',
					'default' => '#ff0000'
				),
				'format'      => array(
					'type'    => 'select',
					'label'   => __( 'Format', 'plugin-name' ),
					'options' => array(
						''          => __( 'All', 'plugin-name' ),
						'hardcover' => __( 'Hardcover', 'plugin-name' ),
						'audio'     => __( 'Audio', 'plugin-name' ),
						'pdf'       => __( 'PDF', 'plugin-name' ),
					),
					'desc'    => 'this is description of select'

				),
				'checkbox1'   => array(
					'type'  => 'checkbox',
					'label' => __( 'Checkbox', 'plugin-name' ),
					'desc'  => 'this is description of checkbox'
				),
				'multicheck1' => array(
					'type'    => 'multicheck',
					'label'   => __( 'Multicheck Options', 'plugin-name' ),
					'options' => array(
						'multi1' => __( 'Multi Choice 1', 'plugin-name' ),
						'multi2' => __( 'Multi Choice no. 2', 'plugin-name' ),
						'multi3' => __( '3rd Multi Choice', 'plugin-name' ),
					),
					'class'   => 'super-class',
					'desc'    => 'this is description of multicheck'
				),
				'radio1'      => array(
					'type'    => 'radio',
					'label'   => __( 'Radio Options', 'plugin-name' ),
					'options' => array(
						'radio1' => __( 'Radio 1', 'plugin-name' ),
						'radio2' => __( 'Radio Choice no. 2', 'plugin-name' ),
						'radio3' => __( '3rd Radio', 'plugin-name' ),
					),
					'class'   => 'super-class',
					'desc'    => 'this is description of radio'
				),
				'textarea1'   => array(
					'type'        => 'textarea',
					'label'       => __( 'Textarea Option', 'plugin-name' ),
					'class'       => 'super-class-textarea',
					'desc'        => 'this is description of textarea',
					'placeholder' => 'placeholder of textarea',
					'rows'        => 2,
					'cols'        => 25,
					'default'     => 'i am default'

				),
				'html1'       => array(
					'type'    => 'html',
					'default' => 'This field is plain html before hr tagThis is Strong and This is italic',

				),
				'pages1'      => array(
					'type'  => 'pages',
					'label' => __( 'Pages List', 'plugin-name' ),
					'desc'  => __( 'Pages Options description', 'plugin-name' ),
				),

				'posts1' => array(
					'type'    => 'posts',
					'label'   => __( 'Posts List (Select)', 'plugin-name' ),
					'desc'    => __( 'Posts Options description', 'plugin-name' ),
					'display' => 'select',
					'options' => array(
						'post_type' => 'book'
					)
				),
				'posts2' => array(
					'type'    => 'posts',
					'label'   => __( 'Posts List (Multicheck)', 'plugin-name' ),
					'desc'    => __( 'Posts Options description', 'plugin-name' ),
					'display' => 'multicheck',
					'options' => array(
						'post_type' => 'book'
					)
				),

				'taxonomy_field1' => array(
					'type'    => 'taxonomy',
					'label'   => __( 'Taxonomy (select)', 'plugin-name' ),
					'desc'    => __( 'description for Taxonomy Select', 'plugin-name' ),
					'display' => 'select',
					'options' => array(
						'taxonomy' => 'category',
						'save'     => 'slug', // or term_id or any term object property
					)
				),

				'taxonomy_field2' => array(
					'type'    => 'taxonomy',
					'label'   => __( 'Taxonomy (multicheck)', 'plugin-name' ),
					'desc'    => __( 'description for Taxonomy', 'plugin-name' ),
					'display' => 'multicheck',
					'options' => array(
						'taxonomy' => 'category',
						'save'     => 'slug', // or term_id or any term object property
					)
				),

				'file_field_id' => array(
					'type'    => 'file',
					'label'   => __( 'File Option', 'plugin-name' ),
					'desc'    => __( 'File description', 'plugin-name' ),
					'options' => array(
						'btn' => 'Get it'
					)
				),

				'media_field1'      => array(
					'type'    => 'media',
					'label'   => __( 'Media', 'plugin-name' ),
					'desc'    => __( 'description for Media', 'plugin-name' ),
					'default' => '',
					'options' => array(
						'btn' => 'Get the image',
					)

				),
				'my_field_override' => array(
					'label'             => __( 'Field with Override Callbacks', 'plugin-name' ),
					'callback'          => function ( $args ) {

						printf(
							'%s',
							$this->get_field_name( 'my_field_override' ),
							$args['label']
						);

						printf( '',
							$this->get_field_id( 'my_field_override' ),
							$this->get_field_name( 'my_field_override' ),
							$args['value'] // You will get the value in $args param
						);
					},
					'sanitize_callback' => 'sanitize_url'
				),
			);

			return $fields_array;

		}

		/**
		 * Outputs the content of the widget
		 *
		 * @param array $args
		 * @param array $instance
		 */
		public function widget_display( $args, $instance ) {

			// Display our widget output
			echo "";
			var_export( $instance );
			echo "";

		}

	}
}

```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/761506c68407153cecbf543b614dd8ea53f07203e346f075c2029d18ca977219?d=identicon)[boospot](/maintainers/boospot)

---

Top Contributors

[![booskills](https://avatars.githubusercontent.com/u/46623905?v=4)](https://github.com/booskills "booskills (7 commits)")

### Embed Badge

![Health badge](/badges/boospot-boo-widget-helper/health.svg)

```
[![Health](https://phpackages.com/badges/boospot-boo-widget-helper/health.svg)](https://phpackages.com/packages/boospot-boo-widget-helper)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
