Admin_Menu::get_integrations()

Returns the list of integrations.


Return Return

(array) $integrations The list of integrations.


Source Source

File: src/core/admin/class-admin-menu.php

	public function get_integrations() {

		// The endpoint url. Change this to live site later.
		$endpoint_url = 'https://automatorplugin.com/wp-json/automator-integrations/v1/list/all?time=' . time(); // Append time to prevent caching.

		// Get integrations from Automator plugin.
		$response = wp_remote_get( esc_url_raw( $endpoint_url ) );

		$integrations = array();

		if ( ! is_wp_error( $response ) ) {

			$api_response = json_decode( wp_remote_retrieve_body( $response ), true );

			if ( isset( $api_response['result'] ) && ! empty( $api_response['result'] ) ) {

				foreach ( $api_response['result']['integrations'] as $integration ) {

					// Construct the permalink.
					$permalink = add_query_arg(
						array(
							'post_type'   => 'uo-recipe',
							'page'        => 'uncanny-automator-integrations',
							'integration' => $integration['post_id'],
						),
						admin_url( 'edit.php' )
					);

					$integration_id = $integration['integration_id'];

					$integrations[ $integration['post_id'] ] = (object) array(
						'id'                 => $integration['post_id'],
						'integration_id'     => $integration['integration_id'],
						'name'               => $integration['name'],
						'permalink'          => $permalink,
						'external_permalink' => $integration['external_permalink'],
						'is_pro'             => $integration['is_pro'],
						'is_built_in'        => $integration['is_built_in'],
						'is_installed'       => $this->is_installed( $integration_id ),
						'short_description'  => $integration['short_description'],
						'icon_url'           => $integration['icon_url'],
					);

				}

				// Save in transients. Refreshes every hour.
				set_transient( 'uo-automator-integration-items', $integrations, HOUR_IN_SECONDS );
			}
		}

		return $integrations;

	}