Site logo

Archived topic

Element hook issue

10 replies · Started by Carsten on April 6, 2020

Viewing posts 1–11 of 11

Hi there, I'm having an issue with Hooks in Elements.

I have created two Hook Elements with the same function and a Hello

1. Element

Hello

<?php bp_send_private_message_button(); ?>

In custom hook: bp_after_directory_members_list

Result:
'Hello'
https://imgur.com/P8e5ydr

2.Element

Hello

<?php bp_send_private_message_button(); ?>

In custom hook: bp_after_member_body

Result:

'Hello'

Send Message Button

https://imgur.com/VUzB1Sf

So bp_send_private_message_button(); is the correct function, and bp_after_member_body is the correct hook, but only 'Hello' is displayed in the bp_after_member_body hook

So the hook can display text but not a function. Execute PHP is activated. What am I doing wrong here?

Regards
Carsten

Hi there,

does the Button display in bp_after_directory_members_list if you remove the 2nd hook ?

No it does not, not even if I change the hook to after_header, bp_send_private_message_button(); or any other function I have tried, does not display.

The menu then becomes inaccessible, and the page has no content.

https://imgur.com/Y6X6Ouz

It's like the element in som cases does not accept php functions.

Can you supply me with a function which should work in an Element, which I can use as reference when I test this further?

Hook Elements do not discriminate as to what can or cannot be executed from within them. It's just an interface that gives you easy access to adding 'stuff' inside a Hook without having to write code:

https://developer.wordpress.org/plugins/hooks/actions/

If you add any plain HTML like your Hello and it displays then this means the Hook exists in the template that is being used at the Display Location you set.

Now if you add a function to that working Hook and it doesn't display or breaks something then it means that function was not built to be called from that hook.

This maybe for many reasons - some simple ones are:
The Function cannot be called from with a Loop.
There is another function being called from that hook that doesn't expect to encounter your code.

The Simply Show Hooks plugin albeit out of date still works and will show you what hooks are present and what functions are being called from them... it might give you some insight to why its not working.

Thanks for the tip for the Simply Show hooks plugin. So far I have been using hookr.io and codex.buddypress.org to find functions and hooks, but I will check this plugin.

I'm aware that there can be many reasons for the element not working, the combination of functions and hooks can be complex, so I have to continue to test the different combinations until it works.

Thanks again

You're welcome - hope you find the answer.

Just to understand this right, I only have to put a function in a tag like this
<?php ;?> in an element, no need to add add_action first ?

Thats correct:

eg. <?php the_function(); ?>

Thanks, how does the element then distinguish between an add_action and an add_filter function?

It doesn't - Hook Element only provides the add_action

This archived topic is closed to new replies.