-
Notifications
You must be signed in to change notification settings - Fork 117
Description
Bug Report
Expected Behavior
When running a CLI job from a shell that does not have a user, if I do an action that causes the into the WP_Stream\Log::log()
method to fire ( e.g. delete or add post meta ), I would like the action to complete without emitting a PHP Warning.
To get into a shell that doesn't have a user, imagine a docker container for WP and run:
docker exec -it -u 1234 my-wp-container-1 /bin/bash
This is a common pattern when wanting to run the shell as a non-root user.
Actual Behavior
The following warning is emitted:
PHP Warning: Trying to access array offset on value of type bool in /var/www/html/wp-content/plugin
s/stream/classes/class-log.php on line 97
Suggested Fix
The issue stems from these lines:
if ( 'wp_cli' === $agent && function_exists( 'posix_getuid' ) ) {
$uid = posix_getuid();
$user_info = posix_getpwuid( $uid );
$user_meta['system_user_id'] = (int) $uid;
$user_meta['system_user_name'] = (string) $user_info['name'];
}
posix_getpwuid( $uid )
returns false in this case. Suggested fix is to update the system_user_name
line to:
$user_meta['system_user_name'] = is_array( $user_info ) ? (string) $user_info['name'] : '';