Making WordPress.org


Ignore:
Timestamp:
10/14/2019 07:40:48 AM (5 years ago)
Author:
dd32
Message:

Support Forums: Prefix the Plugin/Theme name to the notification titles in WordPress.org Notifications.

Fixes #2729.

File:
1 edited

Legend:

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

    r8081 r9178  
    5555            // Exclude certain forums from forum queries.
    5656            add_action( 'pre_get_posts', array( $this, 'exclude_hidden_forums' ), 1 );
     57
     58            // Prefix the theme/plugin to the title for WordPress.org notifications.
     59            add_filter( 'wporg_notifications_info', array( $this, 'wporg_notifications_info' ) );
    5760
    5861            $this->loaded = true;
     
    515518
    516519    /**
     520     * Filter notifications data to prefix the name of the Plugin/Theme to the title.
     521     */
     522    public function wporg_notifications_info( $data ) {
     523        // Bail if this notification isn't a forum topic/reply
     524        if ( $data['type'] != 'forum_topic' && $data['type'] != 'forum_topic_reply' ) {
     525            return $data;
     526        }
     527
     528        $topic_id = $data['topic_id'];
     529        $forum_id = bbp_get_topic_forum_id( $topic_id );
     530
     531        if ( $forum_id === Plugin::PLUGINS_FORUM_ID ) {
     532            $type = 'plugin';
     533        } elseif ( $forum_id === Plugin::THEMES_FORUM_ID ) {
     534            $type = 'theme';
     535        } else {
     536            // Not in a Plugin/Theme forum.
     537            return $data;
     538        }
     539
     540        $slugs = wp_get_post_terms( $topic_id, 'topic-' . $type, array( 'fields' => 'slugs' ) );
     541        $obj   = $slugs ? Directory_Compat::get_object_by_slug_and_type( $slugs[0], $type ) : false;
     542
     543        if ( ! $obj ) {
     544            return $data;
     545        }
     546
     547        // Prefix the Plugin/Theme to the notification title.
     548        $data['title'] = sprintf(
     549            '[%s] %s',
     550            $obj->post_title,
     551            $data['title']
     552        );
     553
     554        return $data;
     555    }
     556
     557    /**
    517558     * In bbPress 1, topics could be referenced using their topic id, and many
    518559     * are indexed/linked via this rather than their pretty permalink. The
Note: See TracChangeset for help on using the changeset viewer.