承接 dream-encode/de-wordpress-plugin-utils 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dream-encode/de-wordpress-plugin-utils

Composer 安装命令:

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

包简介

Reusable WordPress plugin utilities including upgrader and logger abstracts.

README 文档

README

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

Installation

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

Requirements

  • PHP >= 8.2
  • WordPress
  • WooCommerce/Action Scheduler (via woocommerce/action-scheduler)

Provided Abstracts

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

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

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

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

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

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

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

Dream_Encode\WordPress_Plugin_Utils\Abstracts\Abstract_REST_API

Base class for registering a REST API namespace and routes.

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

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

Dream_Encode\WordPress_Plugin_Utils\RestApi\REST_Response

Simple value object for REST API responses.

Properties:

  • $statusstring, defaults to 'error'.
  • $messagestring, defaults to ''.
  • $datamixed, initialised to a fresh stdClass.
  • $successbool|null, defaults to null.

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

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

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

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

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

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

# Lint code
composer lint

# Auto-format code
composer format

# Static analysis
composer analyze

# Run all checks + tests
composer test

License

GPL-3.0-or-later

dream-encode/de-wordpress-plugin-utils 适用场景与选型建议

dream-encode/de-wordpress-plugin-utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 120 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「plugin」 「logger」 「wordpress」 「utilities」 「upgrader」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dream-encode/de-wordpress-plugin-utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dream-encode/de-wordpress-plugin-utils 我们能提供哪些服务?
定制开发 / 二次开发

基于 dream-encode/de-wordpress-plugin-utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 120
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 42
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2026-04-21