Skip to:
Content

bbPress.org


Ignore:
Timestamp:
11/02/2012 07:07:41 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Capabilities:

  • Introduce bbp_get_wp_roles() and use in place of $wp_roles global.
  • See #1939.
File:
1 edited

Legend:

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

    r4292 r4293  
    544544 */
    545545function bbp_add_caps() {
    546         global $wp_roles;
    547 
    548         // Load roles if not set
    549         if ( ! isset( $wp_roles ) )
    550                 $wp_roles = new WP_Roles();
    551546
    552547        // Loop through available roles and add caps
    553         foreach( $wp_roles->role_objects as $role ) {
     548        foreach( bbp_get_wp_roles()->role_objects as $role ) {
    554549                foreach ( bbp_get_caps_for_role( $role->name ) as $cap => $value ) {
    555550                        $role->add_cap( $cap, $value );
     
    566561 */
    567562function bbp_remove_caps() {
    568         global $wp_roles;
    569 
    570         // Load roles if not set
    571         if ( ! isset( $wp_roles ) )
    572                 $wp_roles = new WP_Roles();
    573563
    574564        // Loop through available roles and remove caps
    575         foreach( $wp_roles->role_objects as $role ) {
     565        foreach( bbp_get_wp_roles()->role_objects as $role ) {
    576566                foreach ( array_keys( bbp_get_caps_for_role( $role->name ) ) as $cap ) {
    577567                        $role->remove_cap( $cap );
     
    582572}
    583573
    584 /** Forum Roles ***************************************************************/
    585 
    586 /**
    587  * Add the bbPress roles to the $wp_roles global.
    588  *
    589  * We do this to avoid adding these values to the database.
    590  *
    591  * @since bbPress (rxxxx)
    592  * @global type $wp_roles
    593  */
    594 function bbp_add_forums_roles() {
    595         global $wp_roles, $wp_user_roles;
    596 
     574/**
     575 * Get the $wp_roles global without needing to declare it everywhere
     576 *
     577 * @since bbPress (r4293)
     578 *
     579 * @global WP_Roles $wp_roles
     580 * @return WP_Roles
     581 */
     582function bbp_get_wp_roles() {
     583        global $wp_roles;
     584
     585        // Load roles if not set
    597586        if ( ! isset( $wp_roles ) )
    598587                $wp_roles = new WP_Roles();
    599588
    600         // Loop through bbPress's roles and add them to the global $wp_roles
    601         foreach( bbp_get_forums_editable_roles() as $role_id => $details ) {
     589        return $wp_roles;
     590}
     591
     592/** Forum Roles ***************************************************************/
     593
     594/**
     595 * Add the bbPress roles to the $wp_roles global.
     596 *
     597 * We do this to avoid adding these values to the database.
     598 *
     599 * @since bbPress (r4290)
     600 */
     601function bbp_add_forums_roles() {
     602        $wp_roles = bbp_get_wp_roles();
     603
     604        foreach( bbp_get_editable_roles() as $role_id => $details ) {
    602605                $wp_roles->roles[$role_id]        = $details;
    603606                $wp_roles->role_objects[$role_id] = new WP_Role( $details['name'], $details['capabilities'] );
    604607                $wp_roles->role_names[$role_id]   = $details['name'];
    605608        }
    606 
    607         // Force WordPress not to use the DB
    608         $wp_user_roles = $wp_roles;
    609609}
    610610
     
    626626 * @return array
    627627 */
    628 function bbp_get_forums_editable_roles() {
    629         return (array) apply_filters( 'bbp_get_forums_editable_roles', array(
     628function bbp_get_editable_roles() {
     629        return (array) apply_filters( 'bbp_get_editable_roles', array(
    630630
    631631                // Keymaster
Note: See TracChangeset for help on using the changeset viewer.