Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/15/2015 03:59:23 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Moderators: First pass at per-forum moderators.

This commit introduces a powerful feature commonly found in other popular forum software that has been on our wishlist for nearly 9 years. It includes the following changes:

  • Custom forum-mod taxonomy for assigning user nicenames to forum IDs
  • Associated functions for defining capabilities, labels, etc...
  • New capability filters for ensuring forum moderators have the ability to moderate forums even without the moderator role assignment
  • New option for toggling the entire feature on/off (on by default)

Props jmdodd, netweb. See #459.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/forums/template.php

    r5770 r5834  
    21782178    }
    21792179
     2180/** Moderators ****************************************************************/
     2181
     2182/**
     2183 * Output the unique id of the forum moderators taxonomy
     2184 *
     2185 * @since bbPress (r5834)
     2186 *
     2187 * @uses bbp_get_forum_mod_tax_id() To get the forum modorator taxonomy ID
     2188 */
     2189function bbp_forum_mod_tax_id() {
     2190    echo bbp_get_forum_mod_tax_id();
     2191}
     2192    /**
     2193     * Return the unique id of the forum moderators taxonomy
     2194     *
     2195     * @since bbPress (r5834)
     2196     *
     2197     * @uses apply_filters() Calls 'bbp_get_forum_mod_tax_id' with the forum
     2198     *                        moderator taxonomy id
     2199     * @return string The unique forum moderators taxonomy
     2200     */
     2201    function bbp_get_forum_mod_tax_id() {
     2202        return apply_filters( 'bbp_get_forum_mod_tax_id', bbpress()->forum_mod_tax_id );
     2203    }
     2204
     2205/**
     2206 * Return array of labels used by the forum-mod taxonomy
     2207 *
     2208 * @since bbPress (r5834)
     2209 *
     2210 * @uses apply_filters() Calls 'bbp_get_forum_mod_tax_id' with the forum
     2211 *                        moderator taxonomy labels
     2212 * @return array
     2213 */
     2214function bbp_get_forum_mod_tax_labels() {
     2215    return apply_filters( 'bbp_get_forum_mod_tax_labels', array(
     2216        'name'                       => __( 'Forum Moderators',     'bbpress' ),
     2217        'singular_name'              => __( 'Forum Moderator',      'bbpress' ),
     2218        'search_items'               => __( 'Search Moderators',    'bbpress' ),
     2219        'popular_items'              => __( 'Popular Moderators',   'bbpress' ),
     2220        'all_items'                  => __( 'All Moderators',       'bbpress' ),
     2221        'edit_item'                  => __( 'Edit Moderator',       'bbpress' ),
     2222        'update_item'                => __( 'Update Moderator',     'bbpress' ),
     2223        'add_new_item'               => __( 'Add New Moderator',    'bbpress' ),
     2224        'new_item_name'              => __( 'New Moderator Name',   'bbpress' ),
     2225        'view_item'                  => __( 'View Forum Moderator', 'bbpress' ),
     2226        'separate_items_with_commas' => __( 'Separate moderator names with commas', 'bbpress' ),
     2227    ) );
     2228}
     2229
     2230/**
     2231 * Output a the moderators of a forum
     2232 *
     2233 * @param int   $forum_id Optional. Topic id
     2234 * @param array $args     See {@link bbp_get_forum_mod_list()}
     2235 * @uses bbp_get_topic_tag_list() To get the forum mod list
     2236 */
     2237function bbp_forum_mod_list( $forum_id = 0, $args = array() ) {
     2238    echo bbp_get_forum_mod_list( $forum_id, $args );
     2239}
     2240    /**
     2241     * Return the moderators of a forum
     2242     *
     2243     * @param int   $forum_id Optional. Forum id
     2244     * @param array $args     This function supports these arguments:
     2245     *  - before: Before the tag list
     2246     *  - sep: Tag separator
     2247     *  - after: After the tag list
     2248     * @uses bbp_get_forum_id()  To get the forum id
     2249     * @uses get_the_term_list() To get the moderator list
     2250     *
     2251     * @return string Moderator list of the forum
     2252     */
     2253    function bbp_get_forum_mod_list( $forum_id = 0, $args = array() ) {
     2254
     2255        // Bail if forum-mods are off
     2256        if ( ! bbp_allow_forum_mods() ) {
     2257            return;
     2258        }
     2259
     2260        // Parse arguments against default values
     2261        $r = bbp_parse_args( $args, array(
     2262            'before' => '<div class="bbp-forum-mods"><p>' . esc_html__( 'Moderators:', 'bbpress' ) . '&nbsp;',
     2263            'sep'    => ', ',
     2264            'after'  => '</p></div>'
     2265        ), 'get_forum_mod_list' );
     2266
     2267        $forum_id = bbp_get_forum_id( $forum_id );
     2268
     2269        $retval   = get_the_term_list( $forum_id, bbp_get_forum_mod_id(), $r['before'], $r['sep'], $r['after'] );
     2270
     2271        return $retval;
     2272    }
     2273
    21802274/** Forms *********************************************************************/
    21812275
Note: See TracChangeset for help on using the changeset viewer.