Skip to content

Commit 49273af

Browse files
authored
Merge pull request #126 from wp-cli/121-slug-case-mismatch
Throw error in theme fetcher on non-lowercase slugs
2 parents 7f3a844 + 9ee66dd commit 49273af

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

features/plugin-activate.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,17 @@ Feature: Activate WordPress plugins
8080
"""
8181
Success: No plugins installed.
8282
"""
83+
84+
Scenario: Using a non-lowercase slug should not find a plugin
85+
When I try `wp plugin activate Akismet`
86+
Then STDOUT should be empty
87+
And STDERR should contain:
88+
"""
89+
The 'Akismet' plugin could not be found.
90+
"""
91+
92+
When I run `wp plugin activate akismet`
93+
Then STDOUT should contain:
94+
"""
95+
Plugin 'akismet' activated.
96+
"""

features/theme.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,20 @@ Feature: Manage WordPress themes
517517
"""
518518
Error: Can't find the requested theme's version 1.4.2 in the WordPress.org theme repository (HTTP code 404).
519519
"""
520+
521+
@require-wp-4.4
522+
Scenario: Using a non-lowercase slug should not find a theme
523+
Given a WP install
524+
525+
When I try `wp theme activate TwentySixteen`
526+
Then STDOUT should be empty
527+
And STDERR should contain:
528+
"""
529+
The 'TwentySixteen' theme could not be found.
530+
"""
531+
532+
When I run `wp theme activate twentysixteen`
533+
Then STDOUT should be:
534+
"""
535+
Success: Switched to 'Twenty Sixteen' theme.
536+
"""

src/WP_CLI/Fetchers/Theme.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ class Theme extends Base {
1414

1515
/**
1616
* Get a theme object by name
17-
*
17+
*
1818
* @param string $name
1919
* @return object|false
2020
*/
2121
public function get( $name ) {
22+
// To avoid later issues, we force slugs to be lowercase.
23+
if( strtolower( $name ) !== $name ) {
24+
return false;
25+
}
26+
2227
$theme = wp_get_theme( $name );
2328

2429
if ( !$theme->exists() ) {

0 commit comments

Comments
 (0)