PHPackages                             dream-encode/de-wordpress-plugin-utils - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. dream-encode/de-wordpress-plugin-utils

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

dream-encode/de-wordpress-plugin-utils
======================================

Reusable WordPress plugin utilities including upgrader and logger abstracts.

v1.9.5(1mo ago)0133GPL-3.0-or-laterPHPPHP &gt;=8.2

Since Apr 21Pushed 1mo agoCompare

[ Source](https://github.com/dream-encode/de-wordpress-plugin-utils)[ Packagist](https://packagist.org/packages/dream-encode/de-wordpress-plugin-utils)[ Docs](https://github.com/dream-encode/de-wordpress-plugin-utils)[ RSS](/packages/dream-encode-de-wordpress-plugin-utils/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (13)Versions (35)Used By (0)

DE WordPress Plugin Utils
=========================

[](#de-wordpress-plugin-utils)

Reusable WordPress plugin utilities including abstracts for plugin bootstrap, lifecycle, settings, REST API, logging, background processing, and data migrations.

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

[](#installation)

```
composer require dream-encode/de-wordpress-plugin-utils
```

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

[](#requirements)

- PHP &gt;= 8.2
- WordPress
- WooCommerce/Action Scheduler (via `woocommerce/action-scheduler`)

Provided Abstracts
------------------

[](#provided-abstracts)

### Abstract\_Plugin

[](#abstract_plugin)

`Dream_Encode\WordPress_Plugin_Utils\Abstracts\Abstract_Plugin`

Main plugin bootstrap template. Constructs the loader, loads dependencies, sets locale, and wires admin/public hooks.

**Must implement:**

- `get_plugin_slug(): string` — returns the plugin slug used as `$plugin_name`.
- `get_version_constant(): string` — returns the PHP constant name that holds the plugin version.

**Optional overrides:**

- `get_default_version(): string` — fallback version string when the constant is not yet defined (default `'1.0.0'`).
- `create_loader(): Plugin_Loader` — returns the loader instance; defaults to `new Plugin_Loader()`.
- `load_dependencies(): void` — require additional files/classes.
- `set_locale(): void` — instantiate and register the i18n loader.
- `define_admin_hooks(): void` — register wp-admin actions and filters.
- `define_public_hooks(): void` — register front-end actions and filters.

**Public API:**

- `run(): void` — fires all registered hooks via the loader.
- `get_plugin_name(): string`
- `get_version(): string`
- `get_loader(): Plugin_Loader`

---

### Plugin\_Loader

[](#plugin_loader)

`Dream_Encode\WordPress_Plugin_Utils\Loader\Plugin_Loader`

Concrete class. Stores and bulk-registers WordPress actions and filters. Can be used directly or subclassed for custom hook-registration behaviour.

**Public API:**

- `add_action( $hook, $component, $callback, $priority, $accepted_args ): void`
- `add_filter( $hook, $component, $callback, $priority, $accepted_args ): void`
- `run(): void` — calls `add_action`/`add_filter` for every registered hook.

---

### Abstract\_Plugin\_Activator

[](#abstract_plugin_activator)

`Dream_Encode\WordPress_Plugin_Utils\Abstracts\Abstract_Plugin_Activator`

Consistent entry point for `register_activation_hook`.

**Static entry point:** `activate(): void`

**Optional overrides (all no-ops by default):**

- `before_activate(): void`
- `run_install(): void`
- `after_activate(): void`

---

### Abstract\_Plugin\_Deactivator

[](#abstract_plugin_deactivator)

`Dream_Encode\WordPress_Plugin_Utils\Abstracts\Abstract_Plugin_Deactivator`

Consistent entry point for `register_deactivation_hook`.

**Static entry point:** `deactivate(): void`

**Optional overrides (all no-ops by default):**

- `before_deactivate(): void`
- `delete_options(): void`
- `after_deactivate(): void`

---

### Abstract\_Plugin\_I18n

[](#abstract_plugin_i18n)

`Dream_Encode\WordPress_Plugin_Utils\Abstracts\Abstract_Plugin_I18n`

Loads plugin translations via `load_plugin_textdomain`.

**Must implement:**

- `get_text_domain(): string`
- `get_languages_path(): string`

**Public API:**

- `load_plugin_textdomain(): bool`

---

### Abstract\_Plugin\_Upgrader

[](#abstract_plugin_upgrader)

`Dream_Encode\WordPress_Plugin_Utils\Abstracts\Abstract_Plugin_Upgrader`

Handles plugin upgrade/install logic with cache-clearing for Redis/object cache environments. Integrates with Action Scheduler for deferred tasks.

---

### Asset\_Manager

[](#asset_manager)

`Dream_Encode\WordPress_Plugin_Utils\Assets\Asset_Manager`

Concrete class. Screen-based stylesheet and script enqueuer for both admin and front-end contexts. All configuration is passed via constructor — no subclassing required for common usage.

**Constructor** (all params after `$plugin_version` are optional):

```
new Asset_Manager(
    handle_prefix: 'my-plugin-',
    plugin_path:   MY_PLUGIN_PATH,
    plugin_url:    MY_PLUGIN_URL,
    plugin_version: MY_PLUGIN_VERSION,
    screens_to_assets: [ 'edit-post' => [ ['name' => 'editor'] ] ],
    localization_global: 'MY_PLUGIN',
    screens_localization_data: [ 'edit-post' => [ 'REST_URL' => '...' ] ],
    asset_subdir: 'admin/',        // default ''
    asset_file_prefix: 'admin-',   // default ''
);
```

**Public API:**

- `add_screens( array $screens ): void` — merge additional screen entries at runtime.
- `add_screens_localization_data( array $data ): void` — merge additional localization entries.
- `enqueue_styles(): void`
- `enqueue_scripts(): void`
- `current_screen_assets(): array` — asset definitions for the current screen.
- `current_screen_has_assets(): int`
- `screen_assets( WP_Screen $screen ): array`
- `screen_has_assets( WP_Screen $screen ): int`
- `screen_get_localized_data( WP_Screen $screen ): array`

---

### Abstract\_REST\_API

[](#abstract_rest_api)

`Dream_Encode\WordPress_Plugin_Utils\Abstracts\Abstract_REST_API`

Base class for registering a REST API namespace and routes.

---

### Abstract\_REST\_Controller

[](#abstract_rest_controller)

`Dream_Encode\WordPress_Plugin_Utils\Abstracts\Abstract_REST_Controller`

Extends `WP_REST_Controller` with a reusable pattern for REST endpoint controllers.

**Must implement:**

- `check_user_permission(): bool`

---

### REST\_Authentication

[](#rest_authentication)

`Dream_Encode\WordPress_Plugin_Utils\RestApi\REST_Authentication`

Handles WP REST API authentication, including cookie auth error checking, app password authentication, and permission helpers. Auto-registers the `rest_authentication_errors` filter when the file is loaded.

**Static permission helpers:**

- `check_logged_in_permission(): bool`
- `check_admin_permission(): bool`
- `check_editor_permission(): bool`
- `check_user_permission(): bool`
- `check_woocommerce_shop_manager_permission(): bool`
- `check_post_permissions( $post_type, $permission, $user_id ): bool`

**Static accessors:**

- `get_wp_rest_nonce(): string`
- `get_wp_user_id(): int`

---

### REST\_Response

[](#rest_response)

`Dream_Encode\WordPress_Plugin_Utils\RestApi\REST_Response`

Simple value object for REST API responses.

**Properties:**

- `$status` — `string`, defaults to `'error'`.
- `$message` — `string`, defaults to `''`.
- `$data` — `mixed`, initialised to a fresh `stdClass`.
- `$success` — `bool|null`, defaults to `null`.

---

### Object\_Data

[](#object_data)

`Dream_Encode\WordPress_Plugin_Utils\Data\Object_Data`

Concrete class. WooCommerce-style data object. Tracks a `$data` array, a `$changes` diff, and optional `$extra_data`. Can be used directly or subclassed to declare typed `$data`/`$extra_data` defaults and domain-specific getters/setters.

**Public API:**

- `get_prop( $prop ): mixed` — reads from `$changes` first, then `$data`.
- `set_prop( $prop, $value ): void`
- `set_props( $props ): void`
- `apply_changes(): void` — merges `$changes` into `$data`.
- `get_data(): array`
- `get_changes(): array`
- `get_extra_data(): array`
- `get_no_cache(): bool`
- `set_no_cache( $no_cache ): void`

---

### Abstract\_WC\_Logger

[](#abstract_wc_logger)

`Dream_Encode\WordPress_Plugin_Utils\Abstracts\Abstract_WC_Logger`

Logs data through WooCommerce's `WC_Logger`, falling back to `error_log` when WooCommerce is unavailable.

---

### Abstract\_Data\_Migrator

[](#abstract_data_migrator)

`Dream_Encode\WordPress_Plugin_Utils\Abstracts\Abstract_Data_Migrator`

Template-method base for multi-run data migrations driven by Action Scheduler. Each migration is broken into individually-scheduled runs; progress, status, and results are persisted via plugin-supplied storage hooks.

**Must implement (persistence — decoupled from any specific storage):**

- `create_new_migration( array $migration ): false|array`
- `create_new_migration_run( array $migration ): false|int`
- `get_migration_option( $migration_id ): false|mixed`
- `update_migration_option( $migration_id, $data ): void`
- `update_migration( array $progress ): void`
- `update_migration_run( array $migration_run ): void`
- `get_migration_run_option( $migration_run_id ): false|mixed`
- `update_migration_run_option( $migration_run_id, $data ): void`
- `save_completed_migration_run( array $migration_run ): void`
- `save_completed_migration( array $progress ): void`
- `create_migration_message( array $args ): void`

**Must implement (metadata):**

- `get_migrator_label( $migrator ): string`
- `get_plugin_setting( $key ): mixed`
- `get_migrator_setting( $migrator, $key, $default ): mixed`
- `get_all_migration_param_keys(): string[]`
- `get_migration_progress_keys(): string[]`
- `get_action_scheduler_hook(): string`
- `get_action_scheduler_group(): string`

**Public API:**

- `queue_migrator( $init_params ): void` — queues the first migration run via Action Scheduler.
- `run( $migration_run_id ): void` — invoked by Action Scheduler to execute one run.
- `process_migration(): void` — override to perform the actual row-level work.
- `get_progress(): array` — current progress snapshot.
- `update_percent_complete(): void`
- `get_migration_id(): false|int`
- `get_migration_run_id(): false|int`
- `get_status(): string`
- `get_percent_complete(): float`
- `get_total_rows(): int`
- `get_total_rows_migrated(): int`
- `get_total_rows_failed(): int`
- `get_total_rows_skipped(): int`
- `get_batch_size(): int`
- `get_is_dry_run(): bool`

---

### Abstract\_Background\_Processor

[](#abstract_background_processor)

`Dream_Encode\WordPress_Plugin_Utils\Abstracts\Abstract_Background_Processor`

Template-method base for long-running asynchronous background processors driven by Action Scheduler. Supports prerequisite sub-processors, configurable batch sizes, and per-run progress tracking.

**Must implement (persistence):**

- `queue_new_background_process( $args ): false|array`
- `create_new_background_process( $args ): false|array`
- `create_new_background_process_run( $background_process ): false|int`
- `get_background_process_option( $background_processes_id, $force_refresh ): false|mixed`
- `update_background_process_option( $background_processes_id, $data ): void`
- `update_background_process( $data ): void`
- `get_background_process_run_option( $background_processes_run_id ): false|mixed`
- `update_background_process_run_option( $background_processes_run_id, $data ): void`
- `update_background_process_run( $data ): void`
- `save_completed_background_process( $data ): void`
- `save_completed_background_process_run( $data ): void`
- `get_background_process_by_id( $background_processes_id ): object|null`
- `update_prerequisite_sub_process_parent_background_process( $background_processes_id ): void`

**Must implement (metadata):**

- `get_all_background_process_param_keys(): string[]`
- `get_background_process_progress_keys(): string[]`
- `get_processor_sub_params(): array`
- `get_background_processor_label( $processor ): string`
- `create_background_processes_message( $args ): void`
- `get_plugin_setting( $key ): mixed`
- `get_processor_setting( $processor, $key, $default ): mixed`
- `get_action_scheduler_hook(): string`
- `get_action_scheduler_group(): string`

---

Settings
--------

[](#settings)

### Plugin\_Settings\_Repository

[](#plugin_settings_repository)

`Dream_Encode\WordPress_Plugin_Utils\Settings\Plugin_Settings_Repository`

Thin read/write wrapper around a single WordPress option key. Results are cached in-memory for the request lifetime.

**Constructor:** `__construct( string $option_name, array $defaults = [], bool $autoload = true )`

**Public API:**

- `all(): array` — returns all settings, merged with defaults.
- `get( $key, $default = null ): mixed`
- `set( $key, $value ): bool`
- `update( array $settings ): bool` — overwrites the full option.
- `delete(): bool`
- `refresh(): void` — clears the in-memory cache.
- `get_option_name(): string`

---

Functions
---------

[](#functions)

`Dream_Encode\WordPress_Plugin_Utils\Common\Functions`

All methods are static.

- `maybe_define_constant( string $name, mixed $value ): void` — defines a PHP constant only if it is not already defined.
- `get_mysql_datetime( false|float|int $time, string $timezone_string ): string|false` — converts a Unix timestamp to a MySQL `Y-m-d H:i:s` string (defaults to current time, UTC).
- `mysql_datetime_to_datetime_long( string $datetime ): string|false` — formats a MySQL datetime string to `"Monday January 5, 2026 at 3:42:00 pm"`.
- `format_timestamp_to_datetime_long( null|float|int $timestamp, string $timezone_string ): string|false` — formats a Unix timestamp to the same long format.
- `convert_seconds_to_minutes_seconds( int $seconds ): string` — formats an integer number of seconds as `MM:SS` (e.g. `313` → `"05:13"`).
- `get_user_display_name( int $user_id ): string` — returns the user's `user_nicename`, or `'N/A'` if the user does not exist.

---

Development
-----------

[](#development)

```
# Lint code
composer lint

# Auto-format code
composer format

# Static analysis
composer analyze

# Run all checks + tests
composer test
```

License
-------

[](#license)

GPL-3.0-or-later

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance88

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity58

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 ~2 days

Total

17

Last Release

59d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2af71bff15bb76467ff1ca0b2dafb2a17b06cd57de237a3f7184c14b499ffa63?d=identicon)[dream-encode](/maintainers/dream-encode)

---

Top Contributors

[![dream-encode](https://avatars.githubusercontent.com/u/1900750?v=4)](https://github.com/dream-encode "dream-encode (90 commits)")

---

Tags

pluginwordpressloggerutilitiesupgrader

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/dream-encode-de-wordpress-plugin-utils/health.svg)

```
[![Health](https://phpackages.com/badges/dream-encode-de-wordpress-plugin-utils/health.svg)](https://phpackages.com/packages/dream-encode-de-wordpress-plugin-utils)
```

###  Alternatives

[inpsyde/wonolog

Monolog-based logging package for WordPress.

184637.3k7](/packages/inpsyde-wonolog)[illuminated/console-logger

Logging and Notifications for Laravel Console Commands.

8677.5k](/packages/illuminated-console-logger)[vojtasvoboda/oc-errorlogger-plugin

Sends an error from your OctoberCMS application directly to email, HipChat, Slack, NewRelic and more.

153.3k](/packages/vojtasvoboda-oc-errorlogger-plugin)

PHPackages © 2026

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