Making WordPress.org

Changeset 12233


Ignore:
Timestamp:
11/10/2022 08:58:25 PM (2 years ago)
Author:
coffee2code
Message:

Photo Directory, User: Add functions to get user's pending photos and one to get the file names used by those pending photos.

File:
1 edited

Legend:

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

    r12141 r12233  
    5959     */
    6060    public static function count_pending_photos( $user_id = false ) {
     61        return count( self::get_pending_photos( $user_id ) );
     62    }
     63
     64    /**
     65     * Returns the pending photos for a user.
     66     *
     67     * @param int    $user_id Optional. The user ID. If not defined, assumes global
     68     *                        author. Default false.
     69     * @param string $fields  Optional. The fields to return from the pending photos.
     70     *                        Default 'ids'.
     71     * @return array
     72     */
     73    public static function get_pending_photos( $user_id = false, $fields = 'ids' ) {
    6174        if (  ! $user_id ) {
    6275            global $authordata;
     
    6578        }
    6679
    67         $pending = get_posts( [
    68             'fields'         => 'ids',
     80        return get_posts( [
     81            'fields'         => $fields,
    6982            'posts_per_page' => -1,
    7083            'author'         => $user_id,
     
    7285            'post_type'      => Registrations::get_post_type(),
    7386        ] );
    74 
    75         return count( $pending );
    7687    }
    7788
     
    149160
    150161        return apply_filters( 'wporg_photos_max_concurrent_submissions', self::MAX_PENDING_SUBMISSIONS, $user_id );
     162    }
     163
     164    /**
     165     * Returns the file names for all of a user's pending submissions.
     166     *
     167     * @param int $user_id The user ID. If false, then assumes current user. Default false.
     168     * @return array
     169     */
     170    public static function get_pending_file_names( $user_id = false ) {
     171        global $wpdb;
     172
     173        $names = [];
     174
     175        if ( ! $user_id ) {
     176            $user_id = get_current_user_id();
     177        }
     178
     179        if ( $user_id && $post_ids = self::get_pending_photos( $user_id ) ) {
     180            $post_ids = implode( ',', array_map( 'intval', array_values( $post_ids ) ) );
     181            $names = $wpdb->get_col( $wpdb->prepare(
     182                "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = %s AND post_id IN ($post_ids)",
     183                Registrations::get_meta_key( 'original_filename' )
     184            ) );
     185        }
     186
     187        return $names;
    151188    }
    152189
Note: See TracChangeset for help on using the changeset viewer.