Making WordPress.org

Changeset 12057


Ignore:
Timestamp:
09/08/2022 08:21:21 PM (4 years ago)
Author:
coffee2code
Message:

Photo Directory, User: Start to centralize user-related functions into the same include file.

  • Moves Admin::count_user_rejections() to count_rejected()
  • Moves Photos::count_user_published_photos() to count_published_photos()
  • Moves Photos::count_user_pending_photos() to count_pending_photos()
Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory
Files:
1 added
5 edited

Legend:

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

    r11715 r12057  
    5454                // Modify admin menu links for photo posts.
    5555                add_action( 'admin_menu',                              [ __CLASS__, 'modify_admin_menu_links' ] );
    56         }
    57 
    58         /**
    59          * Returns the count of the number of photo submissions from a user that were rejected.
    60          *
    61          * @param int $user_id The user ID.
    62          * @return int
    63          */
    64         public static function count_user_rejections( $user_id ) {
    65                 global $wpdb;
    66 
    67                 return (int) $wpdb->get_var( $wpdb->prepare(
    68                         "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status = %s AND post_author = %d",
    69                         Registrations::get_post_type(),
    70                         Rejection::get_post_status(),
    71                         $user_id
    72                 ) );
    7356        }
    7457
     
    533516                . sprintf(
    534517                        __( 'Approved: <strong>%s</strong>', 'wporg-photos' ),
    535                         sprintf( '<a href="%s">%d</a>', $approved_link, Photo::count_user_published_photos() )
     518                        sprintf( '<a href="%s">%d</a>', $approved_link, User::count_published_photos() )
    536519                )
    537520                . "</div>\n";
    538521
    539522                // Show number of pending photos if there are any.
    540                 $pending_count = Photo::count_user_pending_photos();
     523                $pending_count = User::count_pending_photos();
    541524                if ( $pending_count ) {
    542525                        $pending_link = add_query_arg( [
     
    763746
    764747                $author = get_user_by( 'id', $post->post_author );
    765                 $photos_count = Photo::count_user_published_photos( $author->ID );
     748                $photos_count = User::count_published_photos( $author->ID );
    766749                $account_created = explode( ' ', $author->user_registered )[0];
    767750                ?>
     
    801784                                        ?></li>
    802785                                        <li><?php
    803                                                 $rejected_count = self::count_user_rejections( $author->ID );
     786                                                $rejected_count = User::count_rejected_photos( $author->ID );
    804787                                                $link_args = [
    805788                                                        'post_type'   => Registrations::get_post_type(),
     
    816799                                        ?></li>
    817800                                        <li><?php
    818                                                 $pending_count = Photo::count_user_pending_photos( $author->ID );
     801                                                $pending_count = User::count_pending_photos( $author->ID );
    819802                                                $link_args = [
    820803                                                        'post_type'   => Registrations::get_post_type(),
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/badges.php

    r11880 r12057  
    3636                } elseif ( 'publish' === $old_status && 'publish' !== $new_status ) {
    3737                        // If the user now has no published Photos, remove the badge.
    38                         if ( ! Photo::count_user_published_photos( $post->post_author ) ) {
     38                        if ( ! User::count_published_photos( $post->post_author ) ) {
    3939                                remove_badge( 'photo-contributor', $post->post_author );
    4040                        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/moderation.php

    r11679 r12057  
    463463
    464464                // Flag if this is user's first submission.
    465                 $published_photos_count = Photo::count_user_published_photos( $post->post_author );
     465                $published_photos_count = User::count_published_photos( $post->post_author );
    466466                if ( ! $published_photos_count ) {
    467467                        $flags[ 'no published photo' ] = 'possible';
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/photo.php

    r11757 r12057  
    424424
    425425        /**
    426          * Returns a count of published photos for a user.
    427          *
    428          * @param int $user_id Optional. The user ID. If not defined, assumes global
    429          *                     author. Default false.
    430          * @return int
    431          */
    432         public static function count_user_published_photos( $user_id = false ) {
    433                 if (  ! $user_id ) {
    434                         global $authordata;
    435 
    436                         $user_id = $authordata->ID;
    437                 }
    438 
    439                 return count_user_posts( $user_id, Registrations::get_post_type(), true );
    440         }
    441 
    442         /**
    443          * Returns a count of pending photos for a user.
    444          *
    445          * @param int $user_id Optional. The user ID. If not defined, assumes global
    446          *                     author. Default false.
    447          * @return int
    448          */
    449         public static function count_user_pending_photos( $user_id = false ) {
    450                 if (  ! $user_id ) {
    451                         global $authordata;
    452 
    453                         $user_id = $authordata->ID;
    454                 }
    455 
    456                 $pending = get_posts( [
    457                         'fields'         => 'ids',
    458                         'posts_per_page' => -1,
    459                         'author'         => $user_id,
    460                         'post_status'    => 'pending',
    461                         'post_type'      => Registrations::get_post_type(),
    462                 ] );
    463 
    464                 return count( $pending );
    465         }
    466 
    467         /**
    468426         * Returns the full photo analysis data from cache or via API call.
    469427         *
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/photo-directory.php

    r11879 r12057  
    2828require_once __DIR__ . '/inc/template-tags.php';
    2929require_once __DIR__ . '/inc/uploads.php';
     30require_once __DIR__ . '/inc/user.php';
    3031require_once __DIR__ . '/inc/google-cloud-storage-stream-metadata.php';
    3132require_once __DIR__ . '/inc/google-cloud-storage.php';
Note: See TracChangeset for help on using the changeset viewer.