PluginProbe ʕ •ᴥ•ʔ
Rank Math SEO – AI SEO Tools to Dominate SEO Rankings / 1.0.267
Rank Math SEO – AI SEO Tools to Dominate SEO Rankings v1.0.267
1.0.272 1.0.271 1.0.271.1 1.0.270 1.0.269 trunk 1.0.216 1.0.217 1.0.218 1.0.219 1.0.220 1.0.221 1.0.222 1.0.223 1.0.224 1.0.225 1.0.226 1.0.227 1.0.227.1 1.0.228 1.0.229 1.0.230 1.0.231 1.0.232 1.0.233 1.0.234 1.0.234.1 1.0.235 1.0.236 1.0.237 1.0.238 1.0.239 1.0.240 1.0.241 1.0.242 1.0.243 1.0.244 1.0.245 1.0.246 1.0.247 1.0.248 1.0.249 1.0.250 1.0.251 1.0.251.1 1.0.252 1.0.252.1 1.0.253 1.0.254 1.0.255 1.0.256 1.0.257 1.0.258 1.0.259 1.0.259.1 1.0.260 1.0.261 1.0.262 1.0.263 1.0.264 1.0.264.1 1.0.265 1.0.266 1.0.266.1 1.0.267 1.0.268
seo-by-rank-math / vendor / wp-media / wp-mixpanel / src / WPConsumer.php
seo-by-rank-math / vendor / wp-media / wp-mixpanel / src Last commit date
Classes 10 months ago Optin.php 9 months ago Tracking.php 8 months ago TrackingPlugin.php 7 months ago WPConsumer.php 10 months ago
WPConsumer.php
86 lines
1 <?php
2 declare(strict_types=1);
3
4 namespace WPMedia\Mixpanel;
5
6 use WPMedia_ConsumerStrategies_AbstractConsumer;
7
8 /**
9 * Consumes messages and sends them to a host/endpoint using WordPress's HTTP API
10 */
11 class WPConsumer extends WPMedia_ConsumerStrategies_AbstractConsumer {
12
13 /**
14 * The host to connect to (e.g. api.mixpanel.com)
15 *
16 * @var string
17 */
18 protected $host;
19
20 /**
21 * The host-relative endpoint to write to (e.g. /engage)
22 *
23 * @var string
24 */
25 protected $endpoint;
26
27 /**
28 * The maximum number of seconds to allow the call to execute. Default is 30 seconds.
29 *
30 * @var int
31 */
32 protected $timeout;
33
34 /**
35 * The protocol to use for the cURL connection
36 *
37 * @var string
38 */
39 protected $protocol;
40
41 /**
42 * Creates a new WPConsumer and assigns properties from the $options array
43 *
44 * @param array{host:string, endpoint:string, timeout?: int, use_ssl?: bool} $options Options for the consumer.
45 */
46 public function __construct( $options ) {
47 parent::__construct( $options );
48
49 $this->host = $options['host'];
50 $this->endpoint = $options['endpoint'];
51 $this->timeout = isset( $options['timeout'] ) ? $options['timeout'] : 30;
52 $this->protocol = isset( $options['use_ssl'] ) && ( true === $options['use_ssl'] ) ? 'https' : 'http';
53 }
54
55 /**
56 * Send post request to the given host/endpoint using WordPress's HTTP API
57 *
58 * @param mixed[] $batch Batch of data to send to mixpanel.
59 *
60 * @return bool
61 */
62 public function persist( $batch ) {
63 if ( count( $batch ) <= 0 ) {
64 return true;
65 }
66
67 $url = $this->protocol . '://' . $this->host . $this->endpoint;
68 $data = 'data=' . $this->_encode( $batch );
69
70 $response = wp_remote_post(
71 $url,
72 [
73 'timeout' => $this->timeout,
74 'body' => $data,
75 ]
76 );
77
78 if ( is_wp_error( $response ) ) {
79 $this->_handleError( $response->get_error_code(), $response->get_error_message() );
80 return false;
81 }
82
83 return true;
84 }
85 }
86