[Resolved] Remove 'Public Message' button in child theme
-
Hi,
I have a child theme based on the bp-default theme. In this theme I wish to remove the Public Message button shown next to the avatar when viewing another user’s profile.
In bp-default/functions php the button is added by
`add_action( ‘bp_member_header_actions’, ‘bp_send_public_message_button’, 20 );`In child-theme/functions php I tried to remove the button by
`remove_action( ‘bp_member_header_actions’, ‘bp_send_public_message_button’, 20 );`This did not work.
I wonder if the functions php in the child-theme is processed before the functions php in the bp-default theme?
If so, then how do I remove the button through the child-theme (to ensure that the modification is preserved across updates).
Any ideas are most welcome!
Cheers
Mort3n
-
Resolved.
Indeed, the child-theme functions php is called before the parent-theme functions php
https://codex.wordpress.org/Child_Themes#Using_functions.phpThe function `bp_dtheme_setup()` where the button is added in bp-default is made pluggable as I’ve just learned that it should be 😉
Therefore, the solution is to override the function in child-theme functions php.
That is, copy the function `bp_dtheme_setup()` from bp-default/functions php to child-theme/functions php and comment out the lines
`
if ( bp_is_active( ‘activity’ ) )
add_action( ‘bp_member_header_actions’, ‘bp_send_public_message_button’, 20 );
`Hope it helps someone!
Cheers
Mort3nhi,
or you can also add this piece of code to plugins/bp-custom.php
`function remove_public_message_button() {
remove_filter( ‘bp_member_header_actions’,’bp_send_public_message_button’, 20);`}
add_action( ‘bp_member_header_actions’, ‘remove_public_message_button’ );https://codex.buddypress.org/developer/customizing/bp-custom-php/
use bp-custom for buddypress code. You preserve you edits if you decide to change or update a theme.
Hi,
Thanks for chiming in!
Good point about bp-custom, will use that instead.
Cheers
Mort3nHi guys
I have tried this code in bp-custom.php as follows but it is not working, am I doing something wrong?
<?php // Removing public message option function remove_public_message_button() { remove_filter( ‘bp_member_header_actions’,'bp_send_public_message_button', 20); } add_action( 'bp_member_header_actions', 'remove_public_message_button' ); ?>
@applegateian
Check the single quotes around bp_member_header_actions. They need to be changed to regular single quotes. If you copied and pasted the code above it would not be right. You can try this in between opening and closing php tags:// Removing public message option function remove_public_message_button() { remove_filter( 'bp_member_header_actions','bp_send_public_message_button', 20); } add_action( 'bp_member_header_actions', 'remove_public_message_button' );
OK thanks – that unfortunately hasn’t worked though 🙁
@applegateian
I tested it and it works as it should so maybe you need to give more info about your setup because something else is interfering with this function. It could be a plugin as well. Also, have you followed the procedures here in regards to theme compatibility:
https://codex.buddypress.org/developer/theme-development/a-quick-look-at-1-7-theme-compatibility/I tried doing all of that and none of it worked.
A super simple solution to removing the button is to use CSS:
#post-mention {display:none;}
Of course, use in a child theme.
This is an old thread!
Using CSS to remove objects in this sense is an incorrect, and unsafe use of CSS.
The filter does work as described in the original solution run from either bp-custom or functions files or disable messaging for a complete solution.
- The topic ‘[Resolved] Remove 'Public Message' button in child theme’ is closed to new replies.