PluginProbe
UpStream: a Project Management Plugin for WordPress / 2.1.0
UpStream: a Project Management Plugin for WordPress v2.1.0
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 2.1.0, at includes/up-labels.php

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