PluginProbe
Extendify / 3.2.0
Extendify v3.2.0
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / app / Shared / Services / PluginDependencies / PluginInstaller.php

PluginInstaller.php in Extendify 3.2.0, at app/Shared/Services/PluginDependencies/PluginInstaller.php

70 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Install plugins programmatically.
5 */
6
7 namespace Extendify\Shared\Services\PluginDependencies;
8
9 defined('ABSPATH') || die('No direct access.');
10
11 use Extendify\Shared\Services\AutoUpdate\AutoUpdate;
12
13 /**
14 * Install plugins programmatically.
15 */
16
17 class PluginInstaller
18 {
19 /**
20 * Install or activate a required plugin
21 *
22 * @param string $slug - The plugin slug.
23 * @param string $fallbackPath - The fallback path.
24 * @return mixed
25 */
26 public static function installPlugin($slug, $fallbackPath)
27 {
28 require_once ABSPATH . 'wp-admin/includes/file.php';
29 require_once ABSPATH . 'wp-admin/includes/plugin.php';
30 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
31 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
32 require_once ABSPATH . 'wp-admin/includes/class-language-pack-upgrader.php';
33
34 // Retrieve the details of the plugin based on the slug.
35 $api = plugins_api(
36 'plugin_information',
37 [
38 'slug' => $slug,
39 'fields' => [
40 'sections' => false,
41 'language_packs' => true,
42 ],
43 ]
44 );
45
46 $skin = new \WP_Ajax_Upgrader_Skin();
47 $upgrader = new \Plugin_Upgrader($skin);
48
49 $upgrader->install($api->download_link);
50 $file = $upgrader->plugin_info();
51
52 if (AutoUpdate::isEnabled()) {
53 AutoUpdate::enableAutoUpdateForPlugin($file);
54 }
55
56 // Install the language pack if available.
57 $currentLocale = get_locale();
58 foreach ($api->language_packs as $pack) {
59 if ($pack['language'] === $currentLocale) {
60 $languageUpgrader = new \Language_Pack_Upgrader($skin);
61 $languageUpgrader->upgrade((object) $pack);
62 break;
63 }
64 }
65
66 // Activate the plugin.
67 return activate_plugin($file ? $file : $fallbackPath);
68 }
69 }
70