Making WordPress.org

Changeset 12735


Ignore:
Timestamp:
07/10/2023 11:23:41 PM (2 years ago)
Author:
coffee2code
Message:

Photo Directory, Moderation: Add admin dashboard widget for simple moderator stats.

Fixes #7130.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/moderation.php

    r12733 r12735  
    6161        // Modify Date column for photo posts table with name of moderator.
    6262        add_action( 'post_date_column_time',              [ __CLASS__, 'add_moderator_to_date_column' ], 10, 3 );
     63
     64        // Register dashboard widget.
     65        add_action( 'wp_dashboard_setup',                 [ __CLASS__, 'dashboard_setup' ] );
    6366    }
    6467
     
    711714    }
    712715
     716    /**
     717     * Registers the admin dashboard.
     718     */
     719    public static function dashboard_setup() {
     720        if ( current_user_can( 'edit_photos' ) ) {
     721            wp_add_dashboard_widget(
     722                'dashboard_photo_moderators',
     723                __( 'Photo Moderators', 'wporg-photos' ),
     724                [ __CLASS__, 'dashboard_photo_moderators' ]
     725            );
     726        }
     727    }
     728
     729    /**
     730     * Outputs the Photo Moderators dashboard.
     731     */
     732    public static function dashboard_photo_moderators() {
     733        echo '<div class="main">';
     734
     735        // Get all users with the 'edit_photos' capability.
     736        $args = [
     737            'capability' => 'edit_photos',
     738        ];
     739        $users = get_users( $args );
     740
     741        echo '<table class="wp-list-table widefat fixed striped table-view-list">';
     742        echo '<thead><tr>';
     743        echo '<th>' . __( 'Username', 'wporg-photos' ) . '</th>';
     744        echo '<th>' . __( 'Name', 'wporg-photos' ) . '</th>';
     745        echo '<th title="' . esc_attr__( 'Number of photos approved', 'wporg-photos' ) . '"><span class="dashicons dashicons-thumbs-up"></span></th>';
     746        echo '<th title="' . esc_attr__( 'Number of photos rejected', 'wporg-photos' ) . '"><span class="dashicons dashicons-thumbs-down"></span></th>';
     747        echo '<th>' . __( 'Last Moderated', 'wporg-photos' ) . '</th>';
     748        echo '</tr></thead>';
     749        echo '<tbody>';
     750
     751        foreach ( $users as $user ) {
     752            $count_approved = User::count_photos_moderated( $user->ID );
     753            $count_rejected = User::count_photos_rejected_as_moderator( $user->ID );
     754
     755            // Bail if user has not moderated any photos.
     756            if ( ! $count_approved && ! $count_rejected ) {
     757                continue;
     758            }
     759
     760            echo '<tr>';
     761            echo '<td>' . sprintf( '<a href="%s">%s</a>', esc_url( 'https://profiles.wordpress.org/' . $user->user_nicename . '/' ), $user->user_nicename ) . '</td>';
     762            echo '<td>' . esc_html( $user->display_name ) . '</td>';
     763            echo '<td>' . number_format_i18n( $count_approved ) . '</td>';
     764            echo '<td>' . number_format_i18n( $count_rejected ) . '</td>';
     765            echo '<td>';
     766            $last_moderated = User::get_last_moderated( $user->ID, true );
     767            if ( $last_moderated ) {
     768                printf( '<a href="%s">%s</a>', get_edit_post_link( $last_moderated->ID ), get_the_date( 'Y-m-d', $last_moderated->ID ) );
     769            }
     770            echo '</td>';
     771            echo '</tr>';
     772        }
     773
     774        echo '</tbody></table>';
     775        echo '</div>';
     776    }
     777
    713778}
    714779
Note: See TracChangeset for help on using the changeset viewer.