{"action":"created","issue":{"url":"https://api.github.com/repos/GM-Alex/user-access-manager/issues/147","repository_url":"https://api.github.com/repos/GM-Alex/user-access-manager","labels_url":"https://api.github.com/repos/GM-Alex/user-access-manager/issues/147/labels{/name}","comments_url":"https://api.github.com/repos/GM-Alex/user-access-manager/issues/147/comments","events_url":"https://api.github.com/repos/GM-Alex/user-access-manager/issues/147/events","html_url":"https://github.com/GM-Alex/user-access-manager/issues/147","id":268221888,"number":147,"title":"Ability to set access programatically","user":{"login":"treetrum","id":4800689,"avatar_url":"https://avatars3.githubusercontent.com/u/4800689?v=4","gravatar_id":"","url":"https://api.github.com/users/treetrum","html_url":"https://github.com/treetrum","followers_url":"https://api.github.com/users/treetrum/followers","following_url":"https://api.github.com/users/treetrum/following{/other_user}","gists_url":"https://api.github.com/users/treetrum/gists{/gist_id}","starred_url":"https://api.github.com/users/treetrum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/treetrum/subscriptions","organizations_url":"https://api.github.com/users/treetrum/orgs","repos_url":"https://api.github.com/users/treetrum/repos","events_url":"https://api.github.com/users/treetrum/events{/privacy}","received_events_url":"https://api.github.com/users/treetrum/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-10-24T23:41:22Z","updated_at":"2017-11-24T00:09:31Z","closed_at":null,"author_association":"NONE","body":"Is there a way to set the access with a filter/hook when a post is saved? I would love to be able to setup some conditional logic in my PHP to set the access for a post when it is created by specific users.\r\n\r\nAlternatively, is there a way to set the access to automatically be set the authors access group?"},"comment":{"url":"https://api.github.com/repos/GM-Alex/user-access-manager/issues/comments/346711439","html_url":"https://github.com/GM-Alex/user-access-manager/issues/147#issuecomment-346711439","issue_url":"https://api.github.com/repos/GM-Alex/user-access-manager/issues/147","id":346711439,"user":{"login":"treetrum","id":4800689,"avatar_url":"https://avatars3.githubusercontent.com/u/4800689?v=4","gravatar_id":"","url":"https://api.github.com/users/treetrum","html_url":"https://github.com/treetrum","followers_url":"https://api.github.com/users/treetrum/followers","following_url":"https://api.github.com/users/treetrum/following{/other_user}","gists_url":"https://api.github.com/users/treetrum/gists{/gist_id}","starred_url":"https://api.github.com/users/treetrum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/treetrum/subscriptions","organizations_url":"https://api.github.com/users/treetrum/orgs","repos_url":"https://api.github.com/users/treetrum/repos","events_url":"https://api.github.com/users/treetrum/events{/privacy}","received_events_url":"https://api.github.com/users/treetrum/received_events","type":"User","site_admin":false},"created_at":"2017-11-24T00:09:31Z","updated_at":"2017-11-24T00:09:31Z","author_association":"NONE","body":"Ok, I think I worked this out.\r\n\r\nI've used the following code in my functions.php file to automatically set the posts access to the authors usergroups when the post is saved.\r\n\r\n```php\r\nfunction set_post_access_to_author_usergroup() {\r\n\r\n    global $userAccessManager;\r\n\r\n    if (isset($userAccessManager)) {\r\n        $uamAccessHandler = $userAccessManager->getAccessHandler();\r\n        $userGroupsForUser = $uamAccessHandler->getUserGroupsForObject(\\UserAccessManager\\Object\\ObjectHandler::GENERAL_USER_OBJECT_TYPE, get_current_user_id());\r\n\r\n        $postId = get_the_id();\r\n        $postType = get_post_type();\r\n\r\n        foreach ($userGroupsForUser as $groupId => $userGroup) {\r\n            $userGroup->addObject($postType, $postId);\r\n            $userGroup->save();\r\n        }\r\n    }\r\n}\r\n\r\n// Must use a priority of > 10 to ensure this runs after UAM\r\nadd_action( 'save_post', 'set_post_access_to_author_usergroup', 11, 0);\r\n```\r\n\r\nObviously this could be very incorrect - I scoured through the source code to work this out. Let me know if there's a better way of doing this 😄 If not, feel free to close this issue.\r\n\r\nOtherwise, hopefully this can help someone else."}}
{"actor":{"display_login":"treetrum"}}