Skip to content

Commit

Permalink
Prevent accessing nonexistent user properties
Browse files Browse the repository at this point in the history
  • Loading branch information
delawski committed Jul 12, 2024
1 parent 82dcf06 commit 40a29bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion alerts/class-alert-type-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function alert( $record_id, $recordarr, $alert ) {
$user = get_user_by( 'id', $user_id );

// translators: Placeholder refers to a username (e.g. "administrator").
$message .= sprintf( __( "User:\t%s", 'stream' ), $user->user_login ) . "\n";
$message .= sprintf( __( "User:\t%s", 'stream' ), ! empty( $user->user_login ) ? $user->user_login : '' ) . "\n";

if ( ! empty( $alert->alert_meta['trigger_context'] ) ) {
$context = $this->plugin->alerts->alert_triggers['context']->get_display_value( 'list_table', $alert );
Expand Down
7 changes: 6 additions & 1 deletion alerts/class-alert-type-ifttt.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ public function notify_ifttt( $alert, $recordarr ) {
* @return string
*/
$user_field = apply_filters( 'wp_stream_alert_ifttt_user_data_value', 'user_login', $alert, $recordarr );
$user_value = ! empty( $user->$user_field ) ? $user->$user_field : $user->user_login;
$user_value = '';
if ( ! empty( $user->$user_field ) ) {
$user_value = $user->$user_field;
} elseif ( ! empty( $user->user_login ) ) {
$user_value = $user->user_login;
}

$created = $recordarr['created'];
/**
Expand Down
19 changes: 10 additions & 9 deletions connectors/class-connector-jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,17 @@ public function callback_jetpack_log_entry( array $entry ) {
$user_id = get_current_user_id();
}

$user = new \WP_User( $user_id );
$user_email = $user->user_email;
$user_login = $user->user_login;
$context = 'users';
$action = $method;
$meta = compact( 'user_id', 'user_email', 'user_login' );
$message = sprintf(
/* translators: %1$s: a user display name, %2$s: a status and the connection either "from" or "to" (e.g. "Jane Doe", "unlinked from") */
$user = new \WP_User( $user_id );
$user_email = ! empty( $user->user_email ) ? $user->user_email : '';
$user_login = ! empty( $user->user_login ) ? $user->user_login : '';
$user_display_name = ! empty( $user->display_name ) ? $user->display_name : '';
$context = 'users';
$action = $method;
$meta = compact( 'user_id', 'user_email', 'user_login' );
$message = sprintf(
/* translators: %1$s: a user display name, %2$s: a status and the connection either "from" or "to" (e.g. "Jane Doe", "unlinked from") */
__( '%1$s\'s account %2$s Jetpack', 'stream' ),
$user->display_name,
$user_display_name,
( 'unlink' === $action ) ? esc_html__( 'unlinked from', 'stream' ) : esc_html__( 'linked to', 'stream' )
);
} elseif ( in_array( $method, array( 'register', 'disconnect', 'subsiteregister', 'subsitedisconnect' ), true ) ) {
Expand Down

0 comments on commit 40a29bc

Please sign in to comment.