src/Monitor.php
/**
	 * Post our data to our support server
	 *
	 * @param boolean $blocking - whether to wait for a response from the server
	 * @return \WP_Error|\StdClass (boolean) - whether the data was successfully posted or not - always true if blocking is false
	 */
Post our data to our support server
@param boolean $blocking - whether to wait for a response from the server
@return \WP_Error|\StdClass (boolean) - whether the data was successfully posted or not - always true if blocking is false
Post our data to our support server @param boolean $blocking - whether to wait for a response from the server @return \ WP_Error| \ StdClass ( boolean ) - whether the data was successfully posted or not - always true if blocking is false
public function post( $blocking = false ) {
		flush(); 
		$data = $this->compile();
		if ( empty( $data ) ) {
			return new \WP_Error( 'no-data', 'No data to send!' );
		}
		$request_args = [
			'timeout' => 30,
			'blocking' => $blocking,
			'headers' => [
				'Content-Type' => 'application/json'
			],
			'body' => json_encode( $data )
		];
		if ( ! wp_http_validate_url( $this->api_endpoint ) ) {
			return new \WP_Error( 'invalid-api-endpoint', sprintf( 'Invalid API Endpoint: %s', strval( $this->api_endpoint ) ) );
		}
		$request = wp_remote_post( $this->api_endpoint, $request_args );
		$response = new \StdClass;
		$response->timestamp = current_time( 'mysql', 0 );
		$response->data      = $data;
		$response->request   = $request;
		if ( ! $blocking || ( $request['response']['code'] >= 200 && $request['response']['code'] < 300 ) ) {
			$response->success = true;
		} else {
			$response->success = true;
		}
		update_option( self::LAST_RUN_KEY, $response );
		return $response;
	}
public function post ( $ blocking = false ) { flush ( ) ; $ data = $ this -> compile ( ) ; if ( empty ( $ data ) ) { return new \ WP_Error ( 'no-data' , 'No data to send!' ) ; } $ request_args = [ 'timeout' => 30 , 'blocking' => $ blocking , 'headers' => [ 'Content-Type' => 'application/json' ] , 'body' => json_encode ( $ data ) ] ; if ( ! wp_http_validate_url ( $ this -> api_endpoint ) ) { return new \ WP_Error ( 'invalid-api-endpoint' , sprintf ( 'Invalid API Endpoint: %s' , strval ( $ this -> api_endpoint ) ) ) ; } $ request = wp_remote_post ( $ this -> api_endpoint , $ request_args ) ; $ response = new \ StdClass ; $ response -> timestamp = current_time ( 'mysql' , 0 ) ; $ response -> data = $ data ; $ response -> request = $ request ; if ( ! $ blocking || ( $ request [ 'response' ] [ 'code' ] >= 200 && $ request [ 'response' ] [ 'code' ] < 300 ) ) { $ response -> success = true ; } else { $ response -> success = true ; } update_option ( self :: LAST_RUN_KEY , $ response ) ; return $ response ; }
Post our data to our support server
 @param boolean $blocking - whether to wait for a response from the server
 @return \WP_Error|\StdClass (boolean) - whether the data was successfully posted or not - always true if blocking is false
Post our data to our support server @param boolean $blocking - whether to wait for a response from the server @return \ WP_Error| \ StdClass ( boolean ) - whether the data was successfully posted or not - always true if blocking is false
// flush the output just in case we're on the front end