[Resolved] Element hook issue

Home Forums Support Element hook issue

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1228980
    Carsten

    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’

    View post on imgur.com

    2.Element

    Hello

    <?php bp_send_private_message_button(); ?>

    In custom hook: bp_after_member_body

    Result:

    ‘Hello’

    Send Message Button

    View post on imgur.com

    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

    #1229162
    David
    Staff
    Customer Support

    Hi there,

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

    #1229580
    Carsten

    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.

    View post on imgur.com

    #1229687
    Carsten

    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?

    #1229707
    David
    Staff
    Customer Support

    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.

    #1229739
    Carsten

    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

    #1229794
    David
    Staff
    Customer Support

    You’re welcome – hope you find the answer.

    #1229837
    Carsten

    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 ?

    #1229840
    David
    Staff
    Customer Support

    Thats correct:

    eg. <?php the_function(); ?>

    #1229966
    Carsten

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

    #1229982
    David
    Staff
    Customer Support

    It doesn’t – Hook Element only provides the add_action

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.