Making WordPress.org

Changeset 14055


Ignore:
Timestamp:
09/16/2024 08:34:15 PM (5 months ago)
Author:
coffee2code
Message:

Photo Directory, Rejection: Separately store and display notes to user for approval and rejection.

  • Allow moderator to leave a note to user when rejecting a published photo
  • For pending photos, only show the note to user field corresponding to approval/rejection based on the rejection dropdown choice
  • Blank and hide rejection note to user if photo is not being rejected

Fixes #7772.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc
Files:
2 edited

Legend:

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

    r13786 r14055  
    391391        // Check for moderator's note to user.
    392392        $mod_note = '';
    393         $mod_note_to_user = Rejection::get_moderator_note_to_user( $post );
     393        $mod_note_to_user = Rejection::get_moderator_note_to_user( $post, 'publish' );
    394394        if ( $mod_note_to_user ) {
    395395            $mod_note = "\n" . __( 'Message from the moderator:', 'wporg-photos' ) . "\n{$mod_note_to_user}\n";
     
    475475
    476476        // Check for moderator's note to user.
    477         $mod_note = Rejection::get_moderator_note_to_user( $post );
     477        $mod_note = Rejection::get_moderator_note_to_user( $post, 'reject' );
    478478        if ( $mod_note ) {
    479479            $rejection_message .= "\n" . __( 'Message from the moderator:', 'wporg-photos' ) . "\n" . $mod_note . "\n";
     
    548548
    549549        // Check for moderator's note to user.
    550         $mod_note = Rejection::get_moderator_note_to_user( $post );
     550        $mod_note = Rejection::get_moderator_note_to_user( $post, 'reject' );
    551551        if ( $mod_note ) {
    552552            $rejection_message .= "\n" . __( 'Message from the moderator:', 'wporg-photos' ) . "\n" . $mod_note . "\n";
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/rejection.php

    r14051 r14055  
    208208                'input_in_metabox' => true,
    209209                'meta_config'      => [
    210                     'description' => __( 'A message sent to the user by the moderator within the approval/rejection email.', 'wporg-photos' ),
     210                    'description' => __( 'A message sent to the user by the moderator within the rejection email.', 'wporg-photos' ),
     211                ],
     212            ],
     213            'moderator_note_to_user_on_publish' => [
     214                'input_in_metabox' => true,
     215                'meta_config'      => [
     216                    'description' => __( 'A message sent to the user by the moderator within the approval email.', 'wporg-photos' ),
    211217                ],
    212218            ],
     
    366372     * Returns the note the moderator has for the user.
    367373     *
    368      * @param int|WP_Post The post or post ID.
     374     * There are two types of notes to user:
     375     * - 'publish': A note sent to the user when a photo is published.
     376     * - 'reject': A note sent to the user when a photo is rejected.
     377     *
     378     * It is possible for both types of notes to apply to a photo. However, it currently does not make sense
     379     * for two separate notes of a given type to be possible, nor does the implementation support it.
     380     *
     381     * @param int|WP_Post $post The post or post ID.
     382     * @param string      $type The note type. Either 'reject' or 'publish'. Default 'reject'.
    369383     * @return string
    370384     */
    371     public static function get_moderator_note_to_user( $post ) {
     385    public static function get_moderator_note_to_user( $post, $type = 'reject' ) {
    372386        $post = get_post( $post );
    373387
     
    376390        }
    377391
    378         return get_post_meta( $post->ID, 'moderator_note_to_user', true );
     392        $meta_key = ( 'publish' === $type ) ? 'moderator_note_to_user_on_publish' : 'moderator_note_to_user';
     393
     394        return get_post_meta( $post->ID, $meta_key, true );
    379395    }
    380396
     
    382398     * Returns the private note left by the moderator.
    383399     *
    384      * @param int|WP_Post The post or post ID.
     400     * @param int|WP_Post $post The post or post ID.
    385401     * @return string
    386402     */
     
    847863                    // Reject button should be disabled if no rejection reason is selected.
    848864                    document.querySelector('#reject-post').disabled = !hasRejectReason;
     865                    // Rejection note to user should be disabled if no rejection reason is selected.
     866                    const inputRejectNoteToUser = document.querySelector('#moderator_note_to_user');
     867                    if ( inputRejectNoteToUser ) {
     868                        inputRejectNoteToUser.disabled = !hasRejectReason || rejectSelect.disabled;
     869                        const rejectNoteToUser = document.querySelector('.moderator_note_to_user');
     870                        // Potentially hide the note input based on whether the dropdown has a value.
     871                        rejectNoteToUser.style.display = !hasRejectReason ? 'none' : 'block';
     872                        // If choosing to not reject photo, then delete the rejection note content to avoid it being saved.
     873                        if ( !hasRejectReason ) {
     874                            inputRejectNoteToUser.value = '';
     875                        }
     876                    }
     877
     878                    // Handling for the note-to-user fields for a pending photo (to facilitate only showing one at a time).
     879                    const pendingPublishNoteToUser = document.querySelector('.pending_moderator_note_to_user.moderator_note_to_user_on_publish');
     880                    const pendingRejectNoteToUser = document.querySelector('.pending_moderator_note_to_user.moderator_note_to_user');
     881                    if ( pendingPublishNoteToUser && pendingRejectNoteToUser ) {
     882                        // Hide one of the note-to-user fields if awaiting initial moderation.
     883                        pendingPublishNoteToUser.style.display = ( hasRejectReason ? 'none' : 'block' );
     884                        pendingRejectNoteToUser.style.display = ( hasRejectReason ? 'block' : 'none' );
     885
     886                        // When a note field gets hidden, transfer note field value to other note then clear it out.
     887                        if ( 'none' === pendingPublishNoteToUser.style.display ) {
     888                            const pendingPublishNote = pendingPublishNoteToUser.querySelector('textarea').value;
     889                            // Transfer value from approval note to rejection note if it had a value.
     890                            if ( pendingPublishNote ) {
     891                                pendingRejectNoteToUser.querySelector('textarea').value = pendingPublishNote;
     892                            }
     893                            pendingPublishNoteToUser.querySelector('textarea').value = '';
     894                        } else {
     895                            const pendingRejectNote = pendingRejectNoteToUser.querySelector('textarea').value;
     896                            // Transfer value from rejection note to approval note if it had a value.
     897                            if ( pendingRejectNote ) {
     898                                pendingPublishNoteToUser.querySelector('textarea').value = pendingRejectNote;
     899                            }
     900                            pendingRejectNoteToUser.querySelector('textarea').value = '';
     901                        }
     902                    }
     903
    849904                    // Notice of rejection of published post should be shown if post is published.
    850905                    const rejectPublishWarn = document.querySelector('.reject-warn-if-about-to-reject-published');
     
    904959        echo '<div class="reject-additional-fields">';
    905960
     961        // Assign a class only if the post is currently in a pending state.
     962        $note_to_user_label_class = ( $is_disabled ? '' : ' pending_moderator_note_to_user' );
     963
    906964        // Markup for optional note to send to user in rejection email.
    907         echo '<label for="moderator_note_to_user">' . __( '(Optional) Note to user:', 'wporg-photos' );
    908         echo '<p class="description"><em>' . __( 'Included in approval/rejection email.', 'wporg-photos' ) . '</em></p>';
     965        echo '<label for="moderator_note_to_user" class="moderator_note_to_user' . esc_attr( $note_to_user_label_class ) . '">' . __( '(Optional) Note to user on rejection:', 'wporg-photos' );
     966        echo '<p class="description"><em>' . __( 'Included in rejection email.', 'wporg-photos' ) . '</em></p>';
    909967        echo '<textarea id="moderator_note_to_user" name="moderator_note_to_user" rows="4"' . disabled( true, $is_disabled, false ) . '>';
    910         echo esc_textarea( self::get_moderator_note_to_user( $post ) );
     968        echo esc_textarea( self::get_moderator_note_to_user( $post, 'reject' ) );
     969        echo '</textarea>';
     970        echo '</label>';
     971
     972        // Markup for optional note sent to user in approval email.
     973        echo '<label for="moderator_note_to_user_on_publish" class="moderator_note_to_user_on_publish' . esc_attr( $note_to_user_label_class ) . '">' . __( '(Optional) Note to user on approval:', 'wporg-photos' );
     974        echo '<p class="description"><em>' . __( 'Included in approval email.', 'wporg-photos' ) . '</em></p>';
     975        echo '<textarea id="moderator_note_to_user_on_publish" name="moderator_note_to_user_on_publish" rows="4"' . disabled( true, $is_disabled, false ) . '>';
     976        echo esc_textarea( self::get_moderator_note_to_user( $post, 'publish' ) );
    911977        echo '</textarea>';
    912978        echo '</label>';
     
    10751141                echo self::get_rejection_reason( $post_id );
    10761142                // Add asterisk to denote there was a moderator note to user.
    1077                 if ( self::get_moderator_note_to_user( $post_id ) ) {
     1143                if ( self::get_moderator_note_to_user( $post_id, 'reject' ) || self::get_moderator_note_to_user( $post_id, 'publish' ) ) {
    10781144                    echo '*';
    10791145                }
Note: See TracChangeset for help on using the changeset viewer.