Skip to content

Commit f351a99

Browse files
authored
Merge pull request #1843 from xwp/fix/log-wp-cli-user-info-array-check
Fix redundant userinfo array checks.
2 parents 488e4a2 + e7e6c28 commit f351a99

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

classes/class-log.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,14 @@ public function log( $connector, $message, $args, $object_id, $context, $action,
9292
if ( 'wp_cli' === $agent && function_exists( 'posix_getuid' ) ) {
9393
$uid = posix_getuid();
9494
$user_info = posix_getpwuid( $uid );
95-
if( ! is_array( $user_info ) ) {
95+
96+
// Normalize the user info to an array if it's not already.
97+
if ( ! is_array( $user_info ) ) {
9698
$user_info = array( 'name' => 'unknown' );
9799
}
98100

99101
$user_meta['system_user_id'] = (int) $uid;
100-
$user_meta['system_user_name'] = is_array( $user_info ) ? (string) $user_info['name'] : '';
102+
$user_meta['system_user_name'] = (string) ( $user_info['name'] ?? 'unknown' );
101103
}
102104

103105
// Prevent any meta with null values from being logged.

0 commit comments

Comments
 (0)