PluginProbe
Migrate to WordPress.com / 6.72
Migrate to WordPress.com v6.72
6.72 6.65 trunk 5.72 5.81 5.88
wpcom-migration / wp_api.php

wp_api.php in Migrate to WordPress.com 6.72, at wp_api.php

43 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('WPCOMWPAPI')) :
5 class WPCOMWPAPI {
6 public $settings;
7
8 public function __construct($settings) {
9 $this->settings = $settings;
10 }
11
12 public function pingbv($method, $body, $public = false) {
13 if ($public) {
14 return $this->do_request($method, $body, $public);
15 } else {
16 $api_public_key = $this->settings->getOption('bvApiPublic');
17 if (!empty($api_public_key) && (strlen($api_public_key) >= 32)) {
18 return $this->do_request($method, $body, $api_public_key);
19 }
20 }
21 }
22
23 public function do_request($method, $body, $pubkey) {
24 $account = WPCOMAccount::find($this->settings, $pubkey);
25 if (isset($account)) {
26 $url = $account->authenticatedUrl($method);
27 return $this->http_request($url, $body);
28 }
29 }
30
31 public function http_request($url, $body, $headers = array()) {
32 $_body = array(
33 'method' => 'POST',
34 'timeout' => 15,
35 'body' => $body
36 );
37 if (!empty($headers)) {
38 $_body['headers'] = $headers;
39 }
40 return wp_remote_post($url, $_body);
41 }
42 }
43 endif;