1. Go to this page and download the library: Download wedevs/wp-utils library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wedevs / wp-utils example snippets
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...
}
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...
}
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...
}
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();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.