Admin_Menu::is_automator_connected()

Checks automator connect and get credits


Return Return

(false|array)


Source Source

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

	public static function is_automator_connected() {
		$have_valid_licence = false;
		$licence_key        = '';
		$item_name          = '';
		$count              = 0;

		if ( defined( 'AUTOMATOR_PRO_FILE' ) && 'valid' !== get_option( 'uap_automator_pro_license_status' ) ) {
			//	return false;
		}

		if ( defined( 'AUTOMATOR_PRO_FILE' ) && 'valid' === get_option( 'uap_automator_pro_license_status' ) ) {
			$licence_key = get_option( 'uap_automator_pro_license_key' );
			$item_name   = AUTOMATOR_PRO_ITEM_NAME;
		} elseif ( 'valid' === get_option( 'uap_automator_free_license_status' ) ) {
			$licence_key = get_option( 'uap_automator_free_license_key' );
			$item_name   = AUTOMATOR_FREE_ITEM_NAME;
		}

		if ( empty( $licence_key ) ) {
			return false;
		}

		$website = preg_replace( '(^https?://)', '', get_home_url() );

		$plugin_version = AUTOMATOR_PLUGIN_VERSION;
		if ( defined( 'AUTOMATOR_PRO_FILE' ) ) {
			$plugin_version = defined( 'AUTOMATOR_PRO_PLUGIN_VERSION' ) ? AUTOMATOR_PRO_PLUGIN_VERSION : \Uncanny_Automator_Pro\InitializePlugin::PLUGIN_VERSION;
		}
		// data to send in our API request
		$api_params = [
			'action'  => 'get_credits',
			'api_ver' => '2.0',
			'plugins' => $plugin_version,
		];

		// Call the custom API.
		$response = wp_remote_post( AUTOMATOR_API_URL . 'v2/credits', array(
			'timeout'   => 15,
			'sslverify' => false,
			'body'      => $api_params,
		) );

		$credit_data = json_decode( wp_remote_retrieve_body( $response ) );

		if ( $credit_data->statusCode == 200 ) {
			return (array) $credit_data->data;

		}

		return false;
	}