Admin_Menu::get_collections()

Contents


Return Return

(array)


Source Source

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

	public function get_collections() {
		// The endpoint url. Change this to live site later.
		$endpoint_url = 'https://automatorplugin.com/wp-json/automator-integrations-collections/v1/list/all?time=' . time(); // Append time to prevent caching.
		// Get integrations from Automator plugin.
		$response = wp_remote_get( esc_url_raw( $endpoint_url ) );
		$collections = 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'] as $collection ) {
					$collections[ $collection['slug'] ] = (object) array(
						'id'           => $collection['slug'],
						'name'         => $collection['name'],
						'description'  => $collection['description'],
						'integrations' => $collection['integrations'],
					);
				}
				// Add "Installed integrations"
				$collections['installed-integrations'] = (object) array(
					'id'           => 'installed-integrations',
					'name'         => esc_html__( 'Installed integrations', 'uncanny-automator' ),
					'description'  => esc_html__( 'Ready-to-use integrations', 'uncanny-automator' ),
					'integrations' => $this->get_installed_integrations_ids(),
				);
				// Save in transients. Refreshes every hour.
				set_transient( 'uo-automator-integration-collection-items', $collections, HOUR_IN_SECONDS );
			}
		}
		return $collections;
	}