-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocument_count.php
More file actions
29 lines (23 loc) · 914 Bytes
/
document_count.php
File metadata and controls
29 lines (23 loc) · 914 Bytes
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
<?php
namespace Openpublishing\DocumentCount;
function update() {
$HOST = 'https://' . get_option('openpublishing_api_host');
$url = $HOST . '/rpc/v2/brand_statistics?method=document_count&brand_name=' . get_option('openpublishing_brand_name');
$count_formatted = '0';
$response = \Openpublishing\Fetch\openpublishing_get_with_auth($url, true);
if ( is_wp_error( $response ) ) {
error_log("[ERROR] " . $response->get_error_message() . ' ' . $url, 0);
}
else {
$status = wp_remote_retrieve_response_code($response);
if (200 == $status) {
$number = json_decode(wp_remote_retrieve_body($response));
$count_formatted = number_format($number, 0, ',', '.');
}
else {
error_log("[ERROR]" . $url .' status - '. $status);
}
}
update_option('openpublishing_document_count', $count_formatted);
}
?>