From af749dca0f3a0b60939aaadcc54cb50eaac78a90 Mon Sep 17 00:00:00 2001 From: Luke Carbis Date: Wed, 9 Sep 2015 10:16:35 +1000 Subject: [PATCH 1/2] Check log entry array keys before using them in Jetpack connector --- connectors/class-connector-jetpack.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/connectors/class-connector-jetpack.php b/connectors/class-connector-jetpack.php index 45037d286..279400df3 100644 --- a/connectors/class-connector-jetpack.php +++ b/connectors/class-connector-jetpack.php @@ -312,12 +312,22 @@ public function register() { * @param array $entry */ public function callback_jetpack_log_entry( array $entry ) { - $method = $entry['code']; - $data = $entry['data']; + if ( isset( $entry['code'] ) ) { + $method = $entry['code']; + } else { + return; + } + if ( isset( $entry['data'] ) ) { + $data = $entry['data']; + } else { + $data = null; + } + $context = null; $action = null; + $meta = array(); - if ( in_array( $method, array( 'activate', 'deactivate' ) ) ) { + if ( in_array( $method, array( 'activate', 'deactivate' ) ) && ! is_null( $data ) ) { $module_slug = $data; $module = \Jetpack::get_module( $module_slug ); $module_name = $module['name']; @@ -329,7 +339,7 @@ public function callback_jetpack_log_entry( array $entry ) { $module_name, ( 'activated' === $action ) ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' ) ); - } elseif ( in_array( $method, array( 'authorize', 'unlink' ) ) ) { + } elseif ( in_array( $method, array( 'authorize', 'unlink' ) ) && ! is_null( $data ) ) { $user_id = intval( $data ); if ( empty( $user_id ) ) { @@ -358,8 +368,6 @@ public function callback_jetpack_log_entry( array $entry ) { return; } - $meta = array(); - if ( ! $is_multisite ) { $message = sprintf( __( 'Site %s Jetpack', 'stream' ), From 07321efbf69ad48a7cef333007e493df69d2c504 Mon Sep 17 00:00:00 2001 From: Luke Carbis Date: Wed, 9 Sep 2015 10:18:54 +1000 Subject: [PATCH 2/2] Add extra space for readability --- connectors/class-connector-jetpack.php | 1 + 1 file changed, 1 insertion(+) diff --git a/connectors/class-connector-jetpack.php b/connectors/class-connector-jetpack.php index 279400df3..48ba1034e 100644 --- a/connectors/class-connector-jetpack.php +++ b/connectors/class-connector-jetpack.php @@ -317,6 +317,7 @@ public function callback_jetpack_log_entry( array $entry ) { } else { return; } + if ( isset( $entry['data'] ) ) { $data = $entry['data']; } else {