diff --git a/public_html/wp-content/mu-plugins/quickbooks/quickbooks.php b/public_html/wp-content/mu-plugins/quickbooks/quickbooks.php index 034617428..bba205eff 100644 --- a/public_html/wp-content/mu-plugins/quickbooks/quickbooks.php +++ b/public_html/wp-content/mu-plugins/quickbooks/quickbooks.php @@ -11,6 +11,28 @@ require_once PLUGIN_DIR . '/includes/admin.php'; add_filter( 'wordcamp_qbo_client_config', __NAMESPACE__ . '\set_client_config' ); +add_action( 'init', __NAMESPACE__ . '\check_qbo_connection_cron' ); +add_action( 'check_qbo_connection_action', __NAMESPACE__ . '\check_qbo_connection' ); + +/** + * Setup hourly qbo connection task. + */ +function check_qbo_connection_cron() { + if ( ! wp_next_scheduled( 'check_qbo_connection_action' ) ) { + wp_schedule_event( time(), 'hourly', 'check_qbo_connection_action' ); + } +} + +/** + * Monitors the Quickbooks connection, and sends message to Slack if not connected. + */ +function check_qbo_connection() { + $client = get_client(); + + if ( ! $client->has_valid_token() && function_exists( 'slack_dm' ) ) { + slack_dm( 'QBO token invalid. Visit to check connection.', 'dotorg' ); + } +} /** * Filter: Add client configuration details depending on the environment.