Making WordPress.org

Changeset 14235


Ignore:
Timestamp:
12/04/2024 07:46:09 PM (8 weeks ago)
Author:
coffee2code
Message:

Photo Directory, User: Allow author template to load for users who have not contributed any photos.

Fixes https://github.com/WordPress/wporg-photo-directory/issues/31

File:
1 edited

Legend:

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

    r14183 r14235  
    5252     */
    5353    public static function init() {
     54        // Show empty state page for users without contributed photos.
     55        add_action( 'template_redirect', [ __CLASS__, 'allow_empty_authors' ] );
     56    }
     57
     58    /**
     59     * Allows the author template to load for users who have not contributed any photos.
     60     */
     61    public static function allow_empty_authors() {
     62        global $wp_query;
     63
     64        if ( is_404() && get_query_var( 'author' ) ) {
     65            $author_id = get_query_var( 'author' );
     66            if ( ! $author_id ) {
     67                return;
     68            }
     69
     70            $authordata= get_userdata( $author_id );
     71            if ( ! $authordata ) {
     72                return;
     73            }
     74
     75            $wp_query->is_author = true;
     76            $wp_query->is_archive = true;
     77            $wp_query->is_404 = false;
     78
     79            // Set global authordata variable to allow use of core user template functions.
     80            $GLOBALS['authordata'] = $authordata;
     81        }
    5482    }
    5583
Note: See TracChangeset for help on using the changeset viewer.