Making WordPress.org

Changeset 14760


Ignore:
Timestamp:
03/26/2026 05:47:24 AM (7 days ago)
Author:
dd32
Message:

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.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-support-compat.php

    r13772 r14760  
    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        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-term-subscription/inc/class-plugin.php

    r14198 r14760  
    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;
     
    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.
     
    5550
    5651        add_action( 'bbp_init', array( $this, 'bbp_init' ) );
     52    }
     53
     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() );
    5777    }
    5878
     
    370390            $topic_url,
    371391            sprintf(
    372                 $this->labels['receipt'],
     392                $this->get_labels()['receipt'],
    373393                $this->get_current_term()->name
    374394            )
     
    510530            $reply_url,
    511531            sprintf(
    512                 $this->labels['receipt'],
     532                $this->get_labels()['receipt'],
    513533                $this->get_current_term()->name
    514534            )
     
    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
     
    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            }
Note: See TracChangeset for help on using the changeset viewer.