<?php
/**
 * Plugin Name:     CoffeeWP Media Cleanup – Scan and Remove Unused Media and Orphan Thumbnails
 * Description:     Manage thumbnail sizes, scan media files, detect unused media, and clean up with backup safety.
 * Author:          Elie Hanna
 * Text Domain:     coffeewp-media-cleanup
 * Version:         1.3.3
 * Requires PHP:    7.4
 * Requires at least: 5.8
 * License:         GPLv2 or later
 * License URI:     https://www.gnu.org/licenses/gpl-2.0.html
 *
 * @package CoffeeWP_Media_Cleanup
 *
 * Third-party notices:
 * Catppuccin color palette — Copyright (c) 2021 Catppuccin (MIT License).
 */

defined( 'ABSPATH' ) || exit;

// Side-by-side activation guard. WP's activate_plugin() may load this file
// while another distribution is still loaded in the same request. Use
// defined() guards so PHP warnings + CWPM_PATH drift cannot derail the
// activation flow.
defined( 'CWPM_VERSION' ) || define( 'CWPM_VERSION', '1.3.3' );
defined( 'CWPM_FILE' ) || define( 'CWPM_FILE', __FILE__ );
defined( 'CWPM_PATH' ) || define( 'CWPM_PATH', plugin_dir_path( __FILE__ ) );
defined( 'CWPM_URL' ) || define( 'CWPM_URL', plugin_dir_url( __FILE__ ) );
defined( 'CWPM_BASENAME' ) || define( 'CWPM_BASENAME', plugin_basename( __FILE__ ) );

/**
 * Operational tuning constants — overrideable from wp-config.php.
 * CWPM_HASH_SIZE_CEILING          Max file size (bytes) the hasher will process.
 * CWPM_SCAN_BATCH_DEFAULT         Default scan batch size (files per request).
 * CWPM_SCAN_BATCH_MAX             Upper clamp for user-configured batch size.
 * CWPM_SCAN_BATCH_MIN             Lower clamp for user-configured batch size.
 * CWPM_HASH_BATCH_DEFAULT         Default hash batch size.
 * CWPM_TRASH_RETENTION_DEFAULT_DAYS  Fallback auto-delete retention (days; 0 = never).
 */
defined( 'CWPM_HASH_SIZE_CEILING' ) || define( 'CWPM_HASH_SIZE_CEILING', 50 * 1024 * 1024 );
defined( 'CWPM_SCAN_BATCH_DEFAULT' ) || define( 'CWPM_SCAN_BATCH_DEFAULT', 50 );
defined( 'CWPM_SCAN_BATCH_MIN' ) || define( 'CWPM_SCAN_BATCH_MIN', 10 );
defined( 'CWPM_SCAN_BATCH_MAX' ) || define( 'CWPM_SCAN_BATCH_MAX', 200 );
defined( 'CWPM_HASH_BATCH_DEFAULT' ) || define( 'CWPM_HASH_BATCH_DEFAULT', 50 );
defined( 'CWPM_TRASH_RETENTION_DEFAULT_DAYS' ) || define( 'CWPM_TRASH_RETENTION_DEFAULT_DAYS', 0 );

require_once CWPM_PATH . 'includes/class-autoloader.php';

CWPM_Autoloader::register();

add_action( 'plugins_loaded', array( CWPM\Core\PathsMigration::class, 'maybe_run' ), 5 );
add_action( 'plugins_loaded', array( CWPM\Core\Db::class, 'install' ) );

CWPM\Plugin::init();
