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

Site_Command: Do not assume get_super_admins() has the 0 array index #432

Merged
merged 1 commit into from Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions features/site-create.feature
Expand Up @@ -46,3 +46,51 @@ Feature: Create a new site on a WP multisite
| blog_id | url |
| 1 | http://localhost/dev/ |
| 2 | http://localhost/dev/newsite/ |

Scenario: Create new site with custom `$super_admins` global
Given an empty directory
And WP files
And a database
And a extra-config file:
"""
define( 'WP_ALLOW_MULTISITE', true );
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false );
define( 'DOMAIN_CURRENT_SITE', 'localhost' );
define( 'PATH_CURRENT_SITE', '/' );
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

$super_admins = array( 1 => 'admin' );
"""
When I run `wp core config {CORE_CONFIG_SETTINGS} --extra-php < extra-config`
Then STDOUT should be:
"""
Success: Generated 'wp-config.php' file.
"""

# Old versions of WP can generate wpdb database errors if the WP tables don't exist, so STDERR may or may not be empty
When I try `wp core multisite-install --url=localhost --title=Test --admin_user=admin --admin_email=admin@example.org`
Then STDOUT should contain:
"""
Success: Network installed. Don't forget to set up rewrite rules
"""
And the return code should be 0

When I run `wp site list --fields=blog_id,url`
Then STDOUT should be a table containing rows:
| blog_id | url |
| 1 | http://localhost/ |

When I run `wp site create --slug=newsite`
Then STDOUT should be:
"""
Success: Site 2 created: http://localhost/newsite/
"""

When I run `wp site list --fields=blog_id,url`
Then STDOUT should be a table containing rows:
| blog_id | url |
| 1 | http://localhost/ |
| 2 | http://localhost/newsite/ |

2 changes: 1 addition & 1 deletion src/Site_Command.php
Expand Up @@ -435,7 +435,7 @@ public function create( $args, $assoc_args ) {
$email = '';
if ( ! empty( $super_admins ) && is_array( $super_admins ) ) {
// Just get the first one
$super_login = $super_admins[0];
$super_login = reset( $super_admins );
$super_user = get_user_by( 'login', $super_login );
if ( $super_user ) {
$email = $super_user->user_email;
Expand Down