Skip to content

getUserPatronage only works correctly for the first user you call it with #142

@SaculRennorb

Description

@SaculRennorb

This

public static function getUserPatronage( $user = false ) {
if ( self::$current_user_pledge_amount != -1 ) {
return self::$current_user_pledge_amount;
}

does not make sense. You accept a user argument but only use one static cache variable. Any call to this function will first check that cache which gets filled by the first valid user. You then return this cached value, regardless of the actual user argument.

This is my proposed solution if you want to keep using the simple cache:

   public static function getUserPatronage( $user = false ) {
- 	if ( self::$current_user_pledge_amount != -1 ) {
-		return self::$current_user_pledge_amount;
-	}
-
  	// If user is not given, try to get the current user attribute ID will be 0 if there is no logged in user
  	if ( $user == false ) {
+		if ( self::$current_user_pledge_amount != -1 ) {
+ 			return self::$current_user_pledge_amount;
+ 		}
  
  		$user = wp_get_current_user();
  	}

It only uses the cache if you actually request the current user. Ofcourse this isnt perfect, and also not the only place that this would have to be fixed, but i hope you get the general idea.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions