Title: Capabilities Undefined Offset error with BBpress
Last modified: January 30, 2018

---

# Capabilities Undefined Offset error with BBpress

 *  Resolved [jasob](https://wordpress.org/support/users/jasob/)
 * (@jasob)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/capabilities-undefined-offset-error-with-bbpress/)
 * After the latest round of updates, I’ve been getting a php error from BBpress:
 *     ```
       Notice: Undefined offset: 0 in ./wp-content/plugins/bbpress/includes/topics/capabilities.php on line 80
       Notice: Undefined offset: 0 in ./wp-content/plugins/bbpress/includes/replies/capabilities.php on line 62
       ```
   
 * BBPress reckons this isn’t their fault [https://bbpress.org/forums/topic/error-bbpress/](https://bbpress.org/forums/topic/error-bbpress/)
   and the only way I’ve been able to stop the error other than disabling the BBPress
   plugin (not an option for me) is to disable the MonsterInsights plugin. Of all
   the 20 plugins I have installed, disabling Monster Insights is the only fix I’ve
   found so far.
 * Any suggestions why that might be? And what I can do to fix it?

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [chriscct7](https://wordpress.org/support/users/chriscct7/)
 * (@chriscct7)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/capabilities-undefined-offset-error-with-bbpress/#post-9915675)
 * Hi there,
    This is a bbPress bug caused because they didn’t handle the idea of
   meta capabilities being used which is why so many plugins are getting support
   tickets for it.
 * Let’s take a look at the first one for example:
    > Notice: Undefined offset: 
   0 in ./wp-content/plugins/bbpress/includes/topics/capabilities.php on line 80
 * So here’s the code for that:
 *     ```
       function bbp_map_reply_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) { 
   
         // What capability is being checked? 
         switch ( $cap ) { 
   
             /** Reading ***********************************************************/ 
   
             case 'read_reply' : 
   
                 // User cannot spectate 
                 if ( ! user_can( $user_id, 'spectate' ) ) { 
                     $caps = array( 'do_not_allow' ); 
   
                 // Do some post ID based logic 
                 } else { 
   
                     // Get the post 
                     $_post = get_post( $args[0] ); 
                     if ( !empty( $_post ) ) { 
       ```
   
 * So what happens here is since another plugin, in this case MonsterInsights, but
   many plugins also use them, are registering a meta capability, this capability
   will need to be resolved.
 * When that happens, the map_meta_filter is called here: [https://core.trac.wordpress.org/browser/tags/4.9/src/wp-includes/capabilities.php#L572](https://core.trac.wordpress.org/browser/tags/4.9/src/wp-includes/capabilities.php#L572)
 * Now, notice the $args param on that. Since MonsterInsights is a custom meta meta_cap,
   what will happen is $args would be populated here: [https://core.trac.wordpress.org/browser/tags/4.9/src/wp-includes/capabilities.php#L554](https://core.trac.wordpress.org/browser/tags/4.9/src/wp-includes/capabilities.php#L554).
 * However, notice how this is surrounded by a check for custom post types. In order
   for $args to be populated, since $args is for passing in custom post type meta
   meta_cap assignments, it will be empty since the MonsterInsights screen is not
   a custom post type.
 * Therefore in bbPress on the lines I had above, $args is going to be empty, and
   since they don’t handle not being on a post, the $args[0] is going to be undefined
   and throw the notice you mentioned.
 * What they need to do is put a check that says
 *     ```
       if ( empty( $args[0] ) ) { 
          return $caps;
       }
       ```
   
 * or something like that above the use of $_post = get_post( $args[0] ); so that
   it circumvents the check. They also need the same fix in the other file as well.
 * I’ll see if I can submit that to them to see if they can ship that.
 *  Plugin Author [chriscct7](https://wordpress.org/support/users/chriscct7/)
 * (@chriscct7)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/capabilities-undefined-offset-error-with-bbpress/#post-9915690)
 * A ticket for BBPress has been opened here: [https://bbpress.trac.wordpress.org/ticket/3190#ticket](https://bbpress.trac.wordpress.org/ticket/3190#ticket)
 *  Thread Starter [jasob](https://wordpress.org/support/users/jasob/)
 * (@jasob)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/capabilities-undefined-offset-error-with-bbpress/#post-9915921)
 * What an outstanding response!
    Thank you so much. This completely clarifies things
   for me. And thank you for taking it up with bbPress!
 *  Plugin Author [chriscct7](https://wordpress.org/support/users/chriscct7/)
 * (@chriscct7)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/capabilities-undefined-offset-error-with-bbpress/#post-9916486)
 * Not a problem! We’re always happy to help 🙂
 * bbPress has just earmarked this to go into their next major release, 2.6. I’ll
   try to get them a patch file today if I can to expedite that merge process.
 * If you haven’t done so already, if you’ve been using MonsterInsights, we really
   appreciate reviews (good as well as bad ones). Good ones help our overall plugin
   rating, which in turn really helps us since there’s a lot of bad ratings for 
   the plugin from before we took over development and rewrote it. Bad ones help
   us find areas we can improve on (generally, though sometimes people just write“
   I hate it” which honestly doesn’t help us out too much). You can leave reviews(
   as well as edit yours at any time) on [https://wordpress.org/support/plugin/google-analytics-for-wordpress/reviews/](https://wordpress.org/support/plugin/google-analytics-for-wordpress/reviews/)
 * -Chris
    -  This reply was modified 8 years, 4 months ago by [chriscct7](https://wordpress.org/support/users/chriscct7/).
 *  [Paul Menard](https://wordpress.org/support/users/pmenard/)
 * (@pmenard)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/capabilities-undefined-offset-error-with-bbpress/#post-9918682)
 * Actually I question your answer. Doing some investigation in the same error and
   found a bug in your plugin. you are calling current_user_can() incorrectly.
 * In version 6.2.7 of your plugin. In the file class-am-notifications.php in the
   function get_remote_notifications() line 92 you have the following:
 * if ( ! current_user_can( apply_filters( ‘am_notifications_display’, is_super_admin()))){
 *  In the inner command you have a filter which will return true or false.
    apply_filters(‘
   am_notifications_display’, is_super_admin() )
 * Then you are passing this true/false into the current_user_can() as the first
   parameter. This is wrong. You should be passing a string like ‘manage_options’
   or ‘edit_posts’ etc. a capability.
 * Down the line when other plugins who are subscribed to the ‘map_meta_cap’ filter
   receive true or false as the $cap parameter (second) instead of a string.
 *  Plugin Author [chriscct7](https://wordpress.org/support/users/chriscct7/)
 * (@chriscct7)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/capabilities-undefined-offset-error-with-bbpress/#post-9918839)
 * This is a separate issue from the one being experienced above (there are other
   tickets, notably a conflict with the Advanced Access Manager plugin that we were
   working on testing that do have this issue which is a valid one, and one we’ve
   issued a fix for).
 * The bbPress one has been patched already for the upcoming bbPress 2.6 release.
 * -Crhis

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Capabilities Undefined Offset error with BBpress’ is closed to new replies.

 * ![](https://ps.w.org/google-analytics-for-wordpress/assets/icon.svg?rev=2976619)
 * [MonsterInsights - Google Analytics Dashboard for WordPress (Website Stats Made Easy)](https://wordpress.org/plugins/google-analytics-for-wordpress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/google-analytics-for-wordpress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/google-analytics-for-wordpress/)
 * [Active Topics](https://wordpress.org/support/plugin/google-analytics-for-wordpress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/google-analytics-for-wordpress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/google-analytics-for-wordpress/reviews/)

 * 6 replies
 * 3 participants
 * Last reply from: [chriscct7](https://wordpress.org/support/users/chriscct7/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/capabilities-undefined-offset-error-with-bbpress/#post-9918839)
 * Status: resolved