Skip to:
Content

bbPress.org


Ignore:
Timestamp:
06/05/2016 06:27:54 PM (8 years ago)
Author:
johnjamesjacoby
Message:

Moderators: Refactor per-forum moderators to use meta-data instead of mocked taxonomy terms.

If the future of Forums is a taxonomy (vs. a custom post-type) then a per-forum Moderator taxonomy for a Forum taxonomy won't work very well, for a few reasons:

  • Scalability
  • Taxonomies for taxonomies is a bit more inception than should be required for this simple feature
  • Forum moderators do not require much of what taxonomy objects provide (permalinks, visibility, metadata, etc...)
  • User taxonomy terms matching nicenames works okay for something like Automattic's P2 theme, but bbPress requires a user ID based solution to avoid data synchronization issues between nicenames & term slugs

So... the future of per-forum per-user capability mappings is in meta-data using map_meta_cap.

This commit:

  • Removes the forum_mod taxonomy and surrounding code additions introduced in the first pass in r5834
  • Renames forum_mod functions to forum_moderator to be more explicit
  • Adds CRUD wrapper functions for per-forum moderator meta data
  • Adds administrative interfaces for assigning moderators to forums for wp-admin and forum edit pages
  • Adds helper functions for getting user nicenames & IDs

Note that this feature has now been refactored to no longer be forum specific (I.E. object agnostic) -- it's possible for any user access to be mapped based on the object type using any meta-data key. While this is currently useful for per-forum moderators, it may be user for per-topic blocking, per-topic-tag moderation, etc...

See #459.

File:
1 edited

Legend:

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

    r6032 r6056  
    21102110    return (bool) apply_filters( 'bbp_current_user_can_access_anonymous_user_form', (bool) $retval );
    21112111}
     2112
     2113/** Moderators ****************************************************************/
     2114
     2115/**
     2116 * Output the moderators of a forum
     2117 *
     2118 * @since 2.6.0 bbPress
     2119 *
     2120 * @param int   $forum_id Optional. Topic id
     2121 * @param array $args     See {@link bbp_get_moderator_list()}
     2122 * @uses bbp_get_moderator_list() To get the moderator list
     2123 */
     2124function bbp_moderator_list( $forum_id = 0, $args = array() ) {
     2125    echo bbp_get_moderator_list( $forum_id, $args );
     2126}
     2127
     2128    /**
     2129     * Return the moderators for an object
     2130     *
     2131     * @since 2.6.0 bbPress
     2132     *
     2133     * @param int   $object_id Optional. Object id
     2134     * @param array $args     This function supports these arguments:
     2135     *  - before: Before the tag list
     2136     *  - sep: Tag separator
     2137     *  - after: After the tag list
     2138     *
     2139     * @return string Moderator list of the object
     2140     */
     2141    function bbp_get_moderator_list( $object_id = 0, $args = array() ) {
     2142
     2143        // Parse arguments against default values
     2144        $r = bbp_parse_args( $args, array(
     2145            'before' => '<div class="bbp-moderators"><p>' . esc_html__( 'Moderators:', 'bbpress' ) . '&nbsp;',
     2146            'sep'    => ', ',
     2147            'after'  => '</p></div>',
     2148            'none'   => ''
     2149        ), 'get_moderator_list' );
     2150
     2151        // Get forum moderators
     2152        $user_ids = bbp_get_moderator_ids( $object_id );
     2153        if ( ! empty( $user_ids ) ) {
     2154
     2155            // In admin, use nicenames
     2156            if ( is_admin() ) {
     2157                $users = bbp_get_user_nicenames_from_ids( $user_ids );
     2158
     2159            // In theme, use display names & profile links
     2160            } else {
     2161                foreach ( $user_ids as $user_id ) {
     2162                    $users[] = bbp_get_user_profile_link( $user_id );
     2163                }
     2164            }
     2165
     2166            $retval = $r['before'] . implode( $r['sep'], $users ) . $r['after'];
     2167
     2168        // No forum moderators
     2169        } else {
     2170            $retval = $r['none'];
     2171        }
     2172
     2173        return apply_filters( 'bbp_get_moderator_list', $retval );
     2174    }
Note: See TracChangeset for help on using the changeset viewer.