PHPackages                             wpbp/widgets-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. wpbp/widgets-helper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wpbp/widgets-helper
===================

A class to ease creating powered Widgets on WordPress

1.0.21(1y ago)1215.1k↓28.3%6GPL-3.0PHP

Since Jun 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/WPBP/Widgets-Helper)[ Packagist](https://packagist.org/packages/wpbp/widgets-helper)[ Docs](https://github.com/WPBP/Widgets-Helper)[ RSS](/packages/wpbp-widgets-helper/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)DependenciesVersions (23)Used By (0)

Widgets Helper Class
====================

[](#widgets-helper-class)

[![License](https://camo.githubusercontent.com/1b0c7e4911720d0444c16a1ffd145a039f14a1a7305362ab51184f757a4dd6bc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d47504c25323076332d626c75652e737667)](http://www.gnu.org/licenses/gpl-3.0)[![Downloads](https://camo.githubusercontent.com/44c6e69334b73c856239afb98a6ec2b7f4e1b32e1f38e304c0ccb2ded821a3e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f777062702f776964676574732d68656c7065722e737667)](https://camo.githubusercontent.com/44c6e69334b73c856239afb98a6ec2b7f4e1b32e1f38e304c0ccb2ded821a3e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f777062702f776964676574732d68656c7065722e737667)

A class that extends the built-in WP\_Widget class to provide an easier/faster way to create Widgets for WordPress.
This is a fork of the original version with updates from the pull requests on the official repo and few little improvements.

Features
--------

[](#features)

- Automatic fields creation
- Validation methods
- Filter methods
- Before/After form output methods
- Custom form fields creation

Install
-------

[](#install)

`composer require wpbp/widgets-helper:dev-master`

[composer-php52](https://github.com/composer-php52/composer-php52) supported.

Example
-------

[](#example)

```
class MV_My_Recent_Posts_Widget extends WPH_Widget {
	function __construct() {
		    // Widget Backend information
			$args = array(
				'label' => __( 'My Recent Posts', 'mv-my-recente-posts' ),
				'description' => __( 'My Recent Posts Widget Description', 'mv-my-recente-posts' ),
				'slug' => 'my_recent_posts',
				'options' => array() //classname, description
			);

			$args['fields'] = array(

				// Title field
				array(
				// field name/label
				'name' => __( 'Title', 'mv-my-recente-posts' ),
				// field description
				'desc' => __( 'Enter the widget title.', 'mv-my-recente-posts' ),
				// field id
				'id' => 'title',
				// field type ( text, checkbox, textarea, select, select-group )
				'type'=>'text',
				// class, rows, cols
				'class' => 'widefat',
				// default value
				'std' => __( 'Recent Posts', 'mv-my-recente-posts' ),
				/* Set the field validation type
					'alpha_dash' Returns FALSE if the value contains anything other than alpha-numeric characters, underscores or dashes
                    'alpha'	Returns FALSE if the value contains anything other than alphabetical characters
                    'alpha_numeric'	Returns FALSE if the value contains anything other than alpha-numeric characters
                    'numeric' Returns FALSE if the value contains anything other than numeric characters
                    'boolean' Returns FALSE if the value contains anything other than a boolean value ( true or false )

				   You can define custom validation methods. Make sure to return a boolean ( TRUE/FALSE )
					'validate' => 'my_custom_validation',
				   Will call for: $this->my_custom_validation( $value_to_validate );
				*/
				'validate' => 'alpha_dash',
				/* Filter data before entering the DB
					 strip_tags ( default )
					 wp_strip_all_tags
					 esc_attr
					 esc_url
					 esc_textarea
				*/
				'filter' => 'strip_tags|esc_attr'
				 ),
				// Amount Field
				array(
				'name' => __( 'Amount' ),
				'desc' => __( 'Select how many posts to show.', 'mv-my-recente-posts' ),
				'id' => 'amount',
				'type'=>'select',
				// selectbox fields
				'fields' => array(
						array(
							// option name
							'name'  => __( '1 Post', 'mv-my-recente-posts' ),
							// option value
							'value' => '1'
						),
						array(
							'name'  => __( '2 Posts', 'mv-my-recente-posts' ),
							'value' => '2'
						),
						array(
							'name'  => __( '3 Posts', 'mv-my-recente-posts' ),
							'value' => '3'
						)
				 ),
				'validate' => 'my_custom_validation',
				'filter' => 'strip_tags|esc_attr',
				 ),
				// Output type checkbox
				array(
				'name' => __( 'Output as list', 'mv-my-recente-posts' ),
				'desc' => __( 'Wraps posts with the  tag.', 'mv-my-recente-posts' ),
				'id' => 'list',
				'type'=>'checkbox',
				// checked by default:
				'std' => 1, // 0 or 1
				'filter' => 'strip_tags|esc_attr',
				 ),
                // Taxonomy Field
    		    array(
    			'name' => __( 'Taxonomy', 'mv-my-recente-posts' ),
    			'desc' => __( 'Set the taxonomy.', 'mv-my-recente-posts' ),
    			'id' => 'taxonomy',
    			'type' => 'taxonomy',
    			'class' => 'widefat',
    		    ),
    		    // Taxonomy Field
    		    array(
    			'name' => __( 'Taxonomy terms', $this->plugin_slug ),
    			'desc' => __( 'Set the taxonomy terms.', $this->plugin_slug ),
    			'id' => 'taxonomyterm',
    			'type' => 'taxonomyterm',
    			'taxonomy' => 'category',
    			'class' => 'widefat',
    		    ),
    		    // Pages Field
    		    array(
    			'name' => __( 'Pages', $this->plugin_slug ),
    			'desc' => __( 'Set the page.', $this->plugin_slug ),
    			'id' => 'pages',
    			'type' => 'pages',
    			'class' => 'widefat',
    		    ),
    		    // Post type Field
    		    array(
    			'name' => __( 'Post type', $this->plugin_slug ),
    			'desc' => __( 'Set the post type.', $this->plugin_slug ),
    			'id' => 'posttype',
    			'type' => 'posttype',
    			'posttype' => 'post',
    			'class' => 'widefat',
    		    ),
			 );

			$this->create_widget( $args );
		}

		/**
        * Custom validation for this widget
        *
        * @param string $value
        * @return boolean
        */
		function my_custom_validation( $value )	{
			if ( strlen( $value ) > 1 )
				return false;
			else
				return true;
		}

		/**
         * Output function
         *
         * @param array $args
         * @param array $instance
         */
		function widget( $args, $instance ) {
		    $out = $args[ 'before_widget' ];
			// And here do whatever you want
			$out  = $args['before_title'];
			$out .= $instance['title'];
			$out .= $args['after_title'];
			// here you would get the most recent posts based on the selected amount: $instance['amount']
			// Then return those posts on the $out variable ready for the output
			$out .= 'Hey There! ';
            $out .= $args[ 'after_widget' ];
			echo $out;
		}

	}

	// Register widget
	if ( ! function_exists( 'mv_my_register_widget' ) )	{
		function mv_my_register_widget() {
			register_widget( 'MV_My_Recent_Posts_Widget' );
		}
		add_action( 'widgets_init', 'mv_my_register_widget', 1 );
	}
```

Credits
-------

[](#credits)

by @sksmatt
[www.mattvarone.com](http://www.mattvarone.com)

Contributors:

Joachim Kudish ( @jkudish )
Joaquin
markyoungdev
riesurya [sksmatt#7](https://github.com/sksmatt/WordPress-Widgets-Helper-Class/pull/7)
ghost [sksmatt#5](https://github.com/sksmatt/WordPress-Widgets-Helper-Class/pull/5)
Mte90

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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.

###  Release Activity

Cadence

Every ~140 days

Recently: every ~24 days

Total

22

Last Release

715d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/403283?v=4)[Daniele Scasciafratte](/maintainers/Mte90)[@Mte90](https://github.com/Mte90)

---

Top Contributors

[![Mte90](https://avatars.githubusercontent.com/u/403283?v=4)](https://github.com/Mte90 "Mte90 (36 commits)")[![sksmatt](https://avatars.githubusercontent.com/u/21919?v=4)](https://github.com/sksmatt "sksmatt (33 commits)")[![jkudish](https://avatars.githubusercontent.com/u/260253?v=4)](https://github.com/jkudish "jkudish (3 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (1 commits)")

---

Tags

wordpresswordpress-php-librarywordpresswidgetwidgets

### Embed Badge

![Health badge](/badges/wpbp-widgets-helper/health.svg)

```
[![Health](https://phpackages.com/badges/wpbp-widgets-helper/health.svg)](https://phpackages.com/packages/wpbp-widgets-helper)
```

###  Alternatives

[klisl/laravel-widgets

Package for using widgets in Laravel-5

103.7k](/packages/klisl-laravel-widgets)

PHPackages © 2026

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