<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][13131] trunk: Let advanced users disable the WP Admin community profile</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/13131">13131</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/13131","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>imath</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-10-28 14:02:28 +0000 (Thu, 28 Oct 2021)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="http://buddypress.trac.wordpress.org/ticket/8479">#8479</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpmembersbpmembersadminphp">trunk/src/bp-members/bp-members-admin.php</a></li>
<li><a href="#trunksrcbpmembersclassesclassbpmembersadminphp">trunk/src/bp-members/classes/class-bp-members-admin.php</a></li>
<li><a href="#trunktestsphpunittestcasescorefunctionsbpCoreGetDirectoryPageIdsphp">trunk/tests/phpunit/testcases/core/functions/bpCoreGetDirectoryPageIds.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpmembersbpmembersadminphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-members/bp-members-admin.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-members/bp-members-admin.php 2021-10-28 13:36:47 UTC (rev 13130)
+++ trunk/src/bp-members/bp-members-admin.php   2021-10-28 14:02:28 UTC (rev 13131)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -10,6 +10,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Exit if accessed directly.
</span><span class="cx" style="display: block; padding: 0 10px"> defined( 'ABSPATH' ) || exit;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * Is the Admin User's community profile enabled?
+ *
+ * @since 10.0.0
+ *
+ * @return bool True if enabled. False otherwise.
+ */
+function bp_members_is_community_profile_enabled() {
+       /**
+        * Filter here to disable the Admin User's Community profile.
+        *
+        * @since 10.0.0
+        *
+        * @param bool $value By default the Admin User's Community profile is enabled.
+        */
+       return apply_filters( 'bp_members_is_community_profile_enabled', true );
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Load the BP Members admin.
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'bp_init', array( 'BP_Members_Admin', 'register_members_admin' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcbpmembersclassesclassbpmembersadminphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-members/classes/class-bp-members-admin.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-members/classes/class-bp-members-admin.php   2021-10-28 13:36:47 UTC (rev 13130)
+++ trunk/src/bp-members/classes/class-bp-members-admin.php     2021-10-28 14:02:28 UTC (rev 13131)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -170,24 +170,32 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Add menu item to all users menu.
</span><span class="cx" style="display: block; padding: 0 10px">                add_action( 'admin_menu',               array( $this, 'admin_menus'       ), 5     );
</span><span class="cx" style="display: block; padding: 0 10px">                add_action( 'network_admin_menu',       array( $this, 'admin_menus'       ), 5     );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                add_action( 'user_admin_menu',          array( $this, 'user_profile_menu' ), 5     );
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Create the Profile Navigation (Profile/Extended Profile).
-               add_action( 'edit_user_profile',        array( $this, 'profile_nav'       ), 99, 1 );
-               add_action( 'show_user_profile',        array( $this, 'profile_nav'       ), 99, 1 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( bp_members_is_community_profile_enabled() ) {
+                       add_action( 'user_admin_menu', array( $this, 'user_profile_menu' ), 5     );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Editing users of a specific site.
-               add_action( "admin_head-site-users.php", array( $this, 'profile_admin_head' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Create the Profile Navigation (Profile/Extended Profile).
+                       add_action( 'edit_user_profile',        array( $this, 'profile_nav'       ), 99, 1 );
+                       add_action( 'show_user_profile',        array( $this, 'profile_nav'       ), 99, 1 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        // Editing users of a specific site.
+                       add_action( "admin_head-site-users.php", array( $this, 'profile_admin_head' ) );
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // Add a row action to users listing.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( bp_core_do_network_admin() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        add_filter( 'ms_user_row_actions',        array( $this, 'row_actions'                    ), 10, 2 );
-                       add_action( 'admin_init',                 array( $this, 'add_edit_profile_url_filter'    )        );
-                       add_action( 'wp_after_admin_bar_render',  array( $this, 'remove_edit_profile_url_filter' )        );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( bp_members_is_community_profile_enabled() ) {
+                               add_filter( 'ms_user_row_actions', array( $this, 'row_actions' ), 10, 2 );
+                       }
+
+                       add_action( 'admin_init', array( $this, 'add_edit_profile_url_filter' ) );
+                       add_action( 'wp_after_admin_bar_render',  array( $this, 'remove_edit_profile_url_filter' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Add user row actions for single site.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                add_filter( 'user_row_actions', array( $this, 'row_actions' ), 10, 2 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( bp_members_is_community_profile_enabled() ) {
+                       add_filter( 'user_row_actions', array( $this, 'row_actions' ), 10, 2 );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Process changes to member type.
</span><span class="cx" style="display: block; padding: 0 10px">                add_action( 'bp_members_admin_load', array( $this, 'process_member_type_update' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -478,15 +486,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Setup the hooks array.
</span><span class="cx" style="display: block; padding: 0 10px">                $hooks = array();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Manage user's profile.
-               $hooks['user'] = $this->user_page = add_submenu_page(
-                       $this->user_profile . '.php',
-                       __( 'Edit Profile',  'buddypress' ),
-                       __( 'Edit Profile',  'buddypress' ),
-                       'read',
-                       'bp-profile-edit',
-                       array( $this, 'user_admin' )
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( bp_members_is_community_profile_enabled() ) {
+                       // Manage user's profile.
+                       $hooks['user'] = $this->user_page = add_submenu_page(
+                               $this->user_profile . '.php',
+                               __( 'Edit Profile',  'buddypress' ),
+                               __( 'Edit Profile',  'buddypress' ),
+                               'read',
+                               'bp-profile-edit',
+                               array( $this, 'user_admin' )
+                       );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Only show sign-ups where they belong.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ( ! bp_is_network_activated() && ! is_network_admin() ) || ( is_network_admin() && bp_is_network_activated() ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -650,53 +660,55 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $min = bp_core_get_minified_asset_suffix();
-               $css = $this->css_url . "admin{$min}.css";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( bp_members_is_community_profile_enabled() ) {
+                       $min = bp_core_get_minified_asset_suffix();
+                       $css = $this->css_url . "admin{$min}.css";
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                /**
-                * Filters the CSS URL to enqueue in the Members admin area.
-                *
-                * @since 2.0.0
-                *
-                * @param string $css URL to the CSS admin file to load.
-                */
-               $css = apply_filters( 'bp_members_admin_css', $css );
-
-               wp_enqueue_style( 'bp-members-css', $css, array(), bp_get_version() );
-
-               wp_style_add_data( 'bp-members-css', 'rtl', 'replace' );
-               if ( $min ) {
-                       wp_style_add_data( 'bp-members-css', 'suffix', $min );
-               }
-
-               // Only load JavaScript for BuddyPress profile.
-               if ( get_current_screen()->id == $this->user_page ) {
-                       $js = $this->js_url . "admin{$min}.js";
-
</del><span class="cx" style="display: block; padding: 0 10px">                         /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                         * Filters the JS URL to enqueue in the Members admin area.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                  * Filters the CSS URL to enqueue in the Members admin area.
</ins><span class="cx" style="display: block; padding: 0 10px">                          *
</span><span class="cx" style="display: block; padding: 0 10px">                         * @since 2.0.0
</span><span class="cx" style="display: block; padding: 0 10px">                         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                         * @param string $js URL to the JavaScript admin file to load.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                  * @param string $css URL to the CSS admin file to load.
</ins><span class="cx" style="display: block; padding: 0 10px">                          */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $js = apply_filters( 'bp_members_admin_js', $js );
-                       wp_enqueue_script( 'bp-members-js', $js, array( 'jquery' ), bp_get_version(), true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $css = apply_filters( 'bp_members_admin_css', $css );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( ! bp_core_get_root_option( 'bp-disable-avatar-uploads' ) && buddypress()->avatar->show_avatars ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 wp_enqueue_style( 'bp-members-css', $css, array(), bp_get_version() );
+
+                       wp_style_add_data( 'bp-members-css', 'rtl', 'replace' );
+                       if ( $min ) {
+                               wp_style_add_data( 'bp-members-css', 'suffix', $min );
+                       }
+
+                       // Only load JavaScript for BuddyPress profile.
+                       if ( get_current_screen()->id == $this->user_page ) {
+                               $js = $this->js_url . "admin{$min}.js";
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                 * Get Thickbox.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                          * Filters the JS URL to enqueue in the Members admin area.
</ins><span class="cx" style="display: block; padding: 0 10px">                                  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                 * We cannot simply use add_thickbox() here as WordPress is not playing
-                                * nice with Thickbox width/height see https://core.trac.wordpress.org/ticket/17249
-                                * Using media-upload might be interesting in the future for the send to editor stuff
-                                * and we make sure the tb_window is wide enough
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                          * @since 2.0.0
+                                *
+                                * @param string $js URL to the JavaScript admin file to load.
</ins><span class="cx" style="display: block; padding: 0 10px">                                  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                wp_enqueue_style ( 'thickbox' );
-                               wp_enqueue_script( 'media-upload' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $js = apply_filters( 'bp_members_admin_js', $js );
+                               wp_enqueue_script( 'bp-members-js', $js, array( 'jquery' ), bp_get_version(), true );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                // Get Avatar Uploader.
-                               bp_attachments_enqueue_scripts( 'BP_Attachment_Avatar' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( ! bp_core_get_root_option( 'bp-disable-avatar-uploads' ) && buddypress()->avatar->show_avatars ) {
+                                       /**
+                                        * Get Thickbox.
+                                        *
+                                        * We cannot simply use add_thickbox() here as WordPress is not playing
+                                        * nice with Thickbox width/height see https://core.trac.wordpress.org/ticket/17249
+                                        * Using media-upload might be interesting in the future for the send to editor stuff
+                                        * and we make sure the tb_window is wide enough
+                                        */
+                                       wp_enqueue_style ( 'thickbox' );
+                                       wp_enqueue_script( 'media-upload' );
+
+                                       // Get Avatar Uploader.
+                                       bp_attachments_enqueue_scripts( 'BP_Attachment_Avatar' );
+                               }
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1005,7 +1017,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( true === $this->is_self_profile ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $title = __( 'Profile',   'buddypress' );
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $title = __( 'Edit User', 'buddypress' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 /* translators: %s: User's display name. */
+                       $title = sprintf( __( 'Edit User %s', 'buddypress' ), $user->display_name );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Construct URL for form.
</span></span></pre></div>
<a id="trunktestsphpunittestcasescorefunctionsbpCoreGetDirectoryPageIdsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/testcases/core/functions/bpCoreGetDirectoryPageIds.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/testcases/core/functions/bpCoreGetDirectoryPageIds.php        2021-10-28 13:36:47 UTC (rev 13130)
+++ trunk/tests/phpunit/testcases/core/functions/bpCoreGetDirectoryPageIds.php  2021-10-28 14:02:28 UTC (rev 13131)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -292,6 +292,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->markTestSkipped();
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                require BP_PLUGIN_DIR . 'bp-members/bp-members-admin.php';
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // Emulate being in the admin area.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! class_exists( 'BP_Members_Admin', false ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        require BP_PLUGIN_DIR . 'bp-members/classes/class-bp-members-admin.php';
</span></span></pre>
</div>
</div>

</body>
</html>