1. Go to this page and download the library: Download wrd/wp-objective 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/ */
wrd / wp-objective example snippets
// my-plugin/src/Foundation/My_Plugin.php
use Wrd\WpObjective\Foundation\Plugin;
class My_Plugin extends Plugin {
/**
* Files to
/**
* Bindings to bind upon boot.
*
* @var array<string, class-string<Service_Provider>|Service_Provider>
*/
public array $bindings = array(
// Any bindings you want to configure.
// For example, changing the defaut logger:
Log_Manager::class => My_Log_Manager::class,
);
/**
* Service providers to register upon boot.
*
* @var (class-string<Service_Provider>|Service_Provider)[]
*/
public array $providers = array(
// Any service providers you want to provide.
My_Post_State::class,
);
}
// my-plugin/my-plugin.php
use MyVendor\MyPlugin\Foundation\My_Plugin;
// my-plugin/src/Plugin.php
namespace MyPlugin;
use Wrd\WpObjective\Foundation\Plugin;
/**
* Base implementation for a plugin.
*/
class My_Plugin extends Plugin {
/**
* Files to ted array $bindings = array();
/**
* Service providers to register upon boot.
*
* @var (class-string<Service_Provider>|Service_Provider)[]
*/
protected array $providers = array();
/**
* Migrations to load in.
*
* @var class-string<Migration>[]
*/
protected array $migrations = array();
/**
* Runs on the load.
*
* @return void
*/
public function boot(): void {
// This page left intentionally blank.
}
/**
* Runs on the 'init' hook.
*
* @return void
*/
public function init(): void {
// This page left intentionally blank.
}
/**
* Runs on the 'init' hook in an admin screen.
*
* @return void
*/
public function admin(): void {
// This page left intentionally blank.
}
/**
* Runs on the 'rest_api_init' hook in the rest API.
*
* @return void
*/
public function api(): void {
// This page left intentionally blank.
}
/**
* Runs on the 'init' hook in an public screen.
*
* @return void
*/
public function public(): void {
// This page left intentionally blank.
}
}
/**
* Action for toggling between dark & light theme.
*/
class Toggle_Theme_Action extends Action {
/**
* Called to check if the current user can undertake this action.
*
* @return WP_Error|bool
*/
public function permissions_callback(): WP_Error | bool {
return current_user_can( "manage_options" );
}
/**
* Get the redirection URL upon success.
*
* @param array $args The arguments passed to the action.
*
* @return string
*/
public function get_destination( array $args ): string {
return admin_url();
}
/**
* Get the arguments for the action.
*
* @return array
*/
public function get_arguments(): array {
return array(
'theme' => [
'type' => 'enum',
'enum' => array(
'light',
'dark',
'context'
),
]
);
}
/**
* Execute the action.
*
* @param array $args The arguments passed to the action.
*
* @return WP_Error|null
*/
public function handle( array $args ): WP_Error|null {
Settings::set( $t )
}
}
class My_Plugin extends Plugin {
public $providers = [
Toggle_Theme_Action::class
]
}
// OR
plugin()->provide( Toggle_Theme_Action::class );
new Collection( array( 1, 2, 3 ) );
// OR
Collection::from( array( 1, 2, 3 ) );
/**
* Contains the Migration class.
*
* @package wrd/wp-objective
*/
namespace Wrd\WpObjective\Foundation\Migrate;
use Wrd\WpObjective\Database\Database_Manager;
/**
* Migrates to version 1.0.0
*/
class Migration_1_0_0 {
/**
* Get version of the plugin this migration sets up for.
*
* @return string
*/
public function get_version(): string{
return '1.0.0';
}
/**
* Run the migration.
*
* @return void
*/
public function up(){
// Create your custom database table, etc.
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.