| | |
| | | namespace JVBase\managers; |
| | | |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\utility\Features; |
| | | use JVBase\base\Site; |
| | | use WP_User; |
| | | use WP_Role; |
| | | |
| | |
| | | |
| | | public function __construct() |
| | | { |
| | | $this->roles = array_keys(array_map(function ($instance) { |
| | | return $instance->slug; |
| | | }, Registrar::getRegistered('user'))); |
| | | $this->roles = Registrar::getRegistered('user'); |
| | | |
| | | $this->content = array_map(function($content) { |
| | | $registrar = Registrar::getInstance($content); |
| | |
| | | $capabilities['access_dashboard'] = true; |
| | | } |
| | | |
| | | if (Features::forSite()->has('favourites') && $registrar->hasFeature('can_favourite') ?? true) { |
| | | if (Site::has('favourites') && $registrar->hasFeature('can_favourite') ?? true) { |
| | | $capabilities['can_favourite'] = true; |
| | | } |
| | | |
| | |
| | | $user->add_cap(BASE . 'can_own_' . $termID); |
| | | $user->add_cap(BASE . 'can_manage_' . $termID); |
| | | |
| | | $owners = get_term_meta($termID, BASE.'owners', true); |
| | | if (empty($owners)) { |
| | | $owners = []; |
| | | } |
| | | $owners[] = $userID; |
| | | $owners = array_unique($owners); |
| | | update_term_meta($termID, BASE.'owners', $owners); |
| | | |
| | | |
| | | do_action(BASE . 'granted_ownership', $userID, $termID, $taxonomy); |
| | | |
| | | return true; |
| | |
| | | return false; |
| | | } |
| | | |
| | | $owners = get_term_meta($termID, BASE.'owners', true); |
| | | if (empty($owners)) { |
| | | $owners = []; |
| | | } |
| | | if (in_array($userID, $owners)) { |
| | | unset($owners[array_search($userID, $owners)]); |
| | | } |
| | | $owners = array_unique($owners); |
| | | update_term_meta($termID, BASE.'owners', $owners); |
| | | |
| | | $user->remove_cap(BASE . 'can_own_' . $termID); |
| | | |
| | | do_action(BASE . 'revoked_ownership', $userID, $termID, $taxonomy); |
| | |
| | | |
| | | $user->add_cap(BASE . 'can_manage_' . $termID); |
| | | |
| | | $managers = get_term_meta($termID, BASE.'managers', true); |
| | | if (empty($managers)) { |
| | | $managers = []; |
| | | } |
| | | $managers[] = $userID; |
| | | $managers = array_unique($managers); |
| | | update_term_meta($termID, BASE.'managers', $managers); |
| | | |
| | | do_action(BASE . 'granted_management', $userID, $termID, $taxonomy); |
| | | |
| | | return true; |
| | |
| | | |
| | | $user->remove_cap(BASE . 'can_manage_' . $termID); |
| | | |
| | | $managers = get_term_meta($termID, BASE.'managers', true); |
| | | if (empty($managers)) { |
| | | $managers = []; |
| | | } |
| | | if (in_array($userID, $managers)) { |
| | | unset($managers[array_search($userID, $managers)]); |
| | | } |
| | | $managers = array_unique($managers); |
| | | update_term_meta($termID, BASE.'managers', $managers); |
| | | |
| | | do_action(BASE . 'revoked_management', $userID, $termID, $taxonomy); |
| | | |
| | | return true; |