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

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