Skip to content

Commit

Permalink
enhance(directives): Add support for passing multiple roles to @role (
Browse files Browse the repository at this point in the history
Fixes #49)
  • Loading branch information
Log1x committed Jul 29, 2023
1 parent dbbb0e7 commit 36b076b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Directives/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,15 @@

'role' => function ($expression) {
$expression = Util::parse($expression);
$condition = [];

return "<?php if (is_user_logged_in() && in_array(strtolower({$expression->get(0)}), (array) wp_get_current_user()->roles)) : ?>"; // phpcs:ignore
foreach ($expression as $value) {
$condition[] = "&& in_array(strtolower({$value}), (array) wp_get_current_user()->roles)";
}

$conditions = implode(' ', $condition);

return "<?php if (is_user_logged_in() {$conditions}) : ?>"; // phpcs:ignore
},

'endrole' => function () {
Expand Down

0 comments on commit 36b076b

Please sign in to comment.