Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/paid-memberships-pro/includes/crons.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + /**
3 + * Functionality related to cron operations.
4 + *
5 + * The crons themselves are located in /scheduled/crons.php and in corresponding Add-Ons.
6 + */
7 +
8 + /**
9 + * Get the list of registered crons for Paid Memberships Pro.
10 + *
11 + * @since 2.8
12 + *
13 + * @return array The list of registered crons for Paid Memberships Pro.
14 + */
15 + function pmpro_get_crons() {
16 +
17 + /**
18 + * Allow filtering registered crons for Paid Memberships Pro.
19 + *
20 + * @since 2.8
21 + *
22 + * @param array $crons The list of registered crons for Paid Memberships Pro.
23 + */
24 + $crons = (array) apply_filters( 'pmpro_registered_crons', array() );
25 +
26 + // Set up the default information for each cron if not set.
27 + foreach ( $crons as $hook => $cron ) {
28 + if ( empty( $cron['timestamp'] ) ) {
29 + $cron['timestamp'] = current_time( 'timestamp' );
30 + }
31 +
32 + if ( empty( $cron['interval'] ) ) {
33 + $cron['interval'] = 'hourly';
34 + }
35 +
36 + if ( empty( $cron['args'] ) ) {
37 + $cron['args'] = [];
38 + }
39 +
40 + $crons[ $hook ] = $cron;
41 + }
42 +
43 + return $crons;
44 + }
45 +
46 + /**
47 + * Maybe schedule our registered crons.
48 + *
49 + * @since 2.8
50 + */
51 + function pmpro_maybe_schedule_crons() {
52 + $crons = pmpro_get_crons();
53 +
54 + foreach ( $crons as $hook => $cron ) {
55 + pmpro_maybe_schedule_event( $cron['timestamp'], $cron['interval'], $hook, $cron['args'] );
56 + }
57 + }
58 +
59 + /**
60 + * Clear all PMPro related crons.
61 + * @since 2.8.1
62 + */
63 + function pmpro_clear_crons() {
64 + $crons = array_keys( pmpro_get_crons() );
65 + foreach( $crons as $cron ) {
66 + wp_clear_scheduled_hook( $cron );
67 + }
68 + }
69 +
70 + /**
71 + * Handle rescheduling Paid Memberships Pro crons when checking for ready cron tasks.
72 + *
73 + * @since 2.8
74 + *
75 + * @param null|array[] $pre Array of ready cron tasks to return instead. Default null
76 + * to continue using results from _get_cron_array().
77 + *
78 + * @return null|array[] Array of ready cron tasks to return instead. Default null
79 + * to continue using results from _get_cron_array().
80 + */
81 + function pmpro_handle_schedule_crons_on_cron_ready_check( $pre ) {
82 + pmpro_maybe_schedule_crons();
83 +
84 + return $pre;
85 + }
86 +
87 + add_filter( 'pre_get_ready_cron_jobs', 'pmpro_handle_schedule_crons_on_cron_ready_check' );
88 +
89 + /**
90 + * Schedule a periodic event unless one with the same hook is already scheduled.
91 + *
92 + * @since 2.8
93 + *
94 + * @see wp_schedule_event()
95 + * @link https://developer.wordpress.org/reference/functions/wp_schedule_event/
96 + *
97 + * @param int $timestamp Unix timestamp (UTC) for when to next run the event.
98 + * @param string $recurrence How often the event should subsequently recur.
99 + * See wp_get_schedules() for accepted values.
100 + * @param string $hook Action hook to execute when the event is run.
101 + * @param array $args Optional. Array containing arguments to pass to the
102 + * hook's callback function. Each value in the array
103 + * is passed to the callback as an individual parameter.
104 + * The array keys are ignored. Default empty array.
105 + *
106 + * @return bool|WP_Error True when an event is scheduled, WP_Error on failure, and false if the event was already scheduled.
107 + */
108 + function pmpro_maybe_schedule_event( $timestamp, $recurrence, $hook, $args = [] ) {
109 + $next = wp_next_scheduled( $hook, $args );
110 +
111 + if ( empty( $next ) ) {
112 + return wp_schedule_event( $timestamp, $recurrence, $hook, $args, true );
113 + }
114 +
115 + return false;
116 + }
117 +