* @return A standard WordPress error. */ public function __clone() { // Cloning instances of the class is forbidden _doing_it_wrong( __FUNCTION__, esc_html( __( 'Cheating, huh ?', 'affilizz' ) ), '6.0' ); } /** * Creates a class singleton. * @author Affilizz * @return Object An instance of the current class. */ public static function get_instance() { if ( ! isset( self::$instance ) ) { self::$instance = new static(); } return self::$instance; } /** * Retrieves a distant URL after passing the necessary headers. * @author Affilizz * @param $url The URL to retrieve. * @param $headers The custom headers (for APIs for example). * @return $data The return from the distant URL. */ public static function get_distant_url( $url = '', $headers = null ) { $args = array( 'timeout' => \Affilizz\Core::get_api_http_timeout(), ); if ( ! empty( $headers ) ) { $args['headers'] = $headers; } return (string) wp_remote_retrieve_body( wp_remote_get( $url, $args ) ); } /** * Posts to a distant URL after passing the necessary headers. * @author Affilizz * @param $url The URL to retrieve. * @param $headers The custom headers (for APIs for example). * @return $data The return from the distant URL. */ public static function post_to_distant_url( $url = '', $headers = null, $body = array() ) { $timeout = \Affilizz\Core::get_api_http_timeout(); $args = array( 'body' => $body, 'timeout' => $timeout, 'redirection' => '5', 'httpversion' => '1.0', ); if ( ! empty( $headers ) ) { $args['headers'] = $headers; } return wp_remote_retrieve_body( wp_remote_post( $url, $args ) ); } }