PHP code example of fluid22 / modules

1. Go to this page and download the library: Download fluid22/modules 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/ */

    

fluid22 / modules example snippets


use function Fluid22\Module\start;

start( [
    \MyPlugin\Modules\Assets::class,
    \MyPlugin\Modules\Admin::class,
], 'my-plugin' );

do_action( 'fluid22_modules_booted', string $key, array $modules );



namespace MyPlugin\Modules;

use Fluid22\Module\Module;

class Admin extends Module
{
    public function setup(): void
    {
        add_action( 'admin_menu', [ $this, 'register_menu' ] );
    }

    public function register_menu(): void
    {
        // ...
    }
}

$html = $this->get_template( 'hero', [
    'title'   => __( 'Hello', 'my-plugin' ),
    'excerpt' => $text,
] );

add_filter( 'fluid22_container_autowire', function ( bool $enabled, string $key ): bool {
    return $key === 'my-plugin' ? false : $enabled;
}, 10, 2 );

use function Fluid22\Module\container;

container( 'my-plugin' )->add( \MyPlugin\Contracts\Store::class, \MyPlugin\WpOptionsStore::class );

use Fluid22\Module\Models\Options;

$opts = new Options( 'myplugin_' );

$opts->api_key = 'secret';
unset( $opts->old_flag ); // or $opts->remove( 'old_flag' );
$opts->save();