-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend-post-notifications.php
More file actions
55 lines (42 loc) · 1.68 KB
/
send-post-notifications.php
File metadata and controls
55 lines (42 loc) · 1.68 KB
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
<?php
function rsscloud_send_post_notifications( $rss2_url = false ) {
if ( $rss2_url === false ) {
$rss2_url = get_bloginfo( 'rss2_url' );
if ( defined( 'RSSCLOUD_FEED_URL' ) )
$rss2_url = RSSCLOUD_FEED_URL;
}
do_action( 'rsscloud_feed_notifications', $rss2_url );
$notify = rsscloud_get_hub_notifications( );
if ( !is_array( $notify ) )
$notify = array( );
$need_update = false;
foreach ( $notify[$rss2_url] as $notify_url => $n ) {
if ( $n['status'] != 'active' )
continue;
if ( $n['protocol'] == 'http-post' ) {
$url = parse_url( $notify_url );
$port = 80;
if ( !empty( $url['port'] ) )
$port = $url['port'];
$result = wp_safe_remote_post( $notify_url, array( 'method' => 'POST', 'timeout' => RSSCLOUD_HTTP_TIMEOUT, 'user-agent' => RSSCLOUD_USER_AGENT, 'port' => $port, 'body' => array( 'url' => $rss2_url ) ) );
do_action( 'rsscloud_send_notification' );
if ( !is_wp_error( $result ) )
$status_code = (int) $result['response']['code'];
if ( is_wp_error( $result ) || ( $status_code < 200 || $status_code > 299 ) ) {
do_action( 'rsscloud_notify_failure' );
$notify[$rss2_url][$notify_url]['failure_count']++;
if ( $notify[$rss2_url][$notify_url]['failure_count'] > RSSCLOUD_MAX_FAILURES ) {
do_action( 'rsscloud_suspend_notification_url' );
$notify[$rss2_url][$notify_url]['status'] = 'suspended';
}
$need_update = true;
} elseif ( $notify[$rss2_url][$notify_url]['failure_count'] > 0 ) {
do_action( 'rsscloud_reset_failure_count' );
$notify[$rss2_url][$notify_url]['failure_count'] = 0;
$need_update = true;
}
}
} // foreach
if ( $need_update )
rsscloud_update_hub_notifications( $notify );
}