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

517 lines 19.0 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; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- '$post_new_file' is a WordPress core global variable.
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'; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- '$post_new_file' is a WordPress core global variable.
131 else :
132 $post_new_file = 'post-new.php?post_type=campaign'; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- '$post_new_file' is a WordPress core global variable.
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 * @version 1.8.5 Add donors screen.
201 *
202 * @return void
203 */
204 public function admin_header() {
205
206 $is_charitable_page = false;
207
208 // Get the current screen, and check whether we're viewing the campaign post types.
209 $screen = get_current_screen();
210
211 $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', 'charitable_page_charitable-donors', 'charitable_page_charitable-about' ];
212
213 if ( in_array( $screen->post_type, $applicable_post_types, true ) || in_array( $screen->base, $applicable_post_types, true ) ) {
214 $is_charitable_page = true;
215 }
216
217 $is_charitable_page = apply_filters( 'charitable_is_admin_page', $is_charitable_page, $screen );
218
219 if ( false === $is_charitable_page ) {
220 return;
221 }
222
223 include charitable()->get_path( 'includes' ) . 'admin/templates/header.php';
224 }
225
226 /**
227 * Register plugin post types.
228 *
229 * @hook init
230 * @since 1.0.0
231 *
232 * @return void
233 */
234 public function register_post_types() {
235 /**
236 * Filter the campaign post type definition.
237 *
238 * To change any of the arguments used for the post type, other than the name
239 * of the post type itself, use the 'charitable_campaign_post_type' filter.
240 *
241 * @since 1.0.0
242 *
243 * @param array $args Post type arguments.
244 */
245 $args = apply_filters(
246 'charitable_campaign_post_type',
247 array(
248 'labels' => array(
249 'name' => __( 'Campaigns', 'charitable' ),
250 'singular_name' => __( 'Campaign', 'charitable' ),
251 'menu_name' => _x( 'Campaigns', 'Admin menu name', 'charitable' ),
252 'add_new' => __( 'Add New', 'charitable' ),
253 'add_new_item' => __( 'Add Campaign', 'charitable' ),
254 'edit' => __( 'Edit', 'charitable' ),
255 'edit_item' => __( 'Edit Campaign', 'charitable' ),
256 'new_item' => __( 'New Campaign', 'charitable' ),
257 'view' => __( 'View Campaign', 'charitable' ),
258 'view_item' => __( 'View Campaign', 'charitable' ),
259 'search_items' => __( 'Search', 'charitable' ),
260 'not_found' => __( 'No Campaigns found', 'charitable' ),
261 'not_found_in_trash' => __( 'No Campaigns found in trash', 'charitable' ),
262 'parent' => __( 'Parent Campaign', 'charitable' ),
263 ),
264 'description' => __( 'This is where you can create new campaigns for people to support.', 'charitable' ),
265 'public' => true,
266 'show_ui' => true,
267 'capability_type' => 'campaign',
268 'menu_icon' => '',
269 'map_meta_cap' => true,
270 'publicly_queryable' => true,
271 'exclude_from_search' => false,
272 'hierarchical' => false,
273 'rewrite' => array(
274 'slug' => 'campaigns',
275 'with_front' => true,
276 ),
277 'query_var' => true,
278 'supports' => array( 'title', 'thumbnail', 'comments' ),
279 'has_archive' => false,
280 'show_in_nav_menus' => true,
281 'show_in_menu' => false,
282 'show_in_admin_bar' => true,
283
284 )
285 );
286
287 register_post_type( 'campaign', $args );
288
289 /**
290 * Filter the donation post type definition.
291 *
292 * To change any of the arguments used for the post type, other than the name
293 * of the post type itself, use the 'charitable_donation_post_type' filter.
294 *
295 * @since 1.0.0
296 *
297 * @param array $args Post type arguments.
298 */
299 $args = apply_filters(
300 'charitable_donation_post_type',
301 array(
302 'labels' => array(
303 'name' => __( 'Donations', 'charitable' ),
304 'singular_name' => __( 'Donation', 'charitable' ),
305 'menu_name' => _x( 'Donations', 'Admin menu name', 'charitable' ),
306 'add_new' => __( 'Add Donation', 'charitable' ),
307 'add_new_item' => __( 'Add Donation', 'charitable' ),
308 'edit' => __( 'Edit', 'charitable' ),
309 'edit_item' => __( 'Donation Details', 'charitable' ),
310 'new_item' => __( 'New Donation', 'charitable' ),
311 'view' => __( 'View Donation', 'charitable' ),
312 'view_item' => __( 'View Donation', 'charitable' ),
313 'search_items' => __( 'Search Donations', 'charitable' ),
314 'not_found' => __( 'No Donations found', 'charitable' ),
315 'not_found_in_trash' => __( 'No Donations found in trash', 'charitable' ),
316 'parent' => __( 'Parent Donation', 'charitable' ),
317 ),
318 'public' => false,
319 'show_ui' => true,
320 'capability_type' => 'donation',
321 'menu_icon' => '',
322 'map_meta_cap' => true,
323 'publicly_queryable' => false,
324 'exclude_from_search' => false,
325 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
326 'rewrite' => false,
327 'query_var' => false,
328 'supports' => array( '' ),
329 'has_archive' => false,
330 'show_in_nav_menus' => false,
331 'show_in_menu' => false,
332 )
333 );
334
335 register_post_type( 'donation', $args );
336 }
337
338 /**
339 * Register custom post statuses.
340 *
341 * @since 1.0.0
342 *
343 * @return void
344 */
345 public function register_post_statuses() {
346 register_post_status(
347 'charitable-pending',
348 array(
349 'label' => _x( 'Pending', 'Pending Donation Status', 'charitable' ),
350 /* translators: %s: count */
351 'label_count' => _n_noop( 'Pending (%s)', 'Pending (%s)', 'charitable' ),
352 'public' => false,
353 'show_in_admin_all_list' => true,
354 'show_in_admin_status_list' => true,
355 'exclude_from_search' => true,
356 )
357 );
358
359 register_post_status(
360 'charitable-completed',
361 array(
362 'label' => _x( 'Paid', 'Paid Donation Status', 'charitable' ),
363 /* translators: %s: count */
364 'label_count' => _n_noop( 'Paid (%s)', 'Paid (%s)', 'charitable' ),
365 'public' => false,
366 'show_in_admin_all_list' => true,
367 'show_in_admin_status_list' => true,
368 'exclude_from_search' => true,
369 )
370 );
371
372 register_post_status(
373 'charitable-failed',
374 array(
375 'label' => _x( 'Failed', 'Failed Donation Status', 'charitable' ),
376 /* translators: %s: count */
377 'label_count' => _n_noop( 'Failed (%s)', 'Failed (%s)', 'charitable' ),
378 'public' => false,
379 'show_in_admin_all_list' => true,
380 'show_in_admin_status_list' => true,
381 'exclude_from_search' => true,
382 )
383 );
384
385 register_post_status(
386 'charitable-cancelled',
387 array(
388 'label' => _x( 'Canceled', 'Canceled Donation Status', 'charitable' ),
389 /* translators: %s: count */
390 'label_count' => _n_noop( 'Canceled (%s)', 'Canceled (%s)', 'charitable' ),
391 'public' => false,
392 'show_in_admin_all_list' => true,
393 'show_in_admin_status_list' => true,
394 'exclude_from_search' => true,
395 )
396 );
397
398 register_post_status(
399 'charitable-refunded',
400 array(
401 'label' => _x( 'Refunded', 'Refunded Donation Status', 'charitable' ),
402 /* translators: %s: count */
403 'label_count' => _n_noop( 'Refunded (%s)', 'Refunded (%s)', 'charitable' ),
404 'public' => false,
405 'show_in_admin_all_list' => true,
406 'show_in_admin_status_list' => true,
407 'exclude_from_search' => true,
408 )
409 );
410
411 register_post_status(
412 'charitable-preapproved',
413 array(
414 'label' => _x( 'Pre Approved', 'Pre Approved Donation Status', 'charitable' ),
415 /* translators: %s: count */
416 'label_count' => _n_noop( 'Pre Approved (%s)', 'Pre Approved (%s)', 'charitable' ),
417 'public' => false,
418 'show_in_admin_all_list' => true,
419 'show_in_admin_status_list' => true,
420 'exclude_from_search' => true,
421 )
422 );
423 }
424
425 /**
426 * Register the campaign category taxonomy.
427 *
428 * @since 1.0.0
429 *
430 * @return void
431 */
432 public function register_taxonomies() {
433 $labels = array(
434 'name' => _x( 'Campaign Categories', 'Taxonomy General Name', 'charitable' ),
435 'singular_name' => _x( 'Campaign Category', 'Taxonomy Singular Name', 'charitable' ),
436 'menu_name' => __( 'Categories', 'charitable' ),
437 'all_items' => __( 'All Campaign Categories', 'charitable' ),
438 'parent_item' => __( 'Parent Campaign Category', 'charitable' ),
439 'parent_item_colon' => __( 'Parent Campaign Category:', 'charitable' ),
440 'new_item_name' => __( 'New Campaign Category Name', 'charitable' ),
441 'add_new_item' => __( 'Add New Campaign Category', 'charitable' ),
442 'edit_item' => __( 'Edit Campaign Category', 'charitable' ),
443 'update_item' => __( 'Update Campaign Category', 'charitable' ),
444 'view_item' => __( 'View Campaign Category', 'charitable' ),
445 'separate_items_with_commas' => __( 'Separate campaign categories with commas', 'charitable' ),
446 'add_or_remove_items' => __( 'Add or remove campaign categories', 'charitable' ),
447 'choose_from_most_used' => __( 'Choose from the most used', 'charitable' ),
448 'popular_items' => __( 'Popular Campaign Categories', 'charitable' ),
449 'search_items' => __( 'Search Campaign Categories', 'charitable' ),
450 'not_found' => __( 'Not Found', 'charitable' ),
451 );
452
453 $args = array(
454 'labels' => $labels,
455 'hierarchical' => true,
456 'public' => true,
457 'show_ui' => true,
458 'show_admin_column' => true,
459 'show_in_nav_menus' => true,
460 'show_tagcloud' => true,
461 'show_in_menu' => true,
462 'capabilities' => array(
463 'manage_terms' => 'manage_campaign_terms',
464 'edit_terms' => 'edit_campaign_terms',
465 'delete_terms' => 'delete_campaign_terms',
466 'assign_terms' => 'assign_campaign_terms',
467 ),
468 );
469
470 register_taxonomy( 'campaign_category', array( 'campaign' ), $args );
471
472 $labels = array(
473 'name' => _x( 'Campaign Tags', 'Taxonomy General Name', 'charitable' ),
474 'singular_name' => _x( 'Campaign Tag', 'Taxonomy Singular Name', 'charitable' ),
475 'menu_name' => __( 'Tagss', 'charitable' ),
476 'all_items' => __( 'All Campaign Tags', 'charitable' ),
477 'parent_item' => __( 'Parent Campaign Tag', 'charitable' ),
478 'parent_item_colon' => __( 'Parent Campaign Tag:', 'charitable' ),
479 'new_item_name' => __( 'New Campaign Tag Name', 'charitable' ),
480 'add_new_item' => __( 'Add New Campaign Tag', 'charitable' ),
481 'edit_item' => __( 'Edit Campaign Tag', 'charitable' ),
482 'update_item' => __( 'Update Campaign Tag', 'charitable' ),
483 'view_item' => __( 'View Campaign Tag', 'charitable' ),
484 'separate_items_with_commas' => __( 'Separate campaign tags with commas', 'charitable' ),
485 'add_or_remove_items' => __( 'Add or remove campaign tags', 'charitable' ),
486 'choose_from_most_used' => __( 'Choose from the most used', 'charitable' ),
487 'popular_items' => __( 'Popular Campaign Tags', 'charitable' ),
488 'search_items' => __( 'Search Campaign Tags', 'charitable' ),
489 'not_found' => __( 'Not Found', 'charitable' ),
490 );
491
492 $args = array(
493 'labels' => $labels,
494 'hierarchical' => false,
495 'public' => true,
496 'show_ui' => true,
497 'show_admin_column' => true,
498 'show_in_nav_menus' => true,
499 'show_tagcloud' => true,
500 'show_in_menu' => false,
501 'capabilities' => array(
502 'manage_terms' => 'manage_campaign_terms',
503 'edit_terms' => 'edit_campaign_terms',
504 'delete_terms' => 'delete_campaign_terms',
505 'assign_terms' => 'assign_campaign_terms',
506 ),
507 );
508
509 register_taxonomy( 'campaign_tag', array( 'campaign' ), $args );
510
511 register_taxonomy_for_object_type( 'campaign_category', 'campaign' );
512 register_taxonomy_for_object_type( 'campaign_tag', 'campaign' );
513 }
514 }
515
516 endif;
517