@@ -8,9 +8,9 @@ class Plugin {
88 * @todo AJAXify subscription action.
99 */
1010
11- public $ taxonomy = false ;
12- public $ labels = array () ;
13- public $ directory = false ;
11+ public $ taxonomy = false ;
12+ public $ labels_cb = false ;
13+ public $ directory = false ;
1414
1515 protected $ term = false ;
1616 protected $ subscribers = array ();
@@ -36,17 +36,12 @@ public function __construct( $args = array() ) {
3636 $ r = wp_parse_args ( $ args , array (
3737 'taxonomy ' => 'topic-tag ' ,
3838 'directory ' => false ,
39- 'labels ' => array (
40- 'subscribed_header ' => __ ( 'Subscribed Topic Tags ' , 'wporg-forums ' ),
41- 'subscribed_user_notice ' => __ ( 'You are not currently subscribed to any topic tags. ' , 'wporg-forums ' ),
42- 'subscribed_anon_notice ' => __ ( 'This user is not currently subscribed to any topic tags. ' , 'wporg-forums ' ),
43- 'receipt ' => __ ( "You are receiving this email because you are subscribed to the %s tag. " , 'wporg-forums ' ),
44- ),
39+ 'labels ' => false ,
4540 ) );
4641
47- $ this ->taxonomy = $ r ['taxonomy ' ];
48- $ this ->labels = $ r ['labels ' ];
49- $ this ->directory = $ r ['directory ' ];
42+ $ this ->taxonomy = $ r ['taxonomy ' ];
43+ $ this ->labels_cb = $ r ['labels ' ];
44+ $ this ->directory = $ r ['directory ' ];
5045
5146 // If no taxonomy was provided, there's nothing we can do.
5247 if ( ! $ this ->taxonomy ) {
@@ -56,6 +51,31 @@ public function __construct( $args = array() ) {
5651 add_action ( 'bbp_init ' , array ( $ this , 'bbp_init ' ) );
5752 }
5853
54+ /**
55+ * Get the default translated labels.
56+ *
57+ * @return array
58+ */
59+ public function get_default_labels () {
60+ return array (
61+ 'subscribed_header ' => __ ( 'Subscribed Topic Tags ' , 'wporg-forums ' ),
62+ 'subscribed_user_notice ' => __ ( 'You are not currently subscribed to any topic tags. ' , 'wporg-forums ' ),
63+ 'subscribed_anon_notice ' => __ ( 'This user is not currently subscribed to any topic tags. ' , 'wporg-forums ' ),
64+ 'receipt ' => __ ( "You are receiving this email because you are subscribed to the %s tag. " , 'wporg-forums ' ),
65+ );
66+ }
67+
68+ /**
69+ * Get labels, merging any custom labels with the defaults.
70+ *
71+ * @return array
72+ */
73+ public function get_labels () {
74+ $ labels = $ this ->labels_cb ? call_user_func ( $ this ->labels_cb ) : array ();
75+
76+ return wp_parse_args ( $ labels , $ this ->get_default_labels () );
77+ }
78+
5979 /**
6080 * Initialize the plugin.
6181 */
@@ -369,7 +389,7 @@ public function replace_forum_subscription_mail_message( $message, $topic_id, $f
369389 $ topic_content ,
370390 $ topic_url ,
371391 sprintf (
372- $ this ->labels ['receipt ' ],
392+ $ this ->get_labels () ['receipt ' ],
373393 $ this ->get_current_term ()->name
374394 )
375395 );
@@ -509,7 +529,7 @@ public function replace_topic_subscription_mail_message( $message, $reply_id, $t
509529 $ reply_content ,
510530 $ reply_url ,
511531 sprintf (
512- $ this ->labels ['receipt ' ],
532+ $ this ->get_labels () ['receipt ' ],
513533 $ this ->get_current_term ()->name
514534 )
515535 );
@@ -619,7 +639,7 @@ public function user_subscriptions() {
619639 ?>
620640
621641 <div class="bbp-user-subscriptions">
622- <h2 class="entry-title"><?php echo esc_html ( $ this ->labels ['subscribed_header ' ] ); ?> </h2>
642+ <h2 class="entry-title"><?php echo esc_html ( $ this ->get_labels () ['subscribed_header ' ] ); ?> </h2>
623643 <div class="bbp-user-section">
624644 <?php
625645 if ( $ terms ) {
@@ -633,9 +653,9 @@ public function user_subscriptions() {
633653 echo "</p> \n" ;
634654 } else {
635655 if ( bbp_get_user_id () == get_current_user_id () ) {
636- echo '<p> ' . esc_html ( $ this ->labels ['subscribed_user_notice ' ] ) . '</p> ' ;
656+ echo '<p> ' . esc_html ( $ this ->get_labels () ['subscribed_user_notice ' ] ) . '</p> ' ;
637657 } else {
638- echo '<p> ' . esc_html ( $ this ->labels ['subscribed_anon_notice ' ] ) . '</p> ' ;
658+ echo '<p> ' . esc_html ( $ this ->get_labels () ['subscribed_anon_notice ' ] ) . '</p> ' ;
639659 }
640660 }
641661 ?>
0 commit comments