Skip to:
Content

bbPress.org


Ignore:
Timestamp:
11/09/2016 09:51:11 PM (8 years ago)
Author:
johnjamesjacoby
Message:

Roles: Fix infinite loops from load order changes in WordPress 4.7.

  • Do not translate "role names" which are actually role IDs
  • Add dummy function so literal role names are part of the pomo dictionary
  • Introduce common/locale.php for future localization code
  • Introduce roles variable to main bbPress class, and store loaded roles there
  • Introduce bbp_translate_user_role() to help with outputting literal role names in the proper language

See #3017. For trunk (2.6)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/core/capabilities.php

    r6108 r6118  
    288288function bbp_add_forums_roles( $wp_roles = null ) {
    289289
    290     // Attempt to get global roles if not passed in & not mid-initialization
    291     if ( ( null === $wp_roles ) && ! doing_action( 'wp_roles_init' ) ) {
    292         $wp_roles = bbp_get_wp_roles();
    293     }
     290    // Get the dynamic roles
     291    $bbp_roles = bbp_get_dynamic_roles();
    294292
    295293    // Loop through dynamic roles and add them to the $wp_roles array
    296     foreach ( bbp_get_dynamic_roles() as $role_id => $details ) {
     294    foreach ( $bbp_roles as $role_id => $details ) {
    297295        $wp_roles->roles[ $role_id ]        = $details;
    298296        $wp_roles->role_objects[ $role_id ] = new WP_Role( $role_id, $details['capabilities'] );
     
    363361 *
    364362 * @since 2.2.0 bbPress (r4284)
     363 * @since 2.6.0 bbPress (r6117) Use bbpress()->roles
    365364 *
    366365 * @return array
    367366 */
    368367function bbp_get_dynamic_roles() {
    369     static $bbp_roles = null;
    370 
    371     // Only run once
    372     if ( null === $bbp_roles ) {
    373         $bbp_roles = array(
    374 
    375             // Keymaster
    376             bbp_get_keymaster_role() => array(
    377                 'name'         => __( 'Keymaster', 'bbpress' ),
    378                 'capabilities' => bbp_get_caps_for_role( bbp_get_keymaster_role() )
    379             ),
    380 
    381             // Moderator
    382             bbp_get_moderator_role() => array(
    383                 'name'         => __( 'Moderator', 'bbpress' ),
    384                 'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() )
    385             ),
    386 
    387             // Participant
    388             bbp_get_participant_role() => array(
    389                 'name'         => __( 'Participant', 'bbpress' ),
    390                 'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() )
    391             ),
    392 
    393             // Spectator
    394             bbp_get_spectator_role() => array(
    395                 'name'         => __( 'Spectator', 'bbpress' ),
    396                 'capabilities' => bbp_get_caps_for_role( bbp_get_spectator_role() )
    397             ),
    398 
    399             // Blocked
    400             bbp_get_blocked_role() => array(
    401                 'name'         => __( 'Blocked', 'bbpress' ),
    402                 'capabilities' => bbp_get_caps_for_role( bbp_get_blocked_role() )
    403             )
    404         );
     368
     369    // Defaults
     370    $to_array = array();
     371    $roles    = bbpress()->roles;
     372
     373    // Convert WP_Roles objects to arrays
     374    foreach ( $roles as $role_id => $wp_role ) {
     375        $to_array[ $role_id ] = (array) $wp_role;
    405376    }
    406377
    407378    // Filter & return
    408     return (array) apply_filters( 'bbp_get_dynamic_roles', $bbp_roles );
     379    return (array) apply_filters( 'bbp_get_dynamic_roles', $to_array, $roles );
    409380}
    410381
     
    413384 *
    414385 * @since 2.3.0 bbPress (r4792)
     386 * @since 2.6.0 bbPress (r6117) Use bbp_translate_user_role()
    415387 *
    416388 * @param string $role_id
     
    419391function bbp_get_dynamic_role_name( $role_id = '' ) {
    420392    $roles = bbp_get_dynamic_roles();
    421     $role  = isset( $roles[ $role_id ] ) ? $roles[ $role_id ]['name'] : '';
     393    $role  = isset( $roles[ $role_id ] )
     394        ? bbp_translate_user_role( $roles[ $role_id ]['name'] )
     395        : '';
    422396
    423397    return apply_filters( 'bbp_get_dynamic_role_name', $role, $role_id, $roles );
     
    433407 *
    434408 * @param array $all_roles All registered roles
    435  * @return array 
     409 * @return array
    436410 */
    437411function bbp_filter_blog_editable_roles( $all_roles = array() ) {
     
    527501 * Removes bbPress-specific user roles from the `wp_user_roles` array.
    528502 *
    529  * This is currently only used when updating, uninstalling, or resetting bbPress. 
     503 * This is currently only used when updating, uninstalling, or resetting bbPress.
    530504 *
    531505 * @see bbp_admin_reset_handler()
Note: See TracChangeset for help on using the changeset viewer.