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

430 lines 15.2 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 David Bisset
7 * @copyright Copyright (c) 2023, WP Charitable LLC
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 // Add the new v2 header.
63 add_action( 'in_admin_header', [ $this, 'admin_header' ], 100 );
64 add_filter( 'get_search_form', [ $this, 'update_search_form' ], 10, 2 );
65
66 // Alter the "Add New" in admin menu.
67 add_action( 'admin_menu', [ $this, 'add_new_link_for_campaigns' ], 100 );
68
69 // Add "new" indicitator in admin menu.
70 add_filter( 'charitable_campaign_post_type', [ $this, 'add_new_indicitator' ], 100 );
71 }
72
73 /**
74 * Alter "Add New" in admin to produce "new campaign" popup.
75 *
76 * @since 1.8.0
77 *
78 * @param array $post_type_args The post type args.
79 * @return array $post_type_args
80 */
81 public function add_new_indicitator( $post_type_args ) {
82
83 $post_type_args['labels']['menu_name'] = $post_type_args['labels']['menu_name'] . ' <span class="charitable-menu-new-indicator">&nbsp;NEW!</span>';
84
85 return $post_type_args;
86 }
87
88 /**
89 * Alter "Add New" in admin to produce "new campaign" popup.
90 *
91 * @since 1.8.0
92 */
93 public function add_new_link_for_campaigns() {
94
95 global $menu, $submenu;
96
97 if ( isset( $submenu['charitable'][2][2] ) ) {
98 $submenu['charitable'][2][2] = 'edit.php?post_type=campaign&create=campaign'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
99 }
100 }
101
102 /**
103 * Outputs the Charitable Admin Header.
104 *
105 * @since 1.8.0
106 * @param string $form The search form.
107 * @param array $args The search form args.
108 */
109 public function update_search_form( $form = false, $args = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
110
111 return str_replace( 'Search Campaigns', 'Search', $form );
112 }
113
114 /**
115 * Outputs the Charitable Admin Header.
116 *
117 * @since 1.8.0
118 */
119 public function admin_header() {
120
121 $is_charitable_page = false;
122
123 // Get the current screen, and check whether we're viewing the campaign post types.
124 $screen = get_current_screen();
125
126 if ( 'campaign' === $screen->post_type || 'donation' === $screen->post_type || 'charitable_page_charitable-settings' === $screen->base || 'charitable_page_charitable-addons' === $screen->base ) {
127 $is_charitable_page = true;
128 }
129
130 $is_charitable_page = apply_filters( 'charitable_is_admin_page', $is_charitable_page, $screen );
131
132 if ( false === $is_charitable_page ) {
133 return;
134 }
135
136 include charitable()->get_path( 'includes' ) . 'admin/templates/header.php';
137 }
138
139 /**
140 * Register plugin post types.
141 *
142 * @hook init
143 * @since 1.0.0
144 *
145 * @return void
146 */
147 public function register_post_types() {
148 /**
149 * Filter the campaign post type definition.
150 *
151 * To change any of the arguments used for the post type, other than the name
152 * of the post type itself, use the 'charitable_campaign_post_type' filter.
153 *
154 * @since 1.0.0
155 *
156 * @param array $args Post type arguments.
157 */
158 $args = apply_filters(
159 'charitable_campaign_post_type',
160 array(
161 'labels' => array(
162 'name' => __( 'Campaigns', 'charitable' ),
163 'singular_name' => __( 'Campaign', 'charitable' ),
164 'menu_name' => _x( 'Campaigns', 'Admin menu name', 'charitable' ),
165 'add_new' => __( 'Add New', 'charitable' ),
166 'add_new_item' => __( 'Add New Campaign', 'charitable' ),
167 'edit' => __( 'Edit', 'charitable' ),
168 'edit_item' => __( 'Edit Campaign', 'charitable' ),
169 'new_item' => __( 'New Campaign', 'charitable' ),
170 'view' => __( 'View Campaign', 'charitable' ),
171 'view_item' => __( 'View Campaign', 'charitable' ),
172 'search_items' => __( 'Search', 'charitable' ),
173 'not_found' => __( 'No Campaigns found', 'charitable' ),
174 'not_found_in_trash' => __( 'No Campaigns found in trash', 'charitable' ),
175 'parent' => __( 'Parent Campaign', 'charitable' ),
176 ),
177 'description' => __( 'This is where you can create new campaigns for people to support.', 'charitable' ),
178 'public' => true,
179 'show_ui' => true,
180 'capability_type' => 'campaign',
181 'menu_icon' => '',
182 'map_meta_cap' => true,
183 'publicly_queryable' => true,
184 'exclude_from_search' => false,
185 'hierarchical' => false,
186 'rewrite' => array(
187 'slug' => 'campaigns',
188 'with_front' => true,
189 ),
190 'query_var' => true,
191 'supports' => array( 'title', 'thumbnail', 'comments' ),
192 'has_archive' => false,
193 'show_in_nav_menus' => true,
194 'show_in_menu' => false,
195 'show_in_admin_bar' => true,
196
197 )
198 );
199
200 register_post_type( 'campaign', $args );
201
202 /**
203 * Filter the donation post type definition.
204 *
205 * To change any of the arguments used for the post type, other than the name
206 * of the post type itself, use the 'charitable_donation_post_type' filter.
207 *
208 * @since 1.0.0
209 *
210 * @param array $args Post type arguments.
211 */
212 $args = apply_filters(
213 'charitable_donation_post_type',
214 array(
215 'labels' => array(
216 'name' => __( 'Donations', 'charitable' ),
217 'singular_name' => __( 'Donation', 'charitable' ),
218 'menu_name' => _x( 'Donations', 'Admin menu name', 'charitable' ),
219 'add_new' => __( 'Add Donation', 'charitable' ),
220 'add_new_item' => __( 'Add New Donation', 'charitable' ),
221 'edit' => __( 'Edit', 'charitable' ),
222 'edit_item' => __( 'Donation Details', 'charitable' ),
223 'new_item' => __( 'New Donation', 'charitable' ),
224 'view' => __( 'View Donation', 'charitable' ),
225 'view_item' => __( 'View Donation', 'charitable' ),
226 'search_items' => __( 'Search Donations', 'charitable' ),
227 'not_found' => __( 'No Donations found', 'charitable' ),
228 'not_found_in_trash' => __( 'No Donations found in trash', 'charitable' ),
229 'parent' => __( 'Parent Donation', 'charitable' ),
230 ),
231 'public' => false,
232 'show_ui' => true,
233 'capability_type' => 'donation',
234 'menu_icon' => '',
235 'map_meta_cap' => true,
236 'publicly_queryable' => false,
237 'exclude_from_search' => false,
238 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
239 'rewrite' => false,
240 'query_var' => false,
241 'supports' => array( '' ),
242 'has_archive' => false,
243 'show_in_nav_menus' => false,
244 'show_in_menu' => false,
245 )
246 );
247
248 register_post_type( 'donation', $args );
249 }
250
251 /**
252 * Register custom post statuses.
253 *
254 * @since 1.0.0
255 *
256 * @return void
257 */
258 public function register_post_statuses() {
259 register_post_status(
260 'charitable-pending',
261 array(
262 'label' => _x( 'Pending', 'Pending Donation Status', 'charitable' ),
263 /* translators: %s: count */
264 'label_count' => _n_noop( 'Pending (%s)', 'Pending (%s)', 'charitable' ),
265 'public' => false,
266 'show_in_admin_all_list' => true,
267 'show_in_admin_status_list' => true,
268 'exclude_from_search' => true,
269 )
270 );
271
272 register_post_status(
273 'charitable-completed',
274 array(
275 'label' => _x( 'Paid', 'Paid Donation Status', 'charitable' ),
276 /* translators: %s: count */
277 'label_count' => _n_noop( 'Paid (%s)', 'Paid (%s)', 'charitable' ),
278 'public' => false,
279 'show_in_admin_all_list' => true,
280 'show_in_admin_status_list' => true,
281 'exclude_from_search' => true,
282 )
283 );
284
285 register_post_status(
286 'charitable-failed',
287 array(
288 'label' => _x( 'Failed', 'Failed Donation Status', 'charitable' ),
289 /* translators: %s: count */
290 'label_count' => _n_noop( 'Failed (%s)', 'Failed (%s)', 'charitable' ),
291 'public' => false,
292 'show_in_admin_all_list' => true,
293 'show_in_admin_status_list' => true,
294 'exclude_from_search' => true,
295 )
296 );
297
298 register_post_status(
299 'charitable-cancelled',
300 array(
301 'label' => _x( 'Canceled', 'Canceled Donation Status', 'charitable' ),
302 /* translators: %s: count */
303 'label_count' => _n_noop( 'Canceled (%s)', 'Canceled (%s)', 'charitable' ),
304 'public' => false,
305 'show_in_admin_all_list' => true,
306 'show_in_admin_status_list' => true,
307 'exclude_from_search' => true,
308 )
309 );
310
311 register_post_status(
312 'charitable-refunded',
313 array(
314 'label' => _x( 'Refunded', 'Refunded Donation Status', 'charitable' ),
315 /* translators: %s: count */
316 'label_count' => _n_noop( 'Refunded (%s)', 'Refunded (%s)', 'charitable' ),
317 'public' => false,
318 'show_in_admin_all_list' => true,
319 'show_in_admin_status_list' => true,
320 'exclude_from_search' => true,
321 )
322 );
323
324 register_post_status(
325 'charitable-preapproved',
326 array(
327 'label' => _x( 'Pre Approved', 'Pre Approved Donation Status', 'charitable' ),
328 /* translators: %s: count */
329 'label_count' => _n_noop( 'Pre Approved (%s)', 'Pre Approved (%s)', 'charitable' ),
330 'public' => false,
331 'show_in_admin_all_list' => true,
332 'show_in_admin_status_list' => true,
333 'exclude_from_search' => true,
334 )
335 );
336 }
337
338 /**
339 * Register the campaign category taxonomy.
340 *
341 * @since 1.0.0
342 *
343 * @return void
344 */
345 public function register_taxonomies() {
346 $labels = array(
347 'name' => _x( 'Campaign Categories', 'Taxonomy General Name', 'charitable' ),
348 'singular_name' => _x( 'Campaign Category', 'Taxonomy Singular Name', 'charitable' ),
349 'menu_name' => __( 'Categories', 'charitable' ),
350 'all_items' => __( 'All Campaign Categories', 'charitable' ),
351 'parent_item' => __( 'Parent Campaign Category', 'charitable' ),
352 'parent_item_colon' => __( 'Parent Campaign Category:', 'charitable' ),
353 'new_item_name' => __( 'New Campaign Category Name', 'charitable' ),
354 'add_new_item' => __( 'Add New Campaign Category', 'charitable' ),
355 'edit_item' => __( 'Edit Campaign Category', 'charitable' ),
356 'update_item' => __( 'Update Campaign Category', 'charitable' ),
357 'view_item' => __( 'View Campaign Category', 'charitable' ),
358 'separate_items_with_commas' => __( 'Separate campaign categories with commas', 'charitable' ),
359 'add_or_remove_items' => __( 'Add or remove campaign categories', 'charitable' ),
360 'choose_from_most_used' => __( 'Choose from the most used', 'charitable' ),
361 'popular_items' => __( 'Popular Campaign Categories', 'charitable' ),
362 'search_items' => __( 'Search Campaign Categories', 'charitable' ),
363 'not_found' => __( 'Not Found', 'charitable' ),
364 );
365
366 $args = array(
367 'labels' => $labels,
368 'hierarchical' => true,
369 'public' => true,
370 'show_ui' => true,
371 'show_admin_column' => true,
372 'show_in_nav_menus' => true,
373 'show_tagcloud' => true,
374 'show_in_menu' => true,
375 'capabilities' => array(
376 'manage_terms' => 'manage_campaign_terms',
377 'edit_terms' => 'edit_campaign_terms',
378 'delete_terms' => 'delete_campaign_terms',
379 'assign_terms' => 'assign_campaign_terms',
380 ),
381 );
382
383 register_taxonomy( 'campaign_category', array( 'campaign' ), $args );
384
385 $labels = array(
386 'name' => _x( 'Campaign Tags', 'Taxonomy General Name', 'charitable' ),
387 'singular_name' => _x( 'Campaign Tag', 'Taxonomy Singular Name', 'charitable' ),
388 'menu_name' => __( 'Tags', 'charitable' ),
389 'all_items' => __( 'All Campaign Tags', 'charitable' ),
390 'parent_item' => __( 'Parent Campaign Tag', 'charitable' ),
391 'parent_item_colon' => __( 'Parent Campaign Tag:', 'charitable' ),
392 'new_item_name' => __( 'New Campaign Tag Name', 'charitable' ),
393 'add_new_item' => __( 'Add New Campaign Tag', 'charitable' ),
394 'edit_item' => __( 'Edit Campaign Tag', 'charitable' ),
395 'update_item' => __( 'Update Campaign Tag', 'charitable' ),
396 'view_item' => __( 'View Campaign Tag', 'charitable' ),
397 'separate_items_with_commas' => __( 'Separate campaign tags with commas', 'charitable' ),
398 'add_or_remove_items' => __( 'Add or remove campaign tags', 'charitable' ),
399 'choose_from_most_used' => __( 'Choose from the most used', 'charitable' ),
400 'popular_items' => __( 'Popular Campaign Tags', 'charitable' ),
401 'search_items' => __( 'Search Campaign Tags', 'charitable' ),
402 'not_found' => __( 'Not Found', 'charitable' ),
403 );
404
405 $args = array(
406 'labels' => $labels,
407 'hierarchical' => false,
408 'public' => true,
409 'show_ui' => true,
410 'show_admin_column' => true,
411 'show_in_nav_menus' => true,
412 'show_tagcloud' => true,
413 'show_in_menu' => true,
414 'capabilities' => array(
415 'manage_terms' => 'manage_campaign_terms',
416 'edit_terms' => 'edit_campaign_terms',
417 'delete_terms' => 'delete_campaign_terms',
418 'assign_terms' => 'assign_campaign_terms',
419 ),
420 );
421
422 register_taxonomy( 'campaign_tag', array( 'campaign' ), $args );
423
424 register_taxonomy_for_object_type( 'campaign_category', 'campaign' );
425 register_taxonomy_for_object_type( 'campaign_tag', 'campaign' );
426 }
427 }
428
429 endif;
430