<?php
/**
 * Plugin Name: R2 Media Offload (Multi-Cloud)
 * Description: Offload WordPress media to Amazon S3, Cloudflare R2, Backblaze B2, Wasabi, DigitalOcean Spaces, Bunny.net or Google Cloud Storage, rewrite URLs to CDN, and migrate large libraries safely.
 * Version: 1.3.0
 * Author: rise2.studio
 * Requires at least: 6.0
 * Requires PHP: 8.0
 * License: GPL-2.0-or-later
 * Text Domain: r2-offload
 */

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

define( 'R2_OFFLOAD_VERSION', '1.3.0' );
define( 'R2_OFFLOAD_FILE', __FILE__ );
define( 'R2_OFFLOAD_DIR', plugin_dir_path( __FILE__ ) );
define( 'R2_OFFLOAD_URL', plugin_dir_url( __FILE__ ) );
define( 'R2_OFFLOAD_BASENAME', plugin_basename( __FILE__ ) );

$autoload = R2_OFFLOAD_DIR . 'vendor/autoload.php';
if ( file_exists( $autoload ) ) {
	require_once $autoload;
}

spl_autoload_register(
	static function ( $class ) {
		if ( strpos( $class, 'R2_Offload\\' ) !== 0 ) {
			return;
		}
		$relative = str_replace( 'R2_Offload\\', '', $class );
		$relative = str_replace( '\\', DIRECTORY_SEPARATOR, $relative );
		$path     = R2_OFFLOAD_DIR . 'includes' . DIRECTORY_SEPARATOR . $relative . '.php';
		if ( file_exists( $path ) ) {
			require_once $path;
		}
	}
);

register_activation_hook( __FILE__, [ 'R2_Offload\\Activator', 'activate' ] );
register_deactivation_hook( __FILE__, [ 'R2_Offload\\Activator', 'deactivate' ] );

add_action(
	'plugins_loaded',
	static function () {
		R2_Offload\Plugin::instance()->boot();
	}
);
