<?php
/**
 * Plugin Name: YooTheme SEO Figure Element
 * Plugin URI: https://numalis.com
 * Description: Adds a semantic, SEO-optimized figure element to YooTheme Pro with modern image format support (AVIF/WebP), proper HTML5 structure, and performance best practices.
 * Version: 1.0.0
 * Author: Jacques Mojsilovic
 * Author URI: https://numalis.com
 * License: GPL-2.0+
 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain: yt-seo-figure
 * Requires at least: 5.8
 * Requires PHP: 7.4
 * YooTheme: 4.0+
 */

// Exit if accessed directly
if (!defined('ABSPATH')) {
    exit;
}

// Define plugin constants
define('YT_SEO_FIGURE_VERSION', '1.0.0');
define('YT_SEO_FIGURE_PATH', plugin_dir_path(__FILE__));
define('YT_SEO_FIGURE_URL', plugin_dir_url(__FILE__));

/**
 * Load the custom element into YooTheme Pro
 */
add_action('after_setup_theme', function () {

    // Check if YooTheme Pro is active
    if (!class_exists('YOOtheme\Application')) {
        return;
    }

    // Extend YooTheme's Builder to register our custom element
    add_action('init', function () {

        // Get the app instance
        $app = \YOOtheme\Application::getInstance();

        // Add our element path to the builder
        $app->extend(\YOOtheme\Builder::class, function ($builder) {
            $builder->addTypePath(YT_SEO_FIGURE_PATH . 'elements/*/element.json');
            return $builder;
        });
    });
});

/**
 * Show admin notice if YooTheme Pro is not active
 */
add_action('admin_notices', function () {
    if (!class_exists('YOOtheme\Application')) {
        ?>
        <div class="notice notice-warning is-dismissible">
            <p>
                <strong>YooTheme SEO Figure Element</strong> requires YooTheme Pro to be installed and activated.
            </p>
        </div>
        <?php
    }
});
