AnsPress_Prod_Updater::api_request( string $_action, array $_data )

Description #

Calls the API and, if successfull, returns the object delivered by the API.

Parameters #

  • $_action
    string (Required) The requested action.
  • $_data
    array (Required) Parameters for the API action.

Source #

File: admin/updater.php

	private function api_request( $_action, $_data ) {

		global $wp_version;

		$data = array_merge( $this->api_data, $_data );

		if ( $data['slug'] != $this->slug ) {
			return;
		}

		if ( $this->api_url == home_url() ) {
			return false; // Don't allow a plugin to ping itself
		}

		$api_params = array(
			'edd_action'   => 'get_version',
			'license'      => ! empty( $data['license'] ) ? $data['license'] : '',
			'item_name'    => isset( $data['item_name'] ) ? $data['item_name'] : false,
			'item_id'      => isset( $data['item_id'] ) ? $data['item_id'] : false,
			'slug'         => $data['slug'],
			'author'       => $data['author'],
			'url'          => home_url(),
			'anspress_ver' => AP_VERSION,
		);

		$request = wp_remote_post(
			$this->api_url, array(
				'timeout'   => 15,
				'sslverify' => false,
				'body'      => $api_params,
			)
		);

		if ( ! is_wp_error( $request ) ) {
			$request = json_decode( wp_remote_retrieve_body( $request ) );
		}

		if ( $request && isset( $request->sections ) ) {
			$request->sections = maybe_unserialize( $request->sections );
		} else {
			$request = false;
		}

		return $request;
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment