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