PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.6.31
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.6.31
1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 1.8.0 All 210 releases
charitable / includes / class-charitable-cron.php

class-charitable-cron.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.6.31, at includes/class-charitable-cron.php

114 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Events
4 *
5 * @package Charitable/Classes/Charitable_Cron
6 * @version 1.1.0
7 * @author Eric Daams
8 * @copyright Copyright (c) 2020, Studio 164a
9 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Cron' ) ) :
18
19 /**
20 * Charitable_Cron
21 *
22 * @since 1.1.0
23 */
24 class Charitable_Cron {
25
26 /**
27 * The single instance of this class.
28 *
29 * @since 1.1.0
30 *
31 * @var Charitable_Cron|null
32 */
33 private static $instance = null;
34
35 /**
36 * Returns and/or create the single instance of this class.
37 *
38 * @since 1.2.0
39 *
40 * @return Charitable_Cron
41 */
42 public static function get_instance() {
43 if ( is_null( self::$instance ) ) {
44 self::$instance = new self();
45 }
46
47 return self::$instance;
48 }
49
50 /**
51 * Create class object.
52 *
53 * @since 1.1.0
54 */
55 private function __construct() {
56 add_action( 'charitable_daily_scheduled_events', array( $this, 'check_expired_campaigns' ) );
57 }
58
59 /**
60 * Schedule Charitable event hooks.
61 *
62 * @since 1.1.0
63 *
64 * @return boolean
65 */
66 public static function schedule_events() {
67 $ret = false;
68
69 if ( ! wp_next_scheduled( 'charitable_daily_scheduled_events' ) ) {
70 $ret = wp_schedule_event( time(), 'daily', 'charitable_daily_scheduled_events' );
71 }
72
73 return false !== $ret;
74 }
75
76 /**
77 * Check for expired campaigns.
78 *
79 * @since 1.1.0
80 *
81 * @return void
82 */
83 public function check_expired_campaigns() {
84 $yesterday = date( 'Y-m-d H:i:s', strtotime( '-24 hours' ) );
85
86 $args = array(
87 'fields' => 'ids',
88 'post_type' => Charitable::CAMPAIGN_POST_TYPE,
89 'posts_per_page' => -1,
90 'post_status' => 'publish',
91 'meta_query' => array(
92 array(
93 'key' => '_campaign_end_date',
94 'value' => array( $yesterday, date( 'Y-m-d H:i:s' ) ),
95 'compare' => 'BETWEEN',
96 'type' => 'datetime'
97 )
98 )
99 );
100
101 $campaigns = get_posts( $args );
102
103 if ( empty( $campaigns ) ) {
104 return;
105 }
106
107 foreach ( $campaigns as $campaign_id ) {
108 do_action( 'charitable_campaign_end', $campaign_id );
109 }
110 }
111 }
112
113 endif;
114