<?php
/**
 * WordPress Update Loader - Loads WP admin files required for plugin/theme updates.
 *
 * @package FleekDash\Controllers\Plugins
 * @since 2.2.0
 */

namespace FleekDash\Controllers\Plugins;

/**
 * Centralizes loading of WordPress admin includes for update operations.
 */
class WordPressUpdateLoader
{
    public function load(): void
    {
        \FleekDash\Core\PluginHelper::ensurePluginApiLoaded();
        if (!\function_exists('wp_update_plugins')) {
            require_once ABSPATH . 'wp-admin/includes/update.php';
        }
        if (!class_exists('Plugin_Upgrader')) {
            require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
        }
        require_once ABSPATH . 'wp-admin/includes/file.php';
    }

    /**
     * Load includes required for WordPress.org theme upgrades (Theme_Upgrader).
     */
    public function loadThemeUpgrade(): void
    {
        $this->load();
        require_once ABSPATH . 'wp-admin/includes/theme.php';
        if (!\class_exists('Theme_Upgrader')) {
            require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
        }
    }
}
