| | |
| | | <?php |
| | | |
| | | use JVBase\managers\Roles; |
| | | use JVBase\registrar\Registrar; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | |
| | | 'Log in | North\'eh Smoke & Smash'; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Checks if the logged in user is one of us |
| | | * @param int|null $userID |
| | | * @return bool |
| | | */ |
| | | function isOurPeople():bool |
| | | function isOurPeople(?int $userID = null):bool |
| | | { |
| | | if (!is_user_logged_in()) { |
| | | if (is_null($userID) && !is_user_logged_in()) { |
| | | return false; |
| | | } |
| | | $user = wp_get_current_user(); |
| | | |
| | | $user = is_null($userID) ? wp_get_current_user() : get_userdata($userID); |
| | | if ($user || is_wp_error($user)) { |
| | | return false; |
| | | } |
| | | $registered = Registrar::withFeature('has_dashboard', 'user'); |
| | | $mapped = array_map(fn($role) => BASE.$role,$registered); |
| | | return count( |
| | | array_intersect( |
| | | array_values($user->roles), |
| | | array_map(function ($role) { |
| | | return BASE.$role; |
| | | }, |
| | | Registrar::getFeatured('has_dashboard', 'user')) |
| | | $mapped |
| | | ) |
| | | )>0; |
| | | } |
| | |
| | | $types = get_post_meta($postID, BASE.'content_types', true); |
| | | if ($types === '') { |
| | | $types = []; |
| | | $link = (int) get_post_meta($postID, BASE.'link', true); |
| | | $link = (int) get_post_meta($postID, BASE.'profile_link', true); |
| | | if ($link === '' || !is_numeric($link)) { |
| | | return $types; |
| | | } |
| | |
| | | |
| | | $temp = []; |
| | | foreach ($types as $t) { |
| | | $permission = JVB()->roles()->getPermission('edit',$t); |
| | | $permission = Roles::getInstance()()->getPermission('edit',$t); |
| | | if (user_can($link, $permission)){ |
| | | $temp[] = $t; |
| | | } |
| | | } |
| | | |
| | | $types = Registrar::getFeatured('show_feed'); |
| | | $types = Registrar::withFeature('show_feed'); |
| | | $types = array_filter($temp, function ($type) use ($types) { |
| | | return in_array($type, $types); |
| | | }); |