mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Use client id max length as substr
length
This commit is contained in:
parent
82727ac2a1
commit
f39ae459b1
1 changed files with 1 additions and 15 deletions
|
@ -38,14 +38,13 @@ class CustomerRepository {
|
|||
* @return string
|
||||
*/
|
||||
public function customer_id_for_user( int $user_id ): string {
|
||||
$unique_id = $this->generate_unique_id();
|
||||
if ( 0 === $user_id ) {
|
||||
$guest_customer_id = WC()->session->get( 'ppcp_guest_customer_id' );
|
||||
if ( is_string( $guest_customer_id ) && $guest_customer_id ) {
|
||||
return $guest_customer_id;
|
||||
}
|
||||
|
||||
$unique_id = $this->generate_unique_id();
|
||||
$unique_id = substr( $this->prefix . strrev( uniqid() ), 0, self::CLIENT_ID_MAX_LENGTH );
|
||||
WC()->session->set( 'ppcp_guest_customer_id', $unique_id );
|
||||
|
||||
return $unique_id;
|
||||
|
@ -58,17 +57,4 @@ class CustomerRepository {
|
|||
|
||||
return $this->prefix . (string) $user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a unique id based on the length of the prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generate_unique_id(): string {
|
||||
$offset = self::CLIENT_ID_MAX_LENGTH - strlen( $this->prefix );
|
||||
|
||||
return strlen( uniqid() ) > $offset
|
||||
? $this->prefix . substr( uniqid(), $offset )
|
||||
: $this->prefix . uniqid();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue