Opened 6 years ago
Closed 6 years ago
#7847 closed defect (bug) (fixed)
bp_after_message_content hook not working with BP Nouveau
Reported by: | pareshradadiya | Owned by: | imath |
---|---|---|---|
Milestone: | 3.1.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Messages | Keywords: | has-patch commit |
Cc: |
Description
bp_after_message_content hook does not work when BP Nouveau is active.
I use bp_after_message_content
to display some custom stuff after each messages.
So when BP Nouveau is active, my callback function hooked into bp_after_message_content
never get call.
I have done something like this:
add_action( 'bp_after_message_content', 'test_message_meta_display' ) ); function test_message_meta_display() { $message_id = (int) bp_get_the_thread_message_id(); $meta = bp_messages_get_meta( $message_id, 'message_meta' ); ob_start(); // ..some more custom code $content = ob_get_contents(); ob_end_clean(); echo str_replace("\n","",$content); }
Attachments (3)
Change History (16)
#1
@
6 years ago
- Component changed from Core to Messages
- Milestone changed from Awaiting Review to 3.0.1
#2
@
6 years ago
Which is going to be tricky because we'll have to make sure however those templates are loaded in Javascript, that the message content filter is run in the AJAX callback(?).
#3
@
6 years ago
I thought this https://buddypress.trac.wordpress.org/browser/trunk/src/bp-templates/bp-nouveau/buddypress/common/js-templates/messages/index.php#L279 was handling this part. I’ll look at the function to understand what’s going wrong. I think the hook is fired into the JS template. So it’s an approach a bit different, I’ll add an example with messages meta.
#4
@
6 years ago
After a deeper look, i confirm bp_after_message_content
is fired. But it's unusable the way @pareshradadiya tries to use it, because data is available in JavaScript and not in PHP, see screenshot below:
What needs to be done imho:
- improve the Ajax functions that are fetching the messages data :
- by adding a filter to allow plugins to get meta data
- or by populating a metas property with all the meta for the message using
bp_messages_get_meta( bp_get_the_thread_message_id() )
- Add some documentation about how to use it to display the meta value into the UI.
I doubt 1.a. can be done for the 3.0.1 maintenance release, 1.b. is easier but might cause some performance troubles.
#5
@
6 years ago
I confirm bp_after_message_content
callback function get called. I was returning output instead of echoing it on a page in my old test. However, I cannot fetch message meta inside from callback like this.
$message_id = (int) bp_get_the_thread_message_id();
$meta = bp_messages_get_meta( $message_id, 'message_meta' );
#7
@
6 years ago
- Keywords has-patch reporter-feedback added
I chose a 3rd approach. The idea is to change as fiew as possible for plugin authors. I think the new Messages UI is a perfect candidate for the BP Rest API, so untill we can count on it and why not deprecate some actions in favor of this API, i think we should use the existing actions and catch their content using the buffer. As this is done within a messages loop, data is accessible via PHP and it doesn't change anything for plugin authors. Here's a screenshot showing injected content using bp_before_message_content
& bp_after_message_content
:
@pareshradadiya can you test 7847.patch and tell me if it's fixing the issue for you ?
#10
@
6 years ago
- Keywords commit added; reporter-feedback removed
Thanks a lot for your feedback 👍 I'll commit it asap.
Another missing action - a similar problem to #7837