WC_Zapier_Admin_System_Status.php
3.64 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
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
100
101
102
103
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Adds various debugging information to the WooCommerce System Status screen
*
* Class WC_Zapier_Admin_System_Status
*/
class WC_Zapier_Admin_System_Status {
public function __construct() {
add_filter( 'woocommerce_debug_posting', array( $this, 'woocommerce_debug_posting' ) );
}
public function woocommerce_debug_posting( $posting ) {
// Number of active Zapier Feeds
$feeds = WC_Zapier_Feed_Factory::get_enabled_feeds();
$num_feeds = sizeof( $feeds );
$posting['zapier_feeds'] = array(
'name' => __( 'Zapier Integration - Active Feeds', 'wc_zapier' )
, 'note' => sprintf( _n( '%d active Zapier Feed.', '%d active Zapier Feeds.', $num_feeds, 'wc_zapier' ), $num_feeds )
, 'success' => $num_feeds ? true : false
);
// Pending Cron Tasks
$cron_array = _get_cron_array();
$num_cron_tasks = 0;
foreach ( (array) $cron_array as $time => $cron ) {
if ( 'version' == $time ) continue;
foreach ( (array) $cron as $hook => $task ) {
foreach ( (array) $task as $id => $details ) {
if ( strpos( $hook, 'zapier_triggered_' ) !== false ) {
$num_cron_tasks ++;
}
}
}
}
$note = '';
$success = true;
if ( 0 == $num_cron_tasks ) {
$note = sprintf( __( '%d pending Zapier cron tasks.', 'wc_zapier' ), $num_cron_tasks );
} else if ( 1 == $num_cron_tasks ) {
// 1 pending cron task.
$note = sprintf( __( '%1$d pending Zapier cron task. Your WordPress cron may not be working correctly. Please see <a href="%2$s">here for troubleshooting steps</a>.', 'wc_zapier' ), $num_cron_tasks, esc_url( WC_Zapier::documentation_url . '#troubleshooting' ) ) ;
$success = false;
} else {
// 1 or more pending cron tasks.
$note = sprintf( __( '%1$d pending Zapier cron tasks. Your WordPress cron may not be working correctly. Please see <a href="%2$s">here for troubleshooting steps</a>.', 'wc_zapier' ), $num_cron_tasks, esc_url( WC_Zapier::documentation_url . '#troubleshooting' ) ) ;
$success = false;
}
$posting['zapier_cron_tasks'] = array(
'name' => __( 'Zapier Integration - Cron Tasks', 'wc_zapier' )
, 'note' => $note
, 'success' => $success
);
// Send sample data to each active feed
$i = 0;
foreach ( $feeds as $feed ) {
$i++;
$result = $feed->trigger()->send_sample_data_payload( $feed );
$note = '';
if ( true === $result ) {
$note = sprintf( __( 'Successfully sent sample data to %s.', 'wc_zapier' ), esc_url( $feed->webhook_url() ) );
} else {
$note = sprintf( __( 'Error sending sample data to %1$s. Error message: %2$s. Please see <a href="%3$s">here for troubleshooting steps</a>.', 'wc_zapier' ), esc_url( $feed->webhook_url() ), esc_html( $result ), esc_url( WC_Zapier::documentation_url . '#troubleshooting' ) );
$result = false;
}
$posting['zapier_' . $feed->title() . 'feed_name'] = array(
'name' => sprintf( __( 'Zapier Feed #%d Name', 'wc_zapier' ), $i )
, 'note' => $feed->title()
, 'success' => true
);
$posting['zapier_' . $feed->title() . 'webhook_url'] = array(
'name' => sprintf( __( 'Zapier Feed #%d Webhook URL', 'wc_zapier' ), $i )
, 'note' => $feed->webhook_url()
, 'success' => true
);
$posting['zapier_' . $feed->title() . 'trigger'] = array(
'name' => sprintf( __( 'Zapier Feed #%d Trigger', 'wc_zapier' ), $i )
, 'note' => $feed->trigger()->get_trigger_title()
, 'success' => true
);
$posting['zapier_' . $feed->title() . 'result'] = array(
'name' => sprintf( __( 'Zapier Feed #%d Test Result', 'wc_zapier' ), $i )
, 'note' => $note
, 'success' => $result
);
}
return $posting;
}
}