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

(fix): multisite config #34

Merged
merged 2 commits into from
Feb 14, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ See [config](./config/user-roles.php) for all configuration options.

2. Run WP-CLI command to create roles:

Single site:

```shell
wp acorn roles:create
```

In a multisite:

```shell
wp site list --field=url | xargs -n1 -I % wp acorn roles:create --url=%
```
9 changes: 1 addition & 8 deletions src/Console/UserRolesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ public function handle(): void

private function createRolesForSites(): void
{
if (true === is_multisite()) {
foreach (get_sites(['fields' => 'ids']) as $siteId) {
switch_to_blog($siteId);
UserRoles::createRoles();
}
} else {
UserRoles::createRoles();
}
UserRoles::createRoles();
}
}
27 changes: 1 addition & 26 deletions tests/Console/UserRolesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,11 @@

use Facades\Yard\UserRoles\UserRoles;

it('creates roles once when not in multisite', function () {
WP_Mock::userFunction('is_multisite', [
'return' => false,
]);

it('creates roles once ', function () {
UserRoles::shouldReceive('createRoles')->once();

$this->artisan('roles:create')
->expectsOutput('Updating roles...')
->expectsOutput('All done!')
->assertExitCode(0);
});

it('creates roles for each site when in multisite', function () {
WP_Mock::userFunction('is_multisite', [
'return' => true,
]);

WP_Mock::userFunction('get_sites', [
'return' => [1, 2, 3],
]);

WP_Mock::userFunction('switch_to_blog', [
'times' => 3,
]);

UserRoles::shouldReceive('createRoles')->times(3);

$this->artisan('roles:create')
->expectsOutput('Updating roles...')
->expectsOutput('All done!')
->assertExitCode(0);
});
Loading