AutoloadFileWriter.php
11 months ago
AutoloadGenerator.php
11 months ago
AutoloadProcessor.php
11 months ago
CustomAutoloaderPlugin.php
11 months ago
ManifestGenerator.php
11 months ago
autoload.php
11 months ago
class-autoloader-handler.php
11 months ago
class-autoloader-locator.php
11 months ago
class-autoloader.php
11 months ago
class-container.php
11 months ago
class-hook-manager.php
11 months ago
class-latest-autoloader-guard.php
11 months ago
class-manifest-reader.php
11 months ago
class-path-processor.php
11 months ago
class-php-autoloader.php
11 months ago
class-plugin-locator.php
11 months ago
class-plugins-handler.php
11 months ago
class-shutdown-handler.php
11 months ago
class-version-loader.php
11 months ago
class-version-selector.php
11 months ago
index.php
11 months ago
class-plugin-locator.php
76 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | // phpcs:ignore |
| 4 | class Plugin_Locator { |
| 5 | private $path_processor; |
| 6 | public function __construct( $path_processor ) { |
| 7 | $this->path_processor = $path_processor; |
| 8 | } |
| 9 | public function find_current_plugin() { |
| 10 | // Escape from `vendor/__DIR__` to root plugin directory. |
| 11 | $plugin_directory = dirname( __DIR__, 2 ); |
| 12 | // Use the path processor to ensure that this is an autoloader we're referencing. |
| 13 | $path = $this->path_processor->find_directory_with_autoloader( $plugin_directory, array() ); |
| 14 | if ( false === $path ) { |
| 15 | throw new \RuntimeException( 'Failed to locate plugin ' . $plugin_directory ); |
| 16 | } |
| 17 | return $path; |
| 18 | } |
| 19 | public function find_using_option( $option_name, $site_option = false ) { |
| 20 | $raw = $site_option ? get_site_option( $option_name ) : get_option( $option_name ); |
| 21 | if ( false === $raw ) { |
| 22 | return array(); |
| 23 | } |
| 24 | return $this->convert_plugins_to_paths( $raw ); |
| 25 | } |
| 26 | public function find_using_request_action( $allowed_actions ) { |
| 27 | if ( empty( $_REQUEST['_wpnonce'] ) ) { |
| 28 | return array(); |
| 29 | } |
| 30 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Validated just below. |
| 31 | $action = isset( $_REQUEST['action'] ) ? wp_unslash( $_REQUEST['action'] ) : false; |
| 32 | if ( ! in_array( $action, $allowed_actions, true ) ) { |
| 33 | return array(); |
| 34 | } |
| 35 | $plugin_slugs = array(); |
| 36 | switch ( $action ) { |
| 37 | case 'activate': |
| 38 | case 'deactivate': |
| 39 | if ( empty( $_REQUEST['plugin'] ) ) { |
| 40 | break; |
| 41 | } |
| 42 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Validated by convert_plugins_to_paths. |
| 43 | $plugin_slugs[] = wp_unslash( $_REQUEST['plugin'] ); |
| 44 | break; |
| 45 | case 'activate-selected': |
| 46 | case 'deactivate-selected': |
| 47 | if ( empty( $_REQUEST['checked'] ) ) { |
| 48 | break; |
| 49 | } |
| 50 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Validated by convert_plugins_to_paths. |
| 51 | $plugin_slugs = wp_unslash( $_REQUEST['checked'] ); |
| 52 | break; |
| 53 | } |
| 54 | return $this->convert_plugins_to_paths( $plugin_slugs ); |
| 55 | } |
| 56 | private function convert_plugins_to_paths( $plugins ) { |
| 57 | if ( ! is_array( $plugins ) || empty( $plugins ) ) { |
| 58 | return array(); |
| 59 | } |
| 60 | // We're going to look for plugins in the standard directories. |
| 61 | $path_constants = array( WP_PLUGIN_DIR, WPMU_PLUGIN_DIR ); |
| 62 | $plugin_paths = array(); |
| 63 | foreach ( $plugins as $key => $value ) { |
| 64 | $path = $this->path_processor->find_directory_with_autoloader( $key, $path_constants ); |
| 65 | if ( $path ) { |
| 66 | $plugin_paths[] = $path; |
| 67 | } |
| 68 | $path = $this->path_processor->find_directory_with_autoloader( $value, $path_constants ); |
| 69 | if ( $path ) { |
| 70 | $plugin_paths[] = $path; |
| 71 | } |
| 72 | } |
| 73 | return $plugin_paths; |
| 74 | } |
| 75 | } |
| 76 |