PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
← All changes | libraries/freemius/includes/sdk/FreemiusWordPress.php +46 -16 2.0.4 → 3.4 View file →
@@ -164,8 +164,17 @@
164 164 self::$_protocol = 'http';
165 165 }
166 166
167 167 /**
168 + * Sets API connection protocol to HTTPS.
169 + *
170 + * @since 2.5.4
171 + */
172 + public static function SetHttps() {
173 + self::$_protocol = 'https';
174 + }
175 +
176 + /**
168 177 * @since 1.0.4
169 178 *
170 179 * @return bool
171 180 */
@@ -305,9 +314,9 @@
305 314 $bt = debug_backtrace();
306 315
307 316 $start = microtime( true );
308 317
309 - $response = wp_remote_request( $pUrl, $pWPRemoteArgs );
318 + $response = self::RemoteRequest( $pUrl, $pWPRemoteArgs );
310 319
311 320 if ( FS_API__LOGGER_ON ) {
312 321 $end = microtime( true );
313 322
@@ -333,8 +342,33 @@
333 342 return $response;
334 343 }
335 344
336 345 /**
346 + * @author Leo Fajardo (@leorw)
347 + *
348 + * @param string $pUrl
349 + * @param array $pWPRemoteArgs
350 + *
351 + * @return array|WP_Error The response array or a WP_Error on failure.
352 + */
353 + static function RemoteRequest( $pUrl, $pWPRemoteArgs ) {
354 + $response = wp_remote_request( $pUrl, $pWPRemoteArgs );
355 +
356 + if (
357 + is_array( $response ) &&
358 + (
359 + empty( $response['headers'] ) ||
360 + empty( $response['headers']['x-api-server'] )
361 + )
362 + ) {
363 + // API is considered blocked if the response doesn't include the `x-api-server` header. When there's no error but this header doesn't exist, the response is usually not in the expected form (e.g., cannot be JSON-decoded).
364 + $response = new WP_Error( 'api_blocked', htmlentities( $response['body'] ) );
365 + }
366 +
367 + return $response;
368 + }
369 +
370 + /**
337 371 * @return array
338 372 */
339 373 static function GetLogger() {
340 374 return self::$_logger;
@@ -373,9 +407,9 @@
373 407
374 408 $pWPRemoteArgs = array(
375 409 'method' => strtoupper( $pMethod ),
376 410 'connect_timeout' => 10,
377 - 'timeout' => 60,
411 + 'timeout' => WP_FS__API_TIMEOUT,
378 412 'follow_redirects' => true,
379 413 'redirection' => 5,
380 414 'user-agent' => $user_agent,
381 415 'blocking' => true,
@@ -438,10 +472,14 @@
438 472 * @author Vova Feldman (@svovaf)
439 473 */
440 474 if ( filter_var( $matches[1], FILTER_VALIDATE_IP ) ) {
441 475 if ( strlen( inet_pton( $matches[1] ) ) === 16 ) {
442 -// error_log('Invalid IPv6 configuration on server, Please disable or get native IPv6 on your server.');
443 - // Hook to an action triggered just before cURL is executed to resolve the IP version to v4.
476 + /**
477 + * error_log('Invalid IPv6 configuration on server, Please disable or get native IPv6 on your server.');
478 + * Hook to an action triggered just before cURL is executed to resolve the IP version to v4.
479 + *
480 + * @phpstan-ignore-next-line
481 + */
444 482 add_action( 'http_api_curl', 'Freemius_Api_WordPress::CurlResolveToIPv4', 10, 1 );
445 483
446 484 // Re-run request.
447 485 $result = self::ExecuteRequest( $request_url, $pWPRemoteArgs );
@@ -543,27 +581,19 @@
543 581 #region Connectivity Test
544 582 #----------------------------------------------------------------------------------
545 583
546 584 /**
547 - * If successful connectivity to the API endpoint using ping.json endpoint.
585 + * This method exists only for backward compatibility to prevent a fatal error from happening when called from an outdated piece of code.
548 586 *
549 - * - OR -
550 - *
551 - * Validate if ping result object is valid.
552 - *
553 587 * @param mixed $pPong
554 588 *
555 589 * @return bool
556 590 */
557 591 public static function Test( $pPong = null ) {
558 - $pong = is_null( $pPong ) ?
559 - self::Ping() :
560 - $pPong;
561 -
562 592 return (
563 - is_object( $pong ) &&
564 - isset( $pong->api ) &&
565 - 'pong' === $pong->api
593 + is_object( $pPong ) &&
594 + isset( $pPong->api ) &&
595 + 'pong' === $pPong->api
566 596 );
567 597 }
568 598
569 599 /**