Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom filters should execute only on custom page


  • mayschje
    Participant

    @mayschje

    Hi guys,

    at first thanks for doing this great job by providing BuddyPress, I really love it.

    I have one question, maybe I missed an important part of understanding the firing of hooks.

    I set up a custom members directory by creating a page template and adding some custom actions (e. g. bf_before_directory_members, bp_pre_user_query, etc.). Everything works like a charm :-).

    The problem is I want the members page coming initially with BuddyPress also enabled, but without firing the hooks I added for the custom members directory. Now the custom filters are being also applied on this page which I want to prevent. I don’t know how to solve this. I tried it out by adding conditions e. g. if ($page_id == $page_id_custom_member_page), but the page id is not available in all filters.

    Can anybody help me out with this? This would be great.

    Thanks in advance.

    🙂

Viewing 4 replies - 1 through 4 (of 4 total)

  • shanebp
    Moderator

    @shanebp

    How are you loading your page template?
    Have you tried checking the page title?


    mayschje
    Participant

    @mayschje

    Hi shanebp,

    thanks for your reply.

    How are you loading your page template?

    I created the template by copying and pasting the code of members-loop.php and some of index.php (directory /bp-templates/bp-legacy/buddypress/members) and adapting it for my custom needs. Then I created an empty page in the backend and assigned the template to the page by using the drop-down-menu in the backend. I did not thought that there is something more to do to load the template as it – in principal – works as expected (except the issue that hooks are fired on all member sites now which I want to prevent).

    Have you tried checking the page title

    Yes, checking the page title also failed as the title is not available in all hooks (same as trying it out with page id).

    🙂 mayschje


    shanebp
    Moderator

    @shanebp

    In your filter functions, why not check for page_id or title – if not available, then just return.

    Without seeing the code, we cannot tell why your custom filters are being called on the default Members Directory page.

    If you want to share the code – please do not post it here.
    Instead, create a gist and share the link to that gist.


    mayschje
    Participant

    @mayschje

    In your filter functions, why not check for page_id or title – if not available, then just return

    Well, ask the WP/BP page lifecycle 😉 Making a hook dependent on a variable that in some stages of the page lifecycle does not exist leads to that some hooks are never fired (e. g. bp_members_directory_order_options or bp_pre_user_query, etc.).

    Thanks again for your replies and the offer to help out with the code. I solved the issue yesterday by implementing the custom page independent from BuddyPress as it was a faster, cleaner and more reliable solution.

    🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar