/var/www/html_it/wp-content/plugins/elementor/app/modules/import-export/runners/import/plugins.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php

namespace Elementor\App\Modules\ImportExport\Runners\Import;

use 
Elementor\Core\Utils\Collection;
use 
Elementor\Core\Utils\Plugins_Manager;
use 
Elementor\Core\Utils\Str;

class 
Plugins extends Import_Runner_Base {

    
/**
     * @var Plugins_Manager
     */
    
private $plugins_manager;

    public function 
__construct$plugins_manager null ) {
        if ( 
$plugins_manager ) {
            
$this->plugins_manager $plugins_manager;
        } else {
            
$this->plugins_manager = new Plugins_Manager();
        }
    }

    public static function 
get_name() : string {
        return 
'plugins';
    }

    public function 
should_import( array $data ) {
        return (
            isset( 
$data['include'] ) &&
            
in_array'plugins'$data['include'], true ) &&
            ! empty( 
$data['manifest']['plugins'] ) &&
            ! empty( 
$data['selected_plugins'] )
        );
    }

    public function 
import( array $data, array $imported_data ) {
        
$plugins $data['selected_plugins'];

        
$plugins_collection = ( new Collection$plugins ) )
            ->
map( function ( $item ) {
                if ( ! 
Str::ends_with$item['plugin'], '.php' ) ) {
                    
$item['plugin'] .= '.php';
                }
                return 
$item;
            } );

        
$slugs $plugins_collection
            
->map( function ( $item ) {
                return 
$item['plugin'];
            } )
            ->
all();

        
$installed $this->plugins_manager->install$slugs );
        
$activated $this->plugins_manager->activate$installed['succeeded'] );

        
$ordered_activated_plugins $plugins_collection
            
->filter( function ( $item ) use ( $activated ) {
                return 
in_array$item['plugin'], $activated['succeeded'], true );
            } )
            ->
map( function ( $item ) {
                return 
$item['name'];
            } )
            ->
all();

        
$result['plugins'] = $ordered_activated_plugins;

        return 
$result;
    }
}