function gpbbp_apply_capabilities_from_forum($post_id, $forum_id) { $forum_capabilities = Groups_Post_access::get_read_post_capabilities($forum_id); if (!is_array($forum_capabilities)) { return; } foreach ($forum_capabilities as $capability) { Groups_Post_Access::create(array('post_id' => $post_id, 'capability' => $capability)); } unset($capability); }
/** * Save capabilities for attachment post type (Media). * When multiple attachments are saved, this is called once for each. * @param array $post post data * @param array $attachment attachment field data * @return array */ public static function attachment_fields_to_save($post, $attachment) { $post_types_option = Groups_Options::get_option(Groups_Post_Access::POST_TYPES, array()); if (!isset($post_types_option['attachment']['add_meta_box']) || $post_types_option['attachment']['add_meta_box']) { if (current_user_can('edit_attachment')) { Groups_Post_Access::delete($post['ID'], null); if (!empty($attachment[self::CAPABILITY])) { foreach ($attachment[self::CAPABILITY] as $capability_id) { if ($capability = Groups_Capability::read($capability_id)) { Groups_Post_Access::create(array('post_id' => $post['ID'], 'capability' => $capability->capability)); } } } } } return $post; }
/** * Save capabilities for attachment post type (Media). * When multiple attachments are saved, this is called once for each. * @param array $post post data * @param array $attachment attachment field data * @return array */ public static function attachment_fields_to_save($post, $attachment) { $post_types_option = Groups_Options::get_option(Groups_Post_Access::POST_TYPES, array()); if (!isset($post_types_option['attachment']['add_meta_box']) || $post_types_option['attachment']['add_meta_box']) { // if we're here, we assume the user is allowed to edit attachments, // but we still need to check if the user can restrict access if (self::user_can_restrict()) { $post_id = null; if (isset($post['ID'])) { $post_id = $post['ID']; } else { if (isset($post['post_ID'])) { $post_id = $post['post_ID']; } } if ($post_id !== null) { $valid_read_caps = self::get_valid_read_caps_for_user(); foreach ($valid_read_caps as $valid_read_cap) { if ($capability = Groups_Capability::read_by_capability($valid_read_cap)) { if (!empty($attachment[self::CAPABILITY]) && is_array($attachment[self::CAPABILITY]) && in_array($capability->capability_id, $attachment[self::CAPABILITY])) { Groups_Post_Access::create(array('post_id' => $post_id, 'capability' => $capability->capability)); } else { Groups_Post_Access::delete($post_id, $capability->capability); } } } } } } return $post; }
/** * Handles access restriction capability modifications from bulk-editing. * This is called once for each post that is included in bulk-editing. * The fields that are handled here are rendered through the * bulk_edit_custom_box() method in this class. * * @param int $post_id */ public static function save_post($post_id) { if (isset($_REQUEST['capabilities-action'])) { if (wp_verify_nonce($_REQUEST['bulk-post-capability-nonce'], 'post-capability')) { $field = Groups_Post_Access::POSTMETA_PREFIX . 'bulk-' . Groups_Post_Access::READ_POST_CAPABILITY; if (!empty($_REQUEST[$field]) && is_array($_REQUEST[$field])) { if (Groups_Access_Meta_Boxes::user_can_restrict()) { $valid_read_caps = Groups_Access_Meta_Boxes::get_valid_read_caps_for_user(); foreach ($_REQUEST[$field] as $capability_name) { if ($capability = Groups_Capability::read_by_capability($capability_name)) { if (in_array($capability->capability, $valid_read_caps)) { switch ($_REQUEST['capabilities-action']) { case 'add-capability': Groups_Post_Access::create(array('post_id' => $post_id, 'capability' => $capability->capability)); break; case 'remove-capability': Groups_Post_Access::delete($post_id, $capability->capability); break; } } } } } } } } }