PHP code example of camalote-wp / models

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

    

camalote-wp / models example snippets


use CamaloteWP\Models\Core\BootstrapRunner;

// Standard usage (creates internal Loader)
$runner = new BootstrapRunner;
$runner->register([Page\Bootstrap::class])->run();

// With dependency injection (shares Loader instance)
$loader = new Loader;
$runner = new BootstrapRunner($loader);
$runner->register([Page\Bootstrap::class])->run();

// You can also access the shared loader for additional hook registration
$loader->add_action('plugins_loaded', $this, 'load_textdomain');

// PagePostType.php
namespace MyPlugin\Page;

use CamaloteWP\Models\Abstracts\AbstractPostType;

class PagePostType extends AbstractPostType
{
    protected string $model_name = 'page';

    protected function args(): array
    {
        return [
            'public'       => true,
            'has_archive'  => true,
            'show_in_rest' => true,
            'labels' => [
                'name' => 'Pages',
                'singular_name' => 'Page',
            ],
        ];
    }
}

// PageMeta.php
namespace MyPlugin\Page;

use CamaloteWP\Models\Abstracts\AbstractMeta;

class PageMeta extends AbstractMeta
{
    protected string $model_name = 'page';

    protected function schema(): array
    {
        return [
            'subtitle' => ['type' => 'string'],
            'color'    => ['type' => 'string'],
        ];
    }

    protected function get_meta_prefix(): string
    {
        return 'page_';
    }
}

// PageBlocks.php
namespace MyPlugin\Page;

use CamaloteWP\Models\Abstracts\AbstractBlocks;

class PageBlocks extends AbstractBlocks
{
    protected string $model_name = 'page';

    protected function get_block_paths(): array
    {
        return [get_template_directory() . '/blocks'];
    }
}

// Bootstrap.php
namespace MyPlugin\Page;

use CamaloteWP\Models\Abstracts\AbstractBootstrap;

class Bootstrap extends AbstractBootstrap
{
    protected string $model_name = 'page';

    public function get_components(): array
    {
        return [
            PagePostType::class,
            PageMeta::class,
            PageBlocks::class,
        ];
    }
}

// In your plugin's main file or service provider
use CamaloteWP\Models\Core\BootstrapRunner;
use MyPlugin\Page\Bootstrap;

$runner = new BootstrapRunner;
$runner->register([Bootstrap::class])->run();

// Default constructor (backward compatible)
$runner = new BootstrapRunner;
$runner->register([Bootstrap::class])->run();

// With dependency injection
$loader = new Loader;
$runner = new BootstrapRunner($loader);
$runner->register([Bootstrap::class])->run();

// Access shared loader (optional)
$loader = $runner->get_loader();
$loader->add_action('init', $this, 'custom_init');