PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.0-dev2
Elementor Website Builder – more than just a page builder v3.28.0-dev2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / app / modules / import-export / runners / import / plugins.php

plugins.php in Elementor Website Builder – more than just a page builder 3.28.0-dev2, at app/modules/import-export/runners/import/plugins.php

71 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\App\Modules\ImportExport\Runners\Import;
4
5 use Elementor\Core\Utils\Collection;
6 use Elementor\Core\Utils\Plugins_Manager;
7 use Elementor\Core\Utils\Str;
8
9 class Plugins extends Import_Runner_Base {
10
11 /**
12 * @var Plugins_Manager
13 */
14 private $plugins_manager;
15
16 public function __construct( $plugins_manager = null ) {
17 if ( $plugins_manager ) {
18 $this->plugins_manager = $plugins_manager;
19 } else {
20 $this->plugins_manager = new Plugins_Manager();
21 }
22 }
23
24 public static function get_name(): string {
25 return 'plugins';
26 }
27
28 public function should_import( array $data ) {
29 return (
30 isset( $data['include'] ) &&
31 in_array( 'plugins', $data['include'], true ) &&
32 ! empty( $data['manifest']['plugins'] ) &&
33 ! empty( $data['selected_plugins'] )
34 );
35 }
36
37 public function import( array $data, array $imported_data ) {
38 $plugins = $data['selected_plugins'];
39
40 $plugins_collection = ( new Collection( $plugins ) )
41 ->map( function ( $item ) {
42 if ( ! Str::ends_with( $item['plugin'], '.php' ) ) {
43 $item['plugin'] .= '.php';
44 }
45 return $item;
46 } );
47
48 $slugs = $plugins_collection
49 ->map( function ( $item ) {
50 return $item['plugin'];
51 } )
52 ->all();
53
54 $installed = $this->plugins_manager->install( $slugs );
55 $activated = $this->plugins_manager->activate( $installed['succeeded'] );
56
57 $ordered_activated_plugins = $plugins_collection
58 ->filter( function ( $item ) use ( $activated ) {
59 return in_array( $item['plugin'], $activated['succeeded'], true );
60 } )
61 ->map( function ( $item ) {
62 return $item['name'];
63 } )
64 ->all();
65
66 $result['plugins'] = $ordered_activated_plugins;
67
68 return $result;
69 }
70 }
71