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

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

315 lines 12.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 Eric Daams
7 * @copyright Copyright (c) 2019, Studio 164a
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.0.0
10 * @version 1.2.0
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( 'charitable_campaign_post_type', array(
83 'labels' => array(
84 'name' => __( 'Campaigns', 'charitable' ),
85 'singular_name' => __( 'Campaign', 'charitable' ),
86 'menu_name' => _x( 'Campaigns', 'Admin menu name', 'charitable' ),
87 'add_new' => __( 'Add Campaign', 'charitable' ),
88 'add_new_item' => __( 'Add New Campaign', 'charitable' ),
89 'edit' => __( 'Edit', 'charitable' ),
90 'edit_item' => __( 'Edit Campaign', 'charitable' ),
91 'new_item' => __( 'New Campaign', 'charitable' ),
92 'view' => __( 'View Campaign', 'charitable' ),
93 'view_item' => __( 'View Campaign', 'charitable' ),
94 'search_items' => __( 'Search Campaigns', 'charitable' ),
95 'not_found' => __( 'No Campaigns found', 'charitable' ),
96 'not_found_in_trash' => __( 'No Campaigns found in trash', 'charitable' ),
97 'parent' => __( 'Parent Campaign', 'charitable' ),
98 ),
99 'description' => __( 'This is where you can create new campaigns for people to support.', 'charitable' ),
100 'public' => true,
101 'show_ui' => true,
102 'capability_type' => 'campaign',
103 'menu_icon' => '',
104 'map_meta_cap' => true,
105 'publicly_queryable' => true,
106 'exclude_from_search' => false,
107 'hierarchical' => false,
108 'rewrite' => array(
109 'slug' => 'campaigns',
110 'with_front' => true,
111 ),
112 'query_var' => true,
113 'supports' => array( 'title', 'thumbnail', 'comments' ),
114 'has_archive' => false,
115 'show_in_nav_menus' => true,
116 'show_in_menu' => false,
117 'show_in_admin_bar' => true,
118 ) );
119
120 register_post_type( 'campaign', $args );
121
122 /**
123 * Filter the donation post type definition.
124 *
125 * To change any of the arguments used for the post type, other than the name
126 * of the post type itself, use the 'charitable_donation_post_type' filter.
127 *
128 * @since 1.0.0
129 *
130 * @param array $args Post type arguments.
131 */
132 $args = apply_filters( 'charitable_donation_post_type', array(
133 'labels' => array(
134 'name' => __( 'Donations', 'charitable' ),
135 'singular_name' => __( 'Donation', 'charitable' ),
136 'menu_name' => _x( 'Donations', 'Admin menu name', 'charitable' ),
137 'add_new' => __( 'Add Donation', 'charitable' ),
138 'add_new_item' => __( 'Add New Donation', 'charitable' ),
139 'edit' => __( 'Edit', 'charitable' ),
140 'edit_item' => __( 'Donation Details', 'charitable' ),
141 'new_item' => __( 'New Donation', 'charitable' ),
142 'view' => __( 'View Donation', 'charitable' ),
143 'view_item' => __( 'View Donation', 'charitable' ),
144 'search_items' => __( 'Search Donations', 'charitable' ),
145 'not_found' => __( 'No Donations found', 'charitable' ),
146 'not_found_in_trash' => __( 'No Donations found in trash', 'charitable' ),
147 'parent' => __( 'Parent Donation', 'charitable' ),
148 ),
149 'public' => false,
150 'show_ui' => true,
151 'capability_type' => 'donation',
152 'menu_icon' => '',
153 'map_meta_cap' => true,
154 'publicly_queryable' => false,
155 'exclude_from_search' => false,
156 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
157 'rewrite' => false,
158 'query_var' => false,
159 'supports' => array( '' ),
160 'has_archive' => false,
161 'show_in_nav_menus' => false,
162 'show_in_menu' => false,
163 ) );
164
165 register_post_type( 'donation', $args );
166 }
167
168 /**
169 * Register custom post statuses.
170 *
171 * @since 1.0.0
172 *
173 * @return void
174 */
175 public function register_post_statuses() {
176 register_post_status( 'charitable-pending', array(
177 'label' => _x( 'Pending', 'Pending Donation Status', 'charitable' ),
178 /* translators: %s: count */
179 'label_count' => _n_noop( 'Pending (%s)', 'Pending (%s)', 'charitable' ),
180 'public' => false,
181 'show_in_admin_all_list' => true,
182 'show_in_admin_status_list' => true,
183 'exclude_from_search' => true,
184 ) );
185
186 register_post_status( 'charitable-completed', array(
187 'label' => _x( 'Paid', 'Paid Donation Status', 'charitable' ),
188 /* translators: %s: count */
189 'label_count' => _n_noop( 'Paid (%s)', 'Paid (%s)', 'charitable' ),
190 'public' => false,
191 'show_in_admin_all_list' => true,
192 'show_in_admin_status_list' => true,
193 'exclude_from_search' => true,
194 ) );
195
196 register_post_status( 'charitable-failed', array(
197 'label' => _x( 'Failed', 'Failed Donation Status', 'charitable' ),
198 /* translators: %s: count */
199 'label_count' => _n_noop( 'Failed (%s)', 'Failed (%s)', 'charitable' ),
200 'public' => false,
201 'show_in_admin_all_list' => true,
202 'show_in_admin_status_list' => true,
203 'exclude_from_search' => true,
204 ) );
205
206 register_post_status( 'charitable-cancelled', array(
207 'label' => _x( 'Canceled', 'Canceled Donation Status', 'charitable' ),
208 /* translators: %s: count */
209 'label_count' => _n_noop( 'Canceled (%s)', 'Canceled (%s)', 'charitable' ),
210 'public' => false,
211 'show_in_admin_all_list' => true,
212 'show_in_admin_status_list' => true,
213 'exclude_from_search' => true,
214 ) );
215
216 register_post_status( 'charitable-refunded', array(
217 'label' => _x( 'Refunded', 'Refunded Donation Status', 'charitable' ),
218 /* translators: %s: count */
219 'label_count' => _n_noop( 'Refunded (%s)', 'Refunded (%s)', 'charitable' ),
220 'public' => false,
221 'show_in_admin_all_list' => true,
222 'show_in_admin_status_list' => true,
223 'exclude_from_search' => true,
224 ) );
225
226 register_post_status( 'charitable-preapproved', array(
227 'label' => _x( 'Pre Approved', 'Pre Approved Donation Status', 'charitable' ),
228 /* translators: %s: count */
229 'label_count' => _n_noop( 'Pre Approved (%s)', 'Pre Approved (%s)', 'charitable' ),
230 'public' => false,
231 'show_in_admin_all_list' => true,
232 'show_in_admin_status_list' => true,
233 'exclude_from_search' => true,
234 ) );
235 }
236
237 /**
238 * Register the campaign category taxonomy.
239 *
240 * @since 1.0.0
241 *
242 * @return void
243 */
244 public function register_taxonomies() {
245 $labels = array(
246 'name' => _x( 'Campaign Categories', 'Taxonomy General Name', 'charitable' ),
247 'singular_name' => _x( 'Campaign Category', 'Taxonomy Singular Name', 'charitable' ),
248 'menu_name' => __( 'Categories', 'charitable' ),
249 'all_items' => __( 'All Campaign Categories', 'charitable' ),
250 'parent_item' => __( 'Parent Campaign Category', 'charitable' ),
251 'parent_item_colon' => __( 'Parent Campaign Category:', 'charitable' ),
252 'new_item_name' => __( 'New Campaign Category Name', 'charitable' ),
253 'add_new_item' => __( 'Add New Campaign Category', 'charitable' ),
254 'edit_item' => __( 'Edit Campaign Category', 'charitable' ),
255 'update_item' => __( 'Update Campaign Category', 'charitable' ),
256 'view_item' => __( 'View Campaign Category', 'charitable' ),
257 'separate_items_with_commas' => __( 'Separate campaign categories with commas', 'charitable' ),
258 'add_or_remove_items' => __( 'Add or remove campaign categories', 'charitable' ),
259 'choose_from_most_used' => __( 'Choose from the most used', 'charitable' ),
260 'popular_items' => __( 'Popular Campaign Categories', 'charitable' ),
261 'search_items' => __( 'Search Campaign Categories', 'charitable' ),
262 'not_found' => __( 'Not Found', 'charitable' ),
263 );
264
265 $args = array(
266 'labels' => $labels,
267 'hierarchical' => true,
268 'public' => true,
269 'show_ui' => true,
270 'show_admin_column' => true,
271 'show_in_nav_menus' => true,
272 'show_tagcloud' => true,
273 );
274
275 register_taxonomy( 'campaign_category', array( 'campaign' ), $args );
276
277 $labels = array(
278 'name' => _x( 'Campaign Tags', 'Taxonomy General Name', 'charitable' ),
279 'singular_name' => _x( 'Campaign Tag', 'Taxonomy Singular Name', 'charitable' ),
280 'menu_name' => __( 'Tags', 'charitable' ),
281 'all_items' => __( 'All Campaign Tags', 'charitable' ),
282 'parent_item' => __( 'Parent Campaign Tag', 'charitable' ),
283 'parent_item_colon' => __( 'Parent Campaign Tag:', 'charitable' ),
284 'new_item_name' => __( 'New Campaign Tag Name', 'charitable' ),
285 'add_new_item' => __( 'Add New Campaign Tag', 'charitable' ),
286 'edit_item' => __( 'Edit Campaign Tag', 'charitable' ),
287 'update_item' => __( 'Update Campaign Tag', 'charitable' ),
288 'view_item' => __( 'View Campaign Tag', 'charitable' ),
289 'separate_items_with_commas' => __( 'Separate campaign tags with commas', 'charitable' ),
290 'add_or_remove_items' => __( 'Add or remove campaign tags', 'charitable' ),
291 'choose_from_most_used' => __( 'Choose from the most used', 'charitable' ),
292 'popular_items' => __( 'Popular Campaign Tags', 'charitable' ),
293 'search_items' => __( 'Search Campaign Tags', 'charitable' ),
294 'not_found' => __( 'Not Found', 'charitable' ),
295 );
296
297 $args = array(
298 'labels' => $labels,
299 'hierarchical' => false,
300 'public' => true,
301 'show_ui' => true,
302 'show_admin_column' => true,
303 'show_in_nav_menus' => true,
304 'show_tagcloud' => true,
305 );
306
307 register_taxonomy( 'campaign_tag', array( 'campaign' ), $args );
308
309 register_taxonomy_for_object_type( 'campaign_category', 'campaign' );
310 register_taxonomy_for_object_type( 'campaign_tag', 'campaign' );
311 }
312 }
313
314 endif;
315