Skip to content

Commit 723baed

Browse files
committed
Support Forums: Fix PHP notices for early translation loading and missing block pattern slugs.
Defer translation loading in Term_Subscription\Plugin by accepting a labels callback instead of pre-translated strings. Labels are now resolved at time of use, avoiding _load_textdomain_just_in_time warnings introduced in WordPress 6.7. git-svn-id: https://meta.svn.wordpress.org/sites/trunk@14760 74240141-8908-4e6f-9713-ba540dce6ec7
1 parent 9e5a347 commit 723baed

2 files changed

Lines changed: 56 additions & 31 deletions

File tree

wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-support-compat.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -356,27 +356,32 @@ public function is_enabled_on_forum( $retval, $forum_id = 0 ) {
356356
*/
357357
public function load_compat_subscriptions() {
358358
if ( class_exists( 'WordPressdotorg\Forums\Term_Subscription\Plugin' ) ) {
359+
// Labels use callbacks to defer translation loading until bbp_init.
359360
Plugin::get_instance()->plugin_subscriptions = new Term_Subscription\Plugin( array(
360361
'taxonomy' => 'topic-plugin',
361362
'directory' => Plugin::get_instance()->plugins,
362-
'labels' => array(
363-
'subscribed_header' => __( 'Subscribed Plugins', 'wporg-forums' ),
364-
'subscribed_user_notice' => __( 'You are not currently subscribed to any plugins.', 'wporg-forums' ),
365-
'subscribed_anon_notice' => __( 'This user is not currently subscribed to any plugins.', 'wporg-forums' ),
366-
/* translators: %s: Plugin Name. */
367-
'receipt' => __( 'You are receiving this email because you are subscribed to the %s plugin.', 'wporg-forums' ),
368-
),
363+
'labels' => function() {
364+
return array(
365+
'subscribed_header' => __( 'Subscribed Plugins', 'wporg-forums' ),
366+
'subscribed_user_notice' => __( 'You are not currently subscribed to any plugins.', 'wporg-forums' ),
367+
'subscribed_anon_notice' => __( 'This user is not currently subscribed to any plugins.', 'wporg-forums' ),
368+
/* translators: %s: Plugin Name. */
369+
'receipt' => __( 'You are receiving this email because you are subscribed to the %s plugin.', 'wporg-forums' ),
370+
);
371+
},
369372
) );
370373
Plugin::get_instance()->theme_subscriptions = new Term_Subscription\Plugin( array(
371374
'taxonomy' => 'topic-theme',
372375
'directory' => Plugin::get_instance()->themes,
373-
'labels' => array(
374-
'subscribed_header' => __( 'Subscribed Themes', 'wporg-forums' ),
375-
'subscribed_user_notice' => __( 'You are not currently subscribed to any themes.', 'wporg-forums' ),
376-
'subscribed_anon_notice' => __( 'This user is not currently subscribed to any themes.', 'wporg-forums' ),
377-
/* translators: %s: Theme Name. */
378-
'receipt' => __( 'You are receiving this email because you are subscribed to the %s theme.', 'wporg-forums' ),
379-
),
376+
'labels' => function() {
377+
return array(
378+
'subscribed_header' => __( 'Subscribed Themes', 'wporg-forums' ),
379+
'subscribed_user_notice' => __( 'You are not currently subscribed to any themes.', 'wporg-forums' ),
380+
'subscribed_anon_notice' => __( 'This user is not currently subscribed to any themes.', 'wporg-forums' ),
381+
/* translators: %s: Theme Name. */
382+
'receipt' => __( 'You are receiving this email because you are subscribed to the %s theme.', 'wporg-forums' ),
383+
);
384+
},
380385
) );
381386
}
382387
}

wordpress.org/public_html/wp-content/plugins/wporg-bbp-term-subscription/inc/class-plugin.php

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)