/** * Return user nicename suggestions instead of tag suggestions * * @since 2.6.0 bbPress (r5834) * * @uses bbp_get_forum_mod_tax_id() To get the forum moderator taxonomy id * @uses sanitize_key() To sanitize the taxonomy id * @uses get_taxonomy() To get the forum moderator taxonomy * @uses current_user_can() To check if the current user add/edit forum moderators * @uses get_users() To get an array of users * @uses user_nicename() To get the users nice name * * @return Return early if not a request for forum moderators tax */ public function ajax_tag_search() { // Only do AJAX if this is a forum moderators tax search. if (!isset($_GET['tax']) || bbp_get_forum_mod_tax_id() !== $_GET['tax']) { return; } $taxonomy = sanitize_key($_GET['tax']); $tax = get_taxonomy($taxonomy); if (empty($tax)) { wp_die(0); } // Check permissions. if (!current_user_can($tax->cap->assign_terms)) { wp_die(-1); } $s = stripslashes($_GET['q']); // Replace tag delimiter with a comma if needed. $comma = _x(',', 'tag delimiter', 'bbpress'); if (',' !== $comma) { $s = str_replace($comma, ',', $s); } if (false !== strpos($s, ',')) { $s = explode(',', $s); $s = $s[count($s) - 1]; } // Search on at least 2 characters. $s = trim($s); if (strlen($s) < 2) { wp_die(); // Require 2 chars for matching. } // Get users. $results = array(); $users = get_users(array('blog_id' => 0, 'fields' => array('user_nicename'), 'search' => '*' . $s . '*', 'search_columns' => array('user_nicename'), 'orderby' => 'user_nicename')); // Format the users into a nice array. if (!empty($users)) { foreach (array_values($users) as $details) { $results[] = $details->user_nicename; } } // Echo results for AJAX. echo join($results, "\n"); wp_die(); }
/** * Get forums of a moderator * * @since 2.6.0 bbPress (r5834) * * @param int $user_id User id. * @uses get_userdata() To get the user object * @uses bbp_get_forum_mod_tax_id() To get the forum moderator taxonomy * @uses bbp_get_user_taxonomy_term_id() To get the user taxonomy term id * @uses get_term_by() To get the term id * @uses get_objects_in_term() Get the forums the user moderates * @uses is_wp_error() To check for errors * @uses bbp_is_forum() To make sure the objects are forums * * @return boolean|array Return false on error or empty, or array of forum ids */ function bbp_get_moderator_forum_ids($user_id = 0) { // Bail if no user ID. $user_id = bbp_get_user_id($user_id); if (empty($user_id)) { return false; } // Bail if user does not exist. $user = get_userdata($user_id); if (empty($user)) { return false; } // Convert user id to term id. $taxonomy = bbp_get_forum_mod_tax_id(); $term_id = bbp_get_user_taxonomy_term_id($user_id, $taxonomy); // Get moderator forums. $forums = get_objects_in_term($term_id, $taxonomy); // Forums found. if (empty($forums) || is_wp_error($forums)) { return false; } // Make sure the ids returned are forums. $forum_ids = array(); foreach ($forums as $forum_id) { if (bbp_is_forum($forum_id)) { $forum_ids[] = $forum_id; } } // Remove empties $retval = wp_parse_id_list(array_filter($forum_ids)); // Filter & return return apply_filters('bbp_get_moderator_forum_ids', $retval, $user_id); }
/** * Output the unique id of the forum moderators taxonomy * * @since 2.6.0 bbPress (r5834) * * @uses bbp_get_forum_mod_tax_id() To get the forum modorator taxonomy ID */ function bbp_forum_mod_tax_id() { echo bbp_get_forum_mod_tax_id(); }
/** * Register the topic tag and forum moderator taxonomies * * @since 2.0.0 bbPress (r2464) Added bbp_get_topic_tag_tax_id() taxonomy * @since 2.6.0 bbPress (r5834) Added bbp_get_forum_mod_tax_id() taxonomy * * @uses register_taxonomy() To register the taxonomy * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_topic_tag_tax_labels() To get the topic tag taxonomy labels * @uses bbp_get_topic_tag_tax_rewrite() To get the topic tag taxonomy slug * @uses bbp_get_topic_tag_caps() To get topic tag capabilities * @uses bbp_allow_topic_tags() To check if topic tags are allowed * @uses current_user_can() To check if the current user can edit/delete tags * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_forum_mod_tax_labels() To get the forum moderator taxonomy label * @uses bbp_get_forum_mod_caps() To check the forum moderator capabilities * @uses bbp_allow_forum_mods() To check if forum moderators are allowed * @uses current_user_can() To check if the current user can edit/delete forums */ public static function register_taxonomies() { // Register the topic-tag taxonomy. register_taxonomy(bbp_get_topic_tag_tax_id(), bbp_get_topic_post_type(), apply_filters('bbp_register_topic_taxonomy', array('labels' => bbp_get_topic_tag_tax_labels(), 'rewrite' => bbp_get_topic_tag_tax_rewrite(), 'capabilities' => bbp_get_topic_tag_caps(), 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'show_tagcloud' => true, 'hierarchical' => false, 'show_in_nav_menus' => false, 'public' => true, 'show_ui' => bbp_allow_topic_tags() && current_user_can('bbp_topic_tags_admin')))); // Register the forum-mod taxonomy. register_taxonomy(bbp_get_forum_mod_tax_id(), bbp_get_forum_post_type(), apply_filters('bbp_register_forum_moderator_taxonomy', array('labels' => bbp_get_forum_mod_tax_labels(), 'capabilities' => bbp_get_forum_mod_caps(), 'update_count_callback' => '_update_post_term_count', 'query_var' => false, 'show_tagcloud' => true, 'hierarchical' => false, 'show_in_menu' => true, 'show_in_nav_menus' => false, 'public' => false, 'show_ui' => bbp_allow_forum_mods() && current_user_can('bbp_forum_mods_admin')))); }
/** * Get forum mods for a specific forum ID * * @since 2.6.0 bbPress (r5836) * * @param int $forum_id * * @return string */ function bbp_get_forum_mods($forum_id = 0) { $forum_id = bbp_get_forum_id($forum_id); $terms = (array) get_the_terms($forum_id, bbp_get_forum_mod_tax_id()); $forum_mods = array_filter($terms); return apply_filters('bbp_get_forum_mods', $forum_mods, $forum_id); }
function bbp_filter_forum_mod_term_link($termlink = '', $term = '', $taxonomy = '') { // Bail if taxonomy is not forum mod if (bbp_get_forum_mod_tax_id() !== $taxonomy) { return $termlink; } // Bail if forum mods is not allowed if (!bbp_allow_forum_mods()) { return $termlink; } // Get user ID from taxonomy term $user_id = bbp_get_term_taxonomy_user_id($term->term_id, bbp_get_forum_mod_tax_id()); if (is_admin()) { // Get the moderator's display name $display_name = get_userdata($user_id)->display_name; $user_link = get_edit_user_link($user_id); // Link or name only if (!empty($user_link)) { $retval = '<a href="' . esc_url($user_link) . '">' . esc_html($display_name) . '</a>'; // Can't edit } else { $retval = $display_name; } // Theme side term link } else { $retval = bbp_get_user_profile_link($user_id); } return $retval; }