Pico CMS Custom Plugin Development

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Development of Custom Pico Plugin

Pico is a flat PHP engine without database. Content is stored in Markdown files, templates in Twig, config in YAML. Entire system fits in one folder, launches in a minute. Extended via plugins — PHP classes that connect to system events.

How Plugin System Works

Each plugin inherits AbstractPicoPlugin and reacts to events via handler methods. Pico calls them in strict order — from initialization to rendering.

<?php

class MyPlugin extends AbstractPicoPlugin
{
    const API_VERSION = 3;

    protected $enabled = true;

    public function onConfigLoaded(array &$config): void
    {
        // config available and can be modified
        if (!isset($config['my_plugin'])) {
            $config['my_plugin'] = ['option' => 'default'];
        }
    }

    public function onMetaHeaders(array &$headers): void
    {
        // add new YAML header to Markdown files
        $headers['redirect'] = 'Redirect';
        $headers['auth_required'] = 'AuthRequired';
    }

    public function onPageRendering(string &$templateName, array &$twigVariables): void
    {
        // manipulate data before rendering
        $meta = $twigVariables['meta'];
        if (!empty($meta['redirect'])) {
            header('Location: ' . $meta['redirect'], true, 302);
            exit;
        }
    }
}

File is placed in plugins/MyPlugin/MyPlugin.php. Directory structure:

plugins/
└── MyPlugin/
    ├── MyPlugin.php
    ├── config.yml.template
    └── README.md

Event Chain

Event call order in Pico 3.x:

  1. onPluginsLoaded — all plugins loaded, can access others
  2. onConfigLoaded — config parsed
  3. onRequestUrl — request URL known
  4. onContentLoading — before reading Markdown file
  5. onMetaHeaders — list of valid YAML headers
  6. onMetaParsed — page metadata parsed
  7. onContentParsed — Markdown converted to HTML
  8. onPagesLoading / onPagesLoaded — list of all pages
  9. onPageRendering — right before Twig template rendering
  10. onPageRendered — final HTML ready

Most handlers take arguments by reference (&$variable) — key mechanism for data modification.

Example: IP Restriction Plugin

public function onConfigLoaded(array &$config): void
{
    $this->allowedIps = $config['ip_restrict']['allowed'] ?? [];
    $this->restrictedPaths = $config['ip_restrict']['paths'] ?? [];
}

public function onRequestUrl(string &$url): void
{
    $clientIp = $_SERVER['REMOTE_ADDR'] ?? '';

    foreach ($this->restrictedPaths as $path) {
        if (str_starts_with($url, $path)) {
            if (!in_array($clientIp, $this->allowedIps, true)) {
                header('HTTP/1.1 403 Forbidden');
                echo 'Access denied';
                exit;
            }
        }
    }
}

Config in config/config.yml:

ip_restrict:
  allowed:
    - 192.168.1.100
    - 10.0.0.0/8
  paths:
    - /admin
    - /internal

Example: Custom Shortcodes Plugin

Pico doesn't support shortcodes out of box, but easily add via onContentParsed:

public function onContentParsed(string &$content): void
{
    // [youtube id="dQw4w9WgXcQ"]
    $content = preg_replace_callback(
        '/\[youtube\s+id="([a-zA-Z0-9_-]+)"\]/',
        static function (array $matches): string {
            $id = htmlspecialchars($matches[1], ENT_QUOTES);
            return sprintf(
                '<div class="video-embed"><iframe src="https://www.youtube.com/embed/%s" '
                . 'allowfullscreen loading="lazy"></iframe></div>',
                $id
            );
        },
        $content
    );
}

Passing Data to Twig

Plugin can add variables to templates:

public function onPageRendering(string &$templateName, array &$twigVariables): void
{
    $twigVariables['site_stats'] = [
        'total_pages' => count($twigVariables['pages']),
        'build_time'  => microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'],
    ];

    // or register Twig function
    $twig = $this->getPico()->getTwig();
    $twig->addFunction(new \Twig\TwigFunction('asset_url', function (string $path): string {
        return $this->getPico()->getBaseUrl() . '/assets/' . ltrim($path, '/');
    }));
}

In template:

<p>Pages: {{ site_stats.total_pages }}</p>
<img src="{{ asset_url('logo.svg') }}" alt="Logo">

Plugin Publishing

Plugins distributed via Composer:

{
    "name": "vendor/pico-my-plugin",
    "type": "pico-plugin",
    "require": {
        "picocms/pico": "^3.0"
    },
    "extra": {
        "picocms-plugin": {
            "class": "MyPlugin"
        }
    }
}

After composer require vendor/pico-my-plugin plugin automatically appears in plugins/.

Development Timelines

Simple plugin (1–2 events, no external dependencies): 1–2 days. Plugin with custom UI, external API, or complex routing logic: 3–5 days.