Making WordPress.org


Ignore:
Timestamp:
03/10/2022 01:58:09 AM (3 years ago)
Author:
dd32
Message:

Support Forums: Allow moderators (Well, anyone who can edit other users) to unsubscribe a user from Term subscriptions (Tags, Plugins, Themes).

This also allows for users who are not able to login (aka, blocked), to be able to use the email unsubscribe link, as the spectate permission is now only checked for subscribing to a term.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-term-subscription/inc/class-plugin.php

    r11653 r11662  
    161161        $term_id = $term->term_id;
    162162        $auth    = 'nonce';
    163         $user_id = get_current_user_id();
     163        $user_id = isset( $_REQUEST['user_id'] ) ? $_REQUEST['user_id'] : get_current_user_id(); // Must pass nonce check below.
    164164
    165165        // If a user_id + token is provided, verify the request and maybe use the provided user_id.
     
    191191                        esc_attr( $_SERVER['REQUEST_URI'] ),
    192192                        esc_attr__( 'Yes, unsubscribe me', 'wporg-forums' ),
    193                         get_term_link( $term ),
    194                         sprintf(
     193                        esc_url( get_term_link( $term ) ),
     194                        esc_attr( sprintf(
    195195                            /* translators: 1: Plugin, Theme, or Tag name. */
    196                             esc_attr__( 'No, take me to the %s forum.', 'wporg-forums' ),
     196                            __( 'No, take me to the %s forum.', 'wporg-forums' ),
    197197                            $term->name
    198                         )
     198                        ) )
    199199                    )
    200200                );
     
    209209
    210210        // Check nonce.
    211         } elseif ( 'nonce' === $auth && ! bbp_verify_nonce_request( 'toggle-term-subscription_' . $user_id . '_' . $term_id . '_' . $this->taxonomy ) ) {
     211        } elseif ( 'token' !== $auth && ! bbp_verify_nonce_request( 'toggle-term-subscription_' . $user_id . '_' . $term_id . '_' . $this->taxonomy ) ) {
    212212            bbp_add_error( 'wporg_bbp_subscribe_nonce', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'wporg-forums' ) );
    213213
    214         // Check user's ability to spectate.
    215         } elseif ( ! user_can( $user_id, 'spectate' ) ) {
     214        // Check user's ability to spectate if attempting to subscribe to a term.
     215        } elseif ( ! user_can( $user_id, 'spectate' ) && 'wporg_bbp_subscribe_term' === $action ) {
    216216            bbp_add_error( 'wporg_bbp_subscribe_permissions', __( '<strong>ERROR</strong>: You don\'t have permission to do this!', 'wporg-forums' ) );
    217217        }
     
    625625                echo '<p id="bbp-term-' . esc_attr( $this->taxonomy ) . '">' . "\n";
    626626                foreach ( $terms as $term ) {
     627                    $unsub_url = self::get_subscription_url( $user_id, $term->term_id, $this->taxonomy );
    627628                    echo '<a href="' . esc_url( get_term_link( $term->term_id ) ) . '">' . esc_html( $term->name ) . '</a>';
    628                     if ( get_current_user_id() == $user_id ) {
    629                         $url = self::get_subscription_url( $user_id, $term->term_id, $this->taxonomy );
    630                         echo ' (<a href="' . esc_url( $url ) . '">' . esc_html( 'Unsubscribe', 'wporg-forums' ) . '</a>)';
    631                     }
     629                    echo ' (<a href="' . esc_url( $unsub_url ) . '">' . esc_html( 'Unsubscribe', 'wporg-forums' ) . '</a>)';
    632630                    echo "</br>\n";
    633631                }
     
    794792        );
    795793
     794        if ( $user_id != get_current_user_id() ) {
     795            $url = add_query_arg( 'user_id', $user_id, $url );
     796        }
     797
    796798        return esc_url( $url );
    797799    }
Note: See TracChangeset for help on using the changeset viewer.