Skip to content

Commit e58528a

Browse files
committed
Merge branch "release/v1.0.1"
2 parents 75d4f92 + 174ffbc commit e58528a

4 files changed

Lines changed: 50 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# v1.0.1
2+
## 04/29/2026
3+
4+
1. [](#bugfix)
5+
* Fixed PHP 8.1+ deprecation notice — explicit string casts where `null` was being passed to string-typed function arguments.
6+
* Fixed `Cannot use bool as array` fatal on PHP 8.x when the `slack_members` cache entry hadn't been seeded yet. `Cache::fetch()` returns `false` on a miss, but the plugin was destructuring the return value directly. Now guards on `is_array()` before unpacking.
7+
* Skip all Slack API work when `slack_token` is empty. Previously the plugin would still hit Slack on every frontend request even without a token, paying ~200ms of network round-trip just to receive a 401 — slowing down every page on a freshly-installed-but-unconfigured site.
8+
19
# v1.0.0
210
## 02/04/2017
311

blueprints.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Slack Invite
2-
version: 1.0.0
2+
version: 1.0.1
33
description: Easily invite users to Slack
44
icon: slack
55
author:
@@ -12,6 +12,9 @@ bugs: https://github.com/trilbymedia/grav-plugin-slack-invite/issues
1212
docs: https://github.com/trilbymedia/grav-plugin-slack-invite/blob/develop/README.md
1313
license: MIT
1414

15+
compatibility:
16+
grav: ['1.7', '2.0']
17+
1518
dependencies:
1619
- { name: form, version: '~2.0' }
1720

@@ -42,3 +45,11 @@ form:
4245
size: x-large
4346
label: Slack Token
4447
help: You must generate a token from the Slack API site
48+
49+
blacklist:
50+
type: selectize
51+
size: large
52+
label: Blacklist
53+
classes: fancy
54+
validate:
55+
type: commalist

slack-invite.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,31 @@ public function onPluginsInitialized()
4747
return;
4848
}
4949

50+
// No token configured — skip everything. Without this guard the plugin
51+
// would still hit Slack on every frontend request and pay the network
52+
// round-trip just to get back a 401, blocking page render for ~200ms.
53+
// Also rejects the shipped placeholder ('XXX-XXXX...') that survives
54+
// a fresh install when the site owner hasn't yet swapped in their key.
55+
$token = $this->config['plugins.slack-invite.slack_token'] ?? '';
56+
if (!$token || str_starts_with((string) $token, 'XXX-')) {
57+
return;
58+
}
59+
5060
// invite the user
5161
require_once __DIR__ . '/vendor/autoload.php';
5262

5363
$interactor = new CurlInteractor();
5464
$interactor->setResponseFactory(new SlackResponseFactory);
5565

5666
/** @var Commander $commander */
57-
$this->slack = new Commander($this->config['plugins.slack-invite.slack_token'], $interactor);
67+
$this->slack = new Commander($token, $interactor);
5868

5969
$cache = $this->grav['cache'];
6070

61-
list($this->total_members, $this->active_members) = $cache->fetch('slack_members');
71+
$cached = $cache->fetch('slack_members');
72+
if (is_array($cached) && count($cached) === 2) {
73+
[$this->total_members, $this->active_members] = $cached;
74+
}
6275

6376
if (!$this->total_members) {
6477

@@ -127,7 +140,7 @@ public function onFormProcessed(Event $event)
127140
case 'slack-invite':
128141
// make sure we have the email
129142
$email = $form->value('email');
130-
if ($email) {
143+
if ($email && $this->isValidUser($email)) {
131144

132145
/** @var SlackResponse $response */
133146
$response = $this->slack->execute('users.admin.invite', [
@@ -158,4 +171,17 @@ public function onFormProcessed(Event $event)
158171
break;
159172
}
160173
}
174+
175+
protected function isValidUser($email)
176+
{
177+
$blacklist = (array) $this->config['plugins.slack-invite.blacklist'];
178+
179+
foreach($blacklist as $var) {
180+
if (strpos((string) $email, (string) $var) !== false) {
181+
return false;
182+
}
183+
}
184+
185+
return true;
186+
}
161187
}

slack-invite.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
enabled: true
22
cache_timeout: 3600
33
slack_token: XXX-XXXXXXXXXXXXX-XXXXXXXXXXXXX-XXXXXXXXXXXXX
4+
blacklist:
45

0 commit comments

Comments
 (0)