-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbpress-add-member-usernames.php
56 lines (47 loc) · 2.15 KB
/
bbpress-add-member-usernames.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/*
Plugin Name: bbPress/BuddyBoss: Add Member Usernames
Description: Append @user_nicename to the author name on forum posts
Version: 1.0.4
Author: The team at PIE
Author URI: http://pie.co.de
License: GPL3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
*/
/* PIE\BBPressAddMemberUsernames is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or any later version.
PIE\BBPressAddMemberUsernames is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with PIE\BBPressAddMemberUsernames. If not, see https://www.gnu.org/licenses/gpl-3.0.en.html */
namespace PIE\BBPressAddMemberUsernames;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Load Composer autoloader
*/
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
$update_checker = PucFactory::buildUpdateChecker(
'https://pie.github.io/bbpress-add-member-usernames/update.json',
__FILE__,
'bbpress-add-member-usernames'
);
/**
* Add the user's @name to the author role on forum posts
*
* @param string $author_role HTML markup for the author role
* @param array $args array of arguments for display
*
* @return string $author_role
*/
function add_username_to_forum_posts( $author_role, $args ) {
if ( ! function_exists( 'bbp_get_reply_author_id' ) || ! function_exists( 'bbp_get_reply_id' ) ) {
return $author_role;
}
$user_id = \bbp_get_reply_author_id( \bbp_get_reply_id( $args['reply_id'] ) );
if ( $user_id ) {
$user = get_user_by( 'id', $user_id );
$author_role = '<span class="user-nicename">@' . esc_html( $user->user_nicename ) . '</span>' . $author_role;
}
return $author_role;
}
add_filter( 'bbp_get_reply_author_role', __NAMESPACE__ . '\add_username_to_forum_posts', 10, 2 );