Tribe__Events__Aggregator__Service::api()

Create a clean way of fetching API variables

Contents


Return

(stdClass|WP_Error)


Top ↑

Source

File: src/Tribe/Aggregator/Service.php

	public function api() {
		// Make it an Object
		$api = (object) $this->api;

		if ( defined( 'EVENT_AGGREGATOR_API_BASE_URL' ) ) {
			$api->domain = EVENT_AGGREGATOR_API_BASE_URL;
		}

		// Since we don't need to fetch this key elsewhere
		$api->key = get_option( 'pue_install_key_event_aggregator' );
		if ( is_multisite() ) {
			$network_key = get_network_option( null, 'pue_install_key_event_aggregator' );
			$api->key = ! empty( $api->key ) && $network_key !== $api->key ? $api->key : $network_key;
		}

		/**
		 * Creates a clean way to filter and redirect to another API domain/path
		 * @param  stdClass API object
		 */
		$api = (object) apply_filters( 'tribe_aggregator_api', $api );

		// Allows Eventbrite and others to skip ea license check
		if ( ! empty( $api->licenses ) ) {
			foreach ( $api->licenses as $plugin => $key ) {
				// If empty Key was passed we skip
				if ( empty( $key ) ) {
					continue;
				}

				$aggregator = tribe( 'events-aggregator.main' );
				$plugin_name = $aggregator->filter_pue_plugin_name( '', $plugin );

				$pue_notices = Tribe__Main::instance()->pue_notices();
				$has_notice = $pue_notices->has_notice( $plugin_name );

				// Means that we have a license and no notice - Valid Key
				if ( ! $has_notice ) {
					return $api;
				}
			}
		}

		// The user doesn't have a license key
		if ( empty( $api->key ) ) {
			return tribe_error( 'core:aggregator:invalid-service-key' );
		}

		$aggregator = tribe( 'events-aggregator.main' );
		$plugin_name = $aggregator->filter_pue_plugin_name( '', 'event-aggregator' );

		$pue_notices = Tribe__Main::instance()->pue_notices();
		$has_notice = $pue_notices->has_notice( $plugin_name );

		// The user doesn't have a valid license key
		if ( empty( $api->key ) || $has_notice ) {
			return tribe_error( 'core:aggregator:invalid-service-key' );
		}

		return $api;
	}