Abstract_Account_Api::ajax_status( string|null $nonce = null )
Handles the request to change the status of an API account.
Contents
Parameters
- $nonce
-
(string|null) (Optional) The nonce that should accompany the request.
Default value: null
Return
(bool) Whether the request was handled or not.
Source
File: src/Tribe/Integrations/Abstract_Account_Api.php
public function ajax_status( $nonce = null ) {
if ( ! $this->check_ajax_nonce( static::$status_action, $nonce ) ) {
return false;
}
$account_id = tribe_get_request_var( 'account_id' );
$account = $this->get_account_by_id( $account_id );
// If no account id found, fail the request.
if ( empty( $account_id ) || empty( $account ) ) {
$error_message = sprintf(
// translators: the placeholders is for the API name.
_x(
'The %1$s Account ID or Account is missing to change the status.',
'Account ID is missing on status change error message.',
'events-virtual'
),
static::$api_name
);
$this->get_settings_message_template( $error_message, 'error' );
wp_die();
}
// Set the status to the opposite of what is saved.
$new_status = tribe_is_truthy( $account['status'] ) ? false : true;
$account['status'] = $new_status;
$this->set_account_by_id( $account );
// Attempt to load the account when status is changed to enabled and on failure display a message.
$loaded = $new_status ? $this->load_account_by_id( $account['id'] ) : true;
if ( empty( $loaded ) ) {
$error_message = sprintf(
// translators: the placeholders are for the API name.
_x(
'There seems to be a problem with the connection to this %1$s account. Please refresh the connection.',
'Message to display when the %1$s account could not be loaded after being enabled.',
'events-virtual'
),
static::$api_name
);
$this->get_settings_message_template( $error_message, 'error' );
wp_die();
}
$status_msg = $new_status
? _x(
'%1$s connection enabled for %2$s',
'Enables the API Account for the Website.',
'events-virtual'
)
: _x(
'%1$s connection disabled for %2$s',
'Disables the API Account for the Website.',
'events-virtual'
);
$message = sprintf(
/* Translators: %1$s is the name of the API, %2$s: the name of the account that has the status change. */
$status_msg,
static::$api_name,
$account['name']
);
$this->get_settings_message_template( $message );
wp_die();
}
Changelog
| Version | Description |
|---|---|
| 1.9.0 | Introduced. |