Making WordPress.org

Changeset 12870


Ignore:
Timestamp:
08/29/2023 08:27:30 PM (18 months ago)
Author:
coffee2code
Message:

Photo Directory, Flagged: Show a count of flagged photos to moderators who otherwise wouldn't know about flagged photos.

See #7119.

File:
1 edited

Legend:

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

    r12868 r12870  
    2828     */
    2929    public static function init() {
     30        $post_type = Registrations::get_post_type();
     31
    3032        // Register post statuses.
    3133        add_action( 'init',                                  [ __CLASS__, 'register_post_statuses' ] );
     
    5254        // Add support to the post edit page.
    5355        add_action( 'admin_footer-post.php',                 [ __CLASS__, 'output_js_for_post_edit_support' ] );
     56
     57        // Add an unlinked 'Flagged (n)' label alongside the table view links.
     58        add_filter( "views_edit-{$post_type}",                 [ __CLASS__, 'add_unlinked_flagged_status' ] );
    5459
    5560        // Add support to quick edit and bulk edit.
     
    339344
    340345    /**
     346     * Adds an unlinked 'Flagged (n)' status and count to the view links for a
     347     * photos post listing for non-Photo Admins.
     348     *
     349     * Photo Admins automatically see a linked version of the link because they
     350     * have access to the listing. Since Moderators don't have that access, this
     351     * at least shows them that the current number of flagged photos.
     352     *
     353     * @param string[] $views An array of available list table views.
     354     * @return string[]
     355     */
     356    public static function add_unlinked_flagged_status( $views ) {
     357        $flagged_count = self::count();
     358        if ( ! $flagged_count ) {
     359            return $views;
     360        }
     361
     362        $flagged_status = self::get_post_status();
     363        if ( filter_input( INPUT_GET, 'post_type' ) === Registrations::get_post_type() ) {
     364            if ( empty( $views[ $flagged_status ] ) ) {
     365                $views[ $flagged_status ] = sprintf(
     366                    _n( 'Flagged <span class="count">(%s)</span>', 'Flagged <span class="count">(%s)</span>', $flagged_count, 'wporg-photos' ),
     367                    number_format_i18n( $flagged_count )
     368                );
     369            }
     370        }
     371
     372        return $views;
     373    }
     374
     375    /**
    341376     * Adds custom post statuses to the Quick Edit panel.
    342377     *
Note: See TracChangeset for help on using the changeset viewer.