Making WordPress.org

Ticket #5881: meta-5881.diff

File meta-5881.diff, 2.4 KB (added by Ipstenu, 5 months ago)

Untested patch

  • wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php

    diff --git a/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php b/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php
    index e9a6fbb56..501b3c4d4 100644
    a b  
    22
    33namespace WordPressdotorg\Forums;
    44
     5use WordPressdotorg\Forums\User_Moderation\Plugin as User_Moderation;
     6
    57class Users {
    68
    79        public function __construct() {
    class Users { 
    911                add_action( 'bbp_user_edit_after_name',         array( $this, 'add_custom_title_input' ) );
    1012                add_action( 'bbp_user_edit_after',              array( $this, 'add_options_section_header' ), 0 );
    1113                add_action( 'bbp_user_edit_after',              array( $this, 'add_auto_topic_subscription_checkbox' ) );
     14                add_action( 'bbp_user_edit_after',              array( $this, 'add_modwatch_checkbox' ) );
    1215
    1316                // Save custom field values.
    1417                add_action( 'personal_options_update',          array( $this, 'save_custom_fields' ), 10, 2 );
    class Users { 
    113116                <?php
    114117        }
    115118
     119        /**
     120         * Add a modwatch checkbox to user's profile.
     121         */
     122        public function add_modwatch_checkbox() {
     123                // Only show to moderators.
     124                if ( ! current_user_can( 'moderate' ) ) {
     125                        return;
     126                }
     127
     128                $user_id = bbp_get_user_id();
     129
     130                $modwatch = ( new User_Moderation() )->is_user_flagged( $user_id );
     131                ?>
     132                <p>
     133                        <input name="flag_user_modwatch" id="flag_user_modwatch" type="checkbox" value="yes" <?php checked( $modwatch ); ?> />
     134                        <label for="flag_user_modwatch"><?php esc_html_e( 'Flag this user for moderation', 'wporg-forums' ); ?></label>
     135                </p>
     136                <?php
     137        }
     138
    116139        /**
    117140         * Save custom field values.
    118141         *
    class Users { 
    125148
    126149                $auto_topic_subscription = isset( $_POST['auto_topic_subscription'] );
    127150                update_user_option( $user_id, 'auto_topic_subscription', $auto_topic_subscription );
     151
     152                // Flag user for moderation.
     153                if ( current_user_can( 'moderate' ) && isset( $_POST['flag_user_modwatch'] ) ) {
     154                        $modwatch = ( new User_Moderation() )->is_user_flagged( $user_id );
     155                        if ( ! $modwatch ) {
     156                                ( new User_Moderation() )->flag_user( $user_id );
     157                        }
     158                } else {
     159                        ( new User_Moderation() )->unflag_user( $user_id );
     160                }
    128161        }
    129162
    130163        public function modify_user_fields( $value, $field, $filter ) {