/** * Return the moderators for an object * * @since 2.6.0 bbPress * * @param int $object_id Optional. Object id * @param array $args This function supports these arguments: * - before: Before the tag list * - sep: Tag separator * - after: After the tag list * * @return string Moderator list of the object */ function bbp_get_moderator_list($object_id = 0, $args = array()) { // Parse arguments against default values $r = bbp_parse_args($args, array('before' => '<div class="bbp-moderators"><p>' . esc_html__('Moderators:', 'bbpress') . ' ', 'sep' => ', ', 'after' => '</p></div>', 'none' => ''), 'get_moderator_list'); // Get forum moderators $user_ids = bbp_get_moderator_ids($object_id); if (!empty($user_ids)) { // In admin, use nicenames if (is_admin()) { $users = bbp_get_user_nicenames_from_ids($user_ids); // In theme, use display names & profile links } else { foreach ($user_ids as $user_id) { $users[] = bbp_get_user_profile_link($user_id); } } $retval = $r['before'] . implode($r['sep'], $users) . $r['after']; // No forum moderators } else { $retval = $r['none']; } return apply_filters('bbp_get_moderator_list', $retval); }
/** * Moderator assignment metabox * * @since 2.6.0 bbPress (r2828) * * @uses get_the_ID() To get the global post ID * @uses get_post_meta() To get the author user information */ function bbp_moderator_assignment_metabox() { // Post ID $object_id = get_the_ID(); $user_ids = bbp_get_moderator_ids($object_id); $user_nicenames = bbp_get_user_nicenames_from_ids($user_ids); $moderators = !empty($user_nicenames) ? implode(', ', array_map('esc_attr', $user_nicenames)) : ''; ?> <p> <label class="screen-reader-text" for="bbp_moderators"><?php esc_html_e('Moderators', 'bbpress'); ?> </label> <input type="text" id="bbp_moderators" name="bbp_moderators" value="<?php echo esc_attr($moderators); ?> " /> </p> <?php do_action('bbp_moderator_assignment_metabox', $object_id); }
/** * Return value of forum moderators field * * @since 2.6.0 bbPress (r5837) * * @uses bbp_is_forum_edit() To check if it's the forum edit page * @uses apply_filters() Calls 'bbp_get_form_forum_mods' with the mods * * @return string Value of forum mods field */ function bbp_get_form_forum_moderators() { // Default return value $forum_mods = ''; // Get _POST data if (bbp_is_forum_form_post_request() && isset($_POST['bbp_moderators'])) { $forum_mods = wp_unslash($_POST['bbp_moderators']); // Get edit data } elseif (bbp_is_single_forum() || bbp_is_forum_edit()) { // Get the forum ID $forum_id = bbp_get_forum_id(get_the_ID()); // Forum exists if (!empty($forum_id)) { // Get moderator IDs $user_ids = bbp_get_moderator_ids($forum_id); if (!empty($user_ids)) { $user_nicenames = bbp_get_user_nicenames_from_ids($user_ids); // Comma separate user nicenames if (!empty($user_nicenames)) { $forum_mods = implode(', ', wp_list_pluck($user_nicenames, 'user_nicename')); } } } } return apply_filters('bbp_get_form_forum_moderators', $forum_mods); }
/** * Get moderators for a specific object ID. Will return global moderators when * object ID is empty. * * @since 2.6.0 bbPress * * @param int $object_id * * @return array */ function bbp_get_moderators($object_id = 0) { // Get global moderators if (empty($object_id)) { $users = get_users(array('role__in' => bbp_get_moderator_role())); // Get object moderators } else { $users = get_users(array('include' => bbp_get_moderator_ids($object_id))); } return apply_filters('bbp_get_moderators', $users, $object_id); }