Making WordPress.org

Changeset 12700


Ignore:
Timestamp:
07/03/2023 07:18:31 PM (3 years ago)
Author:
coffee2code
Message:

Photo Directory, Admin: Display an admin notice on post edit pages to indicate when manually flagged or unflagged

This helps convey that a Photo Admin reviewed the photo and ascertained it wasn't controversial in nature, or who flagged a photo so a follow-up can be made if necessary.

See #7119.

File:
1 edited

Legend:

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

    r12697 r12700  
    5050        add_action( 'do_meta_boxes',                           [ __CLASS__, 'register_photo_contributor_metabox' ], 1, 3 );
    5151
    52         // Admin notices
     52        // Admin notice if killswitch enabled.
    5353        add_action( 'admin_notices',                           [ __CLASS__, 'add_notice_if_killswitch_enabled' ] );
     54
     55        // Admin notice related to flagging/unflagging.
     56        add_action( 'admin_notices',                           [ __CLASS__, 'add_notice_if_flagged_or_unflagged' ] );
    5457
    5558        // Modify admin menu links for photo posts.
     
    7578                __( '<strong>Photo uploads are currently disabled for all users!</strong> Uncheck <a href="%s">the setting</a> to re-enable uploading.', 'wporg-photos' ),
    7679                esc_url( admin_url( 'options-media.php' ) . '#' . Settings::KILLSWITCH_OPTION_NAME )
     80            )
     81        );
     82    }
     83
     84    /**
     85     * Outputs admin notices.
     86     */
     87    public static function add_notice_if_flagged_or_unflagged() {
     88        $screen = get_current_screen();
     89
     90        // Only add notice when editing single photo.
     91        $post_type = Registrations::get_post_type();
     92        if ( ! $screen || $post_type !== $screen->id || $post_type !== $screen->post_type ) {
     93            return;
     94        }
     95
     96        $notice = $user = $user_id = '';
     97        $notice_type = 'warning';
     98
     99        $post = get_post();
     100        if ( ! $post ) {
     101            return;
     102        }
     103
     104        // Don't need to report flagging/unflagging for published posts.
     105        if ( 'published' === $post->post_status ) {
     106            return;
     107        }
     108
     109        // Note: Not reporting who flagged a post once it has been unflagged.
     110        if ( $user_id = Flagged::get_unflagger( $post ) ) {
     111            /* translators: 1: URL to the profile of the user who unflagged the photo, 2: The name of the user who unflagged the photo. */
     112            $notice = __( '<strong>This photo was unflagged by <a href="%1$s">%2$s</a> and is safe to moderate.', 'wporg-photos' );
     113            $notice_type = 'success';
     114        }
     115        elseif ( $user_id = Flagged::get_flagger( $post ) ) {
     116            /* translators: 1: URL to the profile of the user who flagged the photo, 2: The name of the user who flagged the photo. */
     117            $notice = __( '<strong>This photo was flagged by <a href="%1$s">%2$s</a>.', 'wporg-photos' );
     118        }
     119
     120        if ( $user_id ) {
     121            $user = new \WP_User( $user_id );
     122        }
     123
     124        if ( ! $user  || ! $notice ) {
     125            return;
     126        }
     127
     128        printf(
     129            '<div id="message" class="notice notice-%s"><p>%s</p></div>' . "\n",
     130            esc_attr( $notice_type ),
     131            sprintf(
     132                $notice,
     133                'https://profiles.wordpress.org/' . $user->user_nicename . '/',
     134                sanitize_text_field( $user->display_name )
    77135            )
    78136        );
Note: See TracChangeset for help on using the changeset viewer.