<!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][13629] trunk/src: Introduce BP_Members_Invitations_Component.</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/13629">13629</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/13629","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dcavins</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-11-01 16:04:56 +0000 (Wed, 01 Nov 2023)</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'>Introduce BP_Members_Invitations_Component.
Introduce a slim `BP_Members_Invitations_Component`
to handle the addition and management of member and admin bar navigation items for the member invitations feature.
Fixes <a href="http://buddypress.trac.wordpress.org/ticket/9013">#9013</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpmembersbpmembersadminbarphp">trunk/src/bp-members/bp-members-adminbar.php</a></li>
<li><a href="#trunksrcbpmembersbpmembersinvitationsphp">trunk/src/bp-members/bp-members-invitations.php</a></li>
<li><a href="#trunksrcbpmembersbpmembersloaderphp">trunk/src/bp-members/bp-members-loader.php</a></li>
<li><a href="#trunksrcclassbuddypressphp">trunk/src/class-buddypress.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunksrcbpmembersclassesclassbpmembersinvitationscomponentphp">trunk/src/bp-members/classes/class-bp-members-invitations-component.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpmembersbpmembersadminbarphp"></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-adminbar.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-members/bp-members-adminbar.php 2023-10-31 19:13:49 UTC (rev 13628)
+++ trunk/src/bp-members/bp-members-adminbar.php 2023-11-01 16:04:56 UTC (rev 13629)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -280,63 +280,3 @@
</span><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_action( 'add_admin_bar_menus', 'bp_members_remove_edit_page_menu' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-/**
- * Add the "Invitations" menu and submenus.
- *
- * @since 8.0.0
- *
- * @global WP_Admin_Bar $wp_admin_bar WordPress object implementing a Toolbar API.
- */
-function bp_members_admin_bar_add_invitations_menu() {
- global $wp_admin_bar;
-
- // Bail if this is an ajax request.
- if ( wp_doing_ajax() ) {
- return;
- }
-
- if ( bp_current_user_can( 'bp_members_invitations_view_screens' ) ) {
- $bp = buddypress();
- $invite_slug = bp_get_members_invitations_slug();
-
- $wp_admin_bar->add_node(
- array(
- 'id' => $bp->my_account_menu_id . '-invitations',
- 'parent' => $bp->my_account_menu_id,
- 'title' => __( 'Invitations', 'buddypress' ),
- 'href' => bp_loggedin_user_url( bp_members_get_path_chunks( array( $invite_slug ) ) ),
- 'meta' => array(
- 'class' => 'ab-sub-secondary'
- )
- )
- );
-
- if ( bp_current_user_can( 'bp_members_invitations_view_send_screen' ) ) {
- $wp_admin_bar->add_node(
- array(
- 'id' => $bp->my_account_menu_id . '-invitations-send',
- 'parent' => $bp->my_account_menu_id . '-invitations',
- 'title' => __( 'Send Invites', 'buddypress' ),
- 'href' => bp_loggedin_user_url( bp_members_get_path_chunks( array( $invite_slug, 'send-invites' ) ) ),
- 'meta' => array(
- 'class' => 'ab-sub-secondary'
- )
- )
- );
- }
-
- $wp_admin_bar->add_node(
- array(
- 'id' => $bp->my_account_menu_id . '-invitations-list',
- 'parent' => $bp->my_account_menu_id . '-invitations',
- 'title' => __( 'Pending Invites', 'buddypress' ),
- 'href' => bp_loggedin_user_url( bp_members_get_path_chunks( array( $invite_slug, 'list-invites' ) ) ),
- 'meta' => array(
- 'class' => 'ab-sub-secondary'
- )
- )
- );
- }
-}
-add_action( 'bp_setup_admin_bar', 'bp_members_admin_bar_add_invitations_menu', 90 );
</del></span></pre></div>
<a id="trunksrcbpmembersbpmembersinvitationsphp"></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-invitations.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-members/bp-members-invitations.php 2023-10-31 19:13:49 UTC (rev 13628)
+++ trunk/src/bp-members/bp-members-invitations.php 2023-11-01 16:04:56 UTC (rev 13629)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -11,56 +11,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> defined( 'ABSPATH' ) || exit;
</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">- * Set up the displayed user's Members Invitations nav.
- *
- * @since 8.0.0
- */
-function bp_members_invitations_setup_nav() {
- if ( ! bp_get_members_invitations_allowed() ) {
- return;
- }
-
- $user_has_access = bp_user_has_access();
- $default_subnav_slug = ( bp_is_my_profile() && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_send_screen' ) ) ? 'send-invites' : 'list-invites';
-
- /* Add 'Invitations' to the main user profile navigation */
- bp_core_new_nav_item(
- array(
- 'name' => __( 'Invitations', 'buddypress' ),
- 'slug' => bp_get_members_invitations_slug(),
- 'position' => 80,
- 'screen_function' => 'members_screen_send_invites',
- 'default_subnav_slug' => $default_subnav_slug,
- 'show_for_displayed_user' => $user_has_access && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_screens' )
- )
- );
-
- /* Create two subnav items for community invitations */
- bp_core_new_subnav_item(
- array(
- 'name' => __( 'Send Invites', 'buddypress' ),
- 'slug' => 'send-invites',
- 'parent_slug' => bp_get_members_invitations_slug(),
- 'screen_function' => 'members_screen_send_invites',
- 'position' => 10,
- 'user_has_access' => $user_has_access && bp_is_my_profile() && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_send_screen' )
- )
- );
-
- bp_core_new_subnav_item(
- array(
- 'name' => __( 'Pending Invites', 'buddypress' ),
- 'slug' => 'list-invites',
- 'parent_slug' => bp_get_members_invitations_slug(),
- 'screen_function' => 'members_screen_list_sent_invites',
- 'position' => 20,
- 'user_has_access' => $user_has_access && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_screens' )
- )
- );
-}
-add_action( 'bp_setup_nav', 'bp_members_invitations_setup_nav' );
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px"> * When a user joins the network via an invitation, skip sending the activation email.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 8.0.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -216,3 +166,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_members_membership_requests_bypass_manual_approval', 'bp_members_invitations_maybe_bypass_request_approval', 10, 2 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_members_membership_requests_bypass_manual_approval_multisite', 'bp_members_invitations_maybe_bypass_request_approval', 10, 2 );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Whether a user can access invitations screens.
+ * Referred to by BP_Members_Invitations_Component::register_nav().
+ *
+ * @since 12.0.0
+ *
+ * @param bool $access Whether the user can view member invitations screens.
+ */
+function bp_members_invitations_user_can_view_screens() {
+ return bp_user_has_access() && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_screens' );
+}
+
+/**
+ * Whether a user can access the send invitations member screen.
+ * Referred to by BP_Members_Invitations_Component::register_nav().
+ *
+ * @since 12.0.0
+ *
+ * @param bool $access Whether the user can view member invitations send screen.
+ */
+function bp_members_invitations_user_can_view_send_screen() {
+ return bp_is_my_profile() && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_send_screen' );
+}
</ins></span></pre></div>
<a id="trunksrcbpmembersbpmembersloaderphp"></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-loader.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-members/bp-members-loader.php 2023-10-31 19:13:49 UTC (rev 13628)
+++ trunk/src/bp-members/bp-members-loader.php 2023-11-01 16:04:56 UTC (rev 13629)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,3 +19,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> buddypress()->members = new BP_Members_Component();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'bp_setup_components', 'bp_setup_members', 1 );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Set up the bp-members-invitations component.
+ *
+ * @since 12.0.0
+ */
+function bp_setup_members_invitations() {
+ buddypress()->members_invitations = new BP_Members_Invitations_Component();
+}
+add_action( 'bp_setup_components', 'bp_setup_members_invitations', 1 );
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="trunksrcbpmembersclassesclassbpmembersinvitationscomponentphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/bp-members/classes/class-bp-members-invitations-component.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-invitations-component.php (rev 0)
+++ trunk/src/bp-members/classes/class-bp-members-invitations-component.php 2023-11-01 16:04:56 UTC (rev 13629)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,139 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * BP Members Invitations Component.
+ *
+ * @package BuddyPress
+ *
+ * @since 12.0.0
+ */
+
+// Exit if accessed directly.
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+class BP_Members_Invitations_Component extends BP_Component {
+
+ function __construct() {
+ parent::start(
+ 'members_invitations',
+ __( 'Members Invitations', 'buddypress' ),
+ '',
+ array()
+ );
+ }
+
+ /**
+ * Register component navigation.
+ *
+ * @since 12.0.0
+ *
+ * @see `BP_Component::register_nav()` for a description of arguments.
+ *
+ * @param array $main_nav Optional. See `BP_Component::register_nav()` for
+ * description.
+ * @param array $sub_nav Optional. See `BP_Component::register_nav()` for
+ * description.
+ */
+ public function register_nav( $main_nav = array(), $sub_nav = array() ) {
+ if ( ! bp_get_members_invitations_allowed() ) {
+ return;
+ }
+
+ /* Add 'Invitations' to the main user profile navigation */
+ $main_nav = array(
+ 'name' => __( 'Invitations', 'buddypress' ),
+ 'slug' => bp_get_members_invitations_slug(),
+ 'position' => 80,
+ 'screen_function' => 'members_screen_send_invites',
+ 'default_subnav_slug' => 'list-invites',
+ 'show_for_displayed_user' => false, // Non-admin users should only see their own invites.
+ 'user_has_access_callback' => 'bp_members_invitations_user_can_view_screens',
+ );
+
+ /* Create two subnav items for community invitations. */
+ $sub_nav[] = array(
+ 'name' => __( 'Send Invites', 'buddypress' ),
+ 'slug' => 'send-invites',
+ 'parent_slug' => bp_get_members_invitations_slug(),
+ 'screen_function' => 'members_screen_send_invites',
+ 'position' => 10,
+ 'user_has_access' => false,
+ 'user_has_access_callback' => 'bp_members_invitations_user_can_view_send_screen',
+ );
+
+ $sub_nav[] = array(
+ 'name' => __( 'Pending Invites', 'buddypress' ),
+ 'slug' => 'list-invites',
+ 'parent_slug' => bp_get_members_invitations_slug(),
+ 'screen_function' => 'members_screen_list_sent_invites',
+ 'position' => 20,
+ 'user_has_access' => false,
+ 'user_has_access_callback' => 'bp_members_invitations_user_can_view_screens',
+ );
+
+ parent::register_nav( $main_nav, $sub_nav );
+ }
+
+ /**
+ * Set up component navigation.
+ *
+ * @since 12.0.0 Used to customize the default subnavigation slug.
+ *
+ * @see `BP_Component::setup_nav()` for a description of arguments.
+ *
+ * @param array $main_nav Optional. See `BP_Component::setup_nav()` for
+ * description.
+ * @param array $sub_nav Optional. See `BP_Component::setup_nav()` for
+ * description.
+ */
+ public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
+ if ( bp_is_my_profile() && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_send_screen' ) ) {
+ $this->main_nav['default_subnav_slug'] = 'send-invites';
+ }
+
+ parent::setup_nav( $main_nav, $sub_nav );
+ }
+
+ /**
+ * Set up the component entries in the WordPress Admin Bar.
+ *
+ * @since 1.0.0
+ *
+ * @see BP_Component::setup_admin_bar() for a description of arguments.
+ *
+ * @param array $wp_admin_nav See BP_Component::setup_admin_bar()
+ * for description.
+ */
+ public function setup_admin_bar( $wp_admin_nav = array() ) {
+ if ( bp_current_user_can( 'bp_members_invitations_view_screens' ) ) {
+ $bp = buddypress();
+ $invite_slug = bp_get_members_invitations_slug();
+ $invite_menu_id = $bp->my_account_menu_id . '-invitations';
+
+ $wp_admin_nav[] = array(
+ 'id' => $invite_menu_id,
+ 'parent' => $bp->my_account_menu_id,
+ 'title' => __( 'Invitations', 'buddypress' ),
+ 'href' => bp_loggedin_user_url( bp_members_get_path_chunks( array( $invite_slug ) ) ),
+ );
+
+ if ( bp_current_user_can( 'bp_members_invitations_view_send_screen' ) ) {
+ $wp_admin_nav[] = array(
+ 'id' => $bp->my_account_menu_id . '-invitations-send',
+ 'parent' => $invite_menu_id,
+ 'title' => __( 'Send Invites', 'buddypress' ),
+ 'href' => bp_loggedin_user_url( bp_members_get_path_chunks( array( $invite_slug, 'send-invites' ) ) ),
+ );
+ }
+
+ $wp_admin_nav[] = array(
+ 'id' => $bp->my_account_menu_id . '-invitations-list',
+ 'parent' => $invite_menu_id,
+ 'title' => __( 'Pending Invites', 'buddypress' ),
+ 'href' => bp_loggedin_user_url( bp_members_get_path_chunks( array( $invite_slug, 'list-invites' ) ) ),
+ );
+ }
+
+ parent::setup_admin_bar( $wp_admin_nav );
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="trunksrcclassbuddypressphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/class-buddypress.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/class-buddypress.php 2023-10-31 19:13:49 UTC (rev 13628)
+++ trunk/src/class-buddypress.php 2023-11-01 16:04:56 UTC (rev 13629)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -766,6 +766,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'BP_REST_Signup_Endpoint' => 'members',
</span><span class="cx" style="display: block; padding: 0 10px"> 'BP_Members_Invitation_Manager' => 'members',
</span><span class="cx" style="display: block; padding: 0 10px"> 'BP_Members_Invitations_Template' => 'members',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'BP_Members_Invitations_Component' => 'members',
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'BP_REST_Messages_Endpoint' => 'messages',
</span><span class="cx" style="display: block; padding: 0 10px"> 'BP_REST_Sitewide_Notices_Endpoint' => 'messages',
</span></span></pre>
</div>
</div>
</body>
</html>