bp-activity-adminbar.php 1.08 KB
Newer Older
lucha's avatar
lucha committed
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
<?php
/**
 * BuddyPress Activity Toolbar.
 *
 * Handles the activity functions related to the WordPress Toolbar.
 *
 * @package BuddyPress
 * @subpackage Activity
 */

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

/**
 * Add the Activity top-level menu link when viewing single activity item.
 *
 * @since 2.6.0
 *
 * @return null Null if user does not have access to editing functionality.
 */
function bp_activity_admin_menu() {
	global $wp_admin_bar;

	// Only show if viewing a single activity item.
	if ( ! bp_is_single_activity() ) {
		return;
	}

	// Only show this menu to super admins
	if ( ! bp_current_user_can( 'bp_moderate' ) ) {
		return;
	}

	$activity_edit_link = add_query_arg( array(
		'page' => 'bp-activity',
		'aid' => bp_current_action(),
		'action' => 'edit'
	), bp_get_admin_url( 'admin.php' ) );

	// Add the top-level Edit Activity button.
	$wp_admin_bar->add_menu( array(
		'id'    => 'activity-admin',
		'title' => __( 'Edit Activity', 'buddypress' ),
		'href'  => esc_url( $activity_edit_link ),
	) );
}
add_action( 'admin_bar_menu', 'bp_activity_admin_menu', 99 );