Skip to content

Commit

Permalink
Fix PHP warning for empty security module settings
Browse files Browse the repository at this point in the history
Since PR #374 I've noticed a PHP warning in the logs:
```
PHP Warning:  Trying to access array offset on value of type bool in /usr/src/app/packages/security/inc/namespace.php on line 139
```

This is because the `required` key in the `override_two_factor_forced_user_roles` function is not always an array or even present.
For example, if your relevant section of `composer.json` looks like this:
```	json
{
	"extra": {
		"altis": {
			"modules: {
				"security": {}
			}
		}
	}
}
```
you get the warning.

This PR adds a check to ensure that the key is an array before trying to access it.
  • Loading branch information
mikelittle committed Feb 11, 2025
1 parent ac6a31c commit a1b8423
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function override_two_factor_forced_user_roles( $roles ) {
return [];
}

if ( is_array( $config['required'] ) ) {
if ( isset( $config['required'] ) && is_array( $config['required'] ) ) {
return $config['required'];
}

Expand Down

0 comments on commit a1b8423

Please sign in to comment.