PluginProbe
UpStream: a Project Management Plugin for WordPress / 1.39.3
UpStream: a Project Management Plugin for WordPress v1.39.3
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / includes / up-post-types.php

up-post-types.php in UpStream: a Project Management Plugin for WordPress 1.39.3, at includes/up-post-types.php

296 lines 13.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly
4 if ( ! defined('ABSPATH')) {
5 exit;
6 }
7
8
9 /**
10 * Registers and sets up the Downloads custom post type
11 *
12 * @return void
13 * @since 1.0
14 */
15 function upstream_setup_post_types()
16 {
17 up_debug();
18
19 $project_base = upstream_get_project_base();
20 $client_base = upstream_get_client_base();
21
22 $project_labels = apply_filters('upstream_project_labels', [
23 'name' => _x('%2$s', 'project post type name', 'upstream'),
24 'singular_name' => _x('%1$s', 'singular project post type name', 'upstream'),
25 'add_new' => __('New %1s', 'upstream'),
26 'add_new_item' => __('Add New %1$s', 'upstream'),
27 'edit_item' => __('Edit %1$s', 'upstream'),
28 'new_item' => __('New %1$s', 'upstream'),
29 'all_items' => __('%2$s', 'upstream'),
30 'view_item' => __('View %1$s', 'upstream'),
31 'search_items' => __('Search %2$s', 'upstream'),
32 'not_found' => __('No %2$s found', 'upstream'),
33 'not_found_in_trash' => __('No %2$s found in Trash', 'upstream'),
34 'parent_item_colon' => '',
35 'menu_name' => _x('%2$s', 'project post type menu name', 'upstream'),
36 'featured_image' => __('%1$s Image', 'upstream'),
37 'set_featured_image' => __('Set %1$s Image', 'upstream'),
38 'remove_featured_image' => __('Remove %1$s Image', 'upstream'),
39 'use_featured_image' => __('Use as %1$s Image', 'upstream'),
40 'filter_items_list' => __('Filter %2$s list', 'upstream'),
41 'items_list_navigation' => __('%2$s list navigation', 'upstream'),
42 'items_list' => __('%2$s list', 'upstream'),
43 ]);
44
45 foreach ($project_labels as $key => $value) {
46 $project_labels[$key] = sprintf($value, upstream_project_label(), upstream_project_label_plural());
47 }
48
49 $project_args = [
50 'labels' => $project_labels,
51 'public' => true,
52 'publicly_queryable' => true,
53 'show_ui' => true,
54 'show_in_menu' => true,
55 'menu_icon' => 'dashicons-arrow-up-alt',
56 'menu_position' => is_plugin_active('woocommerce-product-vendors/woocommerce-product-vendors.php') ? 993 : 56,
57 'query_var' => true,
58 'rewrite' => ['slug' => $project_base, 'with_front' => false],
59 'capability_type' => 'project',
60 'map_meta_cap' => true,
61 'has_archive' => $project_base,
62 'hierarchical' => false,
63 'supports' => apply_filters('upstream_project_supports', ['title', 'revisions', 'author']),
64 ];
65 register_post_type('project', apply_filters('upstream_project_post_type_args', $project_args));
66
67 if (is_clients_disabled()) {
68 return;
69 }
70
71 /* Client Post Type */
72 $client_labels = apply_filters('upstream_client_labels', [
73 'name' => _x('%2$s', 'project post type name', 'upstream'),
74 'singular_name' => _x('%1$s', 'singular project post type name', 'upstream'),
75 'add_new' => __('New %1s', 'upstream'),
76 'add_new_item' => __('Add New %1$s', 'upstream'),
77 'edit_item' => __('Edit %1$s', 'upstream'),
78 'new_item' => __('New %1$s', 'upstream'),
79 'all_items' => __('%2$s', 'upstream'),
80 'view_item' => __('View %1$s', 'upstream'),
81 'search_items' => __('Search %2$s', 'upstream'),
82 'not_found' => __('No %2$s found', 'upstream'),
83 'not_found_in_trash' => __('No %2$s found in Trash', 'upstream'),
84 'parent_item_colon' => '',
85 'menu_name' => _x('%2$s', 'project post type menu name', 'upstream'),
86 'featured_image' => __('%1$s Image', 'upstream'),
87 'set_featured_image' => __('Set %1$s Image', 'upstream'),
88 'remove_featured_image' => __('Remove %1$s Image', 'upstream'),
89 'use_featured_image' => __('Use as %1$s Image', 'upstream'),
90 'filter_items_list' => __('Filter %2$s list', 'upstream'),
91 'items_list_navigation' => __('%2$s list navigation', 'upstream'),
92 'items_list' => __('%2$s list', 'upstream'),
93 ]);
94
95 foreach ($client_labels as $key => $value) {
96 $client_labels[$key] = sprintf($value, upstream_client_label(), upstream_client_label_plural());
97 }
98
99 $client_args = [
100 'labels' => $client_labels,
101 'public' => false,
102 'publicly_queryable' => false,
103 'show_ui' => true,
104 'show_in_menu' => false,
105 'query_var' => true,
106 'rewrite' => ['slug' => $client_base, 'with_front' => false],
107 'capability_type' => 'client',
108 'map_meta_cap' => true,
109 'has_archive' => false,
110 'hierarchical' => false,
111 'supports' => apply_filters('upstream_client_supports', ['title', 'revisions']),
112 ];
113 register_post_type('client', apply_filters('upstream_client_post_type_args', $client_args));
114
115 \UpStream\Milestones::getInstance()->createPostType();
116 }
117
118 add_action('init', 'upstream_setup_post_types', 1);
119
120 /**
121 * Registers the custom taxonomies for the projects custom post type
122 *
123 * @return void
124 * @since 1.0
125 */
126 function upstream_setup_taxonomies()
127 {
128 if (!is_project_categorization_disabled()) {
129
130 $slug = defined('UPSTREAM_CAT_SLUG') ? UPSTREAM_CAT_SLUG : 'projects';
131
132 /** Categories */
133 $category_labels = [
134 'name' => _x('Category', 'taxonomy general name', 'upstream'),
135 'singular_name' => _x('Category', 'taxonomy singular name', 'upstream'),
136 'search_items' => sprintf(__('Search %s Categories', 'upstream'), upstream_project_label()),
137 'all_items' => sprintf(__('All %s Categories', 'upstream'), upstream_project_label()),
138 'parent_item' => sprintf(__('Parent %s Category', 'upstream'), upstream_project_label()),
139 'parent_item_colon' => sprintf(__('Parent %s Category:', 'upstream'), upstream_project_label()),
140 'edit_item' => sprintf(__('Edit %s Category', 'upstream'), upstream_project_label()),
141 'update_item' => sprintf(__('Update %s Category', 'upstream'), upstream_project_label()),
142 'add_new_item' => sprintf(__('Add New %s Category', 'upstream'), upstream_project_label()),
143 'new_item_name' => sprintf(__('New %s Category Name', 'upstream'), upstream_project_label()),
144 'menu_name' => __('Categories', 'upstream'),
145 ];
146
147 $category_args = apply_filters(
148 'upstream_project_category_args',
149 [
150 'hierarchical' => true,
151 'labels' => apply_filters('_upstream_project_category_labels', $category_labels),
152 'show_ui' => true,
153 'show_in_rest' => true,
154 'show_admin_column' => true,
155 'query_var' => 'project_category',
156 'rewrite' => ['slug' => $slug . '/category', 'with_front' => false, 'hierarchical' => true],
157 'capabilities' => [
158 'manage_terms' => 'manage_project_terms',
159 'edit_terms' => 'edit_project_terms',
160 'assign_terms' => 'assign_project_terms',
161 'delete_terms' => 'delete_project_terms',
162 ],
163 ]
164 );
165 register_taxonomy('project_category', ['project'], $category_args);
166 register_taxonomy_for_object_type('project_category', 'project');
167
168 /** Tags **/
169 $tagsLabels = [
170 'name' => _x('Tags', 'taxonomy (tag) general name', 'upstream'),
171 'singular_name' => _x('Tag', 'taxonomy (tag) singular name', 'upstream'),
172 'search_items' => __('Search Tags', 'upstream'),
173 'popular_items' => __('Popular Tags'),
174 'all_items' => __('All Tags', 'upstream'),
175 'parent_item' => null,
176 'parent_item_colon' => null,
177 'edit_item' => __('Edit Tag', 'upstream'),
178 'update_item' => __('Update Tag', 'upstream'),
179 'add_new_item' => __('Add New Tag', 'upstream'),
180 'new_item_name' => __('New Tag Name', 'upstream'),
181 'add_or_remove_items' => __('Add or remove tags'),
182 'separate_items_with_commas' => __('Separate tags with commas'),
183 'choose_from_most_used' => __('Choose from the most used tags'),
184 'menu_name' => __('Tags', 'upstream'),
185 ];
186
187 $args = [
188 'hierarchical' => false,
189 'labels' => apply_filters('_upstream_project_tags_labels', $tagsLabels),
190 'show_ui' => true,
191 'show_in_rest' => true,
192 'show_admin_column' => true,
193 'query_var' => 'upstream_tag',
194 'rewrite' => [
195 'slug' => 'upstream/tag',
196 'with_front' => false,
197 'hierarchical' => false,
198 ],
199 'capabilities' => [
200 'manage_terms' => 'manage_project_terms',
201 'edit_terms' => 'edit_project_terms',
202 'assign_terms' => 'assign_project_terms',
203 'delete_terms' => 'delete_project_terms',
204 ],
205 ];
206
207 register_taxonomy('upstream_tag', ['project'], $args);
208 register_taxonomy_for_object_type('upstream_tag', 'project');
209
210 }
211
212 /** Milestone Categories **/
213 $tagsLabels = [
214 'name' => upstream_milestone_category_label_plural(),
215 'singular_name' => upstream_milestone_category_label(),
216 'search_items' => sprintf(__('Search %s', 'upstream'),
217 upstream_milestone_category_label_plural()),
218 'popular_items' => sprintf(__('Popular %s'), upstream_milestone_category_label_plural()),
219 'all_items' => sprintf(__('All %s', 'upstream'), upstream_milestone_category_label_plural()),
220 'parent_item' => null,
221 'parent_item_colon' => null,
222 'edit_item' => sprintf(__('Edit %s', 'upstream'), upstream_milestone_category_label()),
223 'update_item' => sprintf(__('Update %s', 'upstream'), upstream_milestone_category_label()),
224 'add_new_item' => sprintf(__('Add New %s', 'upstream'), upstream_milestone_category_label()),
225 'new_item_name' => sprintf(__('New %s Name', 'upstream'), upstream_milestone_category_label()),
226 'add_or_remove_items' => sprintf(__('Add or remove %s'), upstream_milestone_category_label_plural()),
227 'separate_items_with_commas' => sprintf(__('Separate %s with commas'), upstream_milestone_category_label()),
228 'choose_from_most_used' => sprintf(__('Choose from the most used %s'),
229 upstream_milestone_category_label()),
230 'menu_name' => sprintf(__('%s', 'upstream'), upstream_milestone_category_label()),
231 ];
232
233 if ( ! upstream_disable_milestone_categories()) {
234 $args = [
235 'hierarchical' => true,
236 'labels' => apply_filters('_upstream_milestone_categories_labels', $tagsLabels),
237 'show_ui' => true,
238 'show_in_rest' => true,
239 'show_admin_column' => true,
240 'query_var' => 'upstream_milestone_category',
241 'rewrite' => [
242 'slug' => 'upstream/milestone_category',
243 'with_front' => false,
244 'hierarchical' => false,
245 ],
246 'capabilities' => [
247 'manage_terms' => 'manage_project_terms',
248 'edit_terms' => 'edit_project_terms',
249 'assign_terms' => 'assign_project_terms',
250 'delete_terms' => 'delete_project_terms',
251 ],
252 ];
253
254 register_taxonomy('upst_milestone_category', ['upst_milestone'], $args);
255 register_taxonomy_for_object_type('upst_milestone_category', 'upst_milestone');
256 }
257 }
258
259 add_action('init', 'upstream_setup_taxonomies', 1);
260
261 /**
262 * Milestone taxonomies custom fields.
263 */
264 function upstream_milestone_category_form_fields($taxonomy) {
265 $value = '';
266 if (is_object($taxonomy)) {
267 $value = get_term_meta($taxonomy->term_id, 'color', true);
268 }
269
270 ?>
271 <tr class="form-field">
272 <th scope="row" valign="top">
273 <label for="term_color"><?php _e('Default color', 'upstream'); ?></label>
274 </th>
275 <td>
276 <input type="text" name="color" class="color-field" id="term_color" value="<?php echo esc_attr($value); ?>" />
277 <p class="description">Select a default color for milestones related to this category.</p>
278 </td>
279 </tr>
280 <br>
281 <?php
282 }
283
284 function upstream_save_milestone_category_form_fields($termId) {
285 if (isset($_POST['color'])) {
286 update_term_meta($termId, 'color', sanitize_text_field($_POST['color']));
287 }
288 }
289
290 if ( ! is_project_categorization_disabled()) {
291 add_action('upst_milestone_category_add_form_fields', 'upstream_milestone_category_form_fields');
292 add_action('upst_milestone_category_edit_form_fields', 'upstream_milestone_category_form_fields');
293 add_action('edit_terms', 'upstream_save_milestone_category_form_fields');
294 add_action('create_term', 'upstream_save_milestone_category_form_fields');
295 }
296