PHPackages                             unax/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. unax/helper

ActiveLibrary

unax/helper
===========

Helper Library for WordPress

1.0.4(7mo ago)010APACHE-2.0PHPPHP &gt;=8.0

Since Oct 3Pushed 7mo agoCompare

[ Source](https://github.com/unax-org/helper)[ Packagist](https://packagist.org/packages/unax/helper)[ RSS](/packages/unax-helper/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

WP Helper Class
===============

[](#wp-helper-class)

The Helper class provides utilities for WordPress plugin development including logging, email functionality, form generation, encryption, and admin notices.

Installation &amp; Initialization
---------------------------------

[](#installation--initialization)

```
use Unax\Helper\Helper;

// Initialize the helper (sets up logging, creates log directories, etc.)
Helper::init();
```

Configuration
-------------

[](#configuration)

Configure the Helper class by setting properties before calling `config()`:

```
// Basic configuration
Helper::set_text_domain( 'your-plugin-domain' );
Helper::set_administrator_email( 'admin@example.com' );
Helper::set_reply_to( 'no-reply@example.com' );
Helper::set_logs_dir( '/path/to/logs' );
Helper::set_log_prefix( 'your-plugin' );
Helper::set_log_threshold( 'info' ); // debug, info, warning, error
Helper::set_passphrase( 'your-encryption-key' );

// Initialize after configuration
Helper::init();
```

Logging
-------

[](#logging)

### Basic Logging

[](#basic-logging)

```
// Get logger instance
$logger = Helper::get_logger();

// Log with different levels
$logger->debug( 'Debug message' );
$logger->info( 'Info message' );
$logger->warning( 'Warning message' );
$logger->error( 'Error message' );

// Advanced logging with context
Helper::log( 'Context', 'Message', array( 'param1' => 'value1' ), __FILE__, __LINE__, 'error' );
```

Email Functionality
-------------------

[](#email-functionality)

### Send Email

[](#send-email)

```
// Basic email
Helper::send_email( 'user@example.com', 'Subject', 'Message content' );

// Admin notification
Helper::admin_notification( 'Alert Subject', 'Alert message' );

// User notification (includes auto-generated footer)
Helper::notification( 'user@example.com', 'Subject', 'Message' );
```

Admin Notices
-------------

[](#admin-notices)

### Add Admin Notices

[](#add-admin-notices)

```
// Add dismissible admin notice
Helper::add_admin_notice( 'Success message', 'success', true );
Helper::add_admin_notice( 'Error message', 'error', false );

// Display notices (call in admin_notices hook)
add_action( 'admin_notices', array( Helper::class, 'admin_notices' ) );
```

### Frontend Notices

[](#frontend-notices)

```
// Add frontend notice
Helper::add_notice( 'Info message', 'info' );

// Display notices in templates
Helper::notices();

// Get notices array
$notices = Helper::get_notices();
```

Form Generation
---------------

[](#form-generation)

### Labels and Inputs

[](#labels-and-inputs)

```
// Generate label
Helper::generate_label( 'field_id', 'Field Label', 'css-class', true, false );

// Text input
Helper::generate_input_text( 'text', 'field_id', 'Label', 'css-class', 'default_value' );

// Email input
Helper::generate_input_text( 'email', 'email_field', 'Email', 'form-control' );

// Date picker
Helper::generate_input_datepicker( 'date_field', 'Select Date', 'datepicker-class' );

// Textarea
Helper::generate_textarea( 'message_field', 'Message', 'form-control', 'Default text' );
```

### Dropdowns and Radio Buttons

[](#dropdowns-and-radio-buttons)

```
// Dropdown select
$options = array( 'value1' => 'Label 1', 'value2' => 'Label 2' );
Helper::generate_dropdown( 'select_field', $options, 'form-select', 'value1', 'Choose option' );

// Radio buttons
Helper::generate_radio_buttons( 'radio_field', 'Radio Group', $options, 'radio-group', 'value1' );

// Checkbox
Helper::generate_checkbox( 'checkbox_field', 'Checkbox Label', 'checkbox-class', '1', '1' );
```

Form Validation
---------------

[](#form-validation)

### Field Validation

[](#field-validation)

```
// Validate different field types
$result = Helper::validate_field( 'user@example.com', 'email', true, 5, 100 );
$result = Helper::validate_field( '+1234567890', 'tel', true );
$result = Helper::validate_field( 'Text content', 'text', true, 10, 500 );

// Check validation result
if ( $result['success'] ) {
    $validated_value = $result['data'];
} else {
    $error_message = $result['message'];
}
```

### Prepare Form Fields

[](#prepare-form-fields)

```
// Convert underscores to hyphens in field keys
$fields = array( 'field_name' => 'value', 'another_field' => 'value2' );
$prepared = Helper::prepare_fields( $fields );
// Result: array( 'field-name' => 'value', 'another-field' => 'value2' )
```

Security
--------

[](#security)

### Nonce Handling

[](#nonce-handling)

```
// Generate nonce field
Helper::nonce_field( 'action_name', 'context', '_custom_nonce_' );

// Verify nonce
if ( Helper::verify_nonce( 'action_name', 'context', get_the_ID(), '_custom_nonce_' ) ) {
    // Process form
}
```

### Google reCAPTCHA

[](#google-recaptcha)

```
// Verify reCAPTCHA token
$token = $_POST['g-recaptcha-response'];
$secret = 'your-recaptcha-secret-key';

if ( Helper::check_google_recaptcha( $token, $secret ) ) {
    // reCAPTCHA verified
}
```

### Encryption/Decryption

[](#encryptiondecryption)

```
// Encrypt sensitive data
$encrypted = Helper::encrypt( 'sensitive data' );

// Decrypt data
$decrypted = Helper::decrypt( $encrypted );
```

Date Formatting
---------------

[](#date-formatting)

```
// Format date to Y-m-d
$formatted = Helper::format_date( '12/31/2023' );

// Format date using WordPress settings
$wp_formatted = Helper::format_date_wp( '2023-12-31', true ); // includes time
$wp_formatted = Helper::format_date_wp( '2023-12-31', false ); // date only
```

Configuration Properties
------------------------

[](#configuration-properties)

PropertyDefaultDescription`$text_domain`'unax-helper'Plugin text domain for translations`$administrator_email`''Admin email (falls back to WP admin\_email)`$reply_to`'no-reply@localhost'Default reply-to email address`$wp_mail_content_type`'text/html'WordPress mail content type`$passphrase`'passphrase'Encryption passphrase`$cipher_algo`'aes-256-ctr'OpenSSL cipher algorithm`$logs_dir`''Custom logs directory path`$log_threshold`'info'Minimum log level to record`$log_prefix`'helper'Log file prefixError Handling
--------------

[](#error-handling)

The Helper class includes comprehensive error handling:

- Logging initialization errors
- Email sending failures
- Encryption/decryption errors
- Form validation errors
- reCAPTCHA verification errors

All errors are logged using the configured logger and appropriate error messages are returned to the calling code.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance63

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

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

Unknown

Total

1

Last Release

227d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7f109cba3fbe39e075cf79aeda1cd80b0e3a667eb308b764637dba1516eec903?d=identicon)[nant](/maintainers/nant)

---

Top Contributors

[![atanasantonov](https://avatars.githubusercontent.com/u/29710963?v=4)](https://github.com/atanasantonov "atanasantonov (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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