定制 wedevs/wp-utils 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

wedevs/wp-utils

最新稳定版本:v1.1

Composer 安装命令:

composer require wedevs/wp-utils

包简介

Various WordPress classes and traits for WordPress

README 文档

README

License: LGPL v3 Packagist GitHub all releases Packagist Downloads

A collection of useful codes and utilities for WordPress plugin development. These simplifies common tasks and promote code reusability in WordPress projects.

Installation

Install the package via Composer:

composer require wedevs/wp-utils

Usage

ContainerTrait

With ContainerTrait you can easily store and retrieve dynamic properties within your classes, providing a flexible and convenient way to manage and access data without the need for explicitly defined class properties.

Usage example:

use WeDevs\WpUtils\ContainerTrait;

class MyPlugin {

    use ContainerTrait;

    public function __construct() {
        // Register an instance
        $this->my_service = new MyService();

        // Use the instance
        $this->my_service->doSomething();
    }

    // Rest of your plugin code...
}

HookTrait

The HookTrait provides reusable methods for managing WordPress action and filter hooks in your plugin. It simplifies the process of adding, removing, or executing hooks.

use WeDevs\WpUtils\HookTrait;

class MyPlugin {

    use HookTrait;

    public function __construct() {
        // Add an action hook
        $this->add_action( 'init', 'my_init_function' );

        // Add a filter hook
        $this->add_filter( 'the_title', 'my_title_filter' );
    }

    public function my_init_function() {
        // Actions to be performed during 'init'
    }

    public function my_title_filter( $title ) {
        // Modify the post title
        return $title . ' - Customized';
    }

    // Rest of your plugin code...
}

LogTrait

The LogTrait provides a simple logging mechanism for your WordPress plugin. It allows you to log messages to the PHP error log.

Usage example:

use WeDevs\WpUtils\LogTrait;

class MyPlugin {

    use LogTrait;

    public function some_method() {
        // Log an informational message
        $this->log_info( 'Some informational message.' );

        // Log an error message
        $this->log_error( 'An error occurred.' );

        // Log a debug message
        $this->log_debug( 'A debug message' );
    }

    // Rest of your plugin code...
}

SingletonTrait

The SingletonTrait implements the singleton pattern for your WordPress plugin classes. It ensures that only one instance of the class is created and provides a global access point to that instance.

Usage example:

use WeDevs\WpUtils\SingletonTrait;

class MySingletonClass {

    use SingletonTrait;

    // Rest of your singleton class implementation...
}

// Get the instance of the singleton class
$instance = MySingletonClass::instance();

// Use the instance
$instance->doSomething();

License

This project is licensed under the GPL 2.0 or Later License.

统计信息

  • 总下载量: 4.81k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2023-06-06