Making WordPress.org

Changeset 13209


Ignore:
Timestamp:
02/12/2024 10:58:02 PM (8 months ago)
Author:
coffee2code
Message:

Photo Directory, Admin: Add 'Skip' button to allow skipping current photo and loading next photo in queue.

If JS is disabled, the 'Skip Photo' link will appear in a metabox.

Props markmemayank, coffee2code.
Fixes #7308.

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

Legend:

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

    r12959 r13209  
    126126    margin-left: 1.5rem;
    127127}
     128
     129.wp-heading-inline #photo-dir-skip-photo {
     130    margin-left: 1rem;
     131}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/assets/js/admin.js

    r13204 r13209  
    8585    photoRejectionNoteToUser?.addEventListener('input', e => setNoteToUserHighlight());
    8686
     87    // Move the skip button out of its metabox and into the top of the page. Also remove the metabox and its display toggle.
     88    const skipButton = document.getElementById('photo-dir-skip-photo');
     89    if (skipButton) {
     90        document.querySelector('#wpbody-content .wrap h1')?.appendChild(skipButton);
     91        document.querySelector('#photoskip')?.remove();
     92        document.querySelector('label[for="photoskip-hide"]')?.remove();
     93    }
    8794}, false);
    8895
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/admin.php

    r13205 r13209  
    8484        add_filter( 'query_vars',                              [ __CLASS__, 'add_query_var_for_random' ] );
    8585        add_action( 'pre_get_posts',                           [ __CLASS__, 'randomize_the_queue' ] );
     86
     87        // Add button to skip current photo in the queue.
     88        add_action( "add_meta_boxes_{$post_type}",             [ __CLASS__, 'add_skip_queued_photo_meta_box' ], 10, 2 );
     89        add_action( 'admin_init',                              [ __CLASS__, 'admin_redirect_to_next_photo' ] );
    8690    }
    8791
     
    14851489
    14861490    /**
     1491     * Registers meta box used for the 'skip' button to load another photo.
     1492     *
     1493     * @param WP_Post $post Post object.
     1494     */
     1495    public static function add_skip_queued_photo_meta_box( $post ) {
     1496        if ( ! $post ) {
     1497            return;
     1498        }
     1499
     1500        if ( 'pending' === $post->post_status ) {
     1501            add_meta_box(
     1502                'photoskip',
     1503                __( 'Skip Photo', 'wporg-photos' ),
     1504                [ __CLASS__, 'output_skip_queued_photo_meta_box' ],
     1505                $post->post_type,
     1506                'side',
     1507                'core'
     1508            );
     1509        }
     1510
     1511    }
     1512
     1513    /**
     1514     * Outputs the metabox for the skip button.
     1515     *
     1516     * @param WP_Post $post Current post object.
     1517     */
     1518    public static function output_skip_queued_photo_meta_box( $post ) {
     1519        printf(
     1520            '<a href="%s" id="photo-dir-skip-photo" class="page-title-action" title="%s">%s</a>',
     1521            esc_url( add_query_arg( 'skipphoto', '1' ) ),
     1522            esc_attr__( 'Skip this photo and load another.', 'wporg-photos' ),
     1523            __( 'Skip Photo', 'wporg-photos')
     1524        );
     1525    }
     1526
     1527    /**
     1528     * Redirects to the next photo in the queue when the current one is being skipped.
     1529     */
     1530    public static function admin_redirect_to_next_photo() {
     1531        $post_type = Registrations::get_post_type();
     1532
     1533        // If a random photo is being requested, then redirect to one.
     1534        if (
     1535            '1' === ( $_GET['skipphoto'] ?? false )
     1536        &&
     1537            'edit' === ( $_GET['action'] ?? false )
     1538        &&
     1539            ! empty( $_GET['post'] )
     1540        ) {
     1541            $exclude_photos = [ intval( $_GET['post'] ) ];
     1542
     1543            $next_photo = Posts::get_next_post_in_queue( 'rand', '', $exclude_photos );
     1544
     1545            if ( $next_photo ) {
     1546                wp_redirect( get_edit_post_link( $next_photo->ID, 'url' ), 302 );
     1547                exit;
     1548            }
     1549        }
     1550    }
     1551
     1552    /**
    14871553     * Adds 'random' as a custom query variable for photo queue listings.
    14881554     *
Note: See TracChangeset for help on using the changeset viewer.