diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index 255af27c3..69575118a 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -190,6 +190,13 @@ static function ( $dirs ) use ( $excluded_files ) { ); } + // Ensure the correct slug. + if ( is_dir( $plugin ) && empty( $options['slug'] ) ) { + $options['slug'] = basename( $plugin ); + } elseif ( filter_var( $plugin, FILTER_VALIDATE_URL ) && empty( $options['slug'] ) ) { + $options['slug'] = Plugin_Request_Utility::get_slug_from_url( $plugin ); + } + try { $runner->set_experimental_flag( $options['include-experimental'] ); $runner->set_check_slugs( $checks ); diff --git a/includes/Utilities/Plugin_Request_Utility.php b/includes/Utilities/Plugin_Request_Utility.php index 37b1c1868..f687fcc5a 100644 --- a/includes/Utilities/Plugin_Request_Utility.php +++ b/includes/Utilities/Plugin_Request_Utility.php @@ -82,6 +82,26 @@ public static function get_plugin_basename_from_input( $plugin_slug ) { ); } + /** + * Returns the plugin slug based on the input provided. + * + * @since 1.3.0 + * + * @param string $plugin_url The plugin url. + * @return string The plugin slug. + */ + public static function get_slug_from_url( $plugin_url ) { + $plugin_slug = ''; + + if ( false !== strpos( $plugin_url, '#wporgapi:' ) ) { + $plugin_url = substr( $plugin_url, 0, strpos( $plugin_url, '#' ) ); + } + $plugin_slug = basename( $plugin_url ); + $plugin_slug = str_replace( '.zip', '', $plugin_slug ); + + return $plugin_slug; + } + /** * Initializes the runner classes. * diff --git a/tests/phpunit/tests/Utilities/Plugin_Request_Utility_Tests.php b/tests/phpunit/tests/Utilities/Plugin_Request_Utility_Tests.php index fc760ca26..c03d94901 100644 --- a/tests/phpunit/tests/Utilities/Plugin_Request_Utility_Tests.php +++ b/tests/phpunit/tests/Utilities/Plugin_Request_Utility_Tests.php @@ -57,6 +57,12 @@ public function test_get_plugin_basename_from_input_with_invalid_input() { Plugin_Request_Utility::get_plugin_basename_from_input( 'invalid' ); } + public function test_get_slug_from_url() { + $slug = Plugin_Request_Utility::get_slug_from_url( 'http://example.com/wp-content/plugins/plugin-check/' ); + + $this->assertSame( 'plugin-check', $slug ); + } + /** * @runInSeparateProcess * @preserveGlobalState disabled