Use PHP 7.4 featers and PHP 8 polyfills
This commit is contained in:
@@ -36,11 +36,11 @@ class Cron {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
public function init(): void {
|
||||
/*
|
||||
* Creates general schedules for general uses.
|
||||
*/
|
||||
add_action('init', array($this, 'create_schedules'));
|
||||
add_action('init', [$this, 'create_schedules']);
|
||||
|
||||
/*
|
||||
* Deals with renewals for non-auto-renewing
|
||||
@@ -50,22 +50,22 @@ class Cron {
|
||||
* The second hook adds the handler to be called on that schedule.
|
||||
* The third one deals with each membership that needs to be manually renewed.
|
||||
*/
|
||||
add_action('init', array($this, 'schedule_membership_check'));
|
||||
add_action('init', [$this, 'schedule_membership_check']);
|
||||
|
||||
add_action('wu_membership_check', array($this, 'membership_renewal_check'), 10);
|
||||
add_action('wu_membership_check', [$this, 'membership_renewal_check'], 10);
|
||||
|
||||
add_action('wu_membership_check', array($this, 'membership_trial_check'), 10);
|
||||
add_action('wu_membership_check', [$this, 'membership_trial_check'], 10);
|
||||
|
||||
add_action('wu_async_create_renewal_payment', array($this, 'async_create_renewal_payment'), 10, 2);
|
||||
add_action('wu_async_create_renewal_payment', [$this, 'async_create_renewal_payment'], 10, 2);
|
||||
|
||||
/*
|
||||
* On that same check, we'll
|
||||
* search for expired memberships
|
||||
* and mark them as such.
|
||||
*/
|
||||
add_action('wu_membership_check', array($this, 'membership_expired_check'), 20);
|
||||
add_action('wu_membership_check', [$this, 'membership_expired_check'], 20);
|
||||
|
||||
add_action('wu_async_mark_membership_as_expired', array($this, 'async_mark_membership_as_expired'), 10);
|
||||
add_action('wu_async_mark_membership_as_expired', [$this, 'async_mark_membership_as_expired'], 10);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,21 +76,21 @@ class Cron {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function create_schedules() {
|
||||
public function create_schedules(): void {
|
||||
/*
|
||||
* Hourly check
|
||||
*/
|
||||
if (wu_next_scheduled_action('wu_hourly') === false) {
|
||||
$next_hour = strtotime(gmdate('Y-m-d H:00:00', strtotime('+1 hour')));
|
||||
|
||||
wu_schedule_recurring_action($next_hour, HOUR_IN_SECONDS, 'wu_hourly', array(), 'wu_cron');
|
||||
wu_schedule_recurring_action($next_hour, HOUR_IN_SECONDS, 'wu_hourly', [], 'wu_cron');
|
||||
}
|
||||
|
||||
/*
|
||||
* Daily check
|
||||
*/
|
||||
if (wu_next_scheduled_action('wu_daily') === false) {
|
||||
wu_schedule_recurring_action(strtotime('tomorrow'), DAY_IN_SECONDS, 'wu_daily', array(), 'wu_cron');
|
||||
wu_schedule_recurring_action(strtotime('tomorrow'), DAY_IN_SECONDS, 'wu_daily', [], 'wu_cron');
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -99,7 +99,7 @@ class Cron {
|
||||
if (wu_next_scheduled_action('wu_monthly') === false) {
|
||||
$next_month = strtotime(gmdate('Y-m-01 00:00:00', strtotime('+1 month')));
|
||||
|
||||
wu_schedule_recurring_action($next_month, MONTH_IN_SECONDS, 'wu_monthly', array(), 'wu_cron');
|
||||
wu_schedule_recurring_action($next_month, MONTH_IN_SECONDS, 'wu_monthly', [], 'wu_cron');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,12 +113,12 @@ class Cron {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function schedule_membership_check() {
|
||||
public function schedule_membership_check(): void {
|
||||
|
||||
$interval = apply_filters('wu_schedule_membership_check_interval', 1 * HOUR_IN_SECONDS);
|
||||
|
||||
if (wu_next_scheduled_action('wu_membership_check') === false) {
|
||||
wu_schedule_recurring_action(time(), $interval, 'wu_membership_check', array(), 'wu_cron');
|
||||
wu_schedule_recurring_action(time(), $interval, 'wu_membership_check', [], 'wu_cron');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ class Cron {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function membership_renewal_check() {
|
||||
public function membership_renewal_check(): void {
|
||||
/*
|
||||
* Define how many days before we need to
|
||||
* create pending payments.
|
||||
@@ -140,18 +140,18 @@ class Cron {
|
||||
|
||||
$query_params = apply_filters(
|
||||
'wu_membership_renewal_check_query_params',
|
||||
array(
|
||||
[
|
||||
'auto_renew' => false,
|
||||
'status__in' => array(
|
||||
'status__in' => [
|
||||
Membership_Status::ACTIVE,
|
||||
),
|
||||
'date_query' => array(
|
||||
],
|
||||
'date_query' => [
|
||||
'column' => 'date_expiration',
|
||||
'before' => "+{$days_before_expiring} days",
|
||||
'after' => 'yesterday',
|
||||
'inclusive' => true,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
$days_before_expiring
|
||||
);
|
||||
|
||||
@@ -164,9 +164,9 @@ class Cron {
|
||||
foreach ($memberships as $membership) {
|
||||
wu_enqueue_async_action(
|
||||
'wu_async_create_renewal_payment',
|
||||
array(
|
||||
[
|
||||
'membership_id' => $membership->get_id(),
|
||||
),
|
||||
],
|
||||
'wu_cron_check'
|
||||
);
|
||||
}
|
||||
@@ -181,21 +181,21 @@ class Cron {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function membership_trial_check() {
|
||||
public function membership_trial_check(): void {
|
||||
|
||||
$query_params = apply_filters(
|
||||
'wu_membership_trial_check_query_params',
|
||||
array(
|
||||
[
|
||||
'auto_renew' => false,
|
||||
'status__in' => array(
|
||||
'status__in' => [
|
||||
Membership_Status::TRIALING,
|
||||
),
|
||||
'date_query' => array(
|
||||
],
|
||||
'date_query' => [
|
||||
'column' => 'date_trial_end',
|
||||
'before' => '-3 hours',
|
||||
'inclusive' => true,
|
||||
),
|
||||
)
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$memberships = wu_get_memberships($query_params);
|
||||
@@ -207,10 +207,10 @@ class Cron {
|
||||
foreach ($memberships as $membership) {
|
||||
wu_enqueue_async_action(
|
||||
'wu_async_create_renewal_payment',
|
||||
array(
|
||||
[
|
||||
'membership_id' => $membership->get_id(),
|
||||
'trial' => true,
|
||||
),
|
||||
],
|
||||
'wu_cron_check'
|
||||
);
|
||||
}
|
||||
@@ -255,16 +255,16 @@ class Cron {
|
||||
$saved = $membership->save();
|
||||
|
||||
$payment_url = add_query_arg(
|
||||
array(
|
||||
[
|
||||
'payment' => $new_payment->get_hash(),
|
||||
),
|
||||
],
|
||||
wu_get_registration_url()
|
||||
);
|
||||
|
||||
$payload = array_merge(
|
||||
array(
|
||||
[
|
||||
'default_payment_url' => $payment_url,
|
||||
),
|
||||
],
|
||||
wu_generate_event_payload('payment', $new_payment),
|
||||
wu_generate_event_payload('membership', $membership),
|
||||
wu_generate_event_payload('customer', $membership->get_customer())
|
||||
@@ -284,7 +284,7 @@ class Cron {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function membership_expired_check() {
|
||||
public function membership_expired_check(): void {
|
||||
/*
|
||||
* Define how many grace period
|
||||
* days we allow for our customers.
|
||||
@@ -293,19 +293,19 @@ class Cron {
|
||||
|
||||
$query_params = apply_filters(
|
||||
'wu_membership_expired_check_query_params',
|
||||
array(
|
||||
[
|
||||
'auto_renew' => false,
|
||||
'status__in' => array(
|
||||
'status__in' => [
|
||||
Membership_Status::ACTIVE,
|
||||
Membership_Status::ON_HOLD,
|
||||
),
|
||||
'date_expiration__not_in' => array(null, '0000-00-00 00:00:00'),
|
||||
'date_query' => array(
|
||||
],
|
||||
'date_expiration__not_in' => [null, '0000-00-00 00:00:00'],
|
||||
'date_query' => [
|
||||
'column' => 'date_expiration',
|
||||
'before' => "-{$grace_period_days} days",
|
||||
'inclusive' => true,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
$grace_period_days
|
||||
);
|
||||
|
||||
@@ -318,9 +318,9 @@ class Cron {
|
||||
foreach ($memberships as $membership) {
|
||||
wu_enqueue_async_action(
|
||||
'wu_async_mark_membership_as_expired',
|
||||
array(
|
||||
[
|
||||
'membership_id' => $membership->get_id(),
|
||||
),
|
||||
],
|
||||
'wu_cron_check'
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user