ProPanel: Change email “From” address

add_filter('wp_mail_from', function ( $from_email_address = '' ) {
	// When calling the WP 	wp_mail() function is the 'From' header is not defined 
	// it will set the default 'From' email to be 'wordpress@domain.com'. where 'domain.com'.
	// matches the site domain
	
	// So our first check is to see of we are using the default
	$sitename = strtolower( $_SERVER['SERVER_NAME'] );
	if ( substr( $sitename, 0, 4 ) == 'www.' ) {
		$sitename = substr( $sitename, 4 );
	}
	$default_from_email = 'wordpress@' . $sitename;
	
	if ( ( $default_from_email == $from_email_address ) && ( is_user_logged_in() ) ) {
		$current_user = wp_get_current_user();
		$from_email_address = $current_user->user_email;
	}

	return $from_email_address;
});

add_filter( 'wp_mail_from_name', function ( $from_name = '' ) {
	// When calling the WP 	wp_mail() function is the 'From' header is not defined 
	// it will set the default 'From' name to be 'WordPress'. 

	if ( ( $from_name === "WordPress" ) && ( is_user_logged_in() ) ) {
		$current_user = wp_get_current_user();
		$from_name = $current_user->display_name;
	}

	return $from_name;
});