0

I'm looking to hook into a sidebar widget, this one in particular loads the members.

All I'm looking to do is add a link into the widget, I managed to get a result but it's not quite right. It doesn't load the original function, instead it replaces it.

Here's how I far I got:

function members_dir_link(){
echo '<a href="/members/">View Members</a>';
}
add_filter('bp_has_members','members_dir_link');
7
  • What exactly do you want to achieve? What widget are you using? I don't think you should output anything in bp_has_members filter - it's called many times, not only in this widget. – Krzysiek Dróżdż Jun 23 '13 at 11:24
  • Perhaps that's not the right function exactly, I'm trying to target the widget so I can insert static html without modifying the core code. – user1955643 Jun 23 '13 at 11:44
  • OK, but what widget exactly are you trying to modify? What is the name of this widget? – Krzysiek Dróżdż Jun 23 '13 at 11:47
  • It's the members widget, it displays all the users avatars. I'm not really modifying as such, I'm adding html code tot he existing output of this widget. – user1955643 Jun 23 '13 at 12:04
  • It's a buddypress widget, in case you didn't know that already.. – user1955643 Jun 23 '13 at 12:05
1

I don't think it can be done. I'm sorry, but this widget has no hooks in there. You can only use bp_has_members hook, but you shouldn't use it to echo anything, because it's used in many other places, so you may break some things doing it this way.

The only way I can see to achieve this (and it's not perfect), is to write your own widget based on this BP widget. To do that you should:

  1. Find the original widget's source code. (It's in bp-core/bp-core-widgets.php file)
  2. Copy it's code and place it in your themes function.php
  3. Rename it properly (take care of class name, and so on).
  4. Register your new widget with:

    add_action('widgets_init', create_function('', 'return register_widget("");') );

You can also try to inherit this new widget class from original BP widget class (you won't need to copy entire source code then).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.