Making WordPress.org

Changeset 13996


Ignore:
Timestamp:
08/26/2024 11:10:57 PM (6 weeks ago)
Author:
coffee2code
Message:

Photo Directory, Rejection: Help prevent unintended rejection of published photo.

  • Disable rejection reason dropdown for published photos by default.
  • Add a checkbox above rejection dropdown to enable rejection reason dropdown and emphasize that photo is already published.
  • Add a warning adjacent to 'Reject' button that appears if published photo is about to be rejected.

Fixes #7751.

File:
1 edited

Legend:

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

    r12970 r13996  
    814814
    815815        $selected = self::get_rejection_reason( $post );
    816         $is_disabled = in_array( get_post_status( $post ), [ 'trash', self::get_post_status() ] );
     816        $is_disabled = in_array( get_post_status( $post ), [ 'publish', 'trash', self::get_post_status() ] );
    817817
    818818        echo "<style>
     
    826826            .reject-action.post-is-rejected input[type=submit] { background-color: #2271b1; border-color: #2271b1; }
    827827            .reject-action input[type=submit]:hover { background-color: #8f2424; border-color: #8f2424; color: white; }
     828
     829            .reject-warn-if-published { border:1px solid #856404; background-color: #fff3cd; color: #856404; padding: 8px; margin-bottom: 0.5rem; }
     830            .reject-warn-if-about-to-reject-published { border: 1px solid #721c24; background-color: #f8d7da; color: #721c24; padding: 8px 12px; margin-bottom: 0.5rem; }
    828831        </style>\n";
    829832
     
    838841                // Bind changing of value of rejection reason dropdown to toggle whether reject or publish button is enabled.
    839842                const rejectSelect = document.querySelector('#rejected_reason');
    840                 rejectSelect.addEventListener('change', (event) => {
     843                rejectSelect?.addEventListener('change', (event) => {
    841844                    const hasRejectReason = Boolean(event.target.value);
    842845                    // Publish button should be disabled if a rejection reason is selected.
     
    844847                    // Reject button should be disabled if no rejection reason is selected.
    845848                    document.querySelector('#reject-post').disabled = !hasRejectReason;
     849                    // Notice of rejection of published post should be shown if post is published.
     850                    const rejectPublishWarn = document.querySelector('.reject-warn-if-about-to-reject-published');
     851                    if ( rejectPublishWarn ) {
     852                        rejectPublishWarn.style.display = ( hasRejectReason ? 'block' : 'none' );
     853                    }
     854                });
     855
     856                // Bind checkbox for enabling rejection of published photo.
     857                const cbRejectPublished = document.querySelector('#reject-warn-if-reject-published');
     858                cbRejectPublished?.addEventListener('change', (event) => {
     859                    if (rejectSelect) {
     860                        rejectSelect.disabled = !event.target.checked;
     861                    }
    846862                });
    847863
     
    852868        </script>
    853869JS;
     870
     871        // Show a notice if the post is already published and a checkbox for enabling rejection field.
     872        if ( 'publish' === get_post_status( $post ) ) {
     873            echo '<div class="reject-warn-if-published">';
     874            echo '<label class="warn-if-reject-published-container"><input id="reject-warn-if-reject-published" type="checkbox" name="reject_warn_if_reject_published" />';
     875            esc_html_e( 'Allow rejection of published photo?', 'wporg-photos' );
     876            echo "</label></div>\n";
     877        }
    854878
    855879        echo '<label for="rejected_reason">' . __( 'Reject due to:', 'wporg-photos' ) . '<br>';
     
    886910
    887911        echo "</div></div>\n";
     912
     913        // Output a notice adjacent to reject button for use if about to reject a published post.
     914        if ( 'publish' === get_post_status( $post ) ) {
     915            echo '<div class="reject-warn-if-about-to-reject-published" style="display:none;" >';
     916            esc_html_e( 'Warning: You are about to reject a published photo!', 'wporg-photos' );
     917            echo "</div>\n";
     918        }
    888919
    889920        $is_rejected = self::is_post_rejected( $post );
Note: See TracChangeset for help on using the changeset viewer.