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

516 lines 18.5 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 * @version 1.8.1.12
57 */
58 private function __construct() {
59 add_action( 'init', array( $this, 'register_post_types' ), 5 );
60 add_action( 'init', array( $this, 'register_post_statuses' ), 5 );
61 add_action( 'init', array( $this, 'register_taxonomies' ), 6 );
62
63 // Add the new v2 header.
64 add_action( 'in_admin_header', [ $this, 'admin_header' ], 100 );
65 add_filter( 'get_search_form', [ $this, 'update_search_form' ], 10, 2 );
66
67 // Alter the "Add New" in admin menu.
68 add_action( 'admin_menu', [ $this, 'add_new_link_for_campaigns' ], 100 );
69
70 // Update the "add new" button link on the campaign post type page.
71 add_action( 'admin_head', [ $this, 'update_campaign_link_visual_builder' ] );
72
73 // Alter the "Edit" link on the campaign post type page.
74 add_action( 'get_edit_post_link', [ $this, 'campaign_edit_post_link' ], 1000 );
75 }
76
77 /**
78 * Alter the "Edit" link on the campaign post type page, especially in the admin bar on the front end.
79 *
80 * @since 1.8.1.15
81 *
82 * @param string $link The edit post link.
83 *
84 * @return string
85 */
86 public function campaign_edit_post_link( $link = '' ) {
87
88 global $post;
89
90 if ( is_admin() || ! is_object( $post ) || ! is_singular( 'campaign' ) || empty( $post->ID ) ) {
91 return $link;
92 }
93
94 $post_id = intval( $post->ID );
95
96 if ( 0 === $post_id ) {
97 return $link;
98 }
99
100 // Determine if this is a "legacy" campaign.
101 $is_legacy_campaign = charitable_is_campaign_legacy( $post_id );
102
103 if ( ! $is_legacy_campaign ) {
104 $link = admin_url( 'admin.php?page=charitable-campaign-builder&campaign_id=' . $post_id . '&view=design' );
105 return $link;
106 }
107
108 return $link;
109 }
110
111 /**
112 * Alter the "Add New" label on the campaign post type page.
113 *
114 * @since 1.8.1.12
115 * @version 1.8.1.14
116 */
117 public function update_campaign_link_visual_builder() {
118 global $post_new_file, $post_type_object;
119 if ( ! isset( $post_type_object ) || 'campaign' !== $post_type_object->name ) {
120 return false;
121 }
122 // determine if we are on a legacy page or not.
123 $legacy_page = ( ( isset( $_GET['post'] ) && 'campaign' === $_GET['post'] ) || ( isset( $_GET['action'] ) && 'edit' === $_GET['action'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
124 if ( $legacy_page ) {
125 if ( isset( $post_type_object->labels ) && isset( $post_type_object->labels->add_new ) ) {
126 $post_type_object->labels->add_new = 'Add New Legacy Campaign';
127 }
128 } else {
129 if ( charitable_disable_legacy_campaigns() ) :
130 $post_new_file = 'admin.php?page=charitable-campaign-builder&view=template';
131 else :
132 $post_new_file = 'post-new.php?post_type=campaign';
133 if ( isset( $post_type_object->labels ) && isset( $post_type_object->labels->add_new ) ) :
134 $post_type_object->labels->add_new_item = 'Add New Legacy Campaign';
135 endif;
136 endif;
137 }
138 }
139
140 /**
141 * Alter "Add New" in admin to produce "new campaign" popup.
142 * DEPRECATED: This is no longer used.
143 *
144 * @since 1.8.0
145 *
146 * @param array $post_type_args The post type args.
147 * @return array $post_type_args
148 */
149 public function add_new_indicitator( $post_type_args ) {
150
151 $post_type_args['labels']['menu_name'] = $post_type_args['labels']['menu_name'] . ' <span class="charitable-menu-new-indicator">&nbsp;' . esc_html__( 'NEW', 'charitable' ) . '!</span>';
152
153 return $post_type_args;
154 }
155
156 /**
157 * Alter "Add New" in admin to point to visual builder.
158 *
159 * @since 1.8.0
160 */
161 public function add_new_link_for_campaigns() {
162
163 global $menu, $submenu;
164
165 if ( isset( $submenu['charitable'] ) && ! empty( $submenu['charitable'] ) ) {
166 // Find the "Add New" link.
167 foreach ( $submenu['charitable'] as $key => $value ) {
168 if ( 0 === strpos( $value[0], 'Add New' ) ) {
169 // The link depends if the disable legacy campaigns is enabled.
170 $disable_legacy_campaign = charitable_get_option( 'disable_campaign_legacy_mode', false ) ? true : false;
171 if ( charitable_disable_legacy_campaigns() ) {
172 $submenu['charitable'][ $key ][2] = 'admin.php?page=charitable-campaign-builder&view=template'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
173 } else {
174 $submenu['charitable'][ $key ][2] = 'post-new.php?post_type=campaign'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
175 }
176 }
177 }
178 }
179 }
180
181 /**
182 * Outputs the Charitable Admin Header.
183 *
184 * @since 1.8.0
185 * @param string $form The search form.
186 * @param array $args The search form args.
187 */
188 public function update_search_form( $form = false, $args = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
189
190 return str_replace( 'Search Campaigns', 'Search', $form );
191 }
192
193 /**
194 * Outputs the Charitable Admin Header.
195 *
196 * @since 1.8.0
197 * @since 1.8.1 Add reporting screen.
198 * @since 1.8.1.6 Add tools and guide tools screen.
199 * @version 1.8.1.12 Add setup checklist screen.
200 *
201 * @return void
202 */
203 public function admin_header() {
204
205 $is_charitable_page = false;
206
207 // Get the current screen, and check whether we're viewing the campaign post types.
208 $screen = get_current_screen();
209
210 $applicable_post_types = [ 'campaign', 'donation', 'charitable_page_charitable-settings', 'charitable_page_charitable-addons', 'charitable_page_charitable-reports', 'charitable_page_charitable-tools', 'charitable_page_charitable-dashboard', 'charitable_page_charitable-growth-tools', 'charitable_page_charitable-setup-checklist' ];
211
212 if ( in_array( $screen->post_type, $applicable_post_types, true ) || in_array( $screen->base, $applicable_post_types, true ) ) {
213 $is_charitable_page = true;
214 }
215
216 $is_charitable_page = apply_filters( 'charitable_is_admin_page', $is_charitable_page, $screen );
217
218 if ( false === $is_charitable_page ) {
219 return;
220 }
221
222 include charitable()->get_path( 'includes' ) . 'admin/templates/header.php';
223 }
224
225 /**
226 * Register plugin post types.
227 *
228 * @hook init
229 * @since 1.0.0
230 *
231 * @return void
232 */
233 public function register_post_types() {
234 /**
235 * Filter the campaign post type definition.
236 *
237 * To change any of the arguments used for the post type, other than the name
238 * of the post type itself, use the 'charitable_campaign_post_type' filter.
239 *
240 * @since 1.0.0
241 *
242 * @param array $args Post type arguments.
243 */
244 $args = apply_filters(
245 'charitable_campaign_post_type',
246 array(
247 'labels' => array(
248 'name' => __( 'Campaigns', 'charitable' ),
249 'singular_name' => __( 'Campaign', 'charitable' ),
250 'menu_name' => _x( 'Campaigns', 'Admin menu name', 'charitable' ),
251 'add_new' => __( 'Add New', 'charitable' ),
252 'add_new_item' => __( 'Add New Campaign', 'charitable' ),
253 'edit' => __( 'Edit', 'charitable' ),
254 'edit_item' => __( 'Edit Campaign', 'charitable' ),
255 'new_item' => __( 'New Campaign', 'charitable' ),
256 'view' => __( 'View Campaign', 'charitable' ),
257 'view_item' => __( 'View Campaign', 'charitable' ),
258 'search_items' => __( 'Search', 'charitable' ),
259 'not_found' => __( 'No Campaigns found', 'charitable' ),
260 'not_found_in_trash' => __( 'No Campaigns found in trash', 'charitable' ),
261 'parent' => __( 'Parent Campaign', 'charitable' ),
262 ),
263 'description' => __( 'This is where you can create new campaigns for people to support.', 'charitable' ),
264 'public' => true,
265 'show_ui' => true,
266 'capability_type' => 'campaign',
267 'menu_icon' => '',
268 'map_meta_cap' => true,
269 'publicly_queryable' => true,
270 'exclude_from_search' => false,
271 'hierarchical' => false,
272 'rewrite' => array(
273 'slug' => 'campaigns',
274 'with_front' => true,
275 ),
276 'query_var' => true,
277 'supports' => array( 'title', 'thumbnail', 'comments' ),
278 'has_archive' => false,
279 'show_in_nav_menus' => true,
280 'show_in_menu' => false,
281 'show_in_admin_bar' => true,
282
283 )
284 );
285
286 register_post_type( 'campaign', $args );
287
288 /**
289 * Filter the donation post type definition.
290 *
291 * To change any of the arguments used for the post type, other than the name
292 * of the post type itself, use the 'charitable_donation_post_type' filter.
293 *
294 * @since 1.0.0
295 *
296 * @param array $args Post type arguments.
297 */
298 $args = apply_filters(
299 'charitable_donation_post_type',
300 array(
301 'labels' => array(
302 'name' => __( 'Donations', 'charitable' ),
303 'singular_name' => __( 'Donation', 'charitable' ),
304 'menu_name' => _x( 'Donations', 'Admin menu name', 'charitable' ),
305 'add_new' => __( 'Add Donation', 'charitable' ),
306 'add_new_item' => __( 'Add New Donation', 'charitable' ),
307 'edit' => __( 'Edit', 'charitable' ),
308 'edit_item' => __( 'Donation Details', 'charitable' ),
309 'new_item' => __( 'New Donation', 'charitable' ),
310 'view' => __( 'View Donation', 'charitable' ),
311 'view_item' => __( 'View Donation', 'charitable' ),
312 'search_items' => __( 'Search Donations', 'charitable' ),
313 'not_found' => __( 'No Donations found', 'charitable' ),
314 'not_found_in_trash' => __( 'No Donations found in trash', 'charitable' ),
315 'parent' => __( 'Parent Donation', 'charitable' ),
316 ),
317 'public' => false,
318 'show_ui' => true,
319 'capability_type' => 'donation',
320 'menu_icon' => '',
321 'map_meta_cap' => true,
322 'publicly_queryable' => false,
323 'exclude_from_search' => false,
324 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
325 'rewrite' => false,
326 'query_var' => false,
327 'supports' => array( '' ),
328 'has_archive' => false,
329 'show_in_nav_menus' => false,
330 'show_in_menu' => false,
331 )
332 );
333
334 register_post_type( 'donation', $args );
335 }
336
337 /**
338 * Register custom post statuses.
339 *
340 * @since 1.0.0
341 *
342 * @return void
343 */
344 public function register_post_statuses() {
345 register_post_status(
346 'charitable-pending',
347 array(
348 'label' => _x( 'Pending', 'Pending Donation Status', 'charitable' ),
349 /* translators: %s: count */
350 'label_count' => _n_noop( 'Pending (%s)', 'Pending (%s)', 'charitable' ),
351 'public' => false,
352 'show_in_admin_all_list' => true,
353 'show_in_admin_status_list' => true,
354 'exclude_from_search' => true,
355 )
356 );
357
358 register_post_status(
359 'charitable-completed',
360 array(
361 'label' => _x( 'Paid', 'Paid Donation Status', 'charitable' ),
362 /* translators: %s: count */
363 'label_count' => _n_noop( 'Paid (%s)', 'Paid (%s)', 'charitable' ),
364 'public' => false,
365 'show_in_admin_all_list' => true,
366 'show_in_admin_status_list' => true,
367 'exclude_from_search' => true,
368 )
369 );
370
371 register_post_status(
372 'charitable-failed',
373 array(
374 'label' => _x( 'Failed', 'Failed Donation Status', 'charitable' ),
375 /* translators: %s: count */
376 'label_count' => _n_noop( 'Failed (%s)', 'Failed (%s)', 'charitable' ),
377 'public' => false,
378 'show_in_admin_all_list' => true,
379 'show_in_admin_status_list' => true,
380 'exclude_from_search' => true,
381 )
382 );
383
384 register_post_status(
385 'charitable-cancelled',
386 array(
387 'label' => _x( 'Canceled', 'Canceled Donation Status', 'charitable' ),
388 /* translators: %s: count */
389 'label_count' => _n_noop( 'Canceled (%s)', 'Canceled (%s)', 'charitable' ),
390 'public' => false,
391 'show_in_admin_all_list' => true,
392 'show_in_admin_status_list' => true,
393 'exclude_from_search' => true,
394 )
395 );
396
397 register_post_status(
398 'charitable-refunded',
399 array(
400 'label' => _x( 'Refunded', 'Refunded Donation Status', 'charitable' ),
401 /* translators: %s: count */
402 'label_count' => _n_noop( 'Refunded (%s)', 'Refunded (%s)', 'charitable' ),
403 'public' => false,
404 'show_in_admin_all_list' => true,
405 'show_in_admin_status_list' => true,
406 'exclude_from_search' => true,
407 )
408 );
409
410 register_post_status(
411 'charitable-preapproved',
412 array(
413 'label' => _x( 'Pre Approved', 'Pre Approved Donation Status', 'charitable' ),
414 /* translators: %s: count */
415 'label_count' => _n_noop( 'Pre Approved (%s)', 'Pre Approved (%s)', 'charitable' ),
416 'public' => false,
417 'show_in_admin_all_list' => true,
418 'show_in_admin_status_list' => true,
419 'exclude_from_search' => true,
420 )
421 );
422 }
423
424 /**
425 * Register the campaign category taxonomy.
426 *
427 * @since 1.0.0
428 *
429 * @return void
430 */
431 public function register_taxonomies() {
432 $labels = array(
433 'name' => _x( 'Campaign Categories', 'Taxonomy General Name', 'charitable' ),
434 'singular_name' => _x( 'Campaign Category', 'Taxonomy Singular Name', 'charitable' ),
435 'menu_name' => __( 'Categories', 'charitable' ),
436 'all_items' => __( 'All Campaign Categories', 'charitable' ),
437 'parent_item' => __( 'Parent Campaign Category', 'charitable' ),
438 'parent_item_colon' => __( 'Parent Campaign Category:', 'charitable' ),
439 'new_item_name' => __( 'New Campaign Category Name', 'charitable' ),
440 'add_new_item' => __( 'Add New Campaign Category', 'charitable' ),
441 'edit_item' => __( 'Edit Campaign Category', 'charitable' ),
442 'update_item' => __( 'Update Campaign Category', 'charitable' ),
443 'view_item' => __( 'View Campaign Category', 'charitable' ),
444 'separate_items_with_commas' => __( 'Separate campaign categories with commas', 'charitable' ),
445 'add_or_remove_items' => __( 'Add or remove campaign categories', 'charitable' ),
446 'choose_from_most_used' => __( 'Choose from the most used', 'charitable' ),
447 'popular_items' => __( 'Popular Campaign Categories', 'charitable' ),
448 'search_items' => __( 'Search Campaign Categories', 'charitable' ),
449 'not_found' => __( 'Not Found', 'charitable' ),
450 );
451
452 $args = array(
453 'labels' => $labels,
454 'hierarchical' => true,
455 'public' => true,
456 'show_ui' => true,
457 'show_admin_column' => true,
458 'show_in_nav_menus' => true,
459 'show_tagcloud' => true,
460 'show_in_menu' => true,
461 'capabilities' => array(
462 'manage_terms' => 'manage_campaign_terms',
463 'edit_terms' => 'edit_campaign_terms',
464 'delete_terms' => 'delete_campaign_terms',
465 'assign_terms' => 'assign_campaign_terms',
466 ),
467 );
468
469 register_taxonomy( 'campaign_category', array( 'campaign' ), $args );
470
471 $labels = array(
472 'name' => _x( 'Campaign Tags', 'Taxonomy General Name', 'charitable' ),
473 'singular_name' => _x( 'Campaign Tag', 'Taxonomy Singular Name', 'charitable' ),
474 'menu_name' => __( 'Tagss', 'charitable' ),
475 'all_items' => __( 'All Campaign Tags', 'charitable' ),
476 'parent_item' => __( 'Parent Campaign Tag', 'charitable' ),
477 'parent_item_colon' => __( 'Parent Campaign Tag:', 'charitable' ),
478 'new_item_name' => __( 'New Campaign Tag Name', 'charitable' ),
479 'add_new_item' => __( 'Add New Campaign Tag', 'charitable' ),
480 'edit_item' => __( 'Edit Campaign Tag', 'charitable' ),
481 'update_item' => __( 'Update Campaign Tag', 'charitable' ),
482 'view_item' => __( 'View Campaign Tag', 'charitable' ),
483 'separate_items_with_commas' => __( 'Separate campaign tags with commas', 'charitable' ),
484 'add_or_remove_items' => __( 'Add or remove campaign tags', 'charitable' ),
485 'choose_from_most_used' => __( 'Choose from the most used', 'charitable' ),
486 'popular_items' => __( 'Popular Campaign Tags', 'charitable' ),
487 'search_items' => __( 'Search Campaign Tags', 'charitable' ),
488 'not_found' => __( 'Not Found', 'charitable' ),
489 );
490
491 $args = array(
492 'labels' => $labels,
493 'hierarchical' => false,
494 'public' => true,
495 'show_ui' => true,
496 'show_admin_column' => true,
497 'show_in_nav_menus' => true,
498 'show_tagcloud' => true,
499 'show_in_menu' => false,
500 'capabilities' => array(
501 'manage_terms' => 'manage_campaign_terms',
502 'edit_terms' => 'edit_campaign_terms',
503 'delete_terms' => 'delete_campaign_terms',
504 'assign_terms' => 'assign_campaign_terms',
505 ),
506 );
507
508 register_taxonomy( 'campaign_tag', array( 'campaign' ), $args );
509
510 register_taxonomy_for_object_type( 'campaign_category', 'campaign' );
511 register_taxonomy_for_object_type( 'campaign_tag', 'campaign' );
512 }
513 }
514
515 endif;
516