| 1 | <?php |
| 2 | /** |
| 3 | * BuddyPress Activity Toolbar. |
| 4 | * |
| 5 | * Handles the activity functions related to the WordPress Toolbar. |
| 6 | * |
| 7 | * @package BuddyPress |
| 8 | * @subpackage Activity |
| 9 | */ |
| 10 | |
| 11 | // Exit if accessed directly. |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | /** |
| 15 | * Add the Activity top-level menu link when viewing single activity item. |
| 16 | * |
| 17 | * @since 2.4.0 |
| 18 | * |
| 19 | * @return false|null False if not on a single activity item page, or if user does not have |
| 20 | * access to editing functionality. |
| 21 | */ |
| 22 | function bp_activity_admin_menu() { |
| 23 | global $wp_admin_bar; |
| 24 | $bp = buddypress(); |
| 25 | |
| 26 | // Only show if viewing a group |
| 27 | if ( ! bp_is_single_activity() ) { |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | // Only show this menu to super admins |
| 32 | if ( ! bp_current_user_can( 'bp_moderate' ) ) { |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | // Unique ID for the 'Edit Activity' menu |
| 37 | $bp->activity_admin_menu_id = 'activity-admin'; |
| 38 | |
| 39 | // Add the top-level Group Admin button |
| 40 | $wp_admin_bar->add_menu( array( |
| 41 | 'id' => $bp->activity_admin_menu_id, |
| 42 | 'title' => __( 'Edit Activity', 'buddypress' ), |
| 43 | 'href' => add_query_arg( array( 'page' => 'bp-activity', 'aid' => bp_current_action(), 'action' => 'edit' ), bp_get_admin_url( 'admin.php' ) ) |
| 44 | ) ); |
| 45 | |
| 46 | return; |
| 47 | } |
| 48 | add_action( 'admin_bar_menu', 'bp_activity_admin_menu', 99 ); |