[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Membership invitations class. 4 * 5 * @package BuddyPress 6 * @subpackage Core 7 * @since 8.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Membership invitations class. 15 * 16 * An extension of the core Invitations class that adapts the 17 * core logic to accommodate site membership invitation behavior. 18 * 19 * @since 8.0.0 20 */ 21 class BP_Members_Invitation_Manager extends BP_Invitation_Manager { 22 /** 23 * Construct parameters. 24 * 25 * @since 8.0.0 26 * 27 * @param array|string $args. 28 */ 29 public function __construct( $args = '' ) { 30 parent::__construct(); 31 } 32 33 /** 34 * This is where custom actions are added to run when notifications of an 35 * invitation or request need to be generated & sent. 36 * 37 * @since 8.0.0 38 * 39 * @param obj BP_Invitation $invitation The invitation to send. 40 * @return bool True on success, false on failure. 41 */ 42 public function run_send_action( BP_Invitation $invitation ) { 43 // Notify site admins of the pending request 44 if ( 'request' === $invitation->type ) { 45 // Coming soon to a BuddyPress near you! 46 return true; 47 48 // Notify the invitee of the invitation. 49 } else { 50 // Stop if the invitation has already been accepted. 51 if ( $invitation->accepted ) { 52 return false; 53 } 54 55 $inviter_ud = bp_core_get_core_userdata( $invitation->inviter_id ); 56 57 $invite_url = esc_url( 58 add_query_arg( 59 array( 60 'inv' => $invitation->id, 61 'ih' => bp_members_invitations_get_hash( $invitation ), 62 ), 63 bp_get_signup_page() 64 ) 65 ); 66 $unsubscribe_args = array( 67 'user_id' => 0, 68 'email_address' => $invitation->invitee_email, 69 'member_id' => $invitation->inviter_id, 70 'notification_type' => 'bp-members-invitation', 71 ); 72 73 $args = array( 74 'tokens' => array( 75 'inviter.name' => bp_core_get_userlink( $invitation->inviter_id, true, false, true ), 76 'inviter.url' => bp_core_get_user_domain( $invitation->inviter_id ), 77 'inviter.id' => $invitation->inviter_id, 78 'invite.accept_url' => esc_url( $invite_url ), 79 'usermessage' => wp_kses( $invitation->content, array() ), 80 'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ), 81 ), 82 ); 83 84 return bp_send_email( 'bp-members-invitation', $invitation->invitee_email, $args ); 85 } 86 } 87 88 /** 89 * This is where custom actions are added to run when an invitation 90 * or request is accepted. 91 * 92 * @since 8.0.0 93 * 94 * @param string $type Are we accepting an invitation or request? 95 * @param array $r Parameters that describe the invitation being accepted. 96 * @return bool True on success, false on failure. 97 */ 98 public function run_acceptance_action( $type, $r ) { 99 if ( ! $type || ! in_array( $type, array( 'request', 'invite' ), true ) ) { 100 return false; 101 } 102 103 if ( 'invite' === $type ) { 104 105 $invites = $this->get_invitations( $r ); 106 if ( ! $invites ) { 107 return; 108 } 109 110 foreach ( $invites as $invite ) { 111 // Add the accepted invitation ID to the user's meta. 112 $new_user = get_user_by( 'email', $invite->invitee_email ); 113 bp_update_user_meta( $new_user->ID, 'accepted_members_invitation', $invite->id ); 114 115 // We will mark all invitations to this user as "accepted." 116 if ( ! empty( $invite->invitee_email ) ) { 117 $args = array( 118 'invitee_email' => $invite->invitee_email, 119 'item_id' => get_current_network_id(), 120 'type' => 'all' 121 ); 122 $this->mark_accepted( $args ); 123 } 124 125 /** 126 * Fires after a user has accepted a site membership invite. 127 * 128 * @since 8.0.0 129 * 130 * @param BP_Invitation $invite Invitation that was accepted. 131 * @param WP_user $new_user ID of the user who accepted the membership invite. 132 * @param int $inviter_id ID of the user who invited this user to the site. 133 */ 134 do_action( 'members_invitations_invite_accepted', $invite, $new_user, $invite->inviter_id ); 135 } 136 } 137 138 return true; 139 } 140 141 /** 142 * Should this invitation be created? 143 * 144 * @since 8.0.0 145 * 146 * @param array $args. 147 * @return bool 148 */ 149 public function allow_invitation( $args ) { 150 // Does the inviter have this capability? 151 if ( ! bp_user_can( $args['inviter_id'], 'bp_members_send_invitation' ) ) { 152 return false; 153 } 154 155 // Is the invited user eligible to receive an invitation? Hasn't opted out? 156 if ( ! bp_user_can( 0, 'bp_members_receive_invitation', $args ) ) { 157 return false; 158 } 159 160 return true; 161 } 162 163 /** 164 * Should this request be created? 165 * 166 * @since 8.0.0 167 * 168 * @param array $args. 169 * @return bool. 170 */ 171 public function allow_request( $args ) { 172 // Does the requester have this capability? 173 if ( ! bp_user_can( 0, 'bp_network_request_membership', $args ) ) { 174 return false; 175 } 176 177 return true; 178 } 179 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Dec 3 01:00:55 2024 | Cross-referenced by PHPXref 0.7.1 |