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

up-labels.php in UpStream: a Project Management Plugin for WordPress 1.39.2, at includes/up-labels.php

587 lines 16.5 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 * Get Default Labels
11 *
12 * @return array $defaults Default labels
13 * @since 1.0.0
14 */
15 function upstream_get_default_labels()
16 {
17 $option = get_option('upstream_general');
18
19 $defaults = [
20 'projects' => [
21 'singular' => isset($option['project']['single']) ? $option['project']['single'] : __(
22 'Project',
23 'upstream'
24 ),
25 'plural' => isset($option['project']['plural']) ? $option['project']['plural'] : __(
26 'Projects',
27 'upstream'
28 ),
29 ],
30 'clients' => [
31 'singular' => isset($option['client']['single']) ? $option['client']['single'] : __(
32 'Client',
33 'upstream'
34 ),
35 'plural' => isset($option['client']['plural']) ? $option['client']['plural'] : __(
36 'Clients',
37 'upstream'
38 ),
39 ],
40 'milestones' => [
41 'singular' => isset($option['milestone']['single']) ? $option['milestone']['single'] : __(
42 'Milestone',
43 'upstream'
44 ),
45 'plural' => isset($option['milestone']['plural']) ? $option['milestone']['plural'] : __(
46 'Milestones',
47 'upstream'
48 ),
49 ],
50 'milestone_categories' => [
51 'singular' => isset($option['milestone_categories']['single']) ? $option['milestone_categories']['single'] : __(
52 'Milestone Category',
53 'upstream'
54 ),
55 'plural' => isset($option['milestone_categories']['plural']) ? $option['milestone_categories']['plural'] : __(
56 'Milestone Categories',
57 'upstream'
58 ),
59 ],
60 'tasks' => [
61 'singular' => isset($option['task']['single']) ? $option['task']['single'] : __('Task', 'upstream'),
62 'plural' => isset($option['task']['plural']) ? $option['task']['plural'] : __('Tasks', 'upstream'),
63 ],
64 'bugs' => [
65 'singular' => isset($option['bug']['single']) ? $option['bug']['single'] : __('Bug', 'upstream'),
66 'plural' => isset($option['bug']['plural']) ? $option['bug']['plural'] : __('Bugs', 'upstream'),
67 ],
68 'files' => [
69 'singular' => isset($option['file']['single']) ? $option['file']['single'] : __('File', 'upstream'),
70 'plural' => isset($option['file']['plural']) ? $option['file']['plural'] : __('Files', 'upstream'),
71 ],
72 'discussion' => [
73 'singular' => isset($option['discussion']['single']) ? $option['discussion']['single'] : __('Discussion',
74 'upstream'),
75 'plural' => isset($option['discussion']['plural']) ? $option['discussion']['plural'] : __('Discussions',
76 'upstream'),
77 ],
78 ];
79
80 return apply_filters('upstream_default_labels', $defaults);
81 }
82
83 /**
84 * Get Project Labels
85 *
86 * @param bool $lowercase
87 *
88 * @return string $defaults['singular'] Singular label
89 * @since 1.0.0
90 *
91 */
92 function upstream_project_label($lowercase = false)
93 {
94 $defaults = upstream_get_default_labels();
95
96 $label = ($lowercase) ? strtolower($defaults['projects']['singular']) : $defaults['projects']['singular'];
97
98 return __($label, 'upstream');
99 }
100
101 function upstream_project_label_plural($lowercase = false)
102 {
103 $defaults = upstream_get_default_labels();
104
105 $label = ($lowercase) ? strtolower($defaults['projects']['plural']) : $defaults['projects']['plural'];
106
107 return __($label, 'upstream');
108 }
109
110 /**
111 * Get Client Label
112 *
113 * @param bool $lowercase
114 *
115 * @return string $defaults['singular'] Singular label
116 * @since 1.0.0
117 *
118 */
119 function upstream_client_label($lowercase = false)
120 {
121 $defaults = upstream_get_default_labels();
122
123 $label = ($lowercase) ? strtolower($defaults['clients']['singular']) : $defaults['clients']['singular'];
124
125 return __($label, 'upstream');
126 }
127
128 function upstream_client_label_plural($lowercase = false)
129 {
130 $defaults = upstream_get_default_labels();
131
132 $label = ($lowercase) ? strtolower($defaults['clients']['plural']) : $defaults['clients']['plural'];
133
134 return __($label, 'upstream');
135 }
136
137 /**
138 * Get Milestone Label
139 *
140 * @param bool $lowercase
141 *
142 * @return string $defaults['singular'] Singular label
143 * @since 1.0.0
144 *
145 */
146 function upstream_milestone_label($lowercase = false)
147 {
148 $defaults = upstream_get_default_labels();
149
150 $label = ($lowercase) ? strtolower($defaults['milestones']['singular']) : $defaults['milestones']['singular'];
151
152 return __($label, 'upstream');
153 }
154
155 function upstream_milestone_label_plural($lowercase = false)
156 {
157 $defaults = upstream_get_default_labels();
158
159 $label = ($lowercase) ? strtolower($defaults['milestones']['plural']) : $defaults['milestones']['plural'];
160
161 return __($label, 'upstream');
162 }
163
164 /**
165 * Get Milestone Category Label
166 *
167 * @param bool $lowercase
168 *
169 * @return string $defaults['singular'] Singular label
170 * @since 1.0.0
171 *
172 */
173 function upstream_milestone_category_label($lowercase = false)
174 {
175 $defaults = upstream_get_default_labels();
176
177 $label = ($lowercase) ? strtolower($defaults['milestone_categories']['singular']) : $defaults['milestone_categories']['singular'];
178
179 return __($label, 'upstream');
180 }
181
182 function upstream_milestone_category_label_plural($lowercase = false)
183 {
184 $defaults = upstream_get_default_labels();
185
186 $label = ($lowercase) ? strtolower($defaults['milestone_categories']['plural']) : $defaults['milestone_categories']['plural'];
187
188 return __($label, 'upstream');
189 }
190
191 /**
192 * Get Task Label
193 *
194 * @param bool $lowercase
195 *
196 * @return string $defaults['singular'] Singular label
197 * @since 1.0.0
198 *
199 */
200 function upstream_task_label($lowercase = false)
201 {
202 $defaults = upstream_get_default_labels();
203
204 $label = ($lowercase) ? strtolower($defaults['tasks']['singular']) : $defaults['tasks']['singular'];
205
206 return __($label, 'upstream');
207 }
208
209 function upstream_task_label_plural($lowercase = false)
210 {
211 $defaults = upstream_get_default_labels();
212
213 $label = ($lowercase) ? strtolower($defaults['tasks']['plural']) : $defaults['tasks']['plural'];
214
215 return __($label, 'upstream');
216 }
217
218 /**
219 * Get Bug Label
220 *
221 * @param bool $lowercase
222 *
223 * @return string $defaults['singular'] Singular label
224 * @since 1.0.0
225 *
226 */
227 function upstream_bug_label($lowercase = false)
228 {
229 $defaults = upstream_get_default_labels();
230
231 $label = ($lowercase) ? strtolower($defaults['bugs']['singular']) : $defaults['bugs']['singular'];
232
233 return __($label, 'upstream');
234 }
235
236 function upstream_bug_label_plural($lowercase = false)
237 {
238 $defaults = upstream_get_default_labels();
239
240 $label = ($lowercase) ? strtolower($defaults['bugs']['plural']) : $defaults['bugs']['plural'];
241
242 return __($label, 'upstream');
243 }
244
245 /**
246 * Get file Label
247 *
248 * @param bool $lowercase
249 *
250 * @return string $defaults['singular'] Singular label
251 * @since 1.0.0
252 *
253 */
254 function upstream_file_label($lowercase = false)
255 {
256 $defaults = upstream_get_default_labels();
257
258 $label = ($lowercase) ? strtolower($defaults['files']['singular']) : $defaults['files']['singular'];
259
260 return __($label, 'upstream');
261 }
262
263 function upstream_file_label_plural($lowercase = false)
264 {
265 $defaults = upstream_get_default_labels();
266
267 $label = ($lowercase) ? strtolower($defaults['files']['plural']) : $defaults['files']['plural'];
268
269 return __($label, 'upstream');
270 }
271
272 /**
273 * Get discussion Label
274 *
275 * @param bool $lowercase
276 *
277 * @return string $defaults['singular'] Singular label
278 * @since 1.0.0
279 *
280 */
281 function upstream_discussion_label($lowercase = false)
282 {
283 $defaults = upstream_get_default_labels();
284
285 $label = ($lowercase) ? strtolower($defaults['discussion']['singular']) : $defaults['discussion']['singular'];
286
287 return $label;
288 }
289
290 function upstream_discussion_label_plural($lowercase = false)
291 {
292 $defaults = upstream_get_default_labels();
293
294 $label = ($lowercase) ? strtolower($defaults['discussion']['plural']) : $defaults['discussion']['plural'];
295
296 return $label;
297 }
298
299 /**
300 * Change default "Enter title here" input
301 *
302 * @param string $title Default title placeholder text
303 *
304 * @return string $title New placeholder text
305 * @since 1.0.0
306 *
307 */
308 function upstream_change_default_title($title)
309 {
310 $screen = get_current_screen();
311
312 switch ($screen->post_type) {
313 case 'project':
314 $label = upstream_project_label();
315 $title = sprintf(__('Enter %s name here', 'upstream'), $label);
316 break;
317 case 'client':
318 $label = upstream_client_label();
319 $title = sprintf(__('Enter %s name here', 'upstream'), $label);
320 break;
321
322 }
323
324 return $title;
325 }
326
327 add_filter('enter_title_here', 'upstream_change_default_title');
328
329 /**
330 * Get the singular and plural labels for a project taxonomy
331 *
332 * @param string $taxonomy The Taxonomy to get labels for
333 *
334 * @return array Associative array of labels (name = plural)
335 * @since 1.0.0
336 *
337 */
338 function upstream_get_taxonomy_labels($taxonomy = 'project_category')
339 {
340 $allowed_taxonomies = apply_filters('upstream_allowed_project_taxonomies', ['project_category']);
341
342 if ( ! in_array($taxonomy, $allowed_taxonomies)) {
343 return false;
344 }
345
346 $labels = [];
347 $taxonomy = get_taxonomy($taxonomy);
348
349 if (false !== $taxonomy) {
350 $singular = $taxonomy->labels->singular_name;
351 $name = $taxonomy->labels->name;
352
353 $labels = [
354 'name' => $name,
355 'singular_name' => $singular,
356 ];
357 }
358
359 return apply_filters('upstream_get_taxonomy_labels', $labels, $taxonomy);
360 }
361
362
363 /**
364 * Updated Messages
365 *
366 * Returns an array of with all updated messages.
367 *
368 * @param array $messages Post updated message
369 *
370 * @return array $messages New post updated messages
371 * @since 1.0.0
372 *
373 */
374 function upstream_updated_messages($messages)
375 {
376 global $post_ID;
377
378 $postURL = get_permalink($post_ID);
379 $anchorTagOpening = '<a href="' . esc_attr($postURL) . '" target="_blank" rel="noopener noreferrer">';
380 $anchorTagClosing = '</a>';
381
382 $postTypeLabelProject = upstream_project_label();
383 $postTypeLabelClient = upstream_client_label();
384
385 $messages['project'] = [
386 1 => sprintf(
387 __('%2$s updated. %1$sView %2$s%3$s', 'upstream'),
388 $anchorTagOpening,
389 $postTypeLabelProject,
390 $anchorTagClosing
391 ),
392 4 => sprintf(
393 __('%2$s updated. %1$sView %2$s%3$s', 'upstream'),
394 $anchorTagOpening,
395 $postTypeLabelProject,
396 $anchorTagClosing
397 ),
398 6 => sprintf(
399 __('%2$s published. %1$sView %2$s%3$s', 'upstream'),
400 $anchorTagOpening,
401 $postTypeLabelProject,
402 $anchorTagClosing
403 ),
404 7 => sprintf(
405 __('%2$s saved. %1$sView %2$s%3$s', 'upstream'),
406 $anchorTagOpening,
407 $postTypeLabelProject,
408 $anchorTagClosing
409 ),
410 8 => sprintf(
411 __('%2$s submitted. %1$sView %2$s%3$s', 'upstream'),
412 $anchorTagOpening,
413 $postTypeLabelProject,
414 $anchorTagClosing
415 ),
416 ];
417
418 $messages['client'] = [
419 1 => sprintf(__('%1$s updated.', 'upstream'), $postTypeLabelClient),
420 4 => sprintf(__('%1$s updated.', 'upstream'), $postTypeLabelClient),
421 6 => sprintf(__('%1$s published.', 'upstream'), $postTypeLabelClient),
422 7 => sprintf(__('%1$s saved.', 'upstream'), $postTypeLabelClient),
423 8 => sprintf(__('%1$s submitted.', 'upstream'), $postTypeLabelClient),
424 ];
425
426 return $messages;
427 }
428
429 add_filter('post_updated_messages', 'upstream_updated_messages');
430
431 /**
432 * Updated bulk messages
433 *
434 * @param array $bulk_messages Post updated messages
435 * @param array $bulk_counts Post counts
436 *
437 * @return array $bulk_messages New post updated messages
438 * @since 2.3
439 *
440 */
441 function upstream_bulk_updated_messages($bulk_messages, $bulk_counts)
442 {
443 $itemsUpdatedCount = (int)$bulk_counts['updated'];
444 $itemsLockedCount = (int)$bulk_counts['locked'];
445 $itemsDeletedCount = (int)$bulk_counts['deleted'];
446 $itemsTrashedCount = (int)$bulk_counts['trashed'];
447 $itemsUntrashedCount = (int)$bulk_counts['untrashed'];
448
449 $postTypeClientLabelSingular = upstream_client_label();
450 $postTypeClientLabelPlural = upstream_client_label_plural();
451
452 $postTypeProjectLabelSingular = upstream_project_label();
453 $postTypeProjectLabelPlural = upstream_project_label_plural();
454
455 $bulk_messages['client'] = [
456 'updated' => sprintf(
457 _n('%1$s %2$s updated.', '%1$s %3$s updated.', $itemsUpdatedCount, 'upstream'),
458 $itemsUpdatedCount,
459 $postTypeClientLabelSingular,
460 $postTypeClientLabelPlural
461 ),
462 'locked' => sprintf(
463 _n(
464 '%1$s %2$s not updated, somebody is editing it.',
465 '%1$s %3$s not updated, somebody is editing them.',
466 $itemsLockedCount,
467 'upstream'
468 ),
469 $itemsLockedCount,
470 $postTypeClientLabelSingular,
471 $postTypeClientLabelPlural
472 ),
473 'deleted' => sprintf(
474 _n(
475 '%1$s %2$s permanently deleted.',
476 '%1$s %3$s permanently deleted.',
477 $itemsDeletedCount,
478 'upstream'
479 ),
480 $itemsDeletedCount,
481 $postTypeClientLabelSingular,
482 $postTypeClientLabelPlural
483 ),
484 'trashed' => sprintf(
485 _n(
486 '%1$s %2$s moved to the Trash.',
487 '%1$s %3$s moved to the Trash.',
488 $itemsTrashedCount,
489 'upstream'
490 ),
491 $itemsTrashedCount,
492 $postTypeClientLabelSingular,
493 $postTypeClientLabelPlural
494 ),
495 'untrashed' => sprintf(
496 _n(
497 '%1$s %2$s restored from the Trash.',
498 '%1$s %3$s restored from the Trash.',
499 $itemsUntrashedCount,
500 'upstream'
501 ),
502 $itemsUntrashedCount,
503 $postTypeClientLabelSingular,
504 $postTypeClientLabelPlural
505 ),
506 ];
507
508 $bulk_messages['project'] = [
509 'updated' => sprintf(
510 _n('%1$s %2$s updated.', '%1$s %3$s updated.', $itemsUpdatedCount, 'upstream'),
511 $itemsUpdatedCount,
512 $postTypeProjectLabelSingular,
513 $postTypeProjectLabelPlural
514 ),
515 'locked' => sprintf(
516 _n(
517 '%1$s %2$s not updated, somebody is editing it.',
518 '%1$s %3$s not updated, somebody is editing them.',
519 $itemsLockedCount,
520 'upstream'
521 ),
522 $itemsLockedCount,
523 $postTypeProjectLabelSingular,
524 $postTypeProjectLabelPlural
525 ),
526 'deleted' => sprintf(
527 _n(
528 '%1$s %2$s permanently deleted.',
529 '%1$s %3$s permanently deleted.',
530 $itemsDeletedCount,
531 'upstream'
532 ),
533 $itemsDeletedCount,
534 $postTypeProjectLabelSingular,
535 $postTypeProjectLabelPlural
536 ),
537 'trashed' => sprintf(
538 _n(
539 '%1$s %2$s moved to the Trash.',
540 '%1$s %3$s moved to the Trash.',
541 $itemsTrashedCount,
542 'upstream'
543 ),
544 $itemsTrashedCount,
545 $postTypeProjectLabelSingular,
546 $postTypeProjectLabelPlural
547 ),
548 'untrashed' => sprintf(
549 _n(
550 '%1$s %2$s restored from the Trash.',
551 '%1$s %3$s restored from the Trash.',
552 $itemsUntrashedCount,
553 'upstream'
554 ),
555 $itemsUntrashedCount,
556 $postTypeProjectLabelSingular,
557 $postTypeProjectLabelPlural
558 ),
559 ];
560
561 return $bulk_messages;
562 }
563
564 add_filter('bulk_post_updated_messages', 'upstream_bulk_updated_messages', 10, 2);
565
566 /**
567 * Display UpStream notices-errors near the top of admin pages.
568 *
569 * @since 1.9.0
570 */
571 function upstream_admin_notices_errors()
572 {
573 $errors = get_transient('upstream_errors');
574
575 if ( ! empty($errors)): ?>
576 <div class="notice notice-error is-dismissible">
577 <p>
578 <?php echo $errors; ?>
579 </p>
580 </div>
581 <?php
582 delete_transient('upstream_errors');
583 endif;
584 }
585
586 add_filter('admin_notices', 'upstream_admin_notices_errors');
587