Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force slug in wp cli command to ensure that it get's the correct one by default #780

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions includes/CLI/Plugin_Check_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
20 changes: 20 additions & 0 deletions includes/Utilities/Plugin_Request_Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down