PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.6.8
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.6.8
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.8, at includes/class-charitable-cron.php

112 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) 2019, 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' ) ) { exit; }
14
15 if ( ! class_exists( 'Charitable_Cron' ) ) :
16
17 /**
18 * Charitable_Cron
19 *
20 * @since 1.1.0
21 */
22 class Charitable_Cron {
23
24 /**
25 * The single instance of this class.
26 *
27 * @since 1.1.0
28 *
29 * @var Charitable_Cron|null
30 */
31 private static $instance = null;
32
33 /**
34 * Returns and/or create the single instance of this class.
35 *
36 * @since 1.2.0
37 *
38 * @return Charitable_Cron
39 */
40 public static function get_instance() {
41 if ( is_null( self::$instance ) ) {
42 self::$instance = new self();
43 }
44
45 return self::$instance;
46 }
47
48 /**
49 * Create class object.
50 *
51 * @since 1.1.0
52 */
53 private function __construct() {
54 add_action( 'charitable_daily_scheduled_events', array( $this, 'check_expired_campaigns' ) );
55 }
56
57 /**
58 * Schedule Charitable event hooks.
59 *
60 * @since 1.1.0
61 *
62 * @return boolean
63 */
64 public static function schedule_events() {
65 $ret = false;
66
67 if ( ! wp_next_scheduled( 'charitable_daily_scheduled_events' ) ) {
68 $ret = wp_schedule_event( time(), 'daily', 'charitable_daily_scheduled_events' );
69 }
70
71 return false !== $ret;
72 }
73
74 /**
75 * Check for expired campaigns.
76 *
77 * @since 1.1.0
78 *
79 * @return void
80 */
81 public function check_expired_campaigns() {
82 $yesterday = date( 'Y-m-d H:i:s', strtotime( '-24 hours' ) );
83
84 $args = array(
85 'fields' => 'ids',
86 'post_type' => Charitable::CAMPAIGN_POST_TYPE,
87 'posts_per_page' => -1,
88 'post_status' => 'publish',
89 'meta_query' => array(
90 array(
91 'key' => '_campaign_end_date',
92 'value' => array( $yesterday, date( 'Y-m-d H:i:s' ) ),
93 'compare' => 'BETWEEN',
94 'type' => 'datetime'
95 )
96 )
97 );
98
99 $campaigns = get_posts( $args );
100
101 if ( empty( $campaigns ) ) {
102 return;
103 }
104
105 foreach ( $campaigns as $campaign_id ) {
106 do_action( 'charitable_campaign_end', $campaign_id );
107 }
108 }
109 }
110
111 endif;
112