This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

BBP_Akismet::http_post( string $request, string $host, string $path, string $port = 80, string $ip = '' )

Submit data to Akismet service with unique bbPress User Agent

Description

This code is directly taken from the akismet_http_post() function and documented to bbPress 2.0 standard.

Parameters

$request

(Required) The request we are sending

$host

(Required) The host to send our request to

$path

(Required) The path from the host

$port

(Optional) The port to use

Default value: 80

$ip

(Optional) Override $host with an IP address

Default value: ''

Return

(mixed) WP_Error on error, array on success, empty on failure

Source

File: bp-forums/extend/akismet.php

	private function http_post( $request, $host, $path, $port = 80, $ip = '' ) {

		// Preload required variables
		$bbp_version    = bbp_get_version();
		$content_length = strlen( $request );
		$http_host      = $host;
		$blog_charset   = get_option( 'blog_charset' );
		$response       = '';
		$errno          = null;
		$errstr         = null;

		// Untque User Agent
		$akismet_ua     = "bbPress/{$bbp_version} | ";
		$akismet_ua    .= 'Akismet/' . constant( 'AKISMET_VERSION' );

		// Use specific IP (if provided)
		if ( !empty( $ip ) && long2ip( ip2long( $ip ) ) )
			$http_host = $ip;

		// WP HTTP class is available
		if ( function_exists( 'wp_remote_post' ) ) {

			// Setup the arguments
			$http_args = array(
				'body'             => $request,
				'headers'          => array(
					'Content-Type' => 'application/x-www-form-urlencoded; charset=' . $blog_charset,
					'Host'         => $host,
					'User-Agent'   => $akismet_ua
				),
				'httpversion'      => '1.0',
				'timeout'          => 15
			);

			// Where we are sending our request
			$akismet_url = 'http://' . $http_host . $path;

			// Send the request
			$response    = wp_remote_post( $akismet_url, $http_args );

			// Bail if the response is an error
			if ( is_wp_error( $response ) )
				return '';

			// No errors so return response
			return array( $response['headers'], $response['body'] );

		// WP HTTP class is not available (Why not?)
		} else {

			// Header info to use with our socket
			$http_request  = "POST {$path} HTTP/1.0\r\n";
			$http_request .= "Host: {$host}\r\n";
			$http_request .= "Content-Type: application/x-www-form-urlencoded; charset={$blog_charset}\r\n";
			$http_request .= "Content-Length: {$content_length}\r\n";
			$http_request .= "User-Agent: {$akismet_ua}\r\n";
			$http_request .= "\r\n";
			$http_request .= $request;

			// Open a socket connection
			if ( false !== ( $fs = @fsockopen( $http_host, $port, $errno, $errstr, 10 ) ) ) {

				// Write our request to the pointer
				fwrite( $fs, $http_request );

				// Loop through pointer and compile a response
				while ( !feof( $fs ) ) {
					// One TCP-IP packet at a time
					$response .= fgets( $fs, 1160 );
				}

				// Close our socket
				fclose( $fs );

				// Explode the response into usable data
				$response = explode( "\r\n\r\n", $response, 2 );
			}

			// Return the response ('' if error/empty)
			return $response;
		}
	}

Changelog

Changelog
Version Description
bbPress (r3466) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.