Skip to content

Commit

Permalink
fix: plugin activation crashes site when no options found
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbrink committed Dec 6, 2023
1 parent cee775a commit 63be48e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions source/php/WebhooksRegistry/WebhooksRegistry.Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ public function testThatWebhooksGetsCreated()
$this->assertTrue($webhook->isActive());
$this->assertEquals(['Content-Type' => 'application/json'], $webhook->getHeaders());
}

public function testThatNoExceptionIsThrownWhenNoOptionsAreFound()
{
WP_Mock::userFunction('get_field')->andReturn(null);

$webhooksRegistry = new \WebhooksManager\WebhooksRegistry\WebhooksRegistry();
$webhooksRegistry->registerWebhooks();

$webhooks = $webhooksRegistry->getWebhooks();
$this->assertIsArray($webhooks);
$this->assertCount(0, $webhooks);
}
}
2 changes: 1 addition & 1 deletion source/php/WebhooksRegistry/WebhooksRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class WebhooksRegistry implements WebhooksRegistryInterface
*/
public function registerWebhooks(): void
{
$this->webhooksOption = get_field('webhooks', 'option');
$this->webhooksOption = get_field('webhooks', 'option') ?? [];
if (!empty($this->webhooksOption)) {
$this->registerWebhooksFromOptions();
}
Expand Down

0 comments on commit 63be48e

Please sign in to comment.