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\Models\Model;
use WeDevs\WpUtils\Models\Traits\HasTimestamps;
use WeDevs\WpUtils\Models\Traits\SoftDeletes;
class Contact extends Model {
use HasTimestamps, SoftDeletes;
protected static $table = 'crm_contacts';
protected $fillable = [ 'first_name', 'last_name', 'email', 'phone' ];
protected $casts = [
'id' => 'int',
'is_active' => 'bool',
];
protected static function getHookPrefix() {
return 'myplugin';
}
}
use WeDevs\WpUtils\Container;
class MyPlugin {
use Container;
public function __construct() {
$this->my_service = new MyService();
$this->my_service->doSomething();
}
}
use WeDevs\WpUtils\Hooks;
class MyPlugin {
use Hooks;
public function __construct() {
$this->add_action( 'init', 'on_init' );
$this->add_filter( 'the_title', 'filter_title' );
}
public function on_init() {
// ...
}
public function filter_title( $title ) {
return $title . ' - Modified';
}
}
use WeDevs\WpUtils\Logger;
class MyPlugin {
use Logger;
public function some_method() {
$this->log_info( 'User logged in', [ 'user_id' => 5 ] );
$this->log_error( 'Payment failed', [ 'order_id' => 123 ] );
$this->log_warning( 'Rate limit approaching' );
$this->log_debug( 'Query executed' ); // only when WP_DEBUG is on
}
}
// Output: [INFO][MyPlugin] User logged in {"user_id":5}
use WeDevs\WpUtils\Singleton;
class MySingletonClass {
use Singleton;
}
$instance = MySingletonClass::instance();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.