Skip to:
Content

bbPress.org


Ignore:
Timestamp:
06/12/2012 05:36:00 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Capabilities & Settings:

  • Rename bbp_admin_show_ui() to bbp_current_user_can_see().
  • Add detailed support for hiding admin settings sections.
  • Remove BBP_Admin UI override flags in lieu of new method.
  • See #1846.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-core-caps.php

    r3945 r3946  
    654654
    655655/**
    656  * Should the admin UI be visible?
     656 * Can the current user see a specific UI element?
    657657 *
    658  * Used when registering post types and taxonomies to decide if 'show_ui' should
    659  * be set to true or false
     658 * Used when registering post-types and taxonomies to decide if 'show_ui' should
     659 * be set to true or false. Also used for fine-grained control over which admin
     660 * sections are visible under what conditions.
     661 *
     662 * This function is in bbp-core-caps.php rather than in /bbp-admin so that it
     663 * can be used during the bbp_register_post_types action.
    660664 *
    661665 * @since bbPress (r3944)
     666 *
    662667 * @uses current_user_can() To check the 'moderate' capability
     668 * @uses bbp_get_forum_post_type()
     669 * @uses bbp_get_topic_post_type()
     670 * @uses bbp_get_reply_post_type()
     671 * @uses bbp_get_topic_tag_tax_id()
     672 * @uses is_plugin_active()
     673 * @uses is_super_admin()
    663674 * @return bool Results of current_user_can( 'moderate' ) check.
    664675 */
    665 function bbp_admin_show_ui( $component = '' ) {
     676function bbp_current_user_can_see( $component = '' ) {
    666677
    667678    // Define local variable
    668679    $retval = false;
    669680
    670     // Allow for context switching by plugins
     681    // Which component are we checking UI visibility for?
    671682    switch ( $component ) {
    672         case 'bbp_converter'             : // Converter
    673         case 'bbp_settings_main'         : // Settings
     683
     684        /** Everywhere ********************************************************/
     685
     686        case bbp_get_forum_post_type()   : // Forums
     687        case bbp_get_topic_post_type()   : // Topics
     688        case bbp_get_reply_post_type()   : // Replies
     689        case bbp_get_topic_tag_tax_id()  : // Topic-Tags
     690            $retval = current_user_can( 'moderate' );
     691            break;
     692
     693        /** Admin Exclusive ***************************************************/
     694
     695        case 'bbp_settings_buddypress'  : // BuddyPress Extension
     696            $retval = ( is_plugin_active( 'buddypress/bp-loader.php' ) && defined( 'BP_VERSION' ) ) && is_super_admin();
     697            break;
     698
     699        case 'bbp_settings_akismet'     : // Akismet Extension
     700            $retval = ( is_plugin_active( 'akismet/akismet.php' ) && defined( 'AKISMET_VERSION' ) ) && is_super_admin();
     701            break;
     702
     703        case 'bbp_tools_page'            : // Tools Page
     704        case 'bbp_tools_repair_page'     : // Tools - Repair Page
     705        case 'bbp_tools_import_page'     : // Tools - Import Page
     706        case 'bbp_tools_reset_page'      : // Tools - Reset Page
     707        case 'bbp_settings?page'         : // Settings Page
     708        case 'bbp_settings_main'         : // Settings - General
    674709        case 'bbp_settings_theme_compat' : // Settings - Theme compat
    675710        case 'bbp_settings_root_slugs'   : // Settings - Root slugs
     
    677712        case 'bbp_settings_per_page'     : // Settings - Single slugs
    678713        case 'bbp_settings_per_page_rss' : // Settings - Single slugs
    679             $retval = is_super_admin();
    680             break;
    681 
    682         case 'bbp_settings_buddypress'  : // BuddyPress Extension
    683             $retval = ( is_plugin_active( 'buddypress/bp-loader.php' ) && defined( 'BP_VERSION' ) ) && is_super_admin();
    684             break;
    685 
    686         case 'bbp_settings_akismet'     : // Akismet Extension
    687             $retval = ( is_plugin_active( 'akismet/akismet.php' ) && defined( 'AKISMET_VERSION' ) ) && is_super_admin();
    688             break;
    689 
    690         case bbp_get_forum_post_type()  : // Forums
    691         case bbp_get_topic_post_type()  : // Topics
    692         case bbp_get_reply_post_type()  : // Replies
    693         case bbp_get_topic_tag_tax_id() : // Topic-Tags
    694         default                         :
    695             $retval = current_user_can( 'moderate' );
     714        default                          : // Anything else
     715            $retval = current_user_can( bbpress()->admin->minimum_capability );
    696716            break;
    697717    }
    698718
    699     return (bool) apply_filters( 'bbp_admin_show_ui', $retval, $component );
     719    return (bool) apply_filters( 'bbp_current_user_can_see', (bool) $retval, $component );
    700720}
    701721
Note: See TracChangeset for help on using the changeset viewer.