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

366 lines 14.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 * @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 add_filter( 'query_vars', array( $this, 'add_query_vars' ) );
66 }
67
68 /**
69 * Register plugin post types.
70 *
71 * @hook init
72 * @return void
73 * @access public
74 * @since 1.0.0
75 */
76 public function register_post_types() {
77 /**
78 * Campaign post type.
79 *
80 * To change any of the arguments used for the post type, other than the name
81 * of the post type itself, use the 'charitable_campaign_post_type' filter.
82 */
83 register_post_type( 'campaign',
84 apply_filters( 'charitable_campaign_post_type',
85 array(
86 'labels' => array(
87 'name' => __( 'Campaigns', 'charitable' ),
88 'singular_name' => __( 'Campaign', 'charitable' ),
89 'menu_name' => _x( 'Campaigns', 'Admin menu name', 'charitable' ),
90 'add_new' => __( 'Add Campaign', 'charitable' ),
91 'add_new_item' => __( 'Add New Campaign', 'charitable' ),
92 'edit' => __( 'Edit', 'charitable' ),
93 'edit_item' => __( 'Edit Campaign', 'charitable' ),
94 'new_item' => __( 'New Campaign', 'charitable' ),
95 'view' => __( 'View Campaign', 'charitable' ),
96 'view_item' => __( 'View Campaign', 'charitable' ),
97 'search_items' => __( 'Search Campaigns', 'charitable' ),
98 'not_found' => __( 'No Campaigns found', 'charitable' ),
99 'not_found_in_trash' => __( 'No Campaigns found in trash', 'charitable' ),
100 'parent' => __( 'Parent Campaign', 'charitable' ),
101 ),
102 'description' => __( 'This is where you can create new campaigns for people to support.', 'charitable' ),
103 'public' => true,
104 'show_ui' => true,
105 'capability_type' => 'campaign',
106 'menu_icon' => '',
107 'map_meta_cap' => true,
108 'publicly_queryable' => true,
109 'exclude_from_search' => false,
110 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
111 'rewrite' => array( 'slug' => 'campaigns', 'with_front' => true ),
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 );
121
122 /**
123 * Donation post type.
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 register_post_type( 'donation',
129 apply_filters( 'charitable_donation_post_type',
130 array(
131 'labels' => array(
132 'name' => __( 'Donations', 'charitable' ),
133 'singular_name' => __( 'Donation', 'charitable' ),
134 'menu_name' => _x( 'Donations', 'Admin menu name', 'charitable' ),
135 'add_new' => __( 'Add Donation', 'charitable' ),
136 'add_new_item' => __( 'Add New Donation', 'charitable' ),
137 'edit' => __( 'Edit', 'charitable' ),
138 'edit_item' => __( 'Donation Details', 'charitable' ),
139 'new_item' => __( 'New Donation', 'charitable' ),
140 'view' => __( 'View Donation', 'charitable' ),
141 'view_item' => __( 'View Donation', 'charitable' ),
142 'search_items' => __( 'Search Donations', 'charitable' ),
143 'not_found' => __( 'No Donations found', 'charitable' ),
144 'not_found_in_trash' => __( 'No Donations found in trash', 'charitable' ),
145 'parent' => __( 'Parent Donation', 'charitable' ),
146 ),
147 'public' => false,
148 'show_ui' => true,
149 'capability_type' => 'donation',
150 'menu_icon' => '',
151 'map_meta_cap' => true,
152 'publicly_queryable' => false,
153 'exclude_from_search' => false,
154 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
155 'rewrite' => false,
156 'query_var' => false,
157 'supports' => array( '' ),
158 'has_archive' => false,
159 'show_in_nav_menus' => false,
160 'show_in_menu' => false,
161 )
162 )
163 );
164 }
165
166 /**
167 * Register custom post statuses.
168 *
169 * @return void
170 * @access public
171 * @since 1.0.0
172 */
173 public function register_post_statuses() {
174 register_post_status( 'charitable-pending', array(
175 'label' => _x( 'Pending', 'Pending Donation Status', 'charitable' ),
176 'label_count' => _n_noop( 'Pending (%s)', 'Pending (%s)', 'charitable' ),
177 'public' => false,
178 'show_in_admin_all_list' => true,
179 'show_in_admin_status_list' => true,
180 'exclude_from_search' => true,
181 ) );
182
183 register_post_status( 'charitable-completed', array(
184 'label' => _x( 'Paid', 'Paid Donation Status', 'charitable' ),
185 'label_count' => _n_noop( 'Paid (%s)', 'Paid (%s)', 'charitable' ),
186 'public' => false,
187 'show_in_admin_all_list' => true,
188 'show_in_admin_status_list' => true,
189 'exclude_from_search' => true,
190 ) );
191
192 register_post_status( 'charitable-failed', array(
193 'label' => _x( 'Failed', 'Failed Donation Status', 'charitable' ),
194 'label_count' => _n_noop( 'Failed (%s)', 'Failed (%s)', 'charitable' ),
195 'public' => false,
196 'show_in_admin_all_list' => true,
197 'show_in_admin_status_list' => true,
198 'exclude_from_search' => true,
199 ) );
200
201 register_post_status( 'charitable-cancelled', array(
202 'label' => _x( 'Canceled', 'Canceled Donation Status', 'charitable' ),
203 'label_count' => _n_noop( 'Canceled (%s)', 'Canceled (%s)', 'charitable' ),
204 'public' => false,
205 'show_in_admin_all_list' => true,
206 'show_in_admin_status_list' => true,
207 'exclude_from_search' => true,
208 ) );
209
210 register_post_status( 'charitable-refunded', array(
211 'label' => _x( 'Refunded', 'Refunded Donation Status', 'charitable' ),
212 'label_count' => _n_noop( 'Refunded (%s)', 'Refunded (%s)', 'charitable' ),
213 'public' => false,
214 'show_in_admin_all_list' => true,
215 'show_in_admin_status_list' => true,
216 'exclude_from_search' => true,
217 ) );
218
219 register_post_status( 'charitable-preapproved', array(
220 'label' => _x( 'Pre Approved', 'Pre Approved Donation Status', 'charitable' ),
221 'label_count' => _n_noop( 'Pre Approved (%s)', 'Pre Approved (%s)', 'charitable' ),
222 'public' => false,
223 'show_in_admin_all_list' => true,
224 'show_in_admin_status_list' => true,
225 'exclude_from_search' => true,
226 ) );
227 }
228
229 /**
230 * Register the campaign category taxonomy.
231 *
232 * @return void
233 * @access public
234 * @since 1.0.0
235 */
236 public function register_taxonomies() {
237 $labels = array(
238 'name' => _x( 'Campaign Categories', 'Taxonomy General Name', 'charitable' ),
239 'singular_name' => _x( 'Campaign Category', 'Taxonomy Singular Name', 'charitable' ),
240 'menu_name' => __( 'Categories', 'charitable' ),
241 'all_items' => __( 'All Campaign Categories', 'charitable' ),
242 'parent_item' => __( 'Parent Campaign Category', 'charitable' ),
243 'parent_item_colon' => __( 'Parent Campaign Category:', 'charitable' ),
244 'new_item_name' => __( 'New Campaign Category Name', 'charitable' ),
245 'add_new_item' => __( 'Add New Campaign Category', 'charitable' ),
246 'edit_item' => __( 'Edit Campaign Category', 'charitable' ),
247 'update_item' => __( 'Update Campaign Category', 'charitable' ),
248 'view_item' => __( 'View Campaign Category', 'charitable' ),
249 'separate_items_with_commas' => __( 'Separate campaign categories with commas', 'charitable' ),
250 'add_or_remove_items' => __( 'Add or remove campaign categories', 'charitable' ),
251 'choose_from_most_used' => __( 'Choose from the most used', 'charitable' ),
252 'popular_items' => __( 'Popular Campaign Categories', 'charitable' ),
253 'search_items' => __( 'Search Campaign Categories', 'charitable' ),
254 'not_found' => __( 'Not Found', 'charitable' ),
255 );
256
257 $args = array(
258 'labels' => $labels,
259 'hierarchical' => true,
260 'public' => true,
261 'show_ui' => true,
262 'show_admin_column' => true,
263 'show_in_nav_menus' => true,
264 'show_tagcloud' => true,
265 );
266
267 register_taxonomy( 'campaign_category', array( 'campaign' ), $args );
268
269 $labels = array(
270 'name' => _x( 'Campaign Tags', 'Taxonomy General Name', 'charitable' ),
271 'singular_name' => _x( 'Campaign Tag', 'Taxonomy Singular Name', 'charitable' ),
272 'menu_name' => __( 'Tags', 'charitable' ),
273 'all_items' => __( 'All Campaign Tags', 'charitable' ),
274 'parent_item' => __( 'Parent Campaign Tag', 'charitable' ),
275 'parent_item_colon' => __( 'Parent Campaign Tag:', 'charitable' ),
276 'new_item_name' => __( 'New Campaign Tag Name', 'charitable' ),
277 'add_new_item' => __( 'Add New Campaign Tag', 'charitable' ),
278 'edit_item' => __( 'Edit Campaign Tag', 'charitable' ),
279 'update_item' => __( 'Update Campaign Tag', 'charitable' ),
280 'view_item' => __( 'View Campaign Tag', 'charitable' ),
281 'separate_items_with_commas' => __( 'Separate campaign tags with commas', 'charitable' ),
282 'add_or_remove_items' => __( 'Add or remove campaign tags', 'charitable' ),
283 'choose_from_most_used' => __( 'Choose from the most used', 'charitable' ),
284 'popular_items' => __( 'Popular Campaign Tags', 'charitable' ),
285 'search_items' => __( 'Search Campaign Tags', 'charitable' ),
286 'not_found' => __( 'Not Found', 'charitable' ),
287 );
288
289 $args = array(
290 'labels' => $labels,
291 'hierarchical' => false,
292 'public' => true,
293 'show_ui' => true,
294 'show_admin_column' => true,
295 'show_in_nav_menus' => true,
296 'show_tagcloud' => true,
297 );
298
299 register_taxonomy( 'campaign_tag', array( 'campaign' ), $args );
300
301 register_taxonomy_for_object_type( 'campaign_category', 'campaign' );
302 register_taxonomy_for_object_type( 'campaign_tag', 'campaign' );
303 }
304
305 /**
306 * Add custom query vars.
307 *
308 * @return void
309 * @access public
310 * @since 1.4.0
311 */
312 public function add_query_vars( $vars ) {
313 $new_vars = array(
314 'donation_id',
315 'cancel',
316 );
317
318 $vars = array_merge( $vars, $new_vars );
319
320 return $vars;
321 }
322
323 /**
324 * Add custom endpoints.
325 *
326 * @return void
327 * @access public
328 * @since 1.0.0
329 */
330 public function add_endpoints() {
331 add_rewrite_endpoint( 'donate', EP_PERMALINK );
332 add_rewrite_endpoint( 'widget', EP_PERMALINK );
333 add_rewrite_endpoint( 'reset_password', EP_PERMALINK );
334 add_rewrite_endpoint( 'forgot_password', EP_PERMALINK );
335 add_rewrite_endpoint( 'donation_receipt', EP_ROOT );
336 add_rewrite_endpoint( 'donation_processing', EP_ROOT );
337 }
338
339 /**
340 * Add custom rewrite tag.
341 *
342 * @return void
343 * @access public
344 * @since 1.0.0
345 */
346 public function add_rewrite_tags() {
347 add_rewrite_tag( '%donation_id%', '([0-9]+)' );
348 }
349
350 /**
351 * Add endpoint for editing campaigns.
352 *
353 * @return void
354 * @access public
355 * @since 1.0.0
356 */
357 public function add_rewrite_rule() {
358 add_rewrite_rule( 'donation-receipt/([0-9]+)/?$', 'index.php?donation_id=$matches[1]&donation_receipt=1', 'top' );
359 add_rewrite_rule( 'donation-processing/([0-9]+)/?$', 'index.php?donation_id=$matches[1]&donation_processing=1', 'top' );
360 add_rewrite_rule( '(.?.+?)(?:/([0-9]+))?/forgot-password/?$', 'index.php?pagename=$matches[1]&page=$matches[2]&forgot_password=1', 'top' );
361 add_rewrite_rule( '(.?.+?)(?:/([0-9]+))?/reset-password/?$', 'index.php?pagename=$matches[1]&page=$matches[2]&reset_password=1', 'top' );
362 }
363 }
364
365 endif; // End class_exists check.
366