It's working now. Think I may have made a typo earlier. I'll summarize what I did for anyone else who's trying to do something similar.
In order to make Wordpress check if a user is logged in to Modx, I wrote a plugin that looks like this:
$eventName = $modx->event->name;
switch($eventName) {
case 'OnWebLogin':
$_SESSION['wordpressforbidden'] = false;
break;
case 'OnWebLogout':
$_SESSION['wordpressforbidden'] = true;
break;
and connected it to the OnWebLogin and OnWebLogout events.
and in the file index.php in Wordpress' root folder I put this:
require_once '../config.core.php';
require_once MODX_CORE_PATH.'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('web');
if ($_SESSION['wordpressforbidden'] === false) {
// all the stuff that was in index.php already
}
else {
echo 'not authorized';
}
exit();
Of course, this solution is not perfect, because the modification in Wordpress may be overwritten if Wordpress gets to be updated.