/** * Add capabilities for subscribers and contributors. * * By default, subscribers and contributors do not have caps to post, edit or * delete papers. This function injects these caps for users with these roles. * * @param array $caps The mapped caps * @param string $cap The cap being mapped * @param int $user_id The user id in question * @param array $args Optional parameters passed to has_cap(). For us, this means the post ID. * @return array */ function cacsp_map_extra_meta_caps($caps, $cap, $user_id, $args) { switch ($cap) { // give user these caps case 'publish_papers': case 'edit_papers': // handles adding tags/categories break; // meta caps // meta caps case 'edit_paper': case 'delete_paper': // bail if someone else's event if (!empty($caps[0]) && false !== strpos($caps[0], 'others')) { return $caps; } break; case 'read_paper': // Make sure authors can view their own post if ((int) get_post($args[0])->post_author === $user_id) { return array('exist'); } $post_id = $args[0]; if (!cacsp_paper_is_protected($post_id)) { return array('exist'); } else { $paper = new CACSP_Paper($post_id); $paper_reader_ids = $paper->get_reader_ids(); if (in_array(get_current_user_id(), $paper_reader_ids, true)) { return array('exist'); } elseif (function_exists('bp_is_active') && bp_is_active('groups')) { $paper_group_ids = $paper->get_group_ids(); $user_group_ids = cacsp_get_groups_of_user(get_current_user_id()); if (array_intersect($paper_group_ids, $user_group_ids)) { return array('exist'); } } } return array('do_not_allow'); // allow files to be uploaded via AJAX // allow files to be uploaded via AJAX case 'upload_files': if (defined('DOING_AJAX') && true === constant('DOING_AJAX')) { if (false === isset($_REQUEST['post_id'])) { return $caps; } if (false === current_user_can('edit_paper', $_REQUEST['post_id'])) { return $caps; } $user_id = get_current_user_id(); } else { return $caps; } break; default: return $caps; break; } // make sure user is valid $user = new WP_User($user_id); if (!is_a($user, 'WP_User') || empty($user->ID)) { return $caps; } /** * Filters Social Paper basic meta caps. * * @param array Pass 'exist' cap so users are able to manage papers. * @param array $caps The mapped caps * @param string $cap The cap being mapped * @param WP_User The user being tested for the cap. */ return apply_filters('cacsp_map_extra_meta_caps', array('exist'), $caps, $cap, $user); }
esc_html_e('Groups', 'social-paper'); ?> </h3> <p><?php esc_html_e('Your paper will appear in the group directory and activity stream of all associated groups.', 'social-paper'); ?> <?php cacsp_paper_group_selector(get_queried_object_id()); ?> </div> <?php } ?> <div class="sidebar-section-subsection sidebar-section-subsection-readers <?php if (!cacsp_paper_is_protected(get_queried_object_id())) { ?> hidden<?php } ?> "> <h3><?php esc_html_e('Readers', 'social-paper'); ?> </h3> <p><?php esc_html_e('Readers are allowed to read and comment on your paper.', 'social-paper'); ?> <?php cacsp_paper_reader_selector(get_queried_object_id()); ?>