C:\xampp\htdocs\landing\wp-content\updraft\plugins-old\amp\src\PluginRegistry.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
 * Class PluginRegistry.
 *
 * @package AmpProject\AmpWP
 */

namespace AmpProject\AmpWP;

use 
AmpProject\AmpWP\Infrastructure\Service;

/**
 * Get information about plugins and their current status.
 *
 * @package AmpProject\AmpWP
 * @internal
 * @since 2.0
 */
final class PluginRegistry implements Service {

    
/**
     * Plugin folder.
     *
     * @var string
     */
    
private $plugin_folder '';

    
/**
     * Get absolute path to plugin directory.
     *
     * @see WP_PLUGIN_DIR
     * @return string Plugin directory.
     */
    
public function get_plugin_dir() {
        
$plugin_dir WP_PLUGIN_DIR;
        if ( 
$this->plugin_folder ) {
            
$plugin_dir .= '/' trim$this->plugin_folder'/' );
        }
        return 
$plugin_dir;
    }

    
/**
     * Get plugin slug from file.
     *
     * If the plugin file is in a directory, then the slug is just the directory name. Otherwise, if the file is not
     * inside of a directory and is just a single-file plugin, then the slug is the filename of the PHP file.
     *
     * @see \WP_CLI\Utils\get_plugin_name()
     *
     * @param string $plugin_file Plugin file.
     * @return string Plugin slug.
     */
    
public function get_plugin_slug_from_file$plugin_file ) {
        return 
strtok$plugin_file'/' );
    }

    
/**
     * Get array of installed plugins, keyed by slug.
     *
     * @param bool $active_only Limit the returned plugins to just those which are active.
     * @param bool $omit_core   Omit core plugins that should never be listed. These are in particular AMP and Gutenberg.
     * @return array Plugins keyed by slug.
     */
    
public function get_plugins$active_only false$omit_core true ) {
        
$active_plugins get_option'active_plugins', [] );

        
$plugins = [];
        foreach ( 
$this->get_plugins_data() as $plugin_file => $plugin ) {
            if ( 
$active_only && ! in_array$plugin_file$active_pluginstrue ) ) {
                continue;
            }

            
$plugin_slug $this->get_plugin_slug_from_file$plugin_file );

            
/*
             * When a plugin has a nested plugin, such as foo/foo.php also having foo/extra.php, discard the extra.php
             * instance from the registry in favor of only keeping the "main" plugin file entry for foo.php. This is
             * done because when the Reflection API is being used to determine which plugin a given piece of markup is
             * coming from, it cannot absolutely determine which plugin file was responsible for including the PHP file
             * that the function was defined inside of.
             */
            
if ( isset( $plugins$plugin_slug ] ) && basename$plugins$plugin_slug ]['File'] ) === "{$plugin_slug}.php" ) {
                continue;
            }

            
$plugins$plugin_slug ] = array_merge(
                [ 
'File' => $plugin_file ], // PascalCase is used for consistency with the other keys.
                
$plugin
            
);
        }

        if ( 
$omit_core ) {
            unset( 
$plugins['amp'], $plugins['gutenberg'] );
        }

        return 
$plugins;
    }

    
/**
     * Find a plugin from a slug.
     *
     * A slug is a plugin directory name like 'amp' or if the plugin is just a single file, then the PHP file in
     * the plugins directory.
     *
     * @param string $plugin_slug Plugin slug.
     * @return array|null {
     *     Plugin data if found, otherwise null.
     *
     *     @type string $name Plugin name (file).
     *     @type array  $data Plugin data.
     * }
     */
    
public function get_plugin_from_slug$plugin_slug ) {
        
$plugins $this->get_plugins_data();
        if ( isset( 
$plugins$plugin_slug ] ) ) {
            return [
                
'file' => $plugin_slug,
                
'data' => $plugins$plugin_slug ],
            ];
        }
        foreach ( 
$plugins as $plugin_file => $plugin_data ) {
            if ( 
strtok$plugin_file'/' ) === $plugin_slug ) {
                return [
                    
'file' => $plugin_file,
                    
'data' => $plugin_data,
                ];
            }
        }
        return 
null;
    }

    
/**
     * Get the plugins data from WordPress.
     *
     * @return array[]
     */
    
private function get_plugins_data() {
        require_once 
ABSPATH 'wp-admin/includes/plugin.php';
        return 
get_plugins(
            
$this->plugin_folder '/' trim$this->plugin_folder'/' ) : ''
        
);
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586