PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.6.57
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.6.57
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 / data / class-charitable-post-types.php

class-charitable-post-types.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.6.57, at includes/data/class-charitable-post-types.php

351 lines 12.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The class that defines Charitable's custom post types, taxonomies and post statuses.
4 *
5 * @package Charitable/Classes/Charitable_Post_Types
6 * @author Eric Daams
7 * @copyright Copyright (c) 2022, Studio 164a
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.0.0
10 * @version 1.6.39
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Post_Types' ) ) :
18
19 /**
20 * Charitable_Post_Types
21 *
22 * @since 1.0.0
23 */
24 final class Charitable_Post_Types {
25
26 /**
27 * The single instance of this class.
28 *
29 * @var Charitable_Post_Types|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_Post_Types
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 * Set up the class.
50 *
51 * Note that the only way to instantiate an object is with the on_start method,
52 * which can only be called during the start phase. In other words, don't try
53 * to instantiate this object.
54 *
55 * @since 1.0.0
56 */
57 private function __construct() {
58 add_action( 'init', array( $this, 'register_post_types' ), 5 );
59 add_action( 'init', array( $this, 'register_post_statuses' ), 5 );
60 add_action( 'init', array( $this, 'register_taxonomies' ), 6 );
61 }
62
63 /**
64 * Register plugin post types.
65 *
66 * @hook init
67 * @since 1.0.0
68 *
69 * @return void
70 */
71 public function register_post_types() {
72 /**
73 * Filter the campaign post type definition.
74 *
75 * To change any of the arguments used for the post type, other than the name
76 * of the post type itself, use the 'charitable_campaign_post_type' filter.
77 *
78 * @since 1.0.0
79 *
80 * @param array $args Post type arguments.
81 */
82 $args = apply_filters(
83 'charitable_campaign_post_type',
84 array(
85 'labels' => array(
86 'name' => __( 'Campaigns', 'charitable' ),
87 'singular_name' => __( 'Campaign', 'charitable' ),
88 'menu_name' => _x( 'Campaigns', 'Admin menu name', 'charitable' ),
89 'add_new' => __( 'Add Campaign', 'charitable' ),
90 'add_new_item' => __( 'Add New Campaign', 'charitable' ),
91 'edit' => __( 'Edit', 'charitable' ),
92 'edit_item' => __( 'Edit Campaign', 'charitable' ),
93 'new_item' => __( 'New Campaign', 'charitable' ),
94 'view' => __( 'View Campaign', 'charitable' ),
95 'view_item' => __( 'View Campaign', 'charitable' ),
96 'search_items' => __( 'Search Campaigns', 'charitable' ),
97 'not_found' => __( 'No Campaigns found', 'charitable' ),
98 'not_found_in_trash' => __( 'No Campaigns found in trash', 'charitable' ),
99 'parent' => __( 'Parent Campaign', 'charitable' ),
100 ),
101 'description' => __( 'This is where you can create new campaigns for people to support.', 'charitable' ),
102 'public' => true,
103 'show_ui' => true,
104 'capability_type' => 'campaign',
105 'menu_icon' => '',
106 'map_meta_cap' => true,
107 'publicly_queryable' => true,
108 'exclude_from_search' => false,
109 'hierarchical' => false,
110 'rewrite' => array(
111 'slug' => 'campaigns',
112 'with_front' => true,
113 ),
114 'query_var' => true,
115 'supports' => array( 'title', 'thumbnail', 'comments' ),
116 'has_archive' => false,
117 'show_in_nav_menus' => true,
118 'show_in_menu' => false,
119 'show_in_admin_bar' => true,
120 )
121 );
122
123 register_post_type( 'campaign', $args );
124
125 /**
126 * Filter the donation post type definition.
127 *
128 * To change any of the arguments used for the post type, other than the name
129 * of the post type itself, use the 'charitable_donation_post_type' filter.
130 *
131 * @since 1.0.0
132 *
133 * @param array $args Post type arguments.
134 */
135 $args = apply_filters(
136 'charitable_donation_post_type',
137 array(
138 'labels' => array(
139 'name' => __( 'Donations', 'charitable' ),
140 'singular_name' => __( 'Donation', 'charitable' ),
141 'menu_name' => _x( 'Donations', 'Admin menu name', 'charitable' ),
142 'add_new' => __( 'Add Donation', 'charitable' ),
143 'add_new_item' => __( 'Add New Donation', 'charitable' ),
144 'edit' => __( 'Edit', 'charitable' ),
145 'edit_item' => __( 'Donation Details', 'charitable' ),
146 'new_item' => __( 'New Donation', 'charitable' ),
147 'view' => __( 'View Donation', 'charitable' ),
148 'view_item' => __( 'View Donation', 'charitable' ),
149 'search_items' => __( 'Search Donations', 'charitable' ),
150 'not_found' => __( 'No Donations found', 'charitable' ),
151 'not_found_in_trash' => __( 'No Donations found in trash', 'charitable' ),
152 'parent' => __( 'Parent Donation', 'charitable' ),
153 ),
154 'public' => false,
155 'show_ui' => true,
156 'capability_type' => 'donation',
157 'menu_icon' => '',
158 'map_meta_cap' => true,
159 'publicly_queryable' => false,
160 'exclude_from_search' => false,
161 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
162 'rewrite' => false,
163 'query_var' => false,
164 'supports' => array( '' ),
165 'has_archive' => false,
166 'show_in_nav_menus' => false,
167 'show_in_menu' => false,
168 )
169 );
170
171 register_post_type( 'donation', $args );
172 }
173
174 /**
175 * Register custom post statuses.
176 *
177 * @since 1.0.0
178 *
179 * @return void
180 */
181 public function register_post_statuses() {
182 register_post_status(
183 'charitable-pending',
184 array(
185 'label' => _x( 'Pending', 'Pending Donation Status', 'charitable' ),
186 /* translators: %s: count */
187 'label_count' => _n_noop( 'Pending (%s)', 'Pending (%s)', 'charitable' ),
188 'public' => false,
189 'show_in_admin_all_list' => true,
190 'show_in_admin_status_list' => true,
191 'exclude_from_search' => true,
192 )
193 );
194
195 register_post_status(
196 'charitable-completed',
197 array(
198 'label' => _x( 'Paid', 'Paid Donation Status', 'charitable' ),
199 /* translators: %s: count */
200 'label_count' => _n_noop( 'Paid (%s)', 'Paid (%s)', 'charitable' ),
201 'public' => false,
202 'show_in_admin_all_list' => true,
203 'show_in_admin_status_list' => true,
204 'exclude_from_search' => true,
205 )
206 );
207
208 register_post_status(
209 'charitable-failed',
210 array(
211 'label' => _x( 'Failed', 'Failed Donation Status', 'charitable' ),
212 /* translators: %s: count */
213 'label_count' => _n_noop( 'Failed (%s)', 'Failed (%s)', 'charitable' ),
214 'public' => false,
215 'show_in_admin_all_list' => true,
216 'show_in_admin_status_list' => true,
217 'exclude_from_search' => true,
218 )
219 );
220
221 register_post_status(
222 'charitable-cancelled',
223 array(
224 'label' => _x( 'Canceled', 'Canceled Donation Status', 'charitable' ),
225 /* translators: %s: count */
226 'label_count' => _n_noop( 'Canceled (%s)', 'Canceled (%s)', 'charitable' ),
227 'public' => false,
228 'show_in_admin_all_list' => true,
229 'show_in_admin_status_list' => true,
230 'exclude_from_search' => true,
231 )
232 );
233
234 register_post_status(
235 'charitable-refunded',
236 array(
237 'label' => _x( 'Refunded', 'Refunded Donation Status', 'charitable' ),
238 /* translators: %s: count */
239 'label_count' => _n_noop( 'Refunded (%s)', 'Refunded (%s)', 'charitable' ),
240 'public' => false,
241 'show_in_admin_all_list' => true,
242 'show_in_admin_status_list' => true,
243 'exclude_from_search' => true,
244 )
245 );
246
247 register_post_status(
248 'charitable-preapproved',
249 array(
250 'label' => _x( 'Pre Approved', 'Pre Approved Donation Status', 'charitable' ),
251 /* translators: %s: count */
252 'label_count' => _n_noop( 'Pre Approved (%s)', 'Pre Approved (%s)', 'charitable' ),
253 'public' => false,
254 'show_in_admin_all_list' => true,
255 'show_in_admin_status_list' => true,
256 'exclude_from_search' => true,
257 )
258 );
259 }
260
261 /**
262 * Register the campaign category taxonomy.
263 *
264 * @since 1.0.0
265 *
266 * @return void
267 */
268 public function register_taxonomies() {
269 $labels = array(
270 'name' => _x( 'Campaign Categories', 'Taxonomy General Name', 'charitable' ),
271 'singular_name' => _x( 'Campaign Category', 'Taxonomy Singular Name', 'charitable' ),
272 'menu_name' => __( 'Categories', 'charitable' ),
273 'all_items' => __( 'All Campaign Categories', 'charitable' ),
274 'parent_item' => __( 'Parent Campaign Category', 'charitable' ),
275 'parent_item_colon' => __( 'Parent Campaign Category:', 'charitable' ),
276 'new_item_name' => __( 'New Campaign Category Name', 'charitable' ),
277 'add_new_item' => __( 'Add New Campaign Category', 'charitable' ),
278 'edit_item' => __( 'Edit Campaign Category', 'charitable' ),
279 'update_item' => __( 'Update Campaign Category', 'charitable' ),
280 'view_item' => __( 'View Campaign Category', 'charitable' ),
281 'separate_items_with_commas' => __( 'Separate campaign categories with commas', 'charitable' ),
282 'add_or_remove_items' => __( 'Add or remove campaign categories', 'charitable' ),
283 'choose_from_most_used' => __( 'Choose from the most used', 'charitable' ),
284 'popular_items' => __( 'Popular Campaign Categories', 'charitable' ),
285 'search_items' => __( 'Search Campaign Categories', 'charitable' ),
286 'not_found' => __( 'Not Found', 'charitable' ),
287 );
288
289 $args = array(
290 'labels' => $labels,
291 'hierarchical' => true,
292 'public' => true,
293 'show_ui' => true,
294 'show_admin_column' => true,
295 'show_in_nav_menus' => true,
296 'show_tagcloud' => true,
297 'capabilities' => array(
298 'manage_terms' => 'manage_campaign_terms',
299 'edit_terms' => 'edit_campaign_terms',
300 'delete_terms' => 'delete_campaign_terms',
301 'assign_terms' => 'assign_campaign_terms',
302 ),
303 );
304
305 register_taxonomy( 'campaign_category', array( 'campaign' ), $args );
306
307 $labels = array(
308 'name' => _x( 'Campaign Tags', 'Taxonomy General Name', 'charitable' ),
309 'singular_name' => _x( 'Campaign Tag', 'Taxonomy Singular Name', 'charitable' ),
310 'menu_name' => __( 'Tags', 'charitable' ),
311 'all_items' => __( 'All Campaign Tags', 'charitable' ),
312 'parent_item' => __( 'Parent Campaign Tag', 'charitable' ),
313 'parent_item_colon' => __( 'Parent Campaign Tag:', 'charitable' ),
314 'new_item_name' => __( 'New Campaign Tag Name', 'charitable' ),
315 'add_new_item' => __( 'Add New Campaign Tag', 'charitable' ),
316 'edit_item' => __( 'Edit Campaign Tag', 'charitable' ),
317 'update_item' => __( 'Update Campaign Tag', 'charitable' ),
318 'view_item' => __( 'View Campaign Tag', 'charitable' ),
319 'separate_items_with_commas' => __( 'Separate campaign tags with commas', 'charitable' ),
320 'add_or_remove_items' => __( 'Add or remove campaign tags', 'charitable' ),
321 'choose_from_most_used' => __( 'Choose from the most used', 'charitable' ),
322 'popular_items' => __( 'Popular Campaign Tags', 'charitable' ),
323 'search_items' => __( 'Search Campaign Tags', 'charitable' ),
324 'not_found' => __( 'Not Found', 'charitable' ),
325 );
326
327 $args = array(
328 'labels' => $labels,
329 'hierarchical' => false,
330 'public' => true,
331 'show_ui' => true,
332 'show_admin_column' => true,
333 'show_in_nav_menus' => true,
334 'show_tagcloud' => true,
335 'capabilities' => array(
336 'manage_terms' => 'manage_campaign_terms',
337 'edit_terms' => 'edit_campaign_terms',
338 'delete_terms' => 'delete_campaign_terms',
339 'assign_terms' => 'assign_campaign_terms',
340 ),
341 );
342
343 register_taxonomy( 'campaign_tag', array( 'campaign' ), $args );
344
345 register_taxonomy_for_object_type( 'campaign_category', 'campaign' );
346 register_taxonomy_for_object_type( 'campaign_tag', 'campaign' );
347 }
348 }
349
350 endif;
351