Making WordPress.org

Changeset 14427


Ignore:
Timestamp:
04/16/2025 08:51:45 PM (5 months ago)
Author:
coffee2code
Message:

Photo Directory, Flagged: Update approach to amend flagged stats to author column.

A custom author column has replaced the default author column and a new hook is available for cleaner insertion.

File:
1 edited

Legend:

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

    r13207 r14427  
    11<?php
    22/**
    3  * Post handling customizations.
     3 * Flagged photo (aka potentially sensitive content) functionality.
    44 *
    55 * @package WordPressdotorg\Photo_Directory
     
    4848        add_filter( 'display_post_states',                   [ __CLASS__, 'display_post_states' ], 10, 2 );
    4949
    50         // Add count of user's flagged photos in author column.
    51         //     Note: Priority after Admin::add_published_photos_count_to_author()
    52         add_filter( 'the_author',                            [ __CLASS__, 'add_flagged_photos_count_to_author' ], 11 );
     50        // Output count of user's flagged photos in author column.
     51        add_filter( 'photo_author_column_data_end',          [ __CLASS__, 'output_flagged_photos_count_to_author' ] );
    5352
    5453        // Add support to the post edit page.
     
    240239            ? "<span class=\"update-plugins count-{$flagged_count}\"><span class=\"plugin-count\">{$flagged_count}</span></span>"
    241240            : '';
    242  
     241
    243242        // Add 'Flagged' link if user can read flagged photos.
    244243        add_submenu_page(
     
    265264
    266265    /**
    267      * Appends the count of the published photos to author names in photo post
    268      * listings.
    269      *
    270      * @param string $display_name The author's display name.
    271      * @return string
    272      */
    273     public static function add_flagged_photos_count_to_author( $display_name ) {
    274         global $authordata;
    275 
    276         if ( ! is_admin() || ! Admin::should_include_photo_column() ) {
    277             return $display_name;
    278         }
    279 
    280         // Close link to contributor's listing of photos.
    281         $display_name .= '</a>';
     266     * Outputs the count of the flagged photos for the post's author.
     267     *
     268     * @param WP_Post $post Post object.
     269     */
     270    public static function output_flagged_photos_count_to_author( $post ) {
     271        $author_id = (int) get_post_field( 'post_author', $post );
     272        $output = '';
    282273
    283274        // Show number of flagged photos.
    284         $flagged_count = User::count_flagged_photos( $authordata->ID );
     275        $flagged_count = User::count_flagged_photos( $author_id );
    285276        $flagged_link = '';
    286277        if ( $flagged_count ) {
     
    289280                    'post_type'   => Registrations::get_post_type(),
    290281                    'post_status' => self::get_post_status(),
    291                     'author'      => $authordata->ID,
     282                    'author'      => $author_id,
    292283                ], 'edit.php' );
    293284            }
    294             $display_name .= '<div class="user-flagged-count">'
     285            $output .= '<div class="user-flagged-count">'
    295286                . sprintf(
    296287                    /* translators: %s: Count of user's flagged photos possibly linked to listing of their flagged photos. */
     
    301292        }
    302293
    303         // Prevent unbalanced tag.
    304         $display_name .= '<a>';
    305 
    306         return $display_name;
     294        if ( $output ) {
     295            echo $output;
     296        }
    307297    }
    308298
Note: See TracChangeset for help on using the changeset viewer.