Skip to:
Content

BuddyPress.org

Changeset 13131


Ignore:
Timestamp:
10/28/2021 02:02:28 PM (2 years ago)
Author:
imath
Message:

Let advanced users disable the WP Admin community profile

Introduce the bp_members_is_community_profile_enabled() function to check the community profile is enabled. Advanced users can edit this status returning false when filtering bp_members_is_community_profile_enabled.

Props vanpop, dcavins

Fixes #8479

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-admin.php

    r13105 r13131  
    1010// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
     12
     13/**
     14 * Is the Admin User's community profile enabled?
     15 *
     16 * @since 10.0.0
     17 *
     18 * @return bool True if enabled. False otherwise.
     19 */
     20function bp_members_is_community_profile_enabled() {
     21    /**
     22     * Filter here to disable the Admin User's Community profile.
     23     *
     24     * @since 10.0.0
     25     *
     26     * @param bool $value By default the Admin User's Community profile is enabled.
     27     */
     28    return apply_filters( 'bp_members_is_community_profile_enabled', true );
     29}
    1230
    1331// Load the BP Members admin.
  • trunk/src/bp-members/classes/class-bp-members-admin.php

    r12930 r13131  
    171171        add_action( 'admin_menu',               array( $this, 'admin_menus'       ), 5     );
    172172        add_action( 'network_admin_menu',       array( $this, 'admin_menus'       ), 5     );
    173         add_action( 'user_admin_menu',          array( $this, 'user_profile_menu' ), 5     );
    174 
    175         // Create the Profile Navigation (Profile/Extended Profile).
    176         add_action( 'edit_user_profile',        array( $this, 'profile_nav'       ), 99, 1 );
    177         add_action( 'show_user_profile',        array( $this, 'profile_nav'       ), 99, 1 );
    178 
    179         // Editing users of a specific site.
    180         add_action( "admin_head-site-users.php", array( $this, 'profile_admin_head' ) );
     173
     174        if ( bp_members_is_community_profile_enabled() ) {
     175            add_action( 'user_admin_menu', array( $this, 'user_profile_menu' ), 5     );
     176
     177            // Create the Profile Navigation (Profile/Extended Profile).
     178            add_action( 'edit_user_profile',        array( $this, 'profile_nav'       ), 99, 1 );
     179            add_action( 'show_user_profile',        array( $this, 'profile_nav'       ), 99, 1 );
     180
     181            // Editing users of a specific site.
     182            add_action( "admin_head-site-users.php", array( $this, 'profile_admin_head' ) );
     183        }
    181184
    182185        // Add a row action to users listing.
    183186        if ( bp_core_do_network_admin() ) {
    184             add_filter( 'ms_user_row_actions',        array( $this, 'row_actions'                    ), 10, 2 );
    185             add_action( 'admin_init',                 array( $this, 'add_edit_profile_url_filter'    )        );
    186             add_action( 'wp_after_admin_bar_render',  array( $this, 'remove_edit_profile_url_filter' )        );
     187            if ( bp_members_is_community_profile_enabled() ) {
     188                add_filter( 'ms_user_row_actions', array( $this, 'row_actions' ), 10, 2 );
     189            }
     190
     191            add_action( 'admin_init', array( $this, 'add_edit_profile_url_filter' ) );
     192            add_action( 'wp_after_admin_bar_render',  array( $this, 'remove_edit_profile_url_filter' ) );
    187193        }
    188194
    189195        // Add user row actions for single site.
    190         add_filter( 'user_row_actions', array( $this, 'row_actions' ), 10, 2 );
     196        if ( bp_members_is_community_profile_enabled() ) {
     197            add_filter( 'user_row_actions', array( $this, 'row_actions' ), 10, 2 );
     198        }
    191199
    192200        // Process changes to member type.
     
    479487        $hooks = array();
    480488
    481         // Manage user's profile.
    482         $hooks['user'] = $this->user_page = add_submenu_page(
    483             $this->user_profile . '.php',
    484             __( 'Edit Profile',  'buddypress' ),
    485             __( 'Edit Profile',  'buddypress' ),
    486             'read',
    487             'bp-profile-edit',
    488             array( $this, 'user_admin' )
    489         );
     489        if ( bp_members_is_community_profile_enabled() ) {
     490            // Manage user's profile.
     491            $hooks['user'] = $this->user_page = add_submenu_page(
     492                $this->user_profile . '.php',
     493                __( 'Edit Profile',  'buddypress' ),
     494                __( 'Edit Profile',  'buddypress' ),
     495                'read',
     496                'bp-profile-edit',
     497                array( $this, 'user_admin' )
     498            );
     499        }
    490500
    491501        // Only show sign-ups where they belong.
     
    651661        }
    652662
    653         $min = bp_core_get_minified_asset_suffix();
    654         $css = $this->css_url . "admin{$min}.css";
    655 
    656         /**
    657          * Filters the CSS URL to enqueue in the Members admin area.
    658          *
    659          * @since 2.0.0
    660          *
    661          * @param string $css URL to the CSS admin file to load.
    662          */
    663         $css = apply_filters( 'bp_members_admin_css', $css );
    664 
    665         wp_enqueue_style( 'bp-members-css', $css, array(), bp_get_version() );
    666 
    667         wp_style_add_data( 'bp-members-css', 'rtl', 'replace' );
    668         if ( $min ) {
    669             wp_style_add_data( 'bp-members-css', 'suffix', $min );
    670         }
    671 
    672         // Only load JavaScript for BuddyPress profile.
    673         if ( get_current_screen()->id == $this->user_page ) {
    674             $js = $this->js_url . "admin{$min}.js";
     663        if ( bp_members_is_community_profile_enabled() ) {
     664            $min = bp_core_get_minified_asset_suffix();
     665            $css = $this->css_url . "admin{$min}.css";
    675666
    676667            /**
    677              * Filters the JS URL to enqueue in the Members admin area.
     668             * Filters the CSS URL to enqueue in the Members admin area.
    678669             *
    679670             * @since 2.0.0
    680671             *
    681              * @param string $js URL to the JavaScript admin file to load.
     672             * @param string $css URL to the CSS admin file to load.
    682673             */
    683             $js = apply_filters( 'bp_members_admin_js', $js );
    684             wp_enqueue_script( 'bp-members-js', $js, array( 'jquery' ), bp_get_version(), true );
    685 
    686             if ( ! bp_core_get_root_option( 'bp-disable-avatar-uploads' ) && buddypress()->avatar->show_avatars ) {
     674            $css = apply_filters( 'bp_members_admin_css', $css );
     675
     676            wp_enqueue_style( 'bp-members-css', $css, array(), bp_get_version() );
     677
     678            wp_style_add_data( 'bp-members-css', 'rtl', 'replace' );
     679            if ( $min ) {
     680                wp_style_add_data( 'bp-members-css', 'suffix', $min );
     681            }
     682
     683            // Only load JavaScript for BuddyPress profile.
     684            if ( get_current_screen()->id == $this->user_page ) {
     685                $js = $this->js_url . "admin{$min}.js";
     686
    687687                /**
    688                  * Get Thickbox.
     688                 * Filters the JS URL to enqueue in the Members admin area.
    689689                 *
    690                  * We cannot simply use add_thickbox() here as WordPress is not playing
    691                  * nice with Thickbox width/height see https://core.trac.wordpress.org/ticket/17249
    692                  * Using media-upload might be interesting in the future for the send to editor stuff
    693                  * and we make sure the tb_window is wide enough
     690                 * @since 2.0.0
     691                 *
     692                 * @param string $js URL to the JavaScript admin file to load.
    694693                 */
    695                 wp_enqueue_style ( 'thickbox' );
    696                 wp_enqueue_script( 'media-upload' );
    697 
    698                 // Get Avatar Uploader.
    699                 bp_attachments_enqueue_scripts( 'BP_Attachment_Avatar' );
     694                $js = apply_filters( 'bp_members_admin_js', $js );
     695                wp_enqueue_script( 'bp-members-js', $js, array( 'jquery' ), bp_get_version(), true );
     696
     697                if ( ! bp_core_get_root_option( 'bp-disable-avatar-uploads' ) && buddypress()->avatar->show_avatars ) {
     698                    /**
     699                     * Get Thickbox.
     700                     *
     701                     * We cannot simply use add_thickbox() here as WordPress is not playing
     702                     * nice with Thickbox width/height see https://core.trac.wordpress.org/ticket/17249
     703                     * Using media-upload might be interesting in the future for the send to editor stuff
     704                     * and we make sure the tb_window is wide enough
     705                     */
     706                    wp_enqueue_style ( 'thickbox' );
     707                    wp_enqueue_script( 'media-upload' );
     708
     709                    // Get Avatar Uploader.
     710                    bp_attachments_enqueue_scripts( 'BP_Attachment_Avatar' );
     711                }
    700712            }
    701713        }
     
    10061018            $title = __( 'Profile',   'buddypress' );
    10071019        } else {
    1008             $title = __( 'Edit User', 'buddypress' );
     1020            /* translators: %s: User's display name. */
     1021            $title = sprintf( __( 'Edit User %s', 'buddypress' ), $user->display_name );
    10091022        }
    10101023
  • trunk/tests/phpunit/testcases/core/functions/bpCoreGetDirectoryPageIds.php

    r12606 r13131  
    293293        }
    294294
     295        require BP_PLUGIN_DIR . 'bp-members/bp-members-admin.php';
     296
    295297        // Emulate being in the admin area.
    296298        if ( ! class_exists( 'BP_Members_Admin', false ) ) {
Note: See TracChangeset for help on using the changeset viewer.