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

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

ernilambar/widget-helper
========================

WordPress widget helper

1.0.1(5y ago)1221MITPHPPHP &gt;=5.6

Since Jan 1Pushed 4y ago1 watchersCompare

[ Source](https://github.com/ernilambar/widget-helper)[ Packagist](https://packagist.org/packages/ernilambar/widget-helper)[ Docs](https://github.com/ernilambar/widget-helper)[ RSS](/packages/ernilambar-widget-helper/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Widget Helper
=============

[](#widget-helper)

Simple helper library which helps to create WordPress widgets in fast and east way.

Requirements
------------

[](#requirements)

- WordPress 5.1+.
- PHP 5.6+.
- [Composer](https://getcomposer.org/) for managing PHP dependencies.

Installation
------------

[](#installation)

First, you'll need to open your command line tool and change directories to your theme folder.

```
cd path/to/wp-content/themes/
```

Then, use Composer to install the package.

```
composer require ernilambar/widget-helper
```

Assuming you're not already including the Composer autoload file for your theme and are shipping this as part of your theme package, you'll want something like the following bit of code in your theme's `functions.php` to autoload this package (and any others).

The Composer autoload file will automatically load up the package for you and make its code available for you to use.

```
if ( file_exists( get_parent_theme_file_path( 'vendor/autoload.php' ) ) ) {
  require_once( get_parent_theme_file_path( 'vendor/autoload.php' ) );
}
```

Package comes with the JS and CSS needed for the widgets fields. You can enqueue assets like given in the example below.

Usage
-----

[](#usage)

You can create your new widget with extending the helper class.

```
use Nilambar\WidgetHelper\Helper;
use Nilambar\WidgetHelper\Assets;

/**
 * Load widget assets.
 *
 * @since 1.0.0
 *
 * @param string $hook Hook name.
 */
function theme_slug_load_widget_assets( $hook ) {
  if ( 'widgets.php' === $hook ) {
    Assets::load_assets();
  }
}

add_action( 'admin_enqueue_scripts', 'theme_slug_load_widget_assets' );

/**
 * Widget class.
 *
 * @since 1.0.0
 */
class Theme_Hello_World extends Helper {
  /**
   * Constructor.
   *
   * @since 1.0.0
   */
  public function __construct() {
    $args['id']    = 'theme-hello-world';
    $args['label'] = esc_html__( 'Hello World Widget', 'widget-helper' );

    $args['widget'] = array(
      'classname'   => 'theme_hello_world',
      'description' => esc_html__( 'Hello world widget', 'widget-helper' ),
    );

    $args['fields'] = array(
      'sample_title'   => array(
        'label' => esc_html__( 'Title:', 'widget-helper' ),
        'type'  => 'text',
        'class' => 'widefat',
      ),
      'sample_message' => array(
        'label' => esc_html__( 'Message:', 'widget-helper' ),
        'type'  => 'textarea',
        'class' => 'widefat',
      ),
      'sample_image'   => array(
        'label' => esc_html__( 'Image:', 'widget-helper' ),
        'type'  => 'image',
      ),
      'sample_color'   => array(
        'label'   => esc_html__( 'Color:', 'widget-helper' ),
        'type'    => 'color',
        'default' => '#DDDDDD',
      ),
    );

    parent::create_widget( $args );
  }

  /**
   * Echo the widget content.
   *
   * @since 1.0.0
   *
   * @param array $args     Display arguments.
   * @param array $instance Instance of the widget.
   */
  public function widget( $args, $instance ) {
    // Fetch widget values.
    $values = $this->get_field_values( $instance );

    $values['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );

    echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

    if ( ! empty( $values['title'] ) ) {
      echo $args['before_title'] . esc_html( $values['title'] ) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    }

    // Display logic will be here.

    echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
  }

}

/**
 * Register widget.
 *
 * @since 1.0.0
 */
function theme_slug_custom_widgets_init() {
  register_widget( 'Theme_Hello_World' );
}

add_action( 'widgets_init', 'theme_slug_custom_widgets_init' );
```

### Available fields

[](#available-fields)

- Text
- URL
- Email
- Number
- Checkbox
- Radio
- Radio Image
- Color
- Select
- Dropdown Pages
- Dropdown Taxonomies
- Image
- Textarea
- Heading
- Message
- Separator

Copyright and License
---------------------

[](#copyright-and-license)

This project is licensed under the [MIT](http://opensource.org/licenses/MIT).

2020 © [Nilambar Sharma](https://www.nilambar.net).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~162 days

Total

2

Last Release

2166d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2098823?v=4)[Nilambar Sharma](/maintainers/ernilambar)[@ernilambar](https://github.com/ernilambar)

---

Top Contributors

[![ernilambar](https://avatars.githubusercontent.com/u/2098823?v=4)](https://github.com/ernilambar "ernilambar (46 commits)")

---

Tags

wordpress

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[tgmpa/tgm-plugin-activation

TGM Plugin Activation is a PHP library that allows you to easily require or recommend plugins for your WordPress themes (and plugins).

1.8k222.5k13](/packages/tgmpa-tgm-plugin-activation)[aristath/kirki

Extending the WordPress customizer

1.3k73.0k4](/packages/aristath-kirki)[afragen/git-updater

A plugin to automatically update GitHub, Bitbucket, GitLab, or Gitea hosted plugins, themes, and language packs.

3.3k1.6k](/packages/afragen-git-updater)[justintadlock/hybrid-carbon

God-like post featured image script.

202.5k](/packages/justintadlock-hybrid-carbon)[typisttech/wp-admin-notices

A simplified OOP implementation of the WordPress admin notices

141.2k](/packages/typisttech-wp-admin-notices)

PHPackages © 2026

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