PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.14
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.14
1.8.13.1 1.8.13 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 All 212 releases
charitable / includes / campaigns / charitable-campaign-functions.php

charitable-campaign-functions.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.14, at includes/campaigns/charitable-campaign-functions.php

183 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Campaign Functions.
4 *
5 * Campaign related functions.
6 *
7 * @package Charitable/Functions/Campaign
8 * @author David Bisset
9 * @copyright Copyright (c) 2022, WP Charitable LLC
10 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
11 * @since 1.0.0
12 * @version 1.6.54
13 */
14
15 // Exit if accessed directly.
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 }
19
20 /**
21 * Returns the given campaign.
22 *
23 * @since 1.0.0
24 *
25 * @param int $campaign_id The campaign ID.
26 * @return Charitable_Campaign
27 */
28 function charitable_get_campaign( $campaign_id ) {
29 return new Charitable_Campaign( $campaign_id );
30 }
31
32 /**
33 * Create a campaign.
34 *
35 * @since 1.5.9
36 *
37 * @param array $args Values for the campaign.
38 * @return int
39 */
40 function charitable_create_campaign( array $args ) {
41 $processor = new Charitable_Campaign_Processor( $args );
42 return $processor->save();
43 }
44
45 /**
46 * Returns the current campaign.
47 *
48 * @since 1.0.0
49 *
50 * @return Charitable_Campaign|false Campaign object if we're viewing a campaign
51 * within a loop. False otherwise.
52 */
53 function charitable_get_current_campaign() {
54 return charitable_get_request()->get_current_campaign();
55 }
56
57 /**
58 * Returns the current campaign ID.
59 *
60 * @since 1.0.0
61 *
62 * @return int
63 */
64 function charitable_get_current_campaign_id() {
65 return charitable_get_request()->get_current_campaign_id();
66 }
67
68 /**
69 * Returns whether the current user is the creator of the given campaign.
70 *
71 * @since 1.0.0
72 *
73 * @param int $campaign_id The campaign ID.
74 * @return boolean
75 */
76 function charitable_is_current_campaign_creator( $campaign_id = null ) {
77 if ( is_null( $campaign_id ) ) {
78 $campaign_id = charitable_get_current_campaign_id();
79 }
80
81 return get_post_field( 'post_author', $campaign_id ) == get_current_user_id();
82 }
83
84 /**
85 * Returns whether the given campaign can receive donations.
86 *
87 * @since 1.5.14
88 *
89 * @param int $campaign_id The campaign ID.
90 * @return boolean
91 */
92 function charitable_campaign_can_receive_donations( $campaign_id ) {
93 if ( Charitable::CAMPAIGN_POST_TYPE !== get_post_type( $campaign_id ) ) {
94 return false;
95 }
96
97 $campaign = charitable_get_campaign( $campaign_id );
98
99 return $campaign && $campaign->can_receive_donations();
100 }
101
102 /**
103 * Given a campaign ID and a key, return the post field.
104 *
105 * @since 1.6.0
106 *
107 * @param Charitable_Campaign $campaign The campaign object.
108 * @param string $key The meta key.
109 * @return mixed
110 */
111 function charitable_get_campaign_post_field( Charitable_Campaign $campaign, $key ) {
112 if ( ! isset( $campaign->ID ) || 0 === intval( $campaign->ID ) ) {
113 return false;
114 }
115
116 return get_post_field( $key, $campaign->ID );
117 }
118
119 /**
120 * Get the campaign date as a timestamp.
121 *
122 * @since 1.6.54
123 *
124 * @param Charitable_Campaign $campaign The campaign instance.
125 * @return int
126 */
127 function charitable_get_campaign_date_as_timestamp( Charitable_Campaign $campaign ) {
128 return strtotime( $campaign->post_date );
129 }
130
131 /**
132 * Get a particular user field for a campaign's creator.
133 *
134 * @since 1.6.5
135 *
136 * @param Charitable_Campaign $campaign The campaign object.
137 * @param string $key The meta key.
138 * @return string
139 */
140 function charitable_get_campaign_creator_field( Charitable_Campaign $campaign, $key ) {
141 $creator = charitable_get_user( $campaign->get_campaign_creator() );
142 $key = str_replace( 'campaign_creator_', '', $key );
143
144 return $creator->get( $key );
145 }
146
147 /**
148 * Get a particular taxonomy field for a campaign.
149 *
150 * @since 1.6.19
151 *
152 * @param Charitable_Campaign $campaign The campaign object.
153 * @param string $key The meta key.
154 * @return string
155 */
156 function charitable_get_campaign_taxonomy_terms_list( Charitable_Campaign $campaign, $key ) {
157 $taxonomies = array(
158 'categories' => 'campaign_category',
159 'tags' => 'campaign_tag',
160 );
161
162 $taxonomy = array_key_exists( $key, $taxonomies ) ? $taxonomies[ $key ] : $key;
163 $terms = wp_get_object_terms( $campaign->ID, $taxonomy, array( 'fields' => 'names' ) );
164
165 if ( is_wp_error( $terms ) ) {
166 return '';
167 }
168
169 return implode( ', ', $terms );
170 }
171
172 /**
173 * Get the featured image for a particular campaign.
174 *
175 * @since 1.6.25
176 *
177 * @param Charitable_Campaign $campaign The campaign object.
178 * @return string|int
179 */
180 function charitable_get_campaign_featured_image( Charitable_Campaign $campaign ) {
181 return get_post_thumbnail_id( $campaign->ID );
182 }
183