This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-wporg-api.php
99 lines (76 loc) · 1.73 KB
/
wp-wporg-api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* WP WordPress.org API (https://codex.wordpress.org/WordPress.org_API)
*
* @package WP-WpOrgAPI-API
*/
/* Exit if accessed directly. */
if ( ! defined( 'ABSPATH' ) ) { exit; }
/* Check if class exists. */
if ( ! class_exists( 'WpOrgAPI' ) ) {
/**
* WpOrgAPI class.
*/
class WpOrgAPI {
/**
* URL to the API.
*
* @var string
*/
private $base_uri = 'https://api.wordpress.org';
/**
* __construct function.
*
* @access public
* @return void
*/
public function __construct() {
}
/**
* Fetch the request from the API.
*
* @access private
* @param mixed $request Request URL.
* @return $body Body.
*/
private function fetch( $request ) {
$response = wp_remote_get( $request );
$code = wp_remote_retrieve_response_code( $response );
if ( 200 !== $code ) {
return new WP_Error( 'response-error', sprintf( __( 'Server response code: %d', 'text-domain' ), $code ) );
}
$body = wp_remote_retrieve_body( $response );
return json_decode( $body );
}
/**
* get_stats_wp_versions function.
*
* @access public
* @return void
*/
public function get_stats_wp_versions() {
$request = $this->base_uri . '/stats/wordpress/1.0/';
return $this->fetch( $request );
}
/**
* get_stats_wp_php_versions function.
*
* @access public
* @return void
*/
public function get_stats_wp_php_versions() {
$request = $this->base_uri . '/stats/php/1.0/';
return $this->fetch( $request );
}
/**
* get_stats_wp_mysql_versions function.
*
* @access public
* @return void
*/
public function get_stats_wp_mysql_versions() {
$request = $this->base_uri . '/stats/mysql/1.0/';
return $this->fetch( $request );
}
}
}