<?php
/**
 * Plugin Name: Social Publisher
 * Description: Publish WordPress content to multiple social networks with manual publishing, image editing, and Gutenberg auto-post support.
 * Version: 1.4.14
 * Author: CalliopeWP
 * Author URI: https://pluginswordpress.calliope.com.ar/
 * Requires at least: 6.4
 * Requires PHP: 8.0
 * License: GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: calliope-social-publisher
 * Domain Path: /languages
 */

if (!defined('ABSPATH')) {
    exit;
}

// Define plugin constants.
define('CALLIOPE_SP_PATH', plugin_dir_path(__FILE__));
define('CALLIOPE_SP_URL', plugin_dir_url(__FILE__));
define('CALLIOPE_SP_VERSION', '1.4.14');

// Lightweight class autoloader.
// Load classes only when they are actually instantiated or referenced.
if (!function_exists('calliope_social_publisher_autoload')) {
    function calliope_social_publisher_autoload($class) {
        if (strpos($class, 'Calliope_SP_') !== 0) {
            return;
        }

        $relative = substr($class, strlen('Calliope_SP_'));
        if ($relative === '') {
            return;
        }

        $slug = strtolower(str_replace('_', '-', $relative));
        $file = CALLIOPE_SP_PATH . 'classes/class-' . $slug . '.php';

        if (is_readable($file)) {
            require_once $file;
        }
    }
}

spl_autoload_register('calliope_social_publisher_autoload');

// Load the main controller eagerly. The rest will be autoloaded on demand.
require_once CALLIOPE_SP_PATH . 'classes/class-master.php';

/**
 * Initialize the plugin.
 */
function calliope_social_publisher_init() {
    new Calliope_SP_Master();
}
add_action('plugins_loaded', 'calliope_social_publisher_init', 20);
