Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom display of sitewide notices


  • chlab
    Participant

    @chlab

    When sending a sitewide notice, they automatically show up where <?php wp_footer(); ?> is called. In the temlate I’m working on, they’re supposed to show up in the sidebar though, which is done like so:

    <?php if ( bp_is_active( 'messages' ) ) : ?>
      <?php bp_message_get_notices(); ?>
    <?php endif; ?>

    This causes the notices to show up in both places however. So my question is this:
    how can I disable the messages from showing in the footer? I checked the code and saw they are registered as follows:

    add_action( 'wp_footer', array( $this, 'sitewide_notices' ), 9999 );

    Is there a way to hook into wp_footer and get rid of these messages or even a better way?

    Thanks!


    BuddyPress v 2.1.1
    WordPress v 3.9.1
    Link: I’m working on a local vagrant box

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

  • danbp
    Participant

    @danbp

    hi @chlab,

    if you read code documentation in /bp-legacy/buddypress-functions.php

    // Only hook the 'sitewide_notices' overlay if the Sitewide
    // Notices widget is not in use (to avoid duplicate content).
    if ( bp_is_active( 'messages' ) && ! is_active_widget( false, false, 'bp_messages_sitewide_notices_widget', true ) ) {
    add_action( 'wp_footer', array( $this, 'sitewide_notices' ), 9999 );
    }

    I guess you have to modify your custom code accordingly. ๐Ÿ˜‰


    @mercime
    Participant

    @mercime

    theyโ€™re supposed to show up in the sidebar though, which is done like so


    @chlab
    Curious why you’re not using the Sitewide Notices Widget instead?


    chlab
    Participant

    @chlab

    danbp: yeah I saw that comment but didn’t try the widget because I didn’t see it in the backend and I was too lazy to find out why I don’t have it ๐Ÿ™‚

    I’ll go try the widget and report back.
    Thanks.


    chlab
    Participant

    @chlab

    Ok so I activated the widget and it works! So thanks for that!

    However: the widget box shows in the sidebar even when the notice is closed. Is this normal? Is there a way to get the widget to disappear when it has nothing to show?


    chlab
    Participant

    @chlab

    I checked out the code and sadly, buddypress only seems to notice if there isn’t any notice to display while displaying them. I had to write a slightly modified version of the widget to get the desired functionality. For anyone who needs this too, feel free to use this: https://gist.github.com/chlab/ad608eafe2e1262140fb
    It’s no more than a copy of the regular widget which fetches the notices in an output buffer and aborts when there isn’t any content to display.

    We need to update the widget as we should simply bail out if notice closed and not display markup if possible, also I want to add a filter to return false so the option is available to cancel the footer rendering even if widget not in use.


    chlab
    Participant

    @chlab

    That would be perfect!


    thunksalot
    Participant

    @thunksalot

    Chlab, this sounds like just what I need. But, how do I install it? I tried uploading it into my contents/plugins folder (both within a subdirectory and just as a file), but it never shows up in the WP Plugins interface, so I can’t activate it.


    chlab
    Participant

    @chlab

    Hey thunksalot
    You have to upload widgets to your theme directory, never modify the contents of a plugin directory.
    So e.g. add a “widgets” directory in your theme directory and upload it to there. Then you should see a “Smart BuddyPress Sitewide Notices” widget in the WordPress backend. Activate that and disable the default one.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Custom display of sitewide notices’ is closed to new replies.
Skip to toolbar