function updated_auto_register_option($old_value, $value)
{
// Not an API call or CLI call
if (!class_exists('WPCOM_JSON_API_Update_Option_Endpoint') && !(defined('WP_CLI') && WP_CLI)) {
return;
}
remove_action("update_option_{$this->auto_register_option}", array($this, 'updated_auto_register_option'));
$defaults = array('key' => false, 'action' => 'register', 'status' => 'working', 'error' => false);
// `wp_parse_args` uses arrays, might as well be explicit about it.
$registration = (array) json_decode($value);
$registration = wp_parse_args($registration, $defaults);
// If we have a working connection, don't update the key.
if ($this->check_connection(true)) {
$registration['action'] = 'response';
$registration['error'] = 'VaultPress is already registered on this site.';
update_option($this->auto_register_option, json_encode($registration));
return;
}
if (!$registration['key']) {
return;
}
$registration['action'] = 'response';
$response = $this->register($registration['key']);
if (is_wp_error($response)) {
$registration['status'] = 'broken';
$registration['error'] = $response->get_error_message();
} else {
if ($this->get_option('connection_error_code')) {
$registration['status'] = 'broken';
$registration['error'] = $this->get_option('connection_error_message');
} else {
$registration['error'] = false;
}
}
update_option($this->auto_register_option, json_encode($registration));
}