| @@ -262,12 +262,13 @@ | ||
| 262 | 262 | /** |
| 263 | 263 | * Check if the user has a role selected by the admin. |
| 264 | 264 | * |
| 265 | 265 | * @param WP_User|\stdClass $user User object. |
| 266 | + * @param object $model Model object. | |
| 266 | 267 | * |
| 267 | 268 | * @return bool True if the user has a selected role, false otherwise. |
| 268 | 269 | */ |
| 269 | - private function should_enforce_for_user( $user ): bool { | |
| 270 | + private function should_enforce_for_user( $user, $model ): bool { | |
| 270 | 271 | $roles = array(); |
| 271 | 272 | if ( ! is_multisite() ) { |
| 272 | 273 | if ( $user instanceof WP_User ) { |
| 273 | 274 | $roles = $this->get_roles( $user ); |
| @@ -288,26 +289,14 @@ | ||
| 288 | 289 | $roles = array_merge( $u->roles, $roles ); |
| 289 | 290 | } |
| 290 | 291 | } |
| 291 | 292 | |
| 292 | - $user_roles = $this->get_user_roles_property(); | |
| 293 | + $user_roles = array(); | |
| 294 | + if ( is_object( $model ) && property_exists( $model, 'user_roles' ) ) { | |
| 295 | + $user_roles = $model->user_roles; | |
| 296 | + } | |
| 293 | 297 | |
| 294 | 298 | $array_intersect = array_intersect( $user_roles, $roles ); |
| 295 | 299 | |
| 296 | 300 | return array() !== $array_intersect; |
| 297 | - } | |
| 298 | - | |
| 299 | - /** | |
| 300 | - * Retrieve the user roles property dynamically. | |
| 301 | - * | |
| 302 | - * @return array The user roles from the appropriate property. | |
| 303 | - */ | |
| 304 | - private function get_user_roles_property(): array { | |
| 305 | - if ( isset( $this->model ) && property_exists( $this->model, 'user_roles' ) ) { | |
| 306 | - return $this->model->user_roles; | |
| 307 | - } elseif ( isset( $this->settings ) && property_exists( $this->settings, 'user_roles' ) ) { | |
| 308 | - return $this->settings->user_roles; | |
| 309 | - } | |
| 310 | - | |
| 311 | - return array(); | |
| 312 | 301 | } |
| 313 | 302 | } |