Skip to:
Content

BuddyPress.org

Ticket #8582: 8582.4.patch

File 8582.4.patch, 15.7 KB (added by imath, 2 years ago)
  • src/bp-core/admin/bp-core-admin-settings.php

    diff --git src/bp-core/admin/bp-core-admin-settings.php src/bp-core/admin/bp-core-admin-settings.php
    index 86e456c84..0b249b889 100644
    function bp_admin_setting_callback_members_invitations() { 
    211211function bp_admin_setting_callback_membership_requests() {
    212212?>
    213213        <input id="bp-enable-membership-requests" name="bp-enable-membership-requests" type="checkbox" value="1" <?php checked( bp_get_membership_requests_required( 'raw' ) ); ?> />
    214         <label for="bp-enable-membership-requests"><?php _e( 'Enable network membership requests. If enabled, an administrator must approve each new network membership.', 'buddypress' ); ?></label>
     214        <label for="bp-enable-membership-requests"><?php esc_html_e( 'Allow visitors to request a site membership. If enabled, an administrator must approve each new site membership request.', 'buddypress' ); ?></label>
    215215        <?php if ( bp_get_signup_allowed() ) : ?>
    216                 <p class="description"><?php _e( 'Public registration is currently enabled. If you wish to require approval for new memberships, disable public registration and enable the membership requests feature.', 'buddypress' ); ?></p>
     216                <p class="description"><?php esc_html_e( 'Public registration is currently enabled. If you wish to require approval for new memberships, disable public registration and enable the membership requests feature.', 'buddypress' ); ?></p>
    217217        <?php endif; ?>
    218218        <?php
    219219        /**
  • src/bp-core/bp-core-update.php

    diff --git src/bp-core/bp-core-update.php src/bp-core/bp-core-update.php
    index 533efdb86..d7e0d5b5b 100644
    function bp_core_get_8_0_upgrade_email_schema( $emails ) { 
    708708 * 10.0.0 update routine.
    709709 *
    710710 * - Explicitly set all signups to count_sent = 1 & sent_date to registered_date
     711 * - **Create the new BP Emails**.
    711712 *
    712713 * @since 10.0.0
    713714 */
    function bp_update_to_10_0() { 
    716717        // @TODO: Explicitly set all signups to count_sent = 1 & sent_date to registered_date
    717718        // Is there any way to update that meta in bulk? I think it will have to be one at a time.
    718719
     720        // Do we need this upgrade routine?
     721        // Could we just assume if count_sent or sent_date defaults to 1 and to the registered_date into the PHP Code?
    719722}
    720723
    721724/**
  • new file src/bp-members/bp-members-membership-requests.php

    diff --git src/bp-members/bp-members-membership-requests.php src/bp-members/bp-members-membership-requests.php
    new file mode 100644
    index 000000000..7b02da0d1
    - +  
     1<?php
     2/**
     3 * BuddyPress Membership Requests
     4 *
     5 * @package BuddyPress
     6 * @subpackage MembersMembershipRequest
     7 * @since 10.0.0
     8 */
     9
     10// Exit if accessed directly.
     11defined( 'ABSPATH' ) || exit;
     12
     13/**
     14 * When a user creates a network membership request,
     15 * prevent the sending of the activation email so that
     16 * the site admins can send it later.
     17 *
     18 * @since 10.0.0
     19 *
     20 * @param bool   $send           Whether or not to send the activation key.
     21 * @param int    $user_id        User ID to send activation key to.
     22 * @param string $user_email     User email to send activation key to.
     23 * @param string $activation_key Activation key to be sent.
     24 * @param array  $usermeta       Miscellaneous metadata about the user (blog-specific
     25 *                               signup data, xprofile data, etc).
     26 * @return bool Whether or not to send the activation key.
     27 */
     28function bp_members_membership_requests_cancel_activation_email( $send, $user_id = 0, $user_email = '', $activation_key = '', $usermeta = array() ) {
     29
     30        if ( bp_get_membership_requests_required() ) {
     31                $details = array(
     32                        'user_id'        => $user_id,
     33                        'user_email'     => $user_email,
     34                        'activation_key' => $activation_key,
     35                        'usermeta'       => $usermeta,
     36                );
     37
     38                /**
     39                 * Allow some membership requests to be approved immediately.
     40                 * For example, you might want to approve all requests
     41                 * coming from users with certain email address domains.
     42                 * If `true` is returned the activation email will be sent to the user.
     43                 *
     44                 * @since 10.0.0
     45                 *
     46                 * @param bool  $send    Whether or not this membership request should be approved
     47                 *                       immediately and the activation email sent.
     48                 *                       Default is `false` meaning that the request should be
     49                 *                       manually approved by a site admin.
     50                 * @param array $details The details of the request.
     51                 */
     52                $send = apply_filters( 'bp_members_membership_requests_bypass_manual_approval', false, $details );
     53
     54                // If the registration process has been interrupted, this is a new membership request.
     55                if ( ! $send ) {
     56                        $signup = bp_members_get_signup_by( 'activation_key', $activation_key );
     57
     58                        /**
     59                         * Fires when a site membership request has been created and is pending.
     60                         *
     61                         * @since 10.0.0
     62                         *
     63                         * @param BP_Signup $signup  The signup object that has been created.
     64                         * @param array     $details The details of the request.
     65                         */
     66                        do_action( 'bp_members_membership_request_submitted', $signup, $details );
     67                }
     68        }
     69
     70        return $send;
     71}
     72add_filter( 'bp_core_signup_send_activation_key', 'bp_members_membership_requests_cancel_activation_email', 10, 5 );
     73
     74
     75/**
     76 * Notify site admins about a new membership request.
     77 *
     78 * @since 10.0.0
     79 *
     80 * @param BP_Signup $signup  The signup object that has been created.
     81 */
     82function bp_members_membership_requests_notify_site_admins( $signup ) {
     83        // Why not just using get_option( 'admin_email' ) ?
     84        $admin_ids = get_users(
     85                array(
     86                        'fields' => 'ids',
     87                        'role'   => 'administrator',
     88                )
     89        );
     90
     91        foreach ( $admin_ids as $admin_id ) {
     92                // Trigger a BuddyPress Notification.
     93                if ( bp_is_active( 'notifications' ) ) {
     94                        bp_notifications_add_notification(
     95                                array(
     96                                        'user_id'           => $admin_id,
     97                                        'item_id'           => $signup->signup_id,
     98                                        'component_name'    => buddypress()->members->id,
     99                                        'component_action'  => 'membership_request_submitted',
     100                                        'date_notified'     => bp_core_current_time(),
     101                                        'is_new'            => 1,
     102                                )
     103                        );
     104                }
     105
     106                // Bail if member opted out of receiving this email.
     107                if ( 'no' === bp_get_user_meta( $admin_id, 'notification_members_membership_request', true ) ) {
     108                        return;
     109                }
     110
     111                $unsubscribe_args = array(
     112                        'user_id'           => $admin_id,
     113                        'notification_type' => 'members-membership-request',
     114                );
     115
     116                $manage_url = add_query_arg(
     117                        array(
     118                                'mod_req'   => 1,
     119                                'page'      => 'bp-signups',
     120                                'signup_id' => $signup->signup_id,
     121                                'action'    => 'resend',
     122                        ),
     123                        bp_get_admin_url( 'users.php' )
     124                );
     125
     126                $args  = array(
     127                        'tokens' => array(
     128                                'admin.id'                   => $admin_id,
     129                                'manage.url'                 => esc_url_raw( $manage_url ),
     130                                'requesting-user.user_login' => esc_html( $signup->user_login ),
     131                                'unsubscribe'                => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
     132                        ),
     133                );
     134
     135                bp_send_email( 'members-membership-request', (int) $admin_id, $args );
     136        }
     137}
     138add_action( 'bp_members_membership_request_submitted', 'bp_members_membership_requests_notify_site_admins' );
     139
     140/**
     141 * Add "Request Membership" link to Widget login form.
     142 *
     143 * @since 10.0.0
     144 *
     145 * @return string $retval the HTML for the request membership link.
     146 */
     147function bp_members_membership_requests_add_link_to_widget_login_form() {
     148        if ( ! bp_get_membership_requests_required() ) {
     149                return;
     150        }
     151        ?>
     152        <span class="bp-login-widget-request-membership-link">
     153                <a href="<?php echo esc_url( bp_get_signup_page() ); ?>"><?php esc_html_e( 'Request Membership', 'buddypress' ); ?></a>
     154        </span>
     155        <?php
     156}
     157add_action( 'bp_login_widget_form', 'bp_members_membership_requests_add_link_to_widget_login_form' );
     158
     159/**
     160 * In the Nouveau template pack, when membership requests are required,
     161 * change registration form submit button label to "Submit Request".
     162 *
     163 * @since 10.0.0
     164 *
     165 * @return string $retval the HTML for the request membership link.
     166 */
     167function bp_members_membership_requests_filter_complete_signup_button( $buttons ) {
     168        if ( bp_get_membership_requests_required() ) {
     169                $buttons['register']['attributes']['value'] = __( 'Submit Request', 'buddypress' );
     170        }
     171
     172        return $buttons;
     173}
     174add_filter( 'bp_nouveau_get_submit_button', 'bp_members_membership_requests_filter_complete_signup_button' );
  • src/bp-members/bp-members-notifications.php

    diff --git src/bp-members/bp-members-notifications.php src/bp-members/bp-members-notifications.php
    index d63126341..ab63dd8cd 100644
    function members_screen_notification_settings() { 
    254254                                ?>
    255255                                <tr id="members-notification-settings-invitation_accepted">
    256256                                        <td></td>
    257                                         <td><?php _ex( 'Someone accepts your membership invitation', 'Member settings on notification settings page', 'buddypress' ) ?></td>
     257                                        <td><?php echo esc_html_x( 'Someone accepts your membership invitation', 'Member settings on notification settings page', 'buddypress' ); ?></td>
    258258                                        <td class="yes"><input type="radio" name="notifications[notification_members_invitation_accepted]" id="notification-members-invitation-accepted-yes" value="yes" <?php checked( $allow_acceptance_emails, 'yes', true ) ?>/><label for="notification-members-invitation-accepted-yes" class="bp-screen-reader-text"><?php
    259259                                                /* translators: accessibility text */
    260                                                 _e( 'Yes, send email', 'buddypress' );
     260                                                esc_html_e( 'Yes, send email', 'buddypress' );
    261261                                        ?></label></td>
    262262                                        <td class="no"><input type="radio" name="notifications[notification_members_invitation_accepted]" id="notification-members-invitation-accepted-no" value="no" <?php checked( $allow_acceptance_emails, 'no', true ) ?>/><label for="notification-members-invitation-accepted-no" class="bp-screen-reader-text"><?php
    263263                                                /* translators: accessibility text */
    264                                                 _e( 'No, do not send email', 'buddypress' );
     264                                                esc_html_e( 'No, do not send email', 'buddypress' );
    265265                                        ?></label></td>
    266266                                </tr>
    267267                                <?php
    function members_screen_notification_settings() { 
    274274                                ?>
    275275                                <tr id="members-notification-settings-submitted_membership_request">
    276276                                        <td></td>
    277                                         <td><?php _ex( 'Someone has requested site membership', 'Member settings on notification settings page', 'buddypress' ) ?></td>
     277                                        <td><?php echo esc_html_x( 'Someone has requested site membership', 'Member settings on notification settings page', 'buddypress' ) ?></td>
    278278                                        <td class="yes"><input type="radio" name="notifications[notification_members_membership_request]" id="notification-members-submitted_membership_request-yes" value="yes" <?php checked( $allow_request_emails, 'yes', true ) ?>/><label for="notification-members-submitted_membership_request-yes" class="bp-screen-reader-text"><?php
    279279                                                /* translators: accessibility text */
    280                                                 _e( 'Yes, send email', 'buddypress' );
     280                                                esc_html_e( 'Yes, send email', 'buddypress' );
    281281                                        ?></label></td>
    282282                                        <td class="no"><input type="radio" name="notifications[notification_members_membership_request]" id="notification-members-submitted_membership_request-no" value="no" <?php checked( $allow_request_emails, 'no', true ) ?>/><label for="notification-members-submitted_membership_request-no" class="bp-screen-reader-text"><?php
    283283                                                /* translators: accessibility text */
    284                                                 _e( 'No, do not send email', 'buddypress' );
     284                                                esc_html_e( 'No, do not send email', 'buddypress' );
    285285                                        ?></label></td>
    286286                                </tr>
    287287                                <?php
  • src/bp-members/classes/class-bp-members-admin.php

    diff --git src/bp-members/classes/class-bp-members-admin.php src/bp-members/classes/class-bp-members-admin.php
    index 08eb51dbf..ba80808d7 100644
    class BP_Members_Admin { 
    22302230
    22312231                                if ( bp_get_membership_requests_required() ) {
    22322232                                        $header_text = __( 'Approve Membership Requests', 'buddypress' );
    2233                                         if ( 1 == count( $signup_ids ) ) {
     2233                                        if ( 1 === count( $signup_ids ) ) {
    22342234                                                $helper_text = __( 'You are about to send an approval email to the following user:', 'buddypress' );
    22352235                                        } else {
    22362236                                                $helper_text = __( 'You are about to send approval emails to the following users:', 'buddypress' );
    22372237                                        }
    22382238                                } else {
    22392239                                        $header_text = __( 'Resend Activation Emails', 'buddypress' );
    2240                                         if ( 1 == count( $signup_ids ) ) {
     2240                                        if ( 1 === count( $signup_ids ) ) {
    22412241                                                $helper_text = __( 'You are about to resend an activation email to the following account:', 'buddypress' );
    22422242                                        } else {
    22432243                                                $helper_text = __( 'You are about to resend an activation email to the following accounts:', 'buddypress' );
  • src/bp-members/classes/class-bp-members-component.php

    diff --git src/bp-members/classes/class-bp-members-component.php src/bp-members/classes/class-bp-members-component.php
    index ddf725356..8e7e79eb0 100644
    class BP_Members_Component extends BP_Component { 
    6767                        'widgets',
    6868                        'cache',
    6969                        'invitations',
    70                         'membership-requests',
    7170                        'notifications',
    7271                );
    7372
    class BP_Members_Component extends BP_Component { 
    7574                        $includes[] = 'activity';
    7675                }
    7776
     77                if ( bp_is_active( 'members', 'invitations' ) && (bool) bp_get_option( 'bp-enable-membership-requests' ) ) {
     78                        $includes[] = 'membership-requests';
     79                }
     80
    7881                // Include these only if in admin.
    7982                if ( is_admin() ) {
    8083                        $includes[] = 'admin';
  • src/bp-members/classes/class-bp-members-list-table.php

    diff --git src/bp-members/classes/class-bp-members-list-table.php src/bp-members/classes/class-bp-members-list-table.php
    index ddf4b6d02..feb9b4668 100644
    class BP_Members_List_Table extends WP_Users_List_Table { 
    470470                        <h2><?php echo esc_html__( 'Extended Profile Information', 'buddypress' ); ?></h2>
    471471
    472472                        <table class="signup-profile-data-drawer wp-list-table widefat fixed striped">
    473                                 <?php foreach ( $profile_field_ids as $pid => $noop ) :
     473                                <?php if ( 1 <= count( $profile_field_ids ) ): foreach ( $profile_field_ids as $pid => $noop ) :
    474474                                        $field_value = isset( $signup_object->meta[ "field_{$pid}" ] ) ? $signup_object->meta[ "field_{$pid}" ] : ''; ?>
    475475                                        <tr>
    476476                                                <td class="column-fields"><?php echo esc_html( $fdata[ $pid ] ); ?></td>
    477477                                                <td><?php echo $this->format_xprofile_field_for_display( $field_value ); ?></td>
    478478                                        </tr>
    479 
    480                                 <?php endforeach;  ?>
     479                                <?php endforeach;else:  ?>
     480                                        <tr>
     481                                                <td><?php esc_html_e( 'There are no additional information to display.', 'buddypress' ); ?></td>
     482                                        </tr>
     483                                <?php endif; ?>
    481484                        </table>
    482485                </div>
    483486                <?php
  • src/bp-members/classes/class-bp-members-ms-list-table.php

    diff --git src/bp-members/classes/class-bp-members-ms-list-table.php src/bp-members/classes/class-bp-members-ms-list-table.php
    index 557e58952..918748378 100644
    class BP_Members_MS_List_Table extends WP_MS_Users_List_Table { 
    472472                        <h2><?php echo esc_html__( 'Extended Profile Information', 'buddypress' ); ?></h2>
    473473
    474474                        <table class="signup-profile-data-drawer wp-list-table widefat fixed striped">
    475                                 <?php foreach ( $profile_field_ids as $pid => $noop ) :
     475                                <?php if ( 1 <= count( $profile_field_ids ) ): foreach ( $profile_field_ids as $pid => $noop ) :
    476476                                        $field_value = isset( $signup_object->meta[ "field_{$pid}" ] ) ? $signup_object->meta[ "field_{$pid}" ] : ''; ?>
    477477                                        <tr>
    478478                                                <td class="column-fields"><?php echo esc_html( $fdata[ $pid ] ); ?></td>
    479479                                                <td><?php echo $this->format_xprofile_field_for_display( $field_value ); ?></td>
    480480                                        </tr>
    481 
    482                                 <?php endforeach;  ?>
     481                                <?php endforeach;else:  ?>
     482                                        <tr>
     483                                                <td><?php esc_html_e( 'There are no additional information to display.', 'buddypress' ); ?></td>
     484                                        </tr>
     485                                <?php endif; ?>
    483486                        </table>
    484487                </div>
    485488                <?php