# fluent-cart/1.6.4/app/Services/PluginInstaller/BackgroundInstaller.php

FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler, version 1.6.4. 184 lines.

- Page: https://pluginprobe.com/plugins/fluent-cart/1.6.4/code/app/Services/PluginInstaller/BackgroundInstaller.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.6.4/raw/app/Services/PluginInstaller/BackgroundInstaller.php
- Modified: 2026-09-11T13:28:26+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-cart/1.6.4/code/app/Services/PluginInstaller/BackgroundInstaller.php#L10-L20`.

```php
<?php

namespace FluentCart\App\Services\PluginInstaller;

use FluentCart\Framework\Support\Arr;

class BackgroundInstaller
{

    public function installPlugin($pluginSlug)
    {
        $plugin = [
            'name'      => $pluginSlug,
            'repo-slug' => $pluginSlug,
            'file'      => $pluginSlug . '.php'
        ];

        try {
            $this->backgroundInstaller($plugin);
        } catch (\Exception $exception) {
            return new \WP_Error('plugin_install_error', $exception->getMessage());
        }

        return true;
    }

    private function backgroundInstaller($plugin_to_install)
    {
        if (!empty($plugin_to_install['repo-slug'])) {
            require_once ABSPATH . 'wp-admin/includes/file.php';
            require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
            require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
            require_once ABSPATH . 'wp-admin/includes/plugin.php';

            WP_Filesystem();

            $skin = new \Automatic_Upgrader_Skin();
            $upgrader = new \WP_Upgrader($skin);
            $installed_plugins = array_keys(\get_plugins());
            $plugin_slug = $plugin_to_install['repo-slug'];
            $plugin_file = isset($plugin_to_install['file']) ? $plugin_to_install['file'] : $plugin_slug . '.php';
            $plugin_basename = $plugin_slug . '/' . $plugin_file;
            $installed = false;
            $activate = false;

            // See if the plugin is installed already.
            if (in_array($plugin_basename, $installed_plugins, true)) {
                $installed = true;
                $activate = !is_plugin_active($plugin_basename);
            }

            // Install this thing!
            if (!$installed) {
                // Suppress feedback.
                ob_start();

                try {
                    $plugin_information = plugins_api(
                        'plugin_information',
                        array(
                            'slug'   => $plugin_slug,
                            'fields' => array(
                                'short_description' => false,
                                'sections'          => false,
                                'requires'          => false,
                                'rating'            => false,
                                'ratings'           => false,
                                'downloaded'        => false,
                                'last_updated'      => false,
                                'added'             => false,
                                'tags'              => false,
                                'homepage'          => false,
                                'donate_link'       => false,
                                'author_profile'    => false,
                                'author'            => false,
                            ),
                        )
                    );

                    if (is_wp_error($plugin_information)) {
                        throw new \Exception(wp_kses_post($plugin_information->get_error_message()));
                    }

                    $package = $plugin_information->download_link;
                    $download = $upgrader->download_package($package);

                    if (is_wp_error($download)) {
                        throw new \Exception(wp_kses_post($download->get_error_message()));
                    }

                    $working_dir = $upgrader->unpack_package($download, true);

                    if (is_wp_error($working_dir)) {
                        throw new \Exception(wp_kses_post($working_dir->get_error_message()));
                    }

                    $result = $upgrader->install_package(
                        array(
                            'source'                      => $working_dir,
                            'destination'                 => WP_PLUGIN_DIR,
                            'clear_destination'           => false,
                            'abort_if_destination_exists' => false,
                            'clear_working'               => true,
                            'hook_extra'                  => array(
                                'type'   => 'plugin',
                                'action' => 'install',
                            ),
                        )
                    );

                    if (is_wp_error($result)) {
                        throw new \Exception(wp_kses_post($result->get_error_message()));
                    }

                    $activate = true;

                } catch (\Exception $e) {
                    throw new \Exception(esc_html($e->getMessage()));
                }

                // Discard feedback.
                ob_end_clean();
            }

            wp_clean_plugins_cache();

            // Activate this thing.
            if ($activate) {
                try {
                    $result = activate_plugin($plugin_basename);

                    if (is_wp_error($result)) {
                        throw new \Exception(esc_html($result->get_error_message()));
                    }
                } catch (\Exception $e) {
                    throw new \Exception(esc_html($e->getMessage()));
                }
            }
        }
    }

    public function installFromCdn($cdnUrl, $pluginSlug)
    {
        $isHandled = apply_filters('fluent_cart/outside_addon/handle_cdn_install', null, [
            'url'         => $cdnUrl,
            'plugin_slug' => $pluginSlug
        ]);

        if ($isHandled) {
            return $isHandled;
        }

        return [
            'action' => 'copy',
            'url'    => $cdnUrl
        ];
    }

    public function installFromGithub($githubUrl, $pluginSlug, $path = 'zipball_url')
    {
        $mainUrl = $githubUrl;
        $download = null;


        $isHandeled = apply_filters('fluent_cart/outside_addon/handle_install', null, [
            'url'         => $githubUrl,
            'plugin_slug' => $pluginSlug,
            'path'        => $path
        ]);


        if ($isHandeled) {
            return $isHandeled;
        } else {
            return [
                'action' => 'copy',
                'url'    => $mainUrl
            ];
        }
    }


}

```
