Making WordPress.org


Ignore:
Timestamp:
07/03/2023 07:01:16 PM (16 months ago)
Author:
coffee2code
Message:

Photo Directory, User: Add count_flagged_photos() to obtain count of user's flagged photos.

See #7119.

File:
1 edited

Legend:

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

    r12236 r12695  
    115115            Registrations::get_post_type(),
    116116            Rejection::get_post_status(),
     117            $user_id
     118        ) );
     119    }
     120
     121    /**
     122     * Returns a count of flagged photos for a user.
     123     *
     124     * @param int $user_id Optional. The user ID. If not defined, assumes global
     125     *                     author. Default false.
     126     * @return int
     127     */
     128    public static function count_flagged_photos( $user_id = false ) {
     129        global $wpdb;
     130
     131        if (  ! $user_id ) {
     132            global $authordata;
     133
     134            $user_id = $authordata->ID;
     135        }
     136
     137        return (int) $wpdb->get_var( $wpdb->prepare(
     138            "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status = %s AND post_author = %d",
     139            Registrations::get_post_type(),
     140            Flagged::get_post_status(),
    117141            $user_id
    118142        ) );
Note: See TracChangeset for help on using the changeset viewer.