/** * Replicates WP's native recent comments dashboard widget. * * @package BuddyPress Docs * @since 1.1.8 */ function wp_dashboard_recent_comments() { global $wpdb, $bp; if (current_user_can('edit_posts')) { $allowed_states = array('0', '1'); } else { $allowed_states = array('1'); } // Select all comment types and filter out spam later for better query performance. $comments = array(); $start = 0; $widgets = get_option('dashboard_widget_options'); $total_items = isset($widgets['dashboard_recent_comments']) && isset($widgets['dashboard_recent_comments']['items']) ? absint($widgets['dashboard_recent_comments']['items']) : 5; while (count($comments) < $total_items && ($possible = $wpdb->get_results("SELECT c.*, p.post_type AS comment_post_post_type FROM {$wpdb->comments} c LEFT JOIN {$wpdb->posts} p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' ORDER BY c.comment_date_gmt DESC LIMIT {$start}, 50"))) { foreach ($possible as $comment) { if (count($comments) >= $total_items) { break; } // Is the user allowed to read this doc? if ($bp->bp_docs->post_type_name == $comment->comment_post_post_type && !bp_docs_user_can('read', get_current_user_ID(), $comment->comment_post_ID)) { continue; } if (in_array($comment->comment_approved, $allowed_states) && current_user_can('read_post', $comment->comment_post_ID)) { $comments[] = $comment; } } $start = $start + 50; } if ($comments) { ?> <div id="the-comment-list" class="list:comment"> <?php foreach ($comments as $comment) { _wp_dashboard_recent_comments_row($comment); } ?> </div> <?php if (current_user_can('edit_posts')) { ?> <?php _get_list_table('WP_Comments_List_Table')->views(); ?> <?php } wp_comment_reply(-1, false, 'dashboard', false); wp_comment_trashnotice(); } else { ?> <p><?php _e('No comments yet.'); ?> </p> <?php } // $comments; }
/** * @group bp_docs_user_can */ function test_loggedin_user_can_create() { $this->assertTrue(bp_docs_user_can('create', 4)); }
/** * Approve Doc comments as necessary. * * Docs handles its own comment permissions, so we override WP's value * * @since 1.3.3 * @param string $approved * @param array $commentdata * @return string $approved */ public function approve_doc_comments($approved, $commentdata) { $post = get_post($commentdata['comment_post_ID']); if (bp_docs_get_post_type_name() === $post->post_type) { if (bp_docs_user_can('post_comments', bp_loggedin_user_id(), $post->ID)) { $approved = 1; } else { $approved = 0; } } return $approved; }
/** * Determine whether the current user can do something the current doc * * @package BuddyPress Docs * @since 1.0-beta * * @param str $action The cap being tested * @return bool $user_can */ function bp_docs_current_user_can($action = 'edit', $doc_id = false) { $user_can = bp_docs_user_can($action, bp_loggedin_user_id(), $doc_id); return apply_filters('bp_docs_current_user_can', $user_can, $action); }
/** * Determine whether the current user can do something the current doc * * @since 1.0-beta * @deprecated 1.8 * * @param str $action The cap being tested * @return bool $user_can */ function bp_docs_current_user_can($action = 'edit', $doc_id = false) { _deprecated_function(__FUNCTION__, '1.8', 'Use current_user_can() with "bp_docs_" prefixed capabilities instead.'); $user_can = bp_docs_user_can($action, bp_loggedin_user_id(), $doc_id); return apply_filters('bp_docs_current_user_can', $user_can, $action); }
/** * Outputs the links that appear under each Doc in the Doc listing * * @package BuddyPress Docs */ function bp_docs_doc_action_links() { $links = array(); $links[] = '<a href="' . bp_docs_get_group_doc_permalink() . '">' . __('Read', 'bp-docs') . '</a>'; if (bp_docs_user_can('edit', bp_loggedin_user_id())) { $links[] = '<a href="' . bp_docs_get_group_doc_permalink() . '/' . BP_DOCS_EDIT_SLUG . '">' . __('Edit', 'bp-docs') . '</a>'; } if (bp_docs_user_can('view_history', bp_loggedin_user_id())) { $links[] = '<a href="' . bp_docs_get_group_doc_permalink() . '/' . BP_DOCS_HISTORY_SLUG . '">' . __('History', 'bp-docs') . '</a>'; } echo implode(' | ', $links); }