Making WordPress.org


Ignore:
Timestamp:
01/15/2019 03:10:41 AM (8 years ago)
Author:
dd32
Message:

Support Forums: Prefix notifications from the Plugin/Theme forums with the plugin name.

For example: [WordPress.org] [Example Plugin Name] Example Topic Title.

Fixes #2016.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-term-subscription/inc/class-plugin.php

    r7560 r8081  
    1212        private $subscribers = array();
    1313
    14         public $taxonomy = false;
    15         public $labels   = array();
     14        public $taxonomy  = false;
     15        public $labels    = array();
     16        public $directory = false;
    1617
    1718        const META_KEY = '_bbp_term_subscription';
     
    1920        public function __construct( $args = array() ) {
    2021                $r = wp_parse_args( $args, array(
    21                         'taxonomy' => 'topic-tag',
    22                         'labels'   => array(
     22                        'taxonomy'  => 'topic-tag',
     23                        'directory' => false,
     24                        'labels'    => array(
    2325                                'subscribed_header'      => __( 'Subscribed Topic Tags', 'wporg-forums' ),
    2426                                'subscribed_user_notice' => __( 'You are not currently subscribed to any topic tags.', 'wporg-forums' ),
     
    2830                ) );
    2931
    30                 $this->taxonomy = $r['taxonomy'];
    31                 $this->labels   = $r['labels'];
     32                $this->taxonomy  = $r['taxonomy'];
     33                $this->labels    = $r['labels'];
     34                $this->directory = $r['directory'];
    3235
    3336                add_action( 'bbp_init', array( $this, 'bbp_init' ) );
     
    157160         * @param int $topic_author The topic author id
    158161         */
    159         public function notify_term_subscribers_of_new_topic( $topic_id, $forum_id,  $anonymous_data = false, $topic_author = 0 ) {
     162        public function notify_term_subscribers_of_new_topic( $topic_id, $forum_id, $anonymous_data = false, $topic_author = 0 ) {
    160163                $terms = get_the_terms( $topic_id, $this->taxonomy );
    161164                if ( ! $terms ) {
     
    185188                // Replace forum-specific messaging with term subscription messaging.
    186189                add_filter( 'bbp_forum_subscription_mail_message', array( $this, 'replace_forum_subscription_mail_message' ), 10, 4 );
     190                add_filter( 'bbp_forum_subscription_mail_title',   array( $this, 'replace_forum_subscription_mail_title' ), 10, 2 );
    187191
    188192                // Replace forum subscriber list with term subscribers, avoiding duplicates.
     
    193197
    194198                // Remove filters.
    195                 remove_filter( 'bbp_forum_subscription_user_ids', array( $this, 'add_term_subscribers_to_forum' ) );
     199                remove_filter( 'bbp_forum_subscription_user_ids',     array( $this, 'add_term_subscribers_to_forum' ) );
    196200                remove_filter( 'bbp_forum_subscription_mail_message', array( $this, 'replace_forum_subscription_mail_message' ), 10 );
     201                remove_filter( 'bbp_forum_subscription_mail_title',   array( $this, 'replace_forum_subscription_mail_title' ) );
     202
    197203        }
    198204
     
    236242                        $topic_content,
    237243                        $topic_url,
    238                         $this->labels['receipt']
     244                        // String may not have placeholders, ie. in the case of tags.
     245                        sprintf( $this->labels['receipt'], $this->directory ? $this->directory->title() : '' )
    239246                );
    240247
    241248                return $message;
     249        }
     250
     251        /**
     252         * Replace the forum subscription subject/title with term-specific messaging.
     253         *
     254         * @param string $title The current title
     255         * @param int $topic_id The topic id
     256         */
     257        public function replace_forum_subscription_mail_title( $title, $topic_id ) {
     258                if ( $this->directory && $this->directory->title() ) {
     259                        $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     260                        $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) );
     261
     262                        // [WordPress.org] [Plugin Name] This is my threads
     263                        $title = sprintf( '[%s] [%s] %s', $blog_name, $this->directory->title(), $topic_title );
     264                }
     265
     266                return $title;
    242267        }
    243268
     
    281306                // Replace topic-specific messaging with term subscription messaging.
    282307                add_filter( 'bbp_subscription_mail_message', array( $this, 'replace_topic_subscription_mail_message' ), 10, 3 );
     308                add_filter( 'bbp_subscription_mail_title',   array( $this, 'replace_topic_subscription_mail_title' ), 10, 3 );
    283309
    284310                // Replace forum subscriber list with term subscribers, avoiding duplicates.
     
    290316                // Remove filters.
    291317                remove_filter( 'bbp_topic_subscription_user_ids', array( $this, 'add_term_subscribers_to_topic' ) );
    292                 remove_filter( 'bbp_subscription_mail_message', array( $this, 'replace_topic_subscription_mail_message' ), 10 );
     318                remove_filter( 'bbp_subscription_mail_message',   array( $this, 'replace_topic_subscription_mail_message' ) );
     319                remove_filter( 'bbp_subscription_mail_title',     array( $this, 'replace_topic_subscription_mail_title' ) );
    293320        }
    294321
     
    331358                        $reply_content,
    332359                        $reply_url,
    333                         $this->labels['receipt']
     360                        // String may not have placeholders, ie. in the case of tags.
     361                        sprintf( $this->labels['receipt'], $this->directory ? $this->directory->title() : '' )
    334362                );
    335363
    336364                return $message;
     365        }
     366
     367        /**
     368         * Replace the topic subscription subject/title with term-specific messaging.
     369         *
     370         * @param string $title    The current title
     371         * @param int    $reply_id The reply id
     372         * @param int    $topic_id The topic id
     373         */
     374        public function replace_topic_subscription_mail_title( $title, $reply_id, $topic_id ) {
     375                if ( $this->directory && $this->directory->title() ) {
     376                        $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     377                        $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) );
     378
     379                        // [WordPress.org] [Plugin Name] This is my threads
     380                        $title = sprintf( '[%s] [%s] %s', $blog_name, $this->directory->title(), $topic_title );
     381                }
     382
     383                return $title;
    337384        }
    338385
Note: See TracChangeset for help on using the changeset viewer.