public function redirectIntercept() { global $wp_query; if ($wp_query->get('sociallymap-plugin')) { // We don't have the right parameters if (!isset($_POST['entityId']) || !isset($_POST['token'])) { header('HTTP/1.0 400 Bad Request'); Logger::info('Message receive but without $_POST[\'entityId\'] or $_POST[\'token\']', print_r($_POST, true)); exit; } else { foreach ($_POST as $key => &$value) { if ($key != 'entityId') { $value = sanitize_text_field($value); } } } Logger::info('Intercept message in plugin (+sanitize)', print_r($_POST, true)); $collector = new EntityCollection(); $_POST['entityId'] = $_POST['entityId']; $entity = $collector->getByEntityId(sanitize_key($_POST['entityId'])); // Context : Testing connection between sociallymap and wordpress plugin if ($_POST['token'] == 'connection-test') { header('Content-Type: application/json'); if (empty($entity)) { header('HTTP/1.0 404 Not Found'); exit(json_encode(['error' => 'entityId inconnu'])); } else { // header('Content-Type: application/json'); header('HTTP/1.0 200 OK'); exit(json_encode(['message' => 'ok'])); } } // This entity not exists if (empty($entity)) { header('HTTP/1.0 404 Not Found'); exit; } // Try to retrieve the pending messages if ($this->manageMessages($entity) == false) { header('HTTP/1.0 502 Bad gateway'); Logger::error('The plugin can\'t ping to sociallymap'); } else { header('HTTP/1.0 200 OK'); exit(json_encode(['message' => 'ok'])); } } }