Ok, we’re getting there.
Now you don’t ping twice for every page load. That is good. That was the “WTF is happening here?!?” issue.
Now you just ping twice for almost every thing you do through the API. The first ping still happens in the constructor of the Mandrill class at line 20:
$response = $this->request('users/ping2', array( 'key' => $api ) );
if ( !isset($response['PING']) || $response['PING'] != 'PONG!' ) throw new Mandrill_Exception('Invalid API key');
The second ping is done in isConnected()
on line 451 in wpmandrill.php.
What I was trying to explain earlier was that there is only one time we ever need to do the whole ping thing, that is directly after the user has changed his API key through the settings page. That is a good time to verify that the key works. After that single time we must be able to trust the fact that the key is still valid and the Mandrill server is still online. When any of these two facts are no longer true, we will get to know that since a call to any of the API methods that actually do something of value (like sending mail) will fail.
Consider this scenario (events are written in the order they happen in time):
1. I call wpMandrill::mail()
2. self::isConnected() does the ping and everything is still OK
3. The Mandrill service goes down or the API key is revoked
4. self::$mandrill->messages_send($message); fails
Now what was the reason to do (2)?