From 292478fdf0bdaa6885711e4a8b4c4bc1a3725ee4 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Fri, 22 Jan 2016 15:12:27 -0500 Subject: [PATCH 1/4] Fixing bug that prevents log items from being added if the WordPress user responsible for the item does not have a WP_User->roles array that starts with a 0 index. --- classes/class-log.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/class-log.php b/classes/class-log.php index e7fd46be4..4d485426a 100644 --- a/classes/class-log.php +++ b/classes/class-log.php @@ -109,7 +109,7 @@ function( &$v ) { 'site_id' => (int) is_multisite() ? get_current_site()->id : 1, 'blog_id' => (int) apply_filters( 'wp_stream_blog_id_logged', get_current_blog_id() ), 'user_id' => (int) $user_id, - 'user_role' => (string) ! empty( $user->roles ) ? $user->roles[0] : '', + 'user_role' => (string) ! empty( $user->roles ) ? array_values( $user->roles )[0] : '', 'created' => (string) $iso_8601_extended_date, 'summary' => (string) vsprintf( $message, $args ), 'connector' => (string) $connector, @@ -152,7 +152,7 @@ public function is_record_excluded( $connector, $context, $action, $user = null, $ip = wp_stream_filter_var( $ip, FILTER_VALIDATE_IP ); } - $user_role = isset( $user->roles[0] ) ? $user->roles[0] : null; + $user_role = ! empty( $user->roles ) ? array_values( $user->roles )[0] : null; $record = array( 'connector' => $connector, From 81b8f8489a0dede036b715c6c2168f564df64224 Mon Sep 17 00:00:00 2001 From: Tyler Carter Date: Mon, 7 Mar 2016 15:40:18 -0800 Subject: [PATCH 2/4] Expand roles logic Fixes problems with PHP < 5.4 --- classes/class-log.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/classes/class-log.php b/classes/class-log.php index 4d485426a..a5f6739fe 100644 --- a/classes/class-log.php +++ b/classes/class-log.php @@ -104,12 +104,18 @@ function( &$v ) { // Get the current time in milliseconds $iso_8601_extended_date = wp_stream_get_iso_8601_extended_date(); + if ( ! empty( $user->roles ) ) { + $roles = array_values( $user->roles ); + $role = $roles[0]; + } else { + $role = ''; + } $recordarr = array( 'object_id' => (int) $object_id, 'site_id' => (int) is_multisite() ? get_current_site()->id : 1, 'blog_id' => (int) apply_filters( 'wp_stream_blog_id_logged', get_current_blog_id() ), 'user_id' => (int) $user_id, - 'user_role' => (string) ! empty( $user->roles ) ? array_values( $user->roles )[0] : '', + 'user_role' => (string) $role, 'created' => (string) $iso_8601_extended_date, 'summary' => (string) vsprintf( $message, $args ), 'connector' => (string) $connector, From 9b8c5cba7d2c11a53d3704e2cb15be9621ba2e19 Mon Sep 17 00:00:00 2001 From: Tyler Carter Date: Mon, 7 Mar 2016 15:52:30 -0800 Subject: [PATCH 3/4] Expand roles logic Fixes problems with PHP < 5.4 --- classes/class-log.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/classes/class-log.php b/classes/class-log.php index a5f6739fe..a28dd6a97 100644 --- a/classes/class-log.php +++ b/classes/class-log.php @@ -158,8 +158,13 @@ public function is_record_excluded( $connector, $context, $action, $user = null, $ip = wp_stream_filter_var( $ip, FILTER_VALIDATE_IP ); } - $user_role = ! empty( $user->roles ) ? array_values( $user->roles )[0] : null; - + if ( ! empty( $user->roles ) ) { + $roles = array_values( $user->roles ); + $role = $roles[0]; + } else { + $role = ''; + } + $record = array( 'connector' => $connector, 'context' => $context, From f2b378e224bd1978d8f9ebf7a041f2f277391cba Mon Sep 17 00:00:00 2001 From: Tyler Carter Date: Mon, 7 Mar 2016 16:07:38 -0800 Subject: [PATCH 4/4] Fix typo Remove whitespace after control structure. --- classes/class-log.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/classes/class-log.php b/classes/class-log.php index a28dd6a97..7d8cb50e5 100644 --- a/classes/class-log.php +++ b/classes/class-log.php @@ -164,13 +164,12 @@ public function is_record_excluded( $connector, $context, $action, $user = null, } else { $role = ''; } - $record = array( 'connector' => $connector, 'context' => $context, 'action' => $action, 'author' => $user->ID, - 'role' => $user_role, + 'role' => $role, 'ip_address' => $ip, );