A collection of useful codes and utilities for WordPress plugin development..

Overview

WordPress Utils

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.

You might also like...
This repository contains academic codes from experiments and labs I did during my academic years.

Table Of Content Semester 3 Business Communication Skills Computer Graphics Digital Electronics and Logic Design Fundamentals of Data Structures Human

A useful PocketMine-MP plugin that allows you to create crates in-game!

ComplexCrates A useful PocketMine-MP plugin that allows you to create crates in-game! Commands Main command: /crate Sub commands: create

The plugin generates posts/pages. Useful to generate millions of records in wp_posts table
The plugin generates posts/pages. Useful to generate millions of records in wp_posts table

KAGG Generator The plugin generates posts/pages. Useful to generate millions of records in wp_posts table. In WordPress development, sometimes it is n

A PHP web interface for scanning ISBN book codes, identify books with Antolin reading promotion offer

Ein PHP-Webinterface zum Scannen von ISBN-Buchcodes, identifiziere Bücher mit Antolin-Leseförderungs-Angebot. Einfache Installation. Für Mitarbeiter*innen in Schulbüchereien.

Api.video-wordpress-plugin - The official api.video plugin for WordPress
Api.video-wordpress-plugin - The official api.video plugin for WordPress

api.video WordPress Plugin api.video is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managin

Magento-bulk - Bulk Import/Export helper scripts and CLI utilities for Magento Commerce

Magento Bulk Bulk operations for Magento. Configuration Copy config.php.sample to config.php and edit it. Product Attribute Management List All Attrib

Utilities to scan PHP code and generate class maps.

composer/class-map-generator Utilities to generate class maps and scan PHP code. Installation Install the latest version with: $ composer require comp

A set of utilities for working with vk api!

vk-utils Документация на русском языке Installation composer require labile/vk-utils How to use it? Simple example use Astaroth\VkUtils\Client; $api

Releases(v1.1)
Owner
weDevs
We are a WordPress product company. Our products include WP User Frontend, #Dokan and WP Project Manager and WP ERP (@getwperp).
weDevs
This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

DIVE 20 Nov 11, 2022
TEC UTilities (or tut) are a collection of tools for managing plugins.

TEC Utilities TEC UTilities (or tut) are a collection of tools for managing plugins. /^\ L L /

The Events Calendar 5 Dec 2, 2022
A collection of command-line utilities to aid in debugging browser engines.

Browser debug utilities This project contains several scripts that make the process of debugging browser engines much easier (some special cases excep

Clay Freeman 5 May 29, 2023
🎓 Collection of useful PHP frequently asked questions, articles and best practices

PHP.earth documentation These files are available online at PHP.earth. Contributing and license We are always looking forward to see your contribution

PHP.earth 278 Dec 27, 2022
Collection of useful PHP functions, mini-classes, and snippets for every day.

JBZoo / Utils Collection of PHP functions, mini classes and snippets for everyday developer's routine life. Install composer require jbzoo/utils Usage

JBZoo Toolbox 786 Dec 30, 2022
Verify purchase codes right on your WordPress dashboard.

envato-purchase-code-widget Verify purchase codes right on your WordPress dashboard. Install the plugin Go to Settings->EPCW and enter your "Envato AP

null 6 Oct 28, 2021
Magento 2 Blog Extension is a better blog extension for Magento 2 platform. These include all useful features of Wordpress CMS

Magento 2 Blog extension FREE Magento 2 Better Blog by Mageplaza is integrated right into the Magento backend so you can manage your blog and your e-c

Mageplaza 113 Dec 14, 2022
This Kirby V3 Plugin brings snippets and blueprints together in one place. It includes useful tools that completely changing the way you work with Kirby: Fast and well organized.

Kirby Components Overview Do you love to make awesome projects with Kirby CMS? Do you also find it difficult to switch between snippets and blueprints

Roman Gsponer 6 May 31, 2023
:globe_with_meridians: List of all countries with names and ISO 3166-1 codes in all languages and data formats.

symfony upgrade fixer • twig gettext extractor • wisdom • centipede • permissions handler • extraload • gravatar • locurro • country list • transliter

Saša Stamenković 5k Dec 22, 2022
WordPress plugin which contains a collection of modules to apply theme-agnostic front-end modifications

Soil A WordPress plugin which contains a collection of modules to apply theme-agnostic front-end modifications. Soil is a commercial plugin available

Roots 1k Dec 20, 2022