Programmatically assign read permissions
-
Hi,
I am building functionality where pages are created programmatically when certain steps are taken (this part is working fine).
Is it possible to assign read permissions on a page to a particular group programmatically?
Here’s what I have so far. Note that the page and the group’s slugs are, at this stage, assumed to match (as the page is created programmatically when the group is created).
/** * When a new group is created, assign read capabilities to their page * (relies on doublee_create_group_page to create the page) * * @param $group_id */ function doublee_assign_group_page_access($group_id) { // Get the group name and slug for later use $group_name = doublee_get_group_name($group_id); $group_slug = doublee_build_title_slug($group_name); // Get the page ID from the group slug (assumes they match) $page_id = doublee_get_group_page_id($group_slug); // Set up array for the post meta. We can assume no-one is currently set to read this page because it'd brand new $can_read = array(); array_push($can_read, $group_id); // Update the post meta with the new read capability update_post_meta($page_id, 'groups-read', $can_read); } add_action('groups_created_group', 'doublee_assign_group_page_access', 10);
…but it doesn’t work. Is
update_post_meta
the correct way to assign the read capability? Is there something that the plugin provides that could be used to do this?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Programmatically assign read permissions’ is closed to new replies.