Making WordPress.org


Ignore:
Timestamp:
05/21/2025 05:41:06 AM (16 months ago)
Author:
dd32
Message:

Theme Directory: Trac: Use a user session that lasts an entire day, to avoid re-creating them for every trac interaction.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/lib/class-trac.php

    r14439 r14455  
    4242                $this->rpc->headers['Authorization'] = $http_basic_auth;
    4343
    44                 // themes.trac requires both the Authorization header and the logged in Cookie.
    45                 $user = get_user_by( 'login', $username );
    46                 if ( $user ) {
    47                         $this->rpc->headers['Cookie'] = LOGGED_IN_COOKIE . '=' . wp_generate_auth_cookie( $user->ID, time() + HOUR_IN_SECONDS, 'logged_in' );
     44                // themes.trac requires both the Authorization header and the logged in cookie.
     45                $logged_in = get_transient( "trac_logged_in_cookie_{$username}" );
     46                if (
     47                        ! $logged_in ||
     48                        ! wp_validate_auth_cookie( $logged_in, 'logged_in' )
     49                ) {
     50                        // Generate a new WordPress user session, daily.
     51                        $user      = get_user_by( 'login', $username );
     52                        $logged_in = wp_generate_auth_cookie( $user->ID, time() + 2 * DAY_IN_SECONDS, 'logged_in' );
     53
     54                        // Cache the session for 1 day.
     55                        set_transient( "trac_logged_in_cookie_{$username}", $logged_in, DAY_IN_SECONDS );
     56
     57                        // Wait a moment for the session to become active before using it.
     58                        sleep( 1 );
    4859                }
     60
     61                $this->rpc->headers['Cookie'] = LOGGED_IN_COOKIE . '=' . $logged_in;
    4962
    5063        }
Note: See TracChangeset for help on using the changeset viewer.