From c528a1003760f2c181e103771801bec8915eb820 Mon Sep 17 00:00:00 2001 From: Paul Kirby Date: Mon, 15 Oct 2018 13:20:29 -0500 Subject: [PATCH] Working on WP-Cron implementation --- classes/LBRY_Admin.php | 42 ++++++++++++++++++++++++++++++++++++++++++ classes/lbrypress.php | 3 +++ 2 files changed, 45 insertions(+) diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 8ca99b0..0b910ae 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -17,6 +17,31 @@ class LBRY_Admin add_action('admin_menu', array($this, 'create_options_page')); add_action('admin_init', array($this, 'page_init')); add_action('admin_post_lbry_add_channel', array($this, 'add_channel')); + + add_filter('cron_schedules', 'lbry_add_cron_interval'); + + // function lbry_add_cron_interval($schedules) + // { + // $schedules['five_seconds'] = array( + // 'interval' => 5, + // 'display' => esc_html__('Every Five Seconds'), + // ); + // + // return $schedules; + // } + + // if (! wp_next_scheduled('lbry_wallet_balance_hook')) { + // error_log('scheduling'); + // wp_schedule_event(time(), 'five_seconds', 'lbry_wallet_balance_hook'); + // } + + add_action('lbry_wallet_balance_hook', array($this, 'wallet_balance_cron')); + + + + error_log(print_r(_get_cron_array(), true)); + do_action('lbry_wallet_balance_hook', array(LBRY())); + error_log('next: ' . wp_next_scheduled('lbry_wallet_balance_hook')); } /** @@ -204,4 +229,21 @@ class LBRY_Admin wp_safe_redirect($redirect_url); exit(); } + + public static function wallet_balance_cron($lbry) + { + $balance = 2; // LBRY()->daemon->wallet_balance(); + // + if ($balance < 20000) { + $lbry->notice->set_notice('error', 'Your account balance is low, please add LBC to your account to continue publishing to the LBRY Network', true); + } + error_log('Balance: ' . $balance); + } + + public function wallet_balance_deactivate() + { + $timestamp = wp_next_scheduled('lbry_wallet_balance_hook'); + wp_unschedule_event($timestamp, 'lbry_wallet_balance_hook'); + error_log('Disabled: ' . $timestamp); + } } diff --git a/classes/lbrypress.php b/classes/lbrypress.php index c228699..4c83af1 100644 --- a/classes/lbrypress.php +++ b/classes/lbrypress.php @@ -108,6 +108,7 @@ class LBRYPress 'license2' => 'License 2', 'license3' => 'License 3' )); + $this->define('LBRY_MIN_BALANCE', 20); } /** @@ -191,6 +192,8 @@ class LBRYPress */ public function deactivate() { + // Deactivate Wallet Balance cron job + $this->admin->wallet_balance_deactivate(); error_log('Deactivated'); }