HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/wpemobiq/wp-content/plugins/wp-rollback/src/Rollbacks/PluginRollback.php
<?php

declare(strict_types=1);

namespace WpRollback\Free\Rollbacks;

use WpRollback\SharedCore\Plugin\PluginInfo;
use WpRollback\SharedCore\Core\Utilities\PluginUtility;

/**
 * Class PluginRollback
 * 
 * Handles plugin rollback functionality
 */
class PluginRollback {
    /**
     * @var PluginInfo
     */
    private PluginInfo $plugin_info;

    /**
     * Constructor
     *
     * @param string $plugin_slug The plugin slug
     */
    public function __construct(string $plugin_slug) {
        $this->plugin_info = new PluginInfo($plugin_slug);
    }

    /**
     * Initialize the rollback process
     *
     * @param string $version Version to rollback to
     * @return bool|\WP_Error True on success, WP_Error on failure
     */
    public function rollback(string $version) {
        if (!PluginUtility::currentUserCanRollback()) {
            return new \WP_Error(
                'insufficient_permissions',
                __('You do not have permission to perform rollbacks.', 'wp-rollback')
            );
        }

        if (!PluginUtility::isValidVersion($version)) {
            return new \WP_Error(
                'invalid_version',
                __('Invalid version number provided.', 'wp-rollback')
            );
        }

        $current_version = $this->plugin_info->getCurrentVersion();
        if ($current_version === $version) {
            return new \WP_Error(
                'same_version',
                __('Cannot rollback to the same version.', 'wp-rollback')
            );
        }

        $available_versions = $this->plugin_info->getAvailableVersions();
        if (!in_array($version, $available_versions, true)) {
            return new \WP_Error(
                'version_not_found',
                __('The requested version is not available.', 'wp-rollback')
            );
        }

        // Perform rollback logic here
        return true;
    }
}