PHP code example of zestry-dev / wp-toolkit

1. Go to this page and download the library: Download zestry-dev/wp-toolkit 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/ */

    

zestry-dev / wp-toolkit example snippets



/**
 * Plugin Name:       Acme Plugin
 * Text Domain:       acme-plugin
 * Version:           1.0.0
 * Requires at least: 6.9
 * Requires PHP:      8.1
 */

declare( strict_types=1 );

use Acme\Plugin\Core\Kernel\Plugin;



// bootstrap.php

declare( strict_types=1 );

\defined( 'ABSPATH' ) || exit;

use Acme\Plugin\Core\Modules\CLI\CLI;

return array(
    'init' => array(
        CLI::class,
    ),
);


// resources/commands/greet.php

declare( strict_types=1 );

\defined( 'ABSPATH' ) || exit;

use Acme\Plugin\Core\Modules\CLI\Command;

return new class extends Command {

    public function handle( array $args, array $assoc_args ): void {
        $this->success( 'Hello, ' . ( $args[0] ?? 'world' ) . '.' );
    }
};

// bootstrap.php
return array(
    Path::class,      // does nothing until something asks
    Options::class,

    'init' => array(  // acts, and this is when
        CLI::class,
    ),
);

class Shortcode extends Module implements Bootable {

    public function on_boot(): void {
        add_shortcode( 'acme_form', array( $this, 'render' ) );
    }
}

use Acme\Plugin\Core\Modules\CLI\Command;
use Acme\Plugin\Core\Modules\Options;

return new class extends Command {

    public function handle( array $args, array $assoc_args ): void {
        $this->success( $this->with( Options::class )->get( 'greeting', 'hi' ) );
    }
};