Making WordPress.org

Changeset 13980


Ignore:
Timestamp:
08/19/2024 10:26:56 PM (7 weeks ago)
Author:
coffee2code
Message:

Photo Directory, Uploads: Output a grid of the 6 latest submissions by the user on the upload page.

Props topher1kenobe, coffee2code.
Fixes #7600.

File:
1 edited

Legend:

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

    r13816 r13980  
    8181        // Enqueue scripts.
    8282        add_action( 'wp_enqueue_scripts',               [ __CLASS__, 'wp_enqueue_scripts' ] );
     83        // Adds user's recent submissions above upload form.
     84        add_filter( 'wporg_photos_pre_upload_form',     [ __CLASS__, 'output_user_recent_submissions' ] );
    8385        // Disable upload form and show message if user not allowed to upload.
    8486        add_filter( 'the_content',                      [ __CLASS__, 'insert_upload_disallowed_notice' ], 1 );
     
    888890        if ( is_page( self::SUBMIT_PAGE_SLUG ) ) {
    889891            $content .= apply_filters( 'wporg_photos_pre_upload_form', $content );
    890 
    891             if ( User::count_published_photos( get_current_user_id() ) ) {
    892                 $content .= sprintf(
    893                     /* translators: %s: URL to current user's photo archive. */
    894                     '<p>' . __( 'View <a href="%s">your archive of photos</a> to see what you&#8217;ve already had published.', 'wporg-photos' ) . '</p>',
    895                     get_author_posts_url( get_current_user_id() )
    896                 );
    897             }
    898892
    899893            $content .= '<fieldset id="wporg-photo-upload">';
     
    10151009        return $transforms;
    10161010    }
     1011
     1012    /**
     1013     * Adds current user's 6 most recent photo submissions above upload form.
     1014     *
     1015     * @param string $content Existing content before the upload form.
     1016     * @return string
     1017     */
     1018    public static function output_user_recent_submissions( $content ) {
     1019        // Bail if user does not have any published photos.
     1020        if ( ! User::count_published_photos( get_current_user_id() ) ) {
     1021            return $content;
     1022        }
     1023
     1024        $recent_photos = User::get_recent_photos( get_current_user_id(), 6, false );
     1025        if ( $recent_photos ) {
     1026            $content .= '<h2 class="latest-photos">' . esc_html__( 'Your latest published photos', 'wporg-photos' ) . '</h2>' . "\n";
     1027            $content .= '<div class="photos-grid">' . "\n";
     1028
     1029            foreach ( $recent_photos as $photo ) {
     1030                $content .= Template_Tags\get_photo_as_grid_item( $photo, 'medium', 'post' );
     1031            }
     1032
     1033            $content .= "</div>\n";
     1034        }
     1035
     1036        $content .= sprintf(
     1037            /* translators: %s: URL to current user's photo archive. */
     1038            '<p>' . __( 'View <a href="%s">your archive of photos</a> to see everything you&#8217;ve already had published.', 'wporg-photos' ) . '</p>',
     1039            esc_url( get_author_posts_url( get_current_user_id() ) )
     1040        );
     1041
     1042        return $content;
     1043    }
     1044
    10171045}
    10181046
Note: See TracChangeset for help on using the changeset viewer.