Search code examples
buddypress

Add my-events link to buddypress admin bar?


In the Buddypress site I'm working on, I was asked to add a direct link to "my-events" to the admin bar, as it will be the feature used most often by this site's admin. What is the correct way to get the link to this page? I think I'm looking for something like this, but it didn't work:

 get_permalink( get_page_by_path( 'events/my-events' ) );

Solution

  • A direct link to my-events for who ? The admin? The displayed user ?

    This should add an admin link for the displayed user - or at least get you started. Put it in plugins/bp-custom.php

    function add_my_events_link() { 
        global $bp;
        if ( !is_super_admin() || bp_is_my_profile() || !$bp->displayed_user->id )
            return false;
    ?>
        <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'events/my-events/', 'my-events' ) ?>" class="confirm"><?php printf( __( "My Events for ", 'buddypress' ), esc_attr( $bp->displayed_user->fullname ) ) ?></a></li>
    <?php
    }
    add_action( 'bp_adminbar_menus', 'add_my_events_link', 20 );