- This topic has 10 replies, 2 voices, and was last updated 4 years ago by David.
-
AuthorPosts
-
April 6, 2020 at 12:33 pm #1228980Carsten
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’2.Element
Hello
<?php bp_send_private_message_button(); ?>
In custom hook: bp_after_member_body
Result:
‘Hello’
Send Message Button
So
bp_send_private_message_button();
is the correct function, andbp_after_member_body
is the correct hook, but only ‘Hello’ is displayed in thebp_after_member_body
hookSo the hook can display text but not a function. Execute PHP is activated. What am I doing wrong here?
Regards
CarstenApril 6, 2020 at 4:34 pm #1229162DavidStaffCustomer SupportHi there,
does the Button display in
bp_after_directory_members_list
if you remove the 2nd hook ?April 7, 2020 at 3:18 am #1229580CarstenNo 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.
April 7, 2020 at 5:01 am #1229687CarstenIt’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?
April 7, 2020 at 5:22 am #1229707DavidStaffCustomer SupportHook 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.
April 7, 2020 at 6:02 am #1229739CarstenThanks 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
April 7, 2020 at 7:09 am #1229794DavidStaffCustomer SupportYou’re welcome – hope you find the answer.
April 7, 2020 at 7:43 am #1229837CarstenJust to understand this right, I only have to put a function in a tag like this
<?php ;?> in an element, no need to addadd_action
first ?April 7, 2020 at 7:46 am #1229840DavidStaffCustomer SupportThats correct:
eg.
<?php the_function(); ?>
April 7, 2020 at 7:50 am #1229966CarstenThanks, how does the element then distinguish between an
add_action
and anadd_filter
function?April 7, 2020 at 8:06 am #1229982DavidStaffCustomer SupportIt doesn’t – Hook Element only provides the
add_action
-
AuthorPosts
- You must be logged in to reply to this topic.