Making WordPress.org


Ignore:
Timestamp:
02/16/2024 04:46:29 AM (2 years ago)
Author:
dd32
Message:

Registration: Add bulk block, and add room for a reason to be provided, query by country.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/admin/class-user-registrations-list-table.php

    r13200 r13216  
    4343        $current_view = $_REQUEST['view'] ?? $default;
    4444
    45         if ( isset( $_GET['s'] ) ) {
     45        if ( ! empty( $_GET['s'] ) ) {
    4646            $default = 'search';
    4747            $views[0] = [
     
    144144    }
    145145
    146     function get_columns() {
     146    public function get_columns() {
    147147        return [
     148            'cb'              => '<input type="checkbox" />',
    148149            'user_login'      => 'User Login',
    149150            'meta'            => 'Meta',
     
    159160            'user_registered' => array( 'user_registered', true ),
    160161        ];
    161      }
     162    }
     163
     164    protected function get_bulk_actions() {
     165        return array(
     166            'reg_block' => 'Block Reg / Ban user',
     167        );
     168    }
    162169
    163170    function prepare_items() {
     
    184191        }
    185192
    186         $per_page     = $this->get_items_per_page( 'users_per_page', 100 );
     193        $per_page     = $_GET['per_page'] ?? $this->get_items_per_page( 'users_per_page', 100 );
    187194        $current_page = $this->get_pagenum();
    188195
     
    215222        ]);
    216223
     224    }
     225
     226    protected function bulk_actions( $which = '' ) {
     227        parent::bulk_actions( $which );
     228
     229        if ( 'top' !== $which ) {
     230            return;
     231        }
     232        ?>
     233
     234        <fieldset class="alignleft actions">
     235            <input name="block_reason" id="block_reason" placeholder="Ban/Block reason. Used for bulk + single." style="width: 32em;padding: 0.4em;margin: 0;" value="<?php echo esc_attr( $_REQUEST['block_reason'] ?? '' ); ?>" />
     236        </fieldset>
     237        <?php
    217238    }
    218239
     
    249270    }
    250271
     272    public function column_cb( $item ) {
     273        return sprintf(
     274            '<input type="checkbox" name="pending_ids[]" value="%1$s" />',
     275            esc_attr( $item->pending_id ),
     276        );
     277    }
     278
    251279    function column_default( $item, $column_name ) {
    252280        echo esc_html( $item->$column_name );
     
    348376        echo '<div>';
    349377
    350         echo implode( ', ',
    351             array_map(
    352                 function( $ip ) {
    353                     return $this->link_to_search( $ip ) .
    354                         ( is_callable( 'WordPressdotorg\GeoIP\query' ) ?
    355                             ' ' . \WordPressdotorg\GeoIP\query( $ip, 'country_short' ) : '' );
    356                 },
    357                 array_filter( array_unique( [
    358                     $meta->registration_ip ?? false,
    359                     $meta->confirmed_ip ?? false
    360                 ] ) )
    361             )
    362         );
     378        $ips = [];
     379        foreach ( [ 'registration', 'confirmed' ] as $field ) {
     380            if ( empty( $meta->{$field . '_ip'} ) ) {
     381                continue;
     382            }
     383            $ip = $meta->{$field . '_ip'};
     384
     385            $meta->{$field . '_ip_country'} ??= ( is_callable( 'WordPressdotorg\GeoIP\query' ) ? ' ' . \WordPressdotorg\GeoIP\query( $ip, 'country_short' ) : '' );
     386
     387            $ips[] = $ip . ' ' . $meta->{$field . '_ip_country'};
     388        }
     389
     390        echo implode( ', ', array_map( array( $this, 'link_to_Search' ), array_unique( $ips ) ) );
    363391
    364392        echo '<hr>';
     
    446474
    447475        return implode( '', array_map( function( $s ) {
    448             if ( strlen( $s ) >= 3 ) {
     476            if ( strlen( $s ) >= 3 || preg_match( '/^[A-Z]{2}$/', $s ) /* country */ ) {
    449477                return '<a href="' . add_query_arg( 's', urlencode( $s ), admin_url( 'admin.php?page=user-registrations' ) ) . '">' . esc_html( $s ) . '</a>';
    450478            }
Note: See TracChangeset for help on using the changeset viewer.