• Home
  • Knowledgebase
  • DevDocs
  • Translations
  • Support
  • Live Preview

logo DevDocs

By The Events Calendar
Filter by type:
Skip to content
Filter by type:
Search
Browse: Home / Classes / Abstract_Account_Api / Abstract_Account_Api::ajax_status()
Product: Virtual Events

Abstract_Account_Api::ajax_status( string|null $nonce = null )

Handles the request to change the status of an API account.

Contents

  • Parameters
  • Return
  • Source
  • Changelog

Parameters

$nonce

(string|null) (Optional) The nonce that should accompany the request.

Default value: null


Top ↑

Return

(bool) Whether the request was handled or not.


Top ↑

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();
	}

Expand full source code Collapse full source code


Top ↑

Changelog

Changelog
Version Description
1.9.0 Introduced.
The Events Calendar
  • Home
  • Products
  • Blog
  • Support
© 2026 The Events Calendar Terms and Conditions Privacy